Bug 1201535 - Test view source of srcdoc frames. r=mconley
authorJ. Ryan Stinnett <jryans@gmail.com>
Wed, 23 Sep 2015 15:42:44 -0500
changeset 264177 9efdda8b4a180ba0df8f3f80dc9e50ca6c2d6abe
parent 264176 83e1422aecc8b79316839b5bcbd16b859c2f0426
child 264178 cb4bff6374893dfe15348b045b491879b31183bc
push id29430
push userkwierso@gmail.com
push dateThu, 24 Sep 2015 23:42:03 +0000
treeherdermozilla-central@e9aea2b7d9fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1201535
milestone44.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 1201535 - Test view source of srcdoc frames. r=mconley
toolkit/components/viewsource/test/browser/browser.ini
toolkit/components/viewsource/test/browser/browser_srcdoc.js
toolkit/components/viewsource/test/browser/head.js
--- a/toolkit/components/viewsource/test/browser/browser.ini
+++ b/toolkit/components/viewsource/test/browser/browser.ini
@@ -2,10 +2,11 @@
 support-files = head.js
   file_bug464222.html
 
 [browser_bug464222.js]
 [browser_bug699356.js]
 [browser_bug713810.js]
 [browser_contextmenu.js]
 [browser_gotoline.js]
+[browser_srcdoc.js]
 [browser_viewsourceprefs.js]
 skip-if = e10s # Bug ?????? - obscure failure (Syntax highlighting off - Got true, expected false)
new file mode 100644
--- /dev/null
+++ b/toolkit/components/viewsource/test/browser/browser_srcdoc.js
@@ -0,0 +1,30 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const frameSource = `<a href="about:mozilla">good</a>`;
+const source = `<html><iframe srcdoc='${frameSource}' id="f"></iframe></html>`;
+
+add_task(function*() {
+  let url = `data:text/html,${source}`;
+  yield BrowserTestUtils.withNewTab({ gBrowser, url }, checkFrameSource);
+});
+
+function* checkFrameSource() {
+  let sourceTab = yield openViewFrameSourceTab("#f");
+  registerCleanupFunction(function() {
+    gBrowser.removeTab(sourceTab);
+  });
+
+  yield waitForSourceLoaded(sourceTab);
+
+  let browser = gBrowser.selectedBrowser;
+  let textContent = yield ContentTask.spawn(browser, {}, function*() {
+    return content.document.body.textContent;
+  });
+  is(textContent, frameSource, "Correct content loaded");
+  let id = yield ContentTask.spawn(browser, {}, function*() {
+    return content.document.body.id;
+  });
+  is(id, "viewsource", "View source mode enabled")
+}
--- a/toolkit/components/viewsource/test/browser/head.js
+++ b/toolkit/components/viewsource/test/browser/head.js
@@ -44,69 +44,113 @@ function testViewSourceWindow(aURI, aTes
  * Opens a view source tab for a selection (View Selection Source) within the
  * currently selected browser in gBrowser.
  *
  * @param aCSSSelector - used to specify a node within the selection to
  *                       view the source of. It is expected that this node is
  *                       within an existing selection.
  * @returns the new tab which shows the source.
  */
-function* openViewPartialSourceWindow(aCSSSelector) {
-  var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
-  let popupShownPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popupshown");
+function* openViewPartialSourceTab(aCSSSelector) {
+  let contentAreaContextMenuPopup =
+    document.getElementById("contentAreaContextMenu");
+  let popupShownPromise =
+    BrowserTestUtils.waitForEvent(contentAreaContextMenuPopup, "popupshown");
   yield BrowserTestUtils.synthesizeMouseAtCenter(aCSSSelector,
-          { type: "contextmenu", button: 2}, gBrowser.selectedBrowser);
+          { type: "contextmenu", button: 2 }, gBrowser.selectedBrowser);
   yield popupShownPromise;
 
   let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, null);
 
-  let popupHiddenPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popuphidden");
-  EventUtils.synthesizeMouseAtCenter(document.getElementById("context-viewpartialsource-selection"), {});
+  let popupHiddenPromise =
+    BrowserTestUtils.waitForEvent(contentAreaContextMenuPopup, "popuphidden");
+  let item = document.getElementById("context-viewpartialsource-selection");
+  EventUtils.synthesizeMouseAtCenter(item, {});
+  yield popupHiddenPromise;
+
+  return (yield newTabPromise);
+}
+
+/**
+ * Opens a view source tab for a frame (View Frame Source) within the
+ * currently selected browser in gBrowser.
+ *
+ * @param aCSSSelector - used to specify the frame to view the source of.
+ * @returns the new tab which shows the source.
+ */
+function* openViewFrameSourceTab(aCSSSelector) {
+  let contentAreaContextMenuPopup =
+    document.getElementById("contentAreaContextMenu");
+  let popupShownPromise =
+    BrowserTestUtils.waitForEvent(contentAreaContextMenuPopup, "popupshown");
+  yield BrowserTestUtils.synthesizeMouseAtCenter(aCSSSelector,
+          { type: "contextmenu", button: 2 }, gBrowser.selectedBrowser);
+  yield popupShownPromise;
+
+  let frameContextMenu = document.getElementById("frame");
+  popupShownPromise =
+    BrowserTestUtils.waitForEvent(frameContextMenu, "popupshown");
+  EventUtils.synthesizeMouseAtCenter(frameContextMenu, {});
+  yield popupShownPromise;
+
+  let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, null);
+
+  let popupHiddenPromise =
+    BrowserTestUtils.waitForEvent(frameContextMenu, "popuphidden");
+  let item = document.getElementById("context-viewframesource");
+  EventUtils.synthesizeMouseAtCenter(item, {});
   yield popupHiddenPromise;
 
   return (yield newTabPromise);
 }
 
 registerCleanupFunction(function() {
   var windows = Services.wm.getEnumerator("navigator:view-source");
   ok(!windows.hasMoreElements(), "No remaining view source windows still open");
   while (windows.hasMoreElements())
     windows.getNext().close();
 });
 
 /**
+ * For a given view source tab, wait for the source loading step to complete.
+ */
+function waitForSourceLoaded(tab) {
+  return new Promise(resolve => {
+    let mm = tab.linkedBrowser.messageManager;
+    mm.addMessageListener("ViewSource:SourceLoaded", function sourceLoaded() {
+      mm.removeMessageListener("ViewSource:SourceLoaded", sourceLoaded);
+      setTimeout(resolve, 0);
+    });
+  });
+}
+
+/**
  * Open a new document in a new tab, select part of it, and view the source of
  * that selection. The document is not closed afterwards.
  *
  * @param aURI - url to load
  * @param aCSSSelector - used to specify a node to select. All of this node's
  *                       children will be selected.
  * @returns the new tab which shows the source.
- */ 
+ */
 function* openDocumentSelect(aURI, aCSSSelector) {
   let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, aURI);
   registerCleanupFunction(function() {
     gBrowser.removeTab(tab);
   });
 
   yield ContentTask.spawn(gBrowser.selectedBrowser, { selector: aCSSSelector }, function* (arg) {
     let element = content.document.querySelector(arg.selector);
     content.getSelection().selectAllChildren(element);
   });
 
-  let newtab = yield openViewPartialSourceWindow(aCSSSelector);
+  let newtab = yield openViewPartialSourceTab(aCSSSelector);
 
   // Wait until the source has been loaded.
-  yield new Promise(resolve => {
-    let mm = newtab.linkedBrowser.messageManager;
-    mm.addMessageListener("ViewSource:SourceLoaded", function selectionDrawn() {
-      mm.removeMessageListener("ViewSource:SourceLoaded", selectionDrawn);
-      setTimeout(resolve, 0);
-    });
-  });
+  yield waitForSourceLoaded(newtab);
 
   return newtab;
 }
 
 function waitForPrefChange(pref) {
   let deferred = PromiseUtils.defer();
   let observer = () => {
     Preferences.ignore(pref, observer);