Bug 1201535 - Test view source of srcdoc frames. r=mconley, a=sylvestre
authorJ. Ryan Stinnett <jryans@gmail.com>
Wed, 23 Sep 2015 15:42:44 -0500
changeset 296137 6458f1f2c29edf1df7c2212ca51fef72177a90e9
parent 296136 f79cf0398d86ee43cd7a9dd19fba981adeacd6d3
child 296138 ae10b93c046541a6681d01fe6c6421f4523001f2
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, sylvestre
bugs1201535
milestone43.0a2
Bug 1201535 - Test view source of srcdoc frames. r=mconley, a=sylvestre
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);