summaryrefslogtreecommitdiffstats
path: root/toolkit/components/viewsource
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-02-25 15:07:00 -0500
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-04-14 12:55:19 +0200
commiteb70e6e3d0bff11c25f14b1196025791bf2308fb (patch)
tree5ef4ce17db83c74d7b05ec12c8f59e095a6dd5bd /toolkit/components/viewsource
parent32ead795290b3399d56b4708fc75b77d296f6a1a (diff)
downloadUXP-eb70e6e3d0bff11c25f14b1196025791bf2308fb.tar
UXP-eb70e6e3d0bff11c25f14b1196025791bf2308fb.tar.gz
UXP-eb70e6e3d0bff11c25f14b1196025791bf2308fb.tar.lz
UXP-eb70e6e3d0bff11c25f14b1196025791bf2308fb.tar.xz
UXP-eb70e6e3d0bff11c25f14b1196025791bf2308fb.zip
Issue #439 - Remove tests from toolkit/
Diffstat (limited to 'toolkit/components/viewsource')
-rw-r--r--toolkit/components/viewsource/moz.build12
-rw-r--r--toolkit/components/viewsource/test/.eslintrc.js7
-rw-r--r--toolkit/components/viewsource/test/browser/.eslintrc.js7
-rw-r--r--toolkit/components/viewsource/test/browser/browser.ini12
-rw-r--r--toolkit/components/viewsource/test/browser/browser_bug464222.js12
-rw-r--r--toolkit/components/viewsource/test/browser/browser_bug699356.js19
-rw-r--r--toolkit/components/viewsource/test/browser/browser_bug713810.js23
-rw-r--r--toolkit/components/viewsource/test/browser/browser_contextmenu.js107
-rw-r--r--toolkit/components/viewsource/test/browser/browser_gotoline.js36
-rw-r--r--toolkit/components/viewsource/test/browser/browser_srcdoc.js30
-rw-r--r--toolkit/components/viewsource/test/browser/browser_viewsourceprefs.js136
-rw-r--r--toolkit/components/viewsource/test/browser/file_bug464222.html1
-rw-r--r--toolkit/components/viewsource/test/browser/head.js200
-rw-r--r--toolkit/components/viewsource/test/chrome.ini4
-rw-r--r--toolkit/components/viewsource/test/file_empty.html1
-rw-r--r--toolkit/components/viewsource/test/test_bug428653.html45
16 files changed, 2 insertions, 650 deletions
diff --git a/toolkit/components/viewsource/moz.build b/toolkit/components/viewsource/moz.build
index aecd25682..965c0b66f 100644
--- a/toolkit/components/viewsource/moz.build
+++ b/toolkit/components/viewsource/moz.build
@@ -4,14 +4,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']
-MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini']
+EXTRA_JS_MODULES += ['ViewSourceBrowser.jsm']
-JAR_MANIFESTS += ['jar.mn']
-
-EXTRA_JS_MODULES += [
- 'ViewSourceBrowser.jsm',
-]
-
-with Files('**'):
- BUG_COMPONENT = ('Toolkit', 'View Source')
+JAR_MANIFESTS += ['jar.mn'] \ No newline at end of file
diff --git a/toolkit/components/viewsource/test/.eslintrc.js b/toolkit/components/viewsource/test/.eslintrc.js
deleted file mode 100644
index 2c669d844..000000000
--- a/toolkit/components/viewsource/test/.eslintrc.js
+++ /dev/null
@@ -1,7 +0,0 @@
-"use strict";
-
-module.exports = {
- "extends": [
- "../../../../testing/mochitest/chrome.eslintrc.js"
- ]
-};
diff --git a/toolkit/components/viewsource/test/browser/.eslintrc.js b/toolkit/components/viewsource/test/browser/.eslintrc.js
deleted file mode 100644
index 7c8021192..000000000
--- a/toolkit/components/viewsource/test/browser/.eslintrc.js
+++ /dev/null
@@ -1,7 +0,0 @@
-"use strict";
-
-module.exports = {
- "extends": [
- "../../../../../testing/mochitest/browser.eslintrc.js"
- ]
-};
diff --git a/toolkit/components/viewsource/test/browser/browser.ini b/toolkit/components/viewsource/test/browser/browser.ini
deleted file mode 100644
index d9ebbd25f..000000000
--- a/toolkit/components/viewsource/test/browser/browser.ini
+++ /dev/null
@@ -1,12 +0,0 @@
-[DEFAULT]
-support-files = head.js
- file_bug464222.html
-
-[browser_bug464222.js]
-[browser_bug699356.js]
-[browser_bug713810.js]
-[browser_contextmenu.js]
-subsuite = clipboard
-[browser_gotoline.js]
-[browser_srcdoc.js]
-[browser_viewsourceprefs.js]
diff --git a/toolkit/components/viewsource/test/browser/browser_bug464222.js b/toolkit/components/viewsource/test/browser/browser_bug464222.js
deleted file mode 100644
index 30c4fb67a..000000000
--- a/toolkit/components/viewsource/test/browser/browser_bug464222.js
+++ /dev/null
@@ -1,12 +0,0 @@
-const source = "http://example.com/browser/toolkit/components/viewsource/test/browser/file_bug464222.html";
-
-add_task(function *() {
- let viewSourceTab = yield* openDocumentSelect(source, "a");
-
- let href = yield ContentTask.spawn(viewSourceTab.linkedBrowser, { }, function* () {
- return content.document.querySelectorAll("a[href]")[0].href;
- });
-
- is(href, "view-source:" + source, "Relative links broken?");
- gBrowser.removeTab(viewSourceTab);
-});
diff --git a/toolkit/components/viewsource/test/browser/browser_bug699356.js b/toolkit/components/viewsource/test/browser/browser_bug699356.js
deleted file mode 100644
index e55c4cf20..000000000
--- a/toolkit/components/viewsource/test/browser/browser_bug699356.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
-function test() {
- let source = "about:blank";
-
- waitForExplicitFinish();
- openViewSourceWindow(source, function(aWindow) {
- let gBrowser = aWindow.gBrowser;
- let docEl = aWindow.document.documentElement;
-
- is(gBrowser.contentDocument.title, source, "Correct document title");
- is(docEl.getAttribute("title"),
- "Source of: " + source + ("nsILocalFileMac" in Components.interfaces ? "" : " - " + docEl.getAttribute("titlemodifier")),
- "Correct window title");
- closeViewSourceWindow(aWindow, finish);
- });
-}
diff --git a/toolkit/components/viewsource/test/browser/browser_bug713810.js b/toolkit/components/viewsource/test/browser/browser_bug713810.js
deleted file mode 100644
index d5b2f3424..000000000
--- a/toolkit/components/viewsource/test/browser/browser_bug713810.js
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
-const source = '<html xmlns="http://www.w3.org/1999/xhtml"><body><p>This is a paragraph.</p></body></html>';
-
-add_task(function *() {
- let viewSourceTab = yield* openDocumentSelect("data:text/html," + source, "p");
- yield ContentTask.spawn(viewSourceTab.linkedBrowser, null, function* () {
- Assert.equal(content.document.body.textContent, "<p>This is a paragraph.</p>",
- "Correct source for text/html");
- });
- gBrowser.removeTab(viewSourceTab);
-
- viewSourceTab = yield* openDocumentSelect("data:application/xhtml+xml," + source, "p");
- yield ContentTask.spawn(viewSourceTab.linkedBrowser, null, function* () {
- Assert.equal(content.document.body.textContent,
- '<p xmlns="http://www.w3.org/1999/xhtml">This is a paragraph.</p>',
- "Correct source for application/xhtml+xml");
- });
- gBrowser.removeTab(viewSourceTab);
-});
-
diff --git a/toolkit/components/viewsource/test/browser/browser_contextmenu.js b/toolkit/components/viewsource/test/browser/browser_contextmenu.js
deleted file mode 100644
index 72b8a40be..000000000
--- a/toolkit/components/viewsource/test/browser/browser_contextmenu.js
+++ /dev/null
@@ -1,107 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
-var source = "data:text/html,text<link%20href='http://example.com/'%20/>more%20text<a%20href='mailto:abc@def.ghi'>email</a>";
-var gViewSourceWindow, gContextMenu, gCopyLinkMenuItem, gCopyEmailMenuItem;
-
-var expectedData = [];
-
-add_task(function *() {
- // Full source in view source window
- let newWindow = yield loadViewSourceWindow(source);
- yield SimpleTest.promiseFocus(newWindow);
-
- yield* onViewSourceWindowOpen(newWindow, false);
-
- let contextMenu = gViewSourceWindow.document.getElementById("viewSourceContextMenu");
-
- for (let test of expectedData) {
- yield* checkMenuItems(contextMenu, false, test[0], test[1], test[2], test[3]);
- }
-
- yield new Promise(resolve => {
- closeViewSourceWindow(newWindow, resolve);
- });
-
- // Selection source in view source tab
- expectedData = [];
- let newTab = yield openDocumentSelect(source, "body");
- yield* onViewSourceWindowOpen(window, true);
-
- contextMenu = document.getElementById("contentAreaContextMenu");
-
- for (let test of expectedData) {
- yield* checkMenuItems(contextMenu, true, test[0], test[1], test[2], test[3]);
- }
-
- gBrowser.removeTab(newTab);
-
- // Selection source in view source window
- yield pushPrefs(["view_source.tab", false]);
-
- expectedData = [];
- newWindow = yield openDocumentSelect(source, "body");
- yield SimpleTest.promiseFocus(newWindow);
-
- yield* onViewSourceWindowOpen(newWindow, false);
-
- contextMenu = newWindow.document.getElementById("viewSourceContextMenu");
-
- for (let test of expectedData) {
- yield* checkMenuItems(contextMenu, false, test[0], test[1], test[2], test[3]);
- }
-
- yield new Promise(resolve => {
- closeViewSourceWindow(newWindow, resolve);
- });
-});
-
-function* onViewSourceWindowOpen(aWindow, aIsTab) {
- gViewSourceWindow = aWindow;
-
- gCopyLinkMenuItem = aWindow.document.getElementById(aIsTab ? "context-copylink" : "context-copyLink");
- gCopyEmailMenuItem = aWindow.document.getElementById(aIsTab ? "context-copyemail" : "context-copyEmail");
-
- let browser = aIsTab ? gBrowser.selectedBrowser : gViewSourceWindow.gBrowser;
- yield ContentTask.spawn(browser, null, function* (arg) {
- let tags = content.document.querySelectorAll("a[href]");
- Assert.equal(tags[0].href, "view-source:http://example.com/", "Link has correct href");
- Assert.equal(tags[1].href, "mailto:abc@def.ghi", "Link has correct href");
- });
-
- expectedData.push(["a[href]", true, false, "http://example.com/"]);
- expectedData.push(["a[href^=mailto]", false, true, "abc@def.ghi"]);
- expectedData.push(["span", false, false, null]);
-}
-
-function* checkMenuItems(contextMenu, isTab, selector, copyLinkExpected, copyEmailExpected, expectedClipboardContent) {
-
- let browser = isTab ? gBrowser.selectedBrowser : gViewSourceWindow.gBrowser;
- yield ContentTask.spawn(browser, { selector: selector }, function* (arg) {
- content.document.querySelector(arg.selector).scrollIntoView();
- });
-
- let popupShownPromise = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
- yield BrowserTestUtils.synthesizeMouseAtCenter(selector,
- { type: "contextmenu", button: 2}, browser);
- yield popupShownPromise;
-
- is(gCopyLinkMenuItem.hidden, !copyLinkExpected, "Copy link menuitem is " + (copyLinkExpected ? "not hidden" : "hidden"));
- is(gCopyEmailMenuItem.hidden, !copyEmailExpected, "Copy email menuitem is " + (copyEmailExpected ? "not hidden" : "hidden"));
-
- if (copyLinkExpected || copyEmailExpected) {
- yield new Promise((resolve, reject) => {
- waitForClipboard(expectedClipboardContent, function() {
- if (copyLinkExpected)
- gCopyLinkMenuItem.click();
- else
- gCopyEmailMenuItem.click();
- }, resolve, reject);
- });
- }
-
- let popupHiddenPromise = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden");
- contextMenu.hidePopup();
- yield popupHiddenPromise;
-}
diff --git a/toolkit/components/viewsource/test/browser/browser_gotoline.js b/toolkit/components/viewsource/test/browser/browser_gotoline.js
deleted file mode 100644
index 5bb45f9ca..000000000
--- a/toolkit/components/viewsource/test/browser/browser_gotoline.js
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
-Cu.import("resource://testing-common/ContentTaskUtils.jsm", this);
-
-var content = "line 1\nline 2\nline 3";
-
-add_task(function*() {
- // First test with text with the text/html mimetype.
- let win = yield loadViewSourceWindow("data:text/html," + encodeURIComponent(content));
- yield checkViewSource(win);
- yield BrowserTestUtils.closeWindow(win);
-
- win = yield loadViewSourceWindow("data:text/plain," + encodeURIComponent(content));
- yield checkViewSource(win);
- yield BrowserTestUtils.closeWindow(win);
-});
-
-var checkViewSource = Task.async(function* (aWindow) {
- is(aWindow.gBrowser.contentDocument.body.textContent, content, "Correct content loaded");
- let statusPanel = aWindow.document.getElementById("statusbar-line-col");
- is(statusPanel.getAttribute("label"), "", "Correct status bar text");
-
- for (let i = 1; i <= 3; i++) {
- aWindow.viewSourceChrome.goToLine(i);
- yield ContentTask.spawn(aWindow.gBrowser, i, function*(i) {
- let selection = content.getSelection();
- Assert.equal(selection.toString(), "line " + i, "Correct text selected");
- });
-
- yield ContentTaskUtils.waitForCondition(() => {
- return (statusPanel.getAttribute("label") == "Line " + i + ", Col 1");
- }, "Correct status bar text");
- }
-});
diff --git a/toolkit/components/viewsource/test/browser/browser_srcdoc.js b/toolkit/components/viewsource/test/browser/browser_srcdoc.js
deleted file mode 100644
index 542741ffc..000000000
--- a/toolkit/components/viewsource/test/browser/browser_srcdoc.js
+++ /dev/null
@@ -1,30 +0,0 @@
-/* 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")
-}
diff --git a/toolkit/components/viewsource/test/browser/browser_viewsourceprefs.js b/toolkit/components/viewsource/test/browser/browser_viewsourceprefs.js
deleted file mode 100644
index 7361a70a5..000000000
--- a/toolkit/components/viewsource/test/browser/browser_viewsourceprefs.js
+++ /dev/null
@@ -1,136 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
-var plaintextURL = "data:text/plain,hello+world";
-var htmlURL = "about:mozilla";
-
-add_task(function* setup() {
- registerCleanupFunction(function() {
- SpecialPowers.clearUserPref("view_source.tab_size");
- SpecialPowers.clearUserPref("view_source.wrap_long_lines");
- SpecialPowers.clearUserPref("view_source.syntax_highlight");
- });
-});
-
-add_task(function*() {
- yield exercisePrefs(plaintextURL, false);
- yield exercisePrefs(htmlURL, true);
-});
-
-var exercisePrefs = Task.async(function* (source, highlightable) {
- let win = yield loadViewSourceWindow(source);
- let wrapMenuItem = win.document.getElementById("menu_wrapLongLines");
- let syntaxMenuItem = win.document.getElementById("menu_highlightSyntax");
-
- // Strip checked="false" attributes, since we're not interested in them.
- if (wrapMenuItem.getAttribute("checked") == "false") {
- wrapMenuItem.removeAttribute("checked");
- }
- if (syntaxMenuItem.getAttribute("checked") == "false") {
- syntaxMenuItem.removeAttribute("checked");
- }
-
- // Test the default states of these menu items.
- is(wrapMenuItem.hasAttribute("checked"), false,
- "Wrap menu item not checked by default");
- is(syntaxMenuItem.hasAttribute("checked"), true,
- "Syntax menu item checked by default");
-
- yield checkStyle(win, "-moz-tab-size", 4);
- yield checkStyle(win, "white-space", "pre");
-
- // Next, test that the Wrap Long Lines menu item works.
- let prefReady = waitForPrefChange("view_source.wrap_long_lines");
- simulateClick(wrapMenuItem);
- is(wrapMenuItem.hasAttribute("checked"), true, "Wrap menu item checked");
- yield prefReady;
- is(SpecialPowers.getBoolPref("view_source.wrap_long_lines"), true, "Wrap pref set");
-
- yield checkStyle(win, "white-space", "pre-wrap");
-
- prefReady = waitForPrefChange("view_source.wrap_long_lines");
- simulateClick(wrapMenuItem);
- is(wrapMenuItem.hasAttribute("checked"), false, "Wrap menu item unchecked");
- yield prefReady;
- is(SpecialPowers.getBoolPref("view_source.wrap_long_lines"), false, "Wrap pref set");
- yield checkStyle(win, "white-space", "pre");
-
- // Check that the Syntax Highlighting menu item works.
- prefReady = waitForPrefChange("view_source.syntax_highlight");
- simulateClick(syntaxMenuItem);
- is(syntaxMenuItem.hasAttribute("checked"), false, "Syntax menu item unchecked");
- yield prefReady;
- is(SpecialPowers.getBoolPref("view_source.syntax_highlight"), false, "Syntax highlighting pref set");
- yield checkHighlight(win, false);
-
- prefReady = waitForPrefChange("view_source.syntax_highlight");
- simulateClick(syntaxMenuItem);
- is(syntaxMenuItem.hasAttribute("checked"), true, "Syntax menu item checked");
- yield prefReady;
- is(SpecialPowers.getBoolPref("view_source.syntax_highlight"), true, "Syntax highlighting pref set");
- yield checkHighlight(win, highlightable);
- yield BrowserTestUtils.closeWindow(win);
-
- // Open a new view-source window to check that the prefs are obeyed.
- SpecialPowers.setIntPref("view_source.tab_size", 2);
- SpecialPowers.setBoolPref("view_source.wrap_long_lines", true);
- SpecialPowers.setBoolPref("view_source.syntax_highlight", false);
-
- win = yield loadViewSourceWindow(source);
- wrapMenuItem = win.document.getElementById("menu_wrapLongLines");
- syntaxMenuItem = win.document.getElementById("menu_highlightSyntax");
-
- // Strip checked="false" attributes, since we're not interested in them.
- if (wrapMenuItem.getAttribute("checked") == "false") {
- wrapMenuItem.removeAttribute("checked");
- }
- if (syntaxMenuItem.getAttribute("checked") == "false") {
- syntaxMenuItem.removeAttribute("checked");
- }
-
- is(wrapMenuItem.hasAttribute("checked"), true, "Wrap menu item checked");
- is(syntaxMenuItem.hasAttribute("checked"), false, "Syntax menu item unchecked");
- yield checkStyle(win, "-moz-tab-size", 2);
- yield checkStyle(win, "white-space", "pre-wrap");
- yield checkHighlight(win, false);
-
- SpecialPowers.clearUserPref("view_source.tab_size");
- SpecialPowers.clearUserPref("view_source.wrap_long_lines");
- SpecialPowers.clearUserPref("view_source.syntax_highlight");
-
- yield BrowserTestUtils.closeWindow(win);
-});
-
-// Simulate a menu item click, including toggling the checked state.
-// This saves us from opening the menu and trying to click on the item,
-// which doesn't work on Mac OS X.
-function simulateClick(aMenuItem) {
- if (aMenuItem.hasAttribute("checked"))
- aMenuItem.removeAttribute("checked");
- else
- aMenuItem.setAttribute("checked", "true");
-
- aMenuItem.click();
-}
-
-var checkStyle = Task.async(function* (win, styleProperty, expected) {
- let browser = win.gBrowser;
- let value = yield ContentTask.spawn(browser, styleProperty, function* (styleProperty) {
- let style = content.getComputedStyle(content.document.body, null);
- return style.getPropertyValue(styleProperty);
- });
- is(value, expected, "Correct value of " + styleProperty);
-});
-
-var checkHighlight = Task.async(function* (win, expected) {
- let browser = win.gBrowser;
- let highlighted = yield ContentTask.spawn(browser, {}, function* () {
- let spans = content.document.getElementsByTagName("span");
- return Array.some(spans, (span) => {
- let style = content.getComputedStyle(span, null);
- return style.getPropertyValue("color") !== "rgb(0, 0, 0)";
- });
- });
- is(highlighted, expected, "Syntax highlighting " + (expected ? "on" : "off"));
-});
diff --git a/toolkit/components/viewsource/test/browser/file_bug464222.html b/toolkit/components/viewsource/test/browser/file_bug464222.html
deleted file mode 100644
index 4f2a43f0d..000000000
--- a/toolkit/components/viewsource/test/browser/file_bug464222.html
+++ /dev/null
@@ -1 +0,0 @@
-<a href="file_bug464222.html">I'm a link</a> \ No newline at end of file
diff --git a/toolkit/components/viewsource/test/browser/head.js b/toolkit/components/viewsource/test/browser/head.js
deleted file mode 100644
index bb46369b0..000000000
--- a/toolkit/components/viewsource/test/browser/head.js
+++ /dev/null
@@ -1,200 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
-Cu.import("resource://gre/modules/PromiseUtils.jsm");
-Cu.import("resource://gre/modules/Preferences.jsm");
-
-const WINDOW_TYPE = "navigator:view-source";
-
-function openViewSourceWindow(aURI, aCallback) {
- let viewSourceWindow = openDialog("chrome://global/content/viewSource.xul", null, null, aURI);
- viewSourceWindow.addEventListener("pageshow", function pageShowHandler(event) {
- // Wait for the inner window to load, not viewSourceWindow.
- if (event.target.location == "view-source:" + aURI) {
- info("View source window opened: " + event.target.location);
- viewSourceWindow.removeEventListener("pageshow", pageShowHandler, false);
- aCallback(viewSourceWindow);
- }
- }, false);
-}
-
-function loadViewSourceWindow(URL) {
- return new Promise((resolve) => {
- openViewSourceWindow(URL, resolve);
- })
-}
-
-function closeViewSourceWindow(aWindow, aCallback) {
- Services.wm.addListener({
- onCloseWindow: function() {
- Services.wm.removeListener(this);
- executeSoon(aCallback);
- }
- });
- aWindow.close();
-}
-
-function testViewSourceWindow(aURI, aTestCallback, aCloseCallback) {
- openViewSourceWindow(aURI, function(aWindow) {
- aTestCallback(aWindow);
- closeViewSourceWindow(aWindow, aCloseCallback);
- });
-}
-
-function waitForViewSourceWindow() {
- return new Promise(resolve => {
- let windowListener = {
- onOpenWindow(xulWindow) {
- let win = xulWindow.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindow);
- win.addEventListener("load", function listener() {
- win.removeEventListener("load", listener, false);
- if (win.document.documentElement.getAttribute("windowtype") !=
- WINDOW_TYPE) {
- return;
- }
- // Found the window
- resolve(win);
- Services.wm.removeListener(windowListener);
- }, false);
- },
- onCloseWindow() {},
- onWindowTitleChange() {}
- };
- Services.wm.addListener(windowListener);
- });
-}
-
-/**
- * Opens a view source tab / window 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 / window which shows the source.
- */
-function* openViewPartialSource(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 openPromise;
- if (Services.prefs.getBoolPref("view_source.tab")) {
- openPromise = BrowserTestUtils.waitForNewTab(gBrowser, null);
- } else {
- openPromise = waitForViewSourceWindow();
- }
-
- let popupHiddenPromise =
- BrowserTestUtils.waitForEvent(contentAreaContextMenuPopup, "popuphidden");
- let item = document.getElementById("context-viewpartialsource-selection");
- EventUtils.synthesizeMouseAtCenter(item, {});
- yield popupHiddenPromise;
-
- return (yield openPromise);
-}
-
-/**
- * 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(WINDOW_TYPE);
- ok(!windows.hasMoreElements(), "No remaining view source windows still open");
- while (windows.hasMoreElements())
- windows.getNext().close();
-});
-
-/**
- * For a given view source tab / window, wait for the source loading step to
- * complete.
- */
-function waitForSourceLoaded(tabOrWindow) {
- return new Promise(resolve => {
- let mm = tabOrWindow.messageManager ||
- tabOrWindow.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 / window 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 tabOrWindow = yield openViewPartialSource(aCSSSelector);
-
- // Wait until the source has been loaded.
- yield waitForSourceLoaded(tabOrWindow);
-
- return tabOrWindow;
-}
-
-function pushPrefs(...aPrefs) {
- return new Promise(resolve => {
- SpecialPowers.pushPrefEnv({"set": aPrefs}, resolve);
- });
-}
-
-function waitForPrefChange(pref) {
- let deferred = PromiseUtils.defer();
- let observer = () => {
- Preferences.ignore(pref, observer);
- deferred.resolve();
- };
- Preferences.observe(pref, observer);
- return deferred.promise;
-}
diff --git a/toolkit/components/viewsource/test/chrome.ini b/toolkit/components/viewsource/test/chrome.ini
deleted file mode 100644
index bd013ab6c..000000000
--- a/toolkit/components/viewsource/test/chrome.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[DEFAULT]
-
-[test_bug428653.html]
-support-files = file_empty.html
diff --git a/toolkit/components/viewsource/test/file_empty.html b/toolkit/components/viewsource/test/file_empty.html
deleted file mode 100644
index 495c23ec8..000000000
--- a/toolkit/components/viewsource/test/file_empty.html
+++ /dev/null
@@ -1 +0,0 @@
-<!DOCTYPE html><html><body></body></html>
diff --git a/toolkit/components/viewsource/test/test_bug428653.html b/toolkit/components/viewsource/test/test_bug428653.html
deleted file mode 100644
index b1d48bfb3..000000000
--- a/toolkit/components/viewsource/test/test_bug428653.html
+++ /dev/null
@@ -1,45 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=428653
--->
-<head>
- <title>View Source Test (bug 428653)</title>
- <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
- <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
-</head>
-<body>
-
- <iframe id="content" src="http://example.org/tests/toolkit/components/viewsource/test/file_empty.html"></iframe>
-
- <script type="application/javascript">
- /*
- Test that we can't call the content browser's document.open() over Xrays.
- See the security checks in nsHTMLDocument::Open, which make sure that the
- entry global's principal matches that of the document.
- */
- SimpleTest.waitForExplicitFinish();
-
- addLoadEvent(function testDocumentOpen() {
- var browser = document.getElementById("content");
- ok(browser, "got browser");
- var doc = browser.contentDocument;
- ok(doc, "got content document");
-
- var opened = false;
- try {
- doc.open("text/html", "replace");
- opened = true;
- } catch (e) {
- is(e.name, "SecurityError", "Unexpected exception")
- }
- is(opened, false, "Shouldn't have opened document");
-
- doc.wrappedJSObject.open("text/html", "replace");
- ok(true, "Should be able to open document via Xray Waiver");
-
- SimpleTest.finish();
- });
- </script>
-</body>
-</html>