Bug 1354698 - Add tests for View Source in both the tab and window mode when doing DocGroup checks. r=jryans

MozReview-Commit-ID: BDTYuEMho6L

--HG--
extra : rebase_source : e14f373e7e4ba04519e408180aacaf3a27e5e19f
This commit is contained in:
Mike Conley 2017-04-09 01:31:10 -04:00
parent b0e76254de
commit 6fea222c62
3 changed files with 102 additions and 6 deletions

View File

@ -8,5 +8,6 @@ support-files = head.js
[browser_contextmenu.js]
subsuite = clipboard
[browser_gotoline.js]
[browser_open_docgroup.js]
[browser_srcdoc.js]
[browser_viewsourceprefs.js]

View File

@ -0,0 +1,71 @@
"use strict";
/**
* Very basic smoketests for the View Source feature, which also
* forces on the DocGroup mismatch check that was added in
* bug 1340719.
*/
add_task(function* setup() {
yield SpecialPowers.pushPrefEnv({
set: [
["extensions.throw_on_docgroup_mismatch.enabled", true],
],
});
});
/**
* Tests that we can open View Source in a tab.
*/
add_task(function* test_view_source_in_tab() {
yield SpecialPowers.pushPrefEnv({
set: [
["view_source.tab", true],
],
});
yield BrowserTestUtils.withNewTab({
gBrowser,
url: "http://example.com",
}, function* (browser) {
let sourceTab = yield openViewSource(browser);
let sourceBrowser = sourceTab.linkedBrowser;
yield waitForSourceLoaded(sourceBrowser);
yield ContentTask.spawn(sourceBrowser, null, function*() {
Assert.equal(content.document.body.id, "viewsource",
"View source mode enabled");
});
yield BrowserTestUtils.removeTab(sourceTab);
});
yield SpecialPowers.popPrefEnv();
});
/**
* Tests that we can open View Source in a window.
*/
add_task(function* test_view_source_in_window() {
yield SpecialPowers.pushPrefEnv({
set: [
["view_source.tab", false],
],
});
yield BrowserTestUtils.withNewTab({
gBrowser,
url: "http://example.com",
}, function* (browser) {
let sourceWin = yield openViewSource(browser);
yield waitForSourceLoaded(sourceWin);
yield ContentTask.spawn(sourceWin.gBrowser, null, function*() {
Assert.equal(content.document.body.id, "viewsource",
"View source mode enabled");
});
yield closeViewSourceWindow(sourceWin);
});
yield SpecialPowers.popPrefEnv();
});

View File

@ -26,13 +26,18 @@ function loadViewSourceWindow(URL) {
}
function closeViewSourceWindow(aWindow, aCallback) {
Services.wm.addListener({
onCloseWindow() {
Services.wm.removeListener(this);
executeSoon(aCallback);
}
return new Promise(resolve => {
Services.wm.addListener({
onCloseWindow() {
Services.wm.removeListener(this);
if (aCallback) {
executeSoon(aCallback);
}
resolve();
}
});
aWindow.close();
});
aWindow.close();
}
function testViewSourceWindow(aURI, aTestCallback, aCloseCallback) {
@ -65,6 +70,25 @@ function waitForViewSourceWindow() {
});
}
/**
* Opens view source for a browser.
*
* @param browser - the <xul:browser> to open view source for.
* @returns the new tab or window which shows the source.
*/
function* openViewSource(browser) {
let openPromise;
if (Services.prefs.getBoolPref("view_source.tab")) {
openPromise = BrowserTestUtils.waitForNewTab(gBrowser, null);
} else {
openPromise = waitForViewSourceWindow();
}
window.BrowserViewSource(browser);
return (yield openPromise);
}
/**
* Opens a view source tab / window for a selection (View Selection Source)
* within the currently selected browser in gBrowser.