Bug 1543782: Add test for the shortcut key which shows the suggest completion popup. r=pbro
authorDaisuke Akatsuka <daisuke@birchill.co.jp>
Mon, 02 Sep 2019 03:29:17 +0000
changeset 491089 90f33e9e1c48aa5b94b44d34d4249f1d2717015d
parent 491088 e1ba24ca37a496a3334b5f758e2c0f9404aca624
child 491090 6e9f2e7ef81929eca589179b5bd9d0b70dba0d24
push id94222
push userdakatsuka.birchill@mozilla.com
push dateMon, 02 Sep 2019 03:35:51 +0000
treeherderautoland@90f33e9e1c48 [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");
+}