fune/browser/base/content/test/general/browser_viewSourceInTabOnViewSource.js
Paolo Amadini 3320f4e2ef Bug 1486984 - Fix find commands for PDF and special pages, and remove obsolete code. r=Gijs
Support for finding text in a page is now determined by a blacklist of locations, simplifying handling in multi-process mode and restoring the intended behavior.

Differential Revision: https://phabricator.services.mozilla.com/D8005

--HG--
extra : rebase_source : 129f3d4e3cdd3673251ed7a3cc58101dd3cb0c91
2018-10-23 15:29:09 +01:00

51 lines
1.6 KiB
JavaScript

function wait_while_tab_is_busy() {
return new Promise(resolve => {
let progressListener = {
onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
gBrowser.removeProgressListener(this);
setTimeout(resolve, 0);
}
},
};
gBrowser.addProgressListener(progressListener);
});
}
// This function waits for the tab to stop being busy instead of waiting for it
// to load, since the _elementsForViewSource change happens at that time.
var with_new_tab_opened = async function(options, taskFn) {
let busyPromise = wait_while_tab_is_busy();
let tab = await BrowserTestUtils.openNewForegroundTab(options.gBrowser, options.url, false);
await busyPromise;
await taskFn(tab.linkedBrowser);
gBrowser.removeTab(tab);
};
add_task(async function test_regular_page() {
function test_expect_view_source_enabled(browser) {
for (let element of [...XULBrowserWindow._elementsForViewSource]) {
ok(!element.hasAttribute("disabled"),
"View Source should be enabled");
}
}
await with_new_tab_opened({
gBrowser,
url: "http://example.com",
}, test_expect_view_source_enabled);
});
add_task(async function test_view_source_page() {
function test_expect_view_source_disabled(browser) {
for (let element of [...XULBrowserWindow._elementsForViewSource]) {
ok(element.hasAttribute("disabled"),
"View Source should be disabled");
}
}
await with_new_tab_opened({
gBrowser,
url: "view-source:http://example.com",
}, test_expect_view_source_disabled);
});