Bug 1408919 - Rename and enable browser_webconsole_autocomplete_crossdomain_iframe.js; r=Honza.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Thu, 02 Nov 2017 14:24:45 +0100
changeset 443812 ab8cb0873ccb66992d3fa34d7290125c910aee08
parent 443811 a478fd716627ac9547b2783ea894fe4f877de84f
child 443813 8823f33351025e25a949160bc23bae9fba9aac5f
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1408919
milestone58.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 1408919 - Rename and enable browser_webconsole_autocomplete_crossdomain_iframe.js; r=Honza. This bug also renames the support file, and create a dedicated one for the child iframe. An helper method is created to only wait for a single message with given text in it, as well as returning an array of matched message in waitForMessages (we were returning the result of setting the listener, which I doubt is useful for any test. MozReview-Commit-ID: Gz7zqX825oR
devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_crossdomain_iframe.js
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_crossdomain_iframe.js
devtools/client/webconsole/new-console-output/test/mochitest/head.js
devtools/client/webconsole/new-console-output/test/mochitest/test-bug-989025-iframe-parent.html
devtools/client/webconsole/new-console-output/test/mochitest/test-iframe-child.html
devtools/client/webconsole/new-console-output/test/mochitest/test-iframe-parent.html
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -90,17 +90,18 @@ support-files =
   test-bug-782653-css-errors-1.css
   test-bug-782653-css-errors-2.css
   test-bug-782653-css-errors.html
   test-bug-837351-security-errors.html
   test-bug-859170-longstring-hang.html
   test-bug-869003-iframe.html
   test-bug-869003-top-window.html
   test-bug-952277-highlight-nodes-in-vview.html
-  test-bug-989025-iframe-parent.html
+  test-iframe-child.html
+  test-iframe-parent.html
   test-certificate-messages.html
   test-closure-optimized-out.html
   test-closures.html
   test-console-api-stackframe.html
   test-console-clear.html
   test-console-column.html
   test-console-count-external-file.js
   test-console-count.html
@@ -193,16 +194,17 @@ skip-if = true # Bug 1406060
 skip-if = true # Bug 1406060
 [browser_console_webconsole_private_browsing.js]
 skip-if = true #	Bug 1403188
 # old console skip-if = e10s # Bug 1042253 - webconsole e10s tests
 [browser_jsterm_accessibility.js]
 [browser_jsterm_add_edited_input_to_history.js]
 [browser_jsterm_autocomplete_array_no_index.js]
 [browser_jsterm_autocomplete_cached_results.js]
+[browser_jsterm_autocomplete_crossdomain_iframe.js]
 [browser_jsterm_autocomplete_escape_key.js]
 [browser_jsterm_autocomplete_helpers.js]
 [browser_jsterm_autocomplete_inside_text.js]
 [browser_jsterm_autocomplete_nav_and_tab_key.js]
 [browser_jsterm_autocomplete_return_key_no_selection.js]
 [browser_jsterm_autocomplete_return_key.js]
 [browser_jsterm_autocomplete-properties-with-non-alphanumeric-names.js]
 [browser_jsterm_copy_command.js]
@@ -216,18 +218,16 @@ skip-if = true #	Bug 1403188
 [browser_jsterm_popup.js]
 [browser_jsterm_selfxss.js]
 subsuite = clipboard
 [browser_netmonitor_shows_reqs_in_webconsole.js]
 [browser_webconsole_allow_mixedcontent_securityerrors.js]
 tags = mcb
 skip-if = true #	Bug 1403452
 # old console skip-if = (os == 'win' && bits == 64) # Bug 1390001
-[browser_webconsole_autocomplete_crossdomain_iframe.js]
-skip-if = true # Bug 1408919
 [browser_webconsole_autocomplete_in_debugger_stackframe.js]
 skip-if = true # Bug 1408920
 [browser_webconsole_batching.js]
 [browser_webconsole_block_mixedcontent_securityerrors.js]
 tags = mcb
 skip-if = true #	Bug 1403899
 # old console skip-if = (os == 'win' && bits == 64) # Bug 1390001
 [browser_webconsole_cached_messages.js]
rename from devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_crossdomain_iframe.js
rename to devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_crossdomain_iframe.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_autocomplete_crossdomain_iframe.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_jsterm_autocomplete_crossdomain_iframe.js
@@ -1,64 +1,37 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Test that autocomplete doesn't break when trying to reach into objects from
-// a different domain, bug 989025.
+// a different domain. See Bug 989025.
 
 "use strict";
 
-function test() {
-  let hud;
-
-  const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
-                   "test/test-bug-989025-iframe-parent.html";
-
-  Task.spawn(function* () {
-    const {tab} = yield loadTab(TEST_URI);
-    hud = yield openConsole(tab);
-
-    hud.jsterm.execute("document.title");
+const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
+                 "new-console-output/test/mochitest/test-iframe-parent.html";
+add_task(async function () {
+  const hud = await openNewTabAndConsole(TEST_URI);
+  const { jsterm } = hud;
 
-    yield waitForMessages({
-      webconsole: hud,
-      messages: [{
-        text: "989025 - iframe parent",
-        category: CATEGORY_OUTPUT,
-      }],
-    });
-
-    let autocompleteUpdated = hud.jsterm.once("autocomplete-updated");
-
-    hud.jsterm.setInputValue("window[0].document");
-    executeSoon(() => {
-      EventUtils.synthesizeKey(".", {});
-    });
+  const onParentTitle = waitForMessage(hud, "iframe parent");
+  jsterm.execute("document.title");
+  await onParentTitle;
+  ok(true, "root document's title is accessible");
 
-    yield autocompleteUpdated;
-
-    hud.jsterm.setInputValue("window[0].document.title");
-    EventUtils.synthesizeKey("VK_RETURN", {});
-
-    yield waitForMessages({
-      webconsole: hud,
-      messages: [{
-        text: "Permission denied",
-        category: CATEGORY_OUTPUT,
-        severity: SEVERITY_ERROR,
-      }],
-    });
+  // Make sure we don't throw when trying to autocomplete
+  let autocompleteUpdated = hud.jsterm.once("autocomplete-updated");
+  jsterm.setInputValue("window[0].document");
+  EventUtils.synthesizeKey(".", {});
+  await autocompleteUpdated;
 
-    hud.jsterm.execute("window.location");
+  hud.jsterm.setInputValue("window[0].document.title");
+  const onPermissionDeniedMessage = waitForMessage(hud, "Permission denied");
+  EventUtils.synthesizeKey("VK_RETURN", {});
+  const permissionDenied = await onPermissionDeniedMessage;
+  ok(permissionDenied.node.classList.contains("error"),
+    "A message error is shown when trying to inspect window[0]");
 
-    yield waitForMessages({
-      webconsole: hud,
-      messages: [{
-        text: "test-bug-989025-iframe-parent.html",
-        category: CATEGORY_OUTPUT,
-      }],
-    });
-
-    yield closeConsole(tab);
-  }).then(finishTest);
-}
+  const onParentLocation = waitForMessage(hud, "test-iframe-parent.html");
+  hud.jsterm.execute("window.location");
+  await onParentLocation;
+  ok(true, "root document's location is accessible");
+});
--- a/devtools/client/webconsole/new-console-output/test/mochitest/head.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/head.js
@@ -64,50 +64,64 @@ async function openNewTabAndConsole(url,
 
 /**
  * Wait for messages in the web console output, resolving once they are received.
  *
  * @param object options
  *        - hud: the webconsole
  *        - messages: Array[Object]. An array of messages to match.
             Current supported options:
- *            - text: Exact text match in .message-body
+ *            - text: Partial text match in .message-body
  */
 function waitForMessages({ hud, messages }) {
   return new Promise(resolve => {
-    let numMatched = 0;
+    const matchedMessages = [];
     let receivedLog = hud.ui.on("new-messages",
       function messagesReceived(e, newMessages) {
         for (let message of messages) {
           if (message.matched) {
             continue;
           }
 
           for (let newMessage of newMessages) {
             let messageBody = newMessage.node.querySelector(".message-body");
             if (messageBody.textContent.includes(message.text)) {
-              numMatched++;
+              matchedMessages.push(newMessage);
               message.matched = true;
-              info("Matched a message with text: " + message.text +
-                ", still waiting for " + (messages.length - numMatched) + " messages");
+              const messagesLeft = messages.length - matchedMessages.length;
+              info(`Matched a message with text: "${message.text}", ` + (messagesLeft > 0
+                ? `still waiting for ${messagesLeft} messages.`
+                : `all messages received.`)
+              );
               break;
             }
           }
 
-          if (numMatched === messages.length) {
+          if (matchedMessages.length === messages.length) {
             hud.ui.off("new-messages", messagesReceived);
-            resolve(receivedLog);
+            resolve(matchedMessages);
             return;
           }
         }
       });
   });
 }
 
 /**
+ * Wait for a single message in the web console output, resolving once it is received.
+ *
+ * @param {Object} hud : the webconsole
+ * @param {String} text : text included in .message-body
+ */
+async function waitForMessage(hud, text) {
+  const messages = await waitForMessages({hud, messages: [{text}]});
+  return messages[0];
+}
+
+/**
  * Wait for a predicate to return a result.
  *
  * @param function condition
  *        Invoked once in a while until it returns a truthy value. This should be an
  *        idempotent function, since we have to run it a second time after it returns
  *        true in order to return the value.
  * @param string message [optional]
  *        A message to output if the condition fails.
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/test-iframe-child.html
@@ -0,0 +1,12 @@
+<!-- Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>test for bug 989025 - iframe child</title>
+  </head>
+  <body>
+    <p>test for bug 989025 - iframe child</p>
+  </body>
+</html>
rename from devtools/client/webconsole/new-console-output/test/mochitest/test-bug-989025-iframe-parent.html
rename to devtools/client/webconsole/new-console-output/test/mochitest/test-iframe-parent.html
--- a/devtools/client/webconsole/new-console-output/test/mochitest/test-bug-989025-iframe-parent.html
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/test-iframe-parent.html
@@ -1,13 +1,13 @@
+<!-- Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/ -->
 <!DOCTYPE html>
 <html lang="en">
   <head>
     <meta charset="utf-8">
     <title>test for bug 989025 - iframe parent</title>
-    <!-- Any copyright is dedicated to the Public Domain.
-         http://creativecommons.org/publicdomain/zero/1.0/ -->
   </head>
   <body>
     <p>test for bug 989025 - iframe parent</p>
-    <iframe src="http://mochi.test:8888/browser/devtools/client/webconsole/test/test-bug-609872-cd-iframe-child.html"></iframe>
+    <iframe src="http://mochi.test:8888/browser/devtools/client/webconsole/new-console-output/test/mochitest/test-iframe-child.html"></iframe>
   </body>
 </html>