Bug 1543782: Add test for the shortcut key which shows the suggest completion popup. r=pbro
☠☠ backed out by c5ad764d2835 ☠ ☠
authorDaisuke Akatsuka <daisuke@birchill.co.jp>
Fri, 30 Aug 2019 03:15:13 +0000
changeset 551308 d7b6b036d777c0d3290f5d923a987f2cefebff73
parent 551307 2081fd72fd28579d4f75e5faa43744fa6fc83808
child 551309 464a2ec59a588b659465e61c2e65e39046924e53
push id11865
push userbtara@mozilla.com
push dateMon, 02 Sep 2019 08:54:37 +0000
treeherdermozilla-beta@37f59c4671b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1543782
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1543782: Add test for the shortcut key which shows the suggest completion popup. r=pbro Differential Revision: https://phabricator.services.mozilla.com/D43723
devtools/client/inspector/rules/test/browser.ini
devtools/client/inspector/rules/test/browser_rules_completion-shortcut.js
--- a/devtools/client/inspector/rules/test/browser.ini
+++ b/devtools/client/inspector/rules/test/browser.ini
@@ -96,16 +96,17 @@ skip-if = (verify && debug && os == 'win
 [browser_rules_completion-existing-property_02.js]
 [browser_rules_completion-new-property_01.js]
 [browser_rules_completion-new-property_02.js]
 skip-if = (verify && !debug && os == 'win')
 [browser_rules_completion-new-property_03.js]
 [browser_rules_completion-new-property_04.js]
 [browser_rules_completion-new-property_multiline.js]
 [browser_rules_completion-on-empty.js]
+[browser_rules_completion-shortcut.js]
 [browser_rules_computed-lists_01.js]
 [browser_rules_computed-lists_02.js]
 [browser_rules_computed-lists_03.js]
 [browser_rules_completion-popup-hidden-after-navigation.js]
 [browser_rules_content_01.js]
 [browser_rules_content_02.js]
 [browser_rules_variables-in-pseudo-element_01.js]
 [browser_rules_variables-in-pseudo-element_02.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/inspector/rules/test/browser_rules_completion-shortcut.js
@@ -0,0 +1,71 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Tests the shortcut key for the suggest completion popup.
+
+const TEST_URI = "<h1 style='colo: lim'>Header</h1>";
+const TEST_SHORTCUTS = [
+  {
+    key: " ",
+    modifiers: { ctrlKey: true },
+  },
+  {
+    key: "VK_DOWN",
+    modifiers: {},
+  },
+];
+
+add_task(async function() {
+  for (const shortcut of TEST_SHORTCUTS) {
+    info(
+      "Start to test for the shortcut " +
+        `key: "${shortcut.key}" modifiers: ${Object.keys(shortcut.modifiers)}`
+    );
+
+    const tab = await addTab(
+      "data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)
+    );
+    const { inspector, view } = await openRuleView();
+
+    info("Selecting the test node");
+    await selectNode("h1", inspector);
+
+    const rule = getRuleViewRuleEditor(view, 0).rule;
+    const prop = rule.textProps[0];
+
+    info("Test with css property name field");
+    const nameEditor = await focusEditableField(view, prop.editor.nameSpan);
+    await testCompletion(shortcut, view, nameEditor, "color");
+
+    info("Test with css property value field");
+    const valueEditor = inplaceEditor(view.styleDocument.activeElement);
+    await testCompletion(shortcut, view, valueEditor, "lime");
+
+    await removeTab(tab);
+  }
+});
+
+async function testCompletion(shortcut, view, editor, expectedValue) {
+  const spanEl = editor.elt;
+
+  info("Move cursor to the end");
+  EventUtils.synthesizeKey("VK_RIGHT", {}, view.styleWindow);
+  await waitUntil(
+    () => editor.input.selectionStart === editor.input.selectionEnd
+  );
+
+  info("Check whether the popup opens after sending the shortcut key");
+  const onPopupOpened = once(view.popup, "popup-opened");
+  EventUtils.synthesizeKey(shortcut.key, shortcut.modifiers, view.styleWindow);
+  await onPopupOpened;
+  ok(view.popup.isOpen, "The popup opened correctly");
+
+  info("Commit the suggestion");
+  const onChanged = view.once("ruleview-changed");
+  const onPopupClosed = once(view.popup, "popup-closed");
+  EventUtils.synthesizeKey("VK_RETURN", {}, view.styleWindow);
+  await Promise.all([onChanged, onPopupClosed]);
+  is(spanEl.textContent, expectedValue, "The value is set correctly");
+}