mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 16:58:38 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
7
toolkit/components/viewsource/test/browser/.eslintrc.js
Normal file
7
toolkit/components/viewsource/test/browser/.eslintrc.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
"extends": [
|
||||
"../../../../../testing/mochitest/browser.eslintrc.js"
|
||||
]
|
||||
};
|
||||
12
toolkit/components/viewsource/test/browser/browser.ini
Normal file
12
toolkit/components/viewsource/test/browser/browser.ini
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[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]
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
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);
|
||||
});
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/* 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);
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/* 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);
|
||||
});
|
||||
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
/* 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;
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/* 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");
|
||||
}
|
||||
});
|
||||
30
toolkit/components/viewsource/test/browser/browser_srcdoc.js
Normal file
30
toolkit/components/viewsource/test/browser/browser_srcdoc.js
Normal file
|
|
@ -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")
|
||||
}
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
/* 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"));
|
||||
});
|
||||
|
|
@ -0,0 +1 @@
|
|||
<a href="file_bug464222.html">I'm a link</a>
|
||||
200
toolkit/components/viewsource/test/browser/head.js
Normal file
200
toolkit/components/viewsource/test/browser/head.js
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
/* 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue