Bug 1219504 - Test changes (r=Gijs,mconley,jryans,MattN,Mossop)

This commit is contained in:
Bill McCloskey 2015-10-28 16:50:25 -07:00
parent 2e51589db8
commit cbca5a7c3e
39 changed files with 520 additions and 514 deletions

View File

@ -70,12 +70,8 @@ function loadTabInWindow(win, callback) {
info("Loading tab");
let url = "http://user:pass@example.com/";
let tab = win.gBrowser.selectedTab = win.gBrowser.addTab(url);
tab.linkedBrowser.addEventListener("load", function listener() {
BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, url).then(() => {
info("Tab loaded");
if (tab.linkedBrowser.currentURI.spec != url)
return;
tab.linkedBrowser.removeEventListener("load", listener, true);
is(win.gURLBar.textValue, "example.com", "URL bar had user/pass stripped initially");
callback(tab);
}, true);

View File

@ -2,9 +2,7 @@ function test () {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function () {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => {
let doc = gBrowser.contentDocument;
let tooltip = document.getElementById("aHTMLTooltip");
@ -35,9 +33,10 @@ function test () {
gBrowser.removeCurrentTab();
finish();
}, true);
});
content.location =
"http://mochi.test:8888/browser/browser/base/content/test/general/title_test.svg";
gBrowser.loadURI(
"http://mochi.test:8888/browser/browser/base/content/test/general/title_test.svg"
);
}

View File

@ -4,9 +4,7 @@
function test () {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function () {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => {
let doc = gBrowser.contentDocument;
let tooltip = document.getElementById("aHTMLTooltip");
@ -15,9 +13,10 @@ function test () {
gBrowser.removeCurrentTab();
finish();
}, true);
});
content.location =
"http://mochi.test:8888/browser/browser/base/content/test/general/xul_tooltiptext.xhtml";
gBrowser.loadURI(
"http://mochi.test:8888/browser/browser/base/content/test/general/xul_tooltiptext.xhtml"
);
}

View File

@ -1,42 +1,63 @@
function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
// Navigate to a site with a broken cert
window.addEventListener("DOMContentLoaded", testBrokenCert, true);
content.location = "https://nocert.example.com/";
function remote(task) {
return ContentTask.spawn(gBrowser.selectedBrowser, null, task);
}
function testBrokenCert() {
if (gBrowser.contentDocument.documentURI === "about:blank")
return;
window.removeEventListener("DOMContentLoaded", testBrokenCert, true);
add_task(function* () {
gBrowser.selectedTab = gBrowser.addTab();
let promise = remote(function () {
return ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", true, event => {
return content.document.documentURI != "about:blank";
}).then(() => 0); // don't want to send the event to the chrome process
});
gBrowser.loadURI("https://nocert.example.com/");
yield promise;
let uri = yield remote(() => {
return content.document.documentURI;
});
// Confirm that we are displaying the contributed error page, not the default
ok(gBrowser.contentDocument.documentURI.startsWith("about:certerror"), "Broken page should go to about:certerror, not about:neterror");
ok(uri.startsWith("about:certerror"), "Broken page should go to about:certerror, not about:neterror");
let advancedDiv, advancedDivVisibility, technicalDivCollapsed;
[advancedDiv, advancedDivVisibility] = yield remote(() => {
let div = content.document.getElementById("advancedPanel");
if (div) {
return [true, div.ownerDocument.defaultView.getComputedStyle(div, "").visibility];
} else {
return [null, null];
}
});
// Confirm that the expert section is collapsed
var advancedDiv = gBrowser.contentDocument.getElementById("advancedPanel");
ok(advancedDiv, "Advanced content div should exist");
is_element_hidden(advancedDiv, "Advanced content should not be visible by default");
is(advancedDivVisibility, "hidden", "Advanced content should not be visible by default");
// Tweak the expert mode pref
gPrefService.setBoolPref("browser.xul.error_pages.expert_bad_cert", true);
window.addEventListener("DOMContentLoaded", testExpertPref, true);
promise = remote(function () {
return ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", true);
});
gBrowser.reload();
}
yield promise;
[advancedDiv, advancedDivVisibility] = yield remote(() => {
let div = content.document.getElementById("advancedPanel");
if (div) {
return [true, div.ownerDocument.defaultView.getComputedStyle(div, "").visibility];
} else {
return [null, null];
}
});
function testExpertPref() {
window.removeEventListener("DOMContentLoaded", testExpertPref, true);
var advancedDiv = gBrowser.contentDocument.getElementById("advancedPanel");
ok(advancedDiv, "Advanced content div should exist");
is_element_visible(advancedDiv, "Advanced content should be visible by default");
is(advancedDivVisibility, "visible", "Advanced content should be visible by default");
// Clean up
gBrowser.removeCurrentTab();
if (gPrefService.prefHasUserValue("browser.xul.error_pages.expert_bad_cert"))
gPrefService.clearUserPref("browser.xul.error_pages.expert_bad_cert");
finish();
}
});

View File

@ -2,15 +2,16 @@ function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function () {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => {
is(document.getElementById("identity-box").className,
"unknownIdentity mixedDisplayContent",
"identity box has class name for mixed content");
gBrowser.removeCurrentTab();
finish();
}, true);
});
content.location = "https://example.com/browser/browser/base/content/test/general/test_bug435035.html";
gBrowser.loadURI(
"https://example.com/browser/browser/base/content/test/general/test_bug435035.html"
);
}

View File

@ -30,16 +30,16 @@ function test() {
// Start the sub-document load.
let deferred = Promise.defer();
executeSoon(function () {
testBrowser.addEventListener("load", function (e) {
testBrowser.removeEventListener("load", arguments.callee, true);
is(e.target.defaultView.location, TEST_IFRAME_URL, "got the load event for the iframe");
BrowserTestUtils.browserLoaded(testBrowser, true).then(url => {
is(url, TEST_IFRAME_URL, "got the load event for the iframe");
is(ZoomManager.zoom, zoomLevel, "zoom is retained after sub-document load");
FullZoomHelper.removeTabAndWaitForLocationChange().
then(() => deferred.resolve());
}, true);
content.document.querySelector("iframe").src = TEST_IFRAME_URL;
});
ContentTask.spawn(testBrowser, TEST_IFRAME_URL, url => {
content.document.querySelector("iframe").src = url;
});
});
yield deferred.promise;
}).then(finish, FullZoomHelper.failAndContinue(finish));

View File

@ -803,12 +803,9 @@ function test_urlbar() {
function test_wronghost() {
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.addEventListener("load", function() {
if (gBrowser.currentURI.spec != TESTROOT2 + "enabled.html")
return;
gBrowser.removeEventListener("load", arguments.callee, true);
let requestedUrl = TESTROOT2 + "enabled.html";
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, requestedUrl).then(() => {
// Wait for the progress notification
wait_for_progress_notification(function(aPanel) {
// Wait for the complete notification
@ -825,7 +822,7 @@ function test_wronghost() {
});
gBrowser.loadURI(TESTROOT + "corrupt.xpi");
}, true);
});
gBrowser.loadURI(TESTROOT2 + "enabled.html");
},
@ -848,12 +845,8 @@ function test_reload() {
PopupNotifications.panel.addEventListener("popuphiding", test_fail, false);
gBrowser.addEventListener("load", function() {
if (gBrowser.currentURI.spec != TESTROOT2 + "enabled.html")
return;
gBrowser.removeEventListener("load", arguments.callee, true);
let requestedUrl = TESTROOT2 + "enabled.html";
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, requestedUrl).then(() => {
PopupNotifications.panel.removeEventListener("popuphiding", test_fail, false);
AddonManager.getAllInstalls(function(aInstalls) {
@ -864,7 +857,7 @@ function test_reload() {
wait_for_notification_close(runNextTest);
gBrowser.removeTab(gBrowser.selectedTab);
});
}, true);
});
gBrowser.loadURI(TESTROOT2 + "enabled.html");
});

View File

@ -1,9 +1,7 @@
function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function () {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => {
let doc = gBrowser.contentDocument;
let tooltip = document.getElementById("aHTMLTooltip");
let i = doc.getElementById("i");
@ -21,9 +19,10 @@ function test() {
gBrowser.removeCurrentTab();
finish();
}, true);
});
content.location =
"data:text/html,<!DOCTYPE html><html><body><input id='i'></body></html>";
gBrowser.loadURI(
"data:text/html,<!DOCTYPE html><html><body><input id='i'></body></html>"
);
}

View File

@ -14,13 +14,11 @@ function test() {
is(gURLBar.value, URI, "location bar value matches test URI after switching tabs");
waitForExplicitFinish();
gBrowser.selectedBrowser.addEventListener("load", function () {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => {
is(gBrowser.userTypedValue, null, "userTypedValue is null as the page has loaded");
is(gURLBar.value, URI, "location bar value matches test URI as the page has loaded");
gBrowser.removeCurrentTab();
finish();
}, true);
});
}

View File

@ -8,19 +8,18 @@ function test() {
let uriObj = Services.io.newURI(uriString, null, null)
let cp = Components.classes["@mozilla.org/cookie/permission;1"]
.getService(Components.interfaces.nsICookiePermission);
Services.prefs.setIntPref(cookieBehavior, 2);
cp.setAccess(uriObj, cp.ACCESS_ALLOW);
gBrowser.selectedTab = gBrowser.addTab(uriString);
waitForExplicitFinish();
gBrowser.selectedBrowser.addEventListener("load", onTabLoaded, true);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(onTabLoaded);
function onTabLoaded() {
is(gBrowser.selectedBrowser.contentWindow.navigator.cookieEnabled, true,
"navigator.cookieEnabled should be true");
// Clean up
gBrowser.selectedBrowser.removeEventListener("load", onTabLoaded, true);
gBrowser.removeTab(gBrowser.selectedTab);
Services.prefs.setIntPref(cookieBehavior, 0);
cp.setAccess(uriObj, cp.ACCESS_DEFAULT);

View File

@ -5,8 +5,8 @@
function test() {
let newTab = gBrowser.addTab();
waitForExplicitFinish();
newTab.linkedBrowser.addEventListener("load", mainPart, true);
BrowserTestUtils.browserLoaded(newTab.linkedBrowser).then(mainPart);
function mainPart() {
gBrowser.pinTab(newTab);
gBrowser.selectedTab = newTab;
@ -20,7 +20,6 @@ function test() {
openUILinkIn("http://example.org/", "current");
is(gBrowser.tabs.length, 3, "Should open in new tab");
newTab.removeEventListener("load", mainPart, true);
gBrowser.removeTab(newTab);
gBrowser.removeTab(gBrowser.tabs[1]); // example.org tab
finish();

View File

@ -17,12 +17,10 @@ function test() {
var tab = gBrowser.addTab("http://mochi.test:8888/");
var browser = gBrowser.getBrowserForTab(tab);
browser.addEventListener("load", function() {
browser.removeEventListener("load", arguments.callee, true);
BrowserTestUtils.browserLoaded(browser).then(() => {
BrowserTestUtils.removeTab(tab).then(() => {
ok(isUndoCloseEnabled(), "Undo Close Tab should be enabled.");
finish();
});
}, true);
});
}

View File

@ -58,9 +58,7 @@ function todo_check(aElementName, aBarred) {
function test () {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function () {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => {
let testData = [
/* element name, barred */
[ 'input', false, null],
@ -87,9 +85,10 @@ function test () {
gBrowser.removeCurrentTab();
finish();
}, true);
});
content.location =
"data:text/html,<!DOCTYPE html><html><body><form id='content'></form></body></html>";
gBrowser.loadURI(
"data:text/html,<!DOCTYPE html><html><body><form id='content'></form></body></html>"
);
}

View File

@ -5,11 +5,9 @@
function test() {
let newTab = gBrowser.addTab("http://example.com");
waitForExplicitFinish();
newTab.linkedBrowser.addEventListener("load", mainPart, true);
BrowserTestUtils.browserLoaded(newTab.linkedBrowser).then(mainPart);
function mainPart() {
newTab.linkedBrowser.removeEventListener("load", mainPart, true);
gBrowser.pinTab(newTab);
gBrowser.selectedTab = newTab;

View File

@ -17,15 +17,13 @@ function test() {
waitForExplicitFinish();
let tab = gBrowser.selectedTab = gBrowser.addTab();
tab.linkedBrowser.addEventListener("load", (function(event) {
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => {
if (BookmarkingUI.status == BookmarkingUI.STATUS_UPDATING) {
waitForCondition(() => BookmarkingUI.status != BookmarkingUI.STATUS_UPDATING, finishTest, "BookmarkingUI was updating for too long");
} else {
finishTest();
}
}), true);
});
tab.linkedBrowser.loadURI("http://example.com/browser/browser/base/content/test/general/dummy_page.html");
}

View File

@ -4,17 +4,12 @@
function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedTab = gBrowser.addTab("data:text/html,<iframe width='700' height='700' src='about:certerror'></iframe>");
// Open a html page with about:certerror in an iframe
gBrowser.selectedBrowser.addEventListener("load", testIframeCert, true);
content.location = "data:text/html,<iframe width='700' height='700' src='about:certerror'></iframe>";
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(testIframeCert);
}
function testIframeCert(e) {
if (e.target.location.href == "about:blank") {
return;
}
gBrowser.selectedBrowser.removeEventListener("load", testIframeCert, true);
// Confirm that the expert section is hidden
var doc = gBrowser.contentDocument.getElementsByTagName('iframe')[0].contentDocument;
var aP = doc.getElementById("advancedPanel");

View File

@ -3,14 +3,7 @@ function test () {
var isHTTPS = false;
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function () {
if (isHTTPS) {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
}
let doc = gBrowser.contentDocument;
function loadListener() {
function testLocation(link, url, next) {
var tabOpenListener = new TabOpenListener(url, function () {
gBrowser.removeTab(this.tab);
@ -18,18 +11,26 @@ function test () {
next();
});
doc.getElementById(link).click();
ContentTask.spawn(gBrowser.selectedBrowser, link, link => {
content.document.getElementById(link).click();
});
}
function testLink(link, name, next) {
addWindowListener("chrome://mozapps/content/downloads/unknownContentType.xul", function (win) {
is(doc.getElementById("unload-flag").textContent, "Okay", "beforeunload shouldn't have fired");
is(win.document.getElementById("location").value, name, "file name should match");
win.close();
next();
addWindowListener("chrome://mozapps/content/downloads/unknownContentType.xul", function (win) {
ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
return content.document.getElementById("unload-flag").textContent;
}).then(unloadFlag => {
is(unloadFlag, "Okay", "beforeunload shouldn't have fired");
is(win.document.getElementById("location").value, name, "file name should match");
win.close();
next();
});
});
doc.getElementById(link).click();
ContentTask.spawn(gBrowser.selectedBrowser, link, link => {
content.document.getElementById(link).click();
});
}
testLink("link1", "test.txt",
@ -41,18 +42,22 @@ function test () {
testLocation.bind(null, "link7", "http://example.com/",
function () {
if (isHTTPS) {
gBrowser.removeCurrentTab();
finish();
} else {
// same test again with https:
isHTTPS = true;
content.location = "https://example.com:443/browser/browser/base/content/test/general/download_page.html";
gBrowser.loadURI("https://example.com:443/browser/browser/base/content/test/general/download_page.html");
}
})))))));
}, true);
}
content.location = "http://mochi.test:8888/browser/browser/base/content/test/general/download_page.html";
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => {
loadListener();
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(loadListener);
});
gBrowser.loadURI("http://mochi.test:8888/browser/browser/base/content/test/general/download_page.html");
}
@ -97,15 +102,12 @@ TabOpenListener.prototype = {
gBrowser.tabContainer.removeEventListener("TabOpen", this, false);
this.tab = event.originalTarget;
this.browser = this.tab.linkedBrowser;
gBrowser.addEventListener("pageshow", this, false);
} else if (event.type == "pageshow") {
if (event.target.location.href != this.url)
return;
gBrowser.removeEventListener("pageshow", this, false);
this.tab.addEventListener("TabClose", this, false);
var url = this.browser.contentDocument.location.href;
is(url, this.url, "Should have opened the correct tab");
this.opencallback(this.tab, this.browser.contentWindow);
BrowserTestUtils.browserLoaded(this.browser, false, this.url).then(() => {
this.tab.addEventListener("TabClose", this, false);
var url = this.browser.currentURI.spec;
is(url, this.url, "Should have opened the correct tab");
this.opencallback();
});
} else if (event.type == "TabClose") {
if (event.originalTarget != this.tab)
return;

View File

@ -45,10 +45,7 @@ function cleanUpAfterTests() {
//------------------------ Test 1 ------------------------------
function test1A() {
// Removing EventListener because we have to register a new
// one once the page is loaded with mixed content blocker disabled
gTestBrowser.removeEventListener("load", test1A, true);
gTestBrowser.addEventListener("load", test1B, true);
BrowserTestUtils.browserLoaded(gTestBrowser).then(test1B);
assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
@ -65,21 +62,18 @@ function test1B() {
}
function test1C() {
gTestBrowser.removeEventListener("load", test1B, true);
var actual = content.document.getElementById('mctestdiv').innerHTML;
is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1C");
// The Script loaded after we disabled the page, now we are going to reload the
// page and see if our decision is persistent
gTestBrowser.addEventListener("load", test1D, true);
BrowserTestUtils.browserLoaded(gTestBrowser).then(test1D);
var url = gHttpTestRoot1 + "file_bug902156_2.html";
gTestBrowser.contentWindow.location = url;
gTestBrowser.loadURI(url);
}
function test1D() {
gTestBrowser.removeEventListener("load", test1D, true);
// The Control Center button should appear but isMixedContentBlocked should be NOT true,
// because our decision of disabling the mixed content blocker is persistent.
assertMixedContentBlockingState(gTestBrowser, {activeLoaded: true, activeBlocked: false, passiveLoaded: false});
@ -94,16 +88,13 @@ function test1D() {
//------------------------ Test 2 ------------------------------
function test2() {
gTestBrowser.addEventListener("load", test2A, true);
BrowserTestUtils.browserLoaded(gTestBrowser).then(test2A);
var url = gHttpTestRoot2 + "file_bug902156_2.html";
gTestBrowser.contentWindow.location = url;
gTestBrowser.loadURI(url);
}
function test2A() {
// Removing EventListener because we have to register a new
// one once the page is loaded with mixed content blocker disabled
gTestBrowser.removeEventListener("load", test2A, true);
gTestBrowser.addEventListener("load", test2B, true);
BrowserTestUtils.browserLoaded(gTestBrowser).then(test2B);
assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
@ -120,13 +111,12 @@ function test2B() {
}
function test2C() {
gTestBrowser.removeEventListener("load", test2B, true);
var actual = content.document.getElementById('mctestdiv').innerHTML;
is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 2C");
// The Script loaded after we disabled the page, now we are going to reload the
// page and see if our decision is persistent
gTestBrowser.addEventListener("load", test2D, true);
BrowserTestUtils.browserLoaded(gTestBrowser).then(test2D);
// reload the page using the provided link in the html file
var mctestlink = content.document.getElementById("mctestlink");
@ -134,8 +124,6 @@ function test2C() {
}
function test2D() {
gTestBrowser.removeEventListener("load", test2D, true);
// The Control Center button should appear but isMixedContentBlocked should be NOT true,
// because our decision of disabling the mixed content blocker is persistent.
assertMixedContentBlockingState(gTestBrowser, {activeLoaded: true, activeBlocked: false, passiveLoaded: false});
@ -150,16 +138,12 @@ function test2D() {
//------------------------ Test 3 ------------------------------
function test3() {
gTestBrowser.addEventListener("load", test3A, true);
BrowserTestUtils.browserLoaded(gTestBrowser).then(test3A);
var url = gHttpTestRoot1 + "file_bug902156_3.html";
gTestBrowser.contentWindow.location = url;
gTestBrowser.loadURI(url);
}
function test3A() {
// Removing EventListener because we have to register a new
// one once the page is loaded with mixed content blocker disabled
gTestBrowser.removeEventListener("load", test3A, true);
assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
// We are done with tests, clean up
@ -184,7 +168,7 @@ function test() {
newTab.linkedBrowser.stop()
// Starting Test Number 1:
gTestBrowser.addEventListener("load", test1A, true);
BrowserTestUtils.browserLoaded(gTestBrowser).then(test1A);
var url = gHttpTestRoot1 + "file_bug902156_1.html";
gTestBrowser.contentWindow.location = url;
gTestBrowser.loadURI(url);
}

View File

@ -3,32 +3,27 @@
// Tests find bar auto-close behavior
var newTab, iframe;
var newTab;
function test() {
add_task(function* findbar_test() {
waitForExplicitFinish();
newTab = gBrowser.addTab("about:blank");
newTab.linkedBrowser.addEventListener("DOMContentLoaded",
prepareTestFindBarStaysOpenOnSubdocumentLocationChange, false);
newTab.linkedBrowser.contentWindow.location = "http://example.com/browser/" +
"browser/base/content/test/general/test_bug628179.html";
}
function prepareTestFindBarStaysOpenOnSubdocumentLocationChange() {
newTab.linkedBrowser.removeEventListener("DOMContentLoaded",
prepareTestFindBarStaysOpenOnSubdocumentLocationChange, false);
let promise = ContentTask.spawn(newTab.linkedBrowser, null, function* () {
yield ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", false);
});
newTab.linkedBrowser.loadURI("http://example.com/browser/" +
"browser/base/content/test/general/test_bug628179.html");
yield promise;
gFindBar.open();
iframe = newTab.linkedBrowser.contentDocument.getElementById("iframe");
iframe.addEventListener("load",
testFindBarStaysOpenOnSubdocumentLocationChange, false);
iframe.src = "http://example.org/";
}
function testFindBarStaysOpenOnSubdocumentLocationChange() {
iframe.removeEventListener("load",
testFindBarStaysOpenOnSubdocumentLocationChange, false);
yield new ContentTask.spawn(newTab.linkedBrowser, null, function* () {
let iframe = content.document.getElementById("iframe");
let promise = ContentTaskUtils.waitForEvent(iframe, "load", false);
iframe.src = "http://example.org/";
yield promise;
});
ok(!gFindBar.hidden, "the Find bar isn't hidden after the location of a " +
"subdocument changes");
@ -36,5 +31,5 @@ function testFindBarStaysOpenOnSubdocumentLocationChange() {
gFindBar.close();
gBrowser.removeTab(newTab);
finish();
}
});

View File

@ -3,17 +3,16 @@ function test() {
gPrefService.setBoolPref("dom.disable_open_during_load", false);
var browser = gBrowser.selectedBrowser;
browser.addEventListener("load", function () {
browser.removeEventListener("load", arguments.callee, true);
BrowserTestUtils.browserLoaded(browser).then(() => {
if (gPrefService.prefHasUserValue("dom.disable_open_during_load"))
gPrefService.clearUserPref("dom.disable_open_during_load");
findPopup();
}, true);
});
content.location =
"data:text/html,<html><script>popup=open('about:blank','','width=300,height=200')</script>";
browser.loadURI(
"data:text/html,<html><script>popup=open('about:blank','','width=300,height=200')</script>"
);
}
function findPopup() {

View File

@ -41,22 +41,20 @@ function test_getBoolPref() {
function test_openNewTabWith() {
openNewTabWith("http://example.com/");
let tab = gBrowser.selectedTab = gBrowser.tabs[1];
tab.linkedBrowser.addEventListener("load", function onLoad(event) {
tab.linkedBrowser.removeEventListener("load", onLoad, true);
BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => {
is(tab.linkedBrowser.currentURI.spec, "http://example.com/", "example.com loaded");
gBrowser.removeCurrentTab();
runNextTest();
}, true);
});
}
function test_openUILink() {
let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
tab.linkedBrowser.addEventListener("load", function onLoad(event) {
tab.linkedBrowser.removeEventListener("load", onLoad, true);
BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => {
is(tab.linkedBrowser.currentURI.spec, "http://example.org/", "example.org loaded");
gBrowser.removeCurrentTab();
runNextTest();
}, true);
});
openUILink("http://example.org/"); // defaults to "current"
}

View File

@ -6,7 +6,7 @@ function test() {
/** Test for Bug 522545 **/
waitForExplicitFinish();
requestLongerTimeout(2);
requestLongerTimeout(3);
// This tests the following use case:
// User opens a new tab which gets focus. The user types something into the
@ -159,12 +159,10 @@ function test() {
ok(hasUTV, "At least one tab has a userTypedValue with userTypedClear with no loaded URL");
gBrowser.addEventListener("load", firstLoad, true);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(firstLoad);
}
function firstLoad() {
gBrowser.removeEventListener("load", firstLoad, true);
let state = JSON.parse(ss.getBrowserState());
let hasSH = state.windows[0].tabs.some(function(aTab) {
return !("userTypedValue" in aTab) && aTab.entries[0].url;

View File

@ -9,12 +9,10 @@ function test()
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", onLoad, true);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(onLoad);
}
function onLoad(evt) {
gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
function onLoad() {
target = TargetFactory.forTab(gBrowser.selectedTab);
is(target.tab, gBrowser.selectedTab, "Target linked to the right tab.");

View File

@ -131,26 +131,22 @@ function* testTheBasics(widget) {
*/
function checkLinkClick(link) {
function loadListener(e) {
let tab = e.target;
function loadListener(tab) {
var browser = getBrowser().getBrowserForTab(tab);
var uri = browser.currentURI.spec;
// this is horrible, and it's because when we open a new tab
// "about:blank: is first loaded into it, before the actual
// document we want to load.
if (uri != "about:blank") {
info("New browser tab has loaded");
tab.removeEventListener("load", loadListener);
gBrowser.removeTab(tab);
info("Resolve promise with new tab URI");
deferred.resolve(uri);
}
info("New browser tab has loaded");
gBrowser.removeTab(tab);
info("Resolve promise with new tab URI");
deferred.resolve(uri);
}
function newTabListener(e) {
gBrowser.tabContainer.removeEventListener("TabOpen", newTabListener);
var tab = e.target;
tab.addEventListener("load", loadListener, false);
BrowserTestUtils.browserLoaded(tab.linkedBrowser, false,
url => { return url != "about:blank"; })
.then(url => loadListener(tab));
}
let deferred = promise.defer();

View File

@ -27,17 +27,16 @@ function addTab(aURL, aCallback)
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
content.location = aURL;
let tab = gBrowser.selectedTab;
let browser = gBrowser.getBrowserForTab(tab);
function onTabLoad() {
browser.removeEventListener("load", onTabLoad, true);
aCallback(browser, tab, browser.contentDocument);
}
let url = encodeURI(aURL);
browser.addEventListener("load", onTabLoad, true);
BrowserTestUtils.browserLoaded(browser, false, url).then(() => {
aCallback(browser, tab, browser.contentDocument);
});
browser.loadURI(url);
}
function promiseTab(aURL) {

View File

@ -123,12 +123,11 @@ var doc = null;
function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function onload() {
gBrowser.selectedBrowser.removeEventListener("load", onload, true);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => {
doc = content.document;
runTests();
}, true);
content.location = TEST_URI;
});
gBrowser.loadURI(TEST_URI);
}
function runTests() {

View File

@ -58,13 +58,11 @@ const TEST_URI = "data:text/html;charset=UTF-8," + encodeURIComponent(
var doc = null;
function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function onload() {
gBrowser.selectedBrowser.removeEventListener("load", onload, true);
gBrowser.selectedTab = gBrowser.addTab(TEST_URI);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => {
doc = content.document;
runTests();
}, true);
content.location = TEST_URI;
});
}
function runTests() {

View File

@ -1,31 +1,37 @@
/* Make sure that netError won't allow HTML injection through badcert parameters. See bug 441169. */
var newBrowser
// An edited version of the standard neterror url which attempts to
// insert a <span id="test_span"> tag into the text. We will navigate to this page
// and ensure that the span tag is not parsed as HTML.
var chromeURL = "about:neterror?e=nssBadCert&u=https%3A//test.kuix.de/&c=UTF-8&d=This%20sentence%20should%20not%20be%20parsed%20to%20include%20a%20%3Cspan%20id=%22test_span%22%3Enamed%3C/span%3E%20span%20tag.%0A%0AThe%20certificate%20is%20only%20valid%20for%20%3Ca%20id=%22cert_domain_link%22%20title=%22kuix.de%22%3Ekuix.de%3C/a%3E%0A%0A(Error%20code%3A%20ssl_error_bad_cert_domain)";
function task() {
let resolve;
let promise = new Promise(r => { resolve = r; });
addEventListener("DOMContentLoaded", checkPage, false);
function checkPage(event) {
if (event.target != content.document) {
return;
}
removeEventListener("DOMContentLoaded", checkPage, false);
is(content.document.getElementById("test_span"), null, "Error message should not be parsed as HTML, and hence shouldn't include the 'test_span' element.");
resolve();
}
var chromeURL = "about:neterror?e=nssBadCert&u=https%3A//test.kuix.de/&c=UTF-8&d=This%20sentence%20should%20not%20be%20parsed%20to%20include%20a%20%3Cspan%20id=%22test_span%22%3Enamed%3C/span%3E%20span%20tag.%0A%0AThe%20certificate%20is%20only%20valid%20for%20%3Ca%20id=%22cert_domain_link%22%20title=%22kuix.de%22%3Ekuix.de%3C/a%3E%0A%0A(Error%20code%3A%20ssl_error_bad_cert_domain)";
content.location = chromeURL;
return promise;
}
function test() {
waitForExplicitFinish();
var newTab = gBrowser.addTab();
gBrowser.selectedTab = newTab;
newBrowser = gBrowser.getBrowserForTab(newTab);
window.addEventListener("DOMContentLoaded", checkPage, false);
newBrowser.contentWindow.location = chromeURL;
}
function checkPage(event) {
if (event.target != gBrowser.selectedBrowser.contentDocument) {
return;
}
window.removeEventListener("DOMContentLoaded", checkPage, false);
is(newBrowser.contentDocument.getElementById("test_span"), null, "Error message should not be parsed as HTML, and hence shouldn't include the 'test_span' element.");
gBrowser.removeCurrentTab();
finish();
ContentTask.spawn(newBrowser, null, task).then(() => {
gBrowser.removeCurrentTab();
finish();
});
}

View File

@ -14,9 +14,7 @@ function test() {
let tab = gBrowser.addTab('http://example.com');
let tabBrowser = tab.linkedBrowser;
tabBrowser.addEventListener('load', function(aEvent) {
tabBrowser.removeEventListener('load', arguments.callee, true);
BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => {
let cw = tabBrowser.contentWindow;
let oldTitle = cw.document.title;
ok(oldTitle, 'Content window should initially have a title.');
@ -31,5 +29,5 @@ function test() {
gBrowser.removeTab(tab);
finish();
}, true);
});
}

View File

@ -29,10 +29,9 @@ function runPass(getterFile, finishedCallback) {
// First, set the cookie in a normal window.
gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug1108547-1.html");
gBrowser.selectedBrowser.addEventListener("load", afterOpenCookieSetter, true);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(afterOpenCookieSetter);
function afterOpenCookieSetter() {
gBrowser.selectedBrowser.removeEventListener("load", afterOpenCookieSetter, true);
gBrowser.removeCurrentTab();
// Now, open a private window.
@ -47,18 +46,21 @@ function runPass(getterFile, finishedCallback) {
privateWin.gBrowser.tabContainer.addEventListener("TabOpen", onNewTabOpened, true);
}
function fetchResult() {
return ContentTask.spawn(testBrowser, null, function() {
return content.document.getElementById("result").textContent;
});
}
function onNewTabOpened() {
// When the new tab is opened, wait for it to load.
privateWin.gBrowser.tabContainer.removeEventListener("TabOpen", onNewTabOpened, true);
privateWin.gBrowser.tabs[privateWin.gBrowser.tabs.length - 1].linkedBrowser.addEventListener("load", onNewTabLoaded, true);
BrowserTestUtils.browserLoaded(privateWin.gBrowser.tabs[privateWin.gBrowser.tabs.length - 1].linkedBrowser).then(fetchResult).then(onNewTabLoaded);
}
function onNewTabLoaded() {
privateWin.gBrowser.tabs[privateWin.gBrowser.tabs.length - 1].linkedBrowser.removeEventListener("load", onNewTabLoaded, true);
function onNewTabLoaded(result) {
// Now, ensure that the private tab doesn't have access to the cookie set in normal mode.
is(testBrowser.contentDocument.getElementById("result").textContent, "",
"Shouldn't have access to the cookies");
is(result, "", "Shouldn't have access to the cookies");
// We're done with the private window, close it.
privateWin.close();
@ -74,7 +76,7 @@ function runPass(getterFile, finishedCallback) {
function afterPrivateWindowOpened2() {
// In the private window, open the setter file, and wait for it to load.
privateWin.gBrowser.selectedTab = privateWin.gBrowser.addTab(rootDir + "file_bug1108547-1.html");
privateWin.gBrowser.selectedBrowser.addEventListener("load", afterOpenCookieSetter2, true);
BrowserTestUtils.browserLoaded(privateWin.gBrowser.selectedBrowser).then(afterOpenCookieSetter2);
}
function afterOpenCookieSetter2() {
@ -90,15 +92,12 @@ function runPass(getterFile, finishedCallback) {
function onNewTabOpened2() {
// When the new tab is opened, wait for it to load.
gBrowser.tabContainer.removeEventListener("TabOpen", onNewTabOpened2, true);
gBrowser.tabs[gBrowser.tabs.length - 1].linkedBrowser.addEventListener("load", onNewTabLoaded2, true);
BrowserTestUtils.browserLoaded(gBrowser.tabs[gBrowser.tabs.length - 1].linkedBrowser).then(fetchResult).then(onNewTabLoaded2);
}
function onNewTabLoaded2() {
gBrowser.tabs[gBrowser.tabs.length - 1].linkedBrowser.removeEventListener("load", onNewTabLoaded2, true);
function onNewTabLoaded2(result) {
// Now, ensure that the normal tab doesn't have access to the cookie set in private mode.
is(testBrowser.contentDocument.getElementById("result").textContent, "",
"Shouldn't have access to the cookies");
is(result, "", "Shouldn't have access to the cookies");
// Remove both of the tabs opened here.
gBrowser.removeCurrentTab();

View File

@ -12,6 +12,18 @@ function forceRefresh() {
EventUtils.synthesizeKey('R', { accelKey: true, shiftKey: true });
}
function frameScript() {
function eventHandler(event) {
sendAsyncMessage("test:event", {type: event.type});
}
// These are tab-local, so no need to unregister them.
addEventListener('base-load', eventHandler, true, true);
addEventListener('base-register', eventHandler, true, true);
addEventListener('base-sw-ready', eventHandler, true, true);
addEventListener('cached-load', eventHandler, true, true);
}
function test() {
waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [['dom.serviceWorkers.enabled', true],
@ -21,24 +33,29 @@ function test() {
['dom.caches.enabled', true]]},
function() {
var url = gTestRoot + 'browser_base_force_refresh.html';
var tab = gBrowser.addTab(url);
var tab = gBrowser.addTab();
gBrowser.selectedTab = tab;
tab.linkedBrowser.messageManager.loadFrameScript("data:,(" + encodeURIComponent(frameScript) + ")()", true);
gBrowser.loadURI(url);
var cachedLoad = false;
function eventHandler(event) {
if (event.type === 'base-load') {
function eventHandler(msg) {
if (msg.data.type === 'base-load') {
if (cachedLoad) {
tab.linkedBrowser.messageManager.removeMessageListener("test:event", eventHandler);
gBrowser.removeTab(tab);
executeSoon(finish);
}
} else if (event.type === 'base-register') {
} else if (msg.data.type === 'base-register') {
ok(!cachedLoad, 'cached load should not occur before base register');
refresh();
} else if (event.type === 'base-sw-ready') {
} else if (msg.data.type === 'base-sw-ready') {
ok(!cachedLoad, 'cached load should not occur before base ready');
refresh();
} else if (event.type === 'cached-load') {
} else if (msg.data.type === 'cached-load') {
ok(!cachedLoad, 'cached load should not occur twice');
cachedLoad = true;
forceRefresh();
@ -47,9 +64,6 @@ function test() {
return;
}
addEventListener('base-load', eventHandler, true, true);
addEventListener('base-register', eventHandler, true, true);
addEventListener('base-sw-ready', eventHandler, true, true);
addEventListener('cached-load', eventHandler, true, true);
tab.linkedBrowser.messageManager.addMessageListener("test:event", eventHandler);
});
}

View File

@ -36,6 +36,17 @@ var gWin;
var gBrowser;
var ok, is, info;
function removeTab(tab, done)
{
// Remove the tab in a different turn of the event loop. This way
// the nested event loop in removeTab doesn't conflict with the
// event listener shims.
gWin.setTimeout(() => {
gBrowser.removeTab(tab);
done();
}, 0);
}
// Make sure that the shims for window.content, browser.contentWindow,
// and browser.contentDocument are working.
function testContentWindow()
@ -56,8 +67,7 @@ function testContentWindow()
// FIXME: Waiting on bug 1073631.
//is(browser.contentWindow.wrappedJSObject.global, 3, "global available on document");
gBrowser.removeTab(tab);
resolve();
removeTab(tab, resolve);
});
});
}
@ -108,8 +118,7 @@ function testListeners()
is(event.target.documentURI, url2, "second load is for second page loaded");
is(loadWithRemoveCount, 1, "load handler is only called once");
gBrowser.removeTab(tab);
resolve();
removeTab(tab, resolve);
}
}, true);
@ -162,8 +171,7 @@ function testCapturing()
gBrowser.removeEventListener("mousedown", capturingHandler, true);
gBrowser.removeEventListener("mousedown", nonCapturingHandler, false);
gBrowser.removeTab(tab);
resolve();
removeTab(tab, resolve);
});
});
}
@ -194,8 +202,7 @@ function testObserver()
is(observerFired, 1, "got observer notification");
gBrowser.removeTab(tab);
resolve();
removeTab(tab, resolve);
}
}, true);
});
@ -232,8 +239,7 @@ function testSandbox()
is(browser.contentDocument.getElementById("output").innerHTML, "hello2",
"EP sandbox code ran successfully");
gBrowser.removeTab(tab);
resolve();
removeTab(tab, resolve);
}, true);
});
}
@ -255,10 +261,8 @@ function testAddonContent()
let tab = gBrowser.addTab(url);
let browser = tab.linkedBrowser;
addLoadListener(browser, function handler() {
gBrowser.removeTab(tab);
res.setSubstitution("addonshim1", null);
resolve();
removeTab(tab, resolve);
});
});
}
@ -501,9 +505,8 @@ function testAboutModuleRegistration()
addLoadListener(browser, function() {
testAboutModulesWork(browser).then(() => {
gBrowser.removeTab(newTab);
unregisterModules();
resolve();
removeTab(newTab, resolve);
});
});
});
@ -545,10 +548,9 @@ function testProgressListener()
ok(sawGlobalLocChange, "Saw global onLocationChange");
ok(sawTabsLocChange, "Saw tabs onLocationChange");
gBrowser.removeTab(tab);
gBrowser.removeProgressListener(globalListener);
gBrowser.removeTabsProgressListener(tabsListener);
resolve();
removeTab(tab, resolve);
});
});
}
@ -572,8 +574,7 @@ function testRootTreeItem()
.getInterface(Components.interfaces.nsIDOMWindow);
is(root, gWin, "got correct chrome window");
gBrowser.removeTab(tab);
resolve();
removeTab(tab, resolve);
});
});
}
@ -598,8 +599,7 @@ function testImportNode()
is(result, node, "got expected import result");
}
gBrowser.removeTab(tab);
resolve();
removeTab(tab, resolve);
});
});
}

View File

@ -1,82 +1,94 @@
const HTML_NS = "http://www.w3.org/1999/xhtml";
const ids = {
INPUT_ID: "input1",
FORM1_ID: "form1",
FORM2_ID: "form2",
CHANGE_INPUT_ID: "input2",
};
const INPUT_ID = "input1";
const FORM1_ID = "form1";
const FORM2_ID = "form2";
const CHANGE_INPUT_ID = "input2";
function task(ids) {
let resolve;
let promise = new Promise(r => { resolve = r; });
function test() {
waitForExplicitFinish();
let tab = gBrowser.selectedTab =
gBrowser.addTab("data:text/html;charset=utf-8," +
"<html><body>" +
"<form id='" + FORM1_ID + "'><input id='" + CHANGE_INPUT_ID + "'></form>" +
"<form id='" + FORM2_ID + "'></form>" +
"</body></html>");
tab.linkedBrowser.addEventListener("load", tabLoad, true);
function unexpectedContentEvent(evt) {
ok(false, "Received a " + evt.type + " event on content");
}
var gDoc = null;
addEventListener("load", tabLoad, true);
function tabLoad() {
if (content.location.href == "about:blank")
return;
removeEventListener("load", tabLoad, true);
gDoc = content.document;
gDoc.addEventListener("DOMFormHasPassword", unexpectedContentEvent, false);
gDoc.defaultView.setTimeout(test_inputAdd, 0);
}
function test_inputAdd() {
addEventListener("DOMFormHasPassword", test_inputAddHandler, false);
let input = gDoc.createElementNS("http://www.w3.org/1999/xhtml", "input");
input.setAttribute("type", "password");
input.setAttribute("id", ids.INPUT_ID);
input.setAttribute("data-test", "unique-attribute");
gDoc.getElementById(ids.FORM1_ID).appendChild(input);
}
function test_inputAddHandler(evt) {
removeEventListener(evt.type, test_inputAddHandler, false);
is(evt.target.id, ids.FORM1_ID,
evt.type + " event targets correct form element (added password element)");
gDoc.defaultView.setTimeout(test_inputChangeForm, 0);
}
function test_inputChangeForm() {
addEventListener("DOMFormHasPassword", test_inputChangeFormHandler, false);
let input = gDoc.getElementById(ids.INPUT_ID);
input.setAttribute("form", ids.FORM2_ID);
}
function test_inputChangeFormHandler(evt) {
removeEventListener(evt.type, test_inputChangeFormHandler, false);
is(evt.target.id, ids.FORM2_ID,
evt.type + " event targets correct form element (changed form)");
gDoc.defaultView.setTimeout(test_inputChangesType, 0);
}
function test_inputChangesType() {
addEventListener("DOMFormHasPassword", test_inputChangesTypeHandler, false);
let input = gDoc.getElementById(ids.CHANGE_INPUT_ID);
input.setAttribute("type", "password");
}
function test_inputChangesTypeHandler(evt) {
removeEventListener(evt.type, test_inputChangesTypeHandler, false);
is(evt.target.id, ids.FORM1_ID,
evt.type + " event targets correct form element (changed type)");
gDoc.defaultView.setTimeout(finish, 0);
}
function finish() {
gDoc.removeEventListener("DOMFormHasPassword", unexpectedContentEvent, false);
resolve();
}
return promise;
}
function unexpectedContentEvent(evt) {
ok(false, "Received a " + evt.type + " event on content");
}
add_task(function* () {
let tab = gBrowser.selectedTab = gBrowser.addTab();
var gDoc = null;
let promise = ContentTask.spawn(tab.linkedBrowser, ids, task);
tab.linkedBrowser.loadURI("data:text/html;charset=utf-8," +
"<html><body>" +
"<form id='" + ids.FORM1_ID + "'>" +
"<input id='" + ids.CHANGE_INPUT_ID + "'></form>" +
"<form id='" + ids.FORM2_ID + "'></form>" +
"</body></html>");
yield promise;
function tabLoad() {
let tab = gBrowser.selectedTab;
tab.linkedBrowser.removeEventListener("load", tabLoad, true);
gDoc = gBrowser.selectedBrowser.contentDocument;
// These events shouldn't escape to content.
gDoc.addEventListener("DOMFormHasPassword", unexpectedContentEvent, false);
gDoc.defaultView.setTimeout(test_inputAdd, 0);
}
function test_inputAdd() {
gBrowser.addEventListener("DOMFormHasPassword", test_inputAddHandler, false);
let input = gDoc.createElementNS(HTML_NS, "input");
input.setAttribute("type", "password");
input.setAttribute("id", INPUT_ID);
input.setAttribute("data-test", "unique-attribute");
gDoc.getElementById(FORM1_ID).appendChild(input);
info("Done appending the input element");
}
function test_inputAddHandler(evt) {
gBrowser.removeEventListener(evt.type, test_inputAddHandler, false);
is(evt.target.id, FORM1_ID,
evt.type + " event targets correct form element (added password element)");
gDoc.defaultView.setTimeout(test_inputChangeForm, 0);
}
function test_inputChangeForm() {
gBrowser.addEventListener("DOMFormHasPassword", test_inputChangeFormHandler, false);
let input = gDoc.getElementById(INPUT_ID);
input.setAttribute("form", FORM2_ID);
}
function test_inputChangeFormHandler(evt) {
gBrowser.removeEventListener(evt.type, test_inputChangeFormHandler, false);
is(evt.target.id, FORM2_ID,
evt.type + " event targets correct form element (changed form)");
gDoc.defaultView.setTimeout(test_inputChangesType, 0);
}
function test_inputChangesType() {
gBrowser.addEventListener("DOMFormHasPassword", test_inputChangesTypeHandler, false);
let input = gDoc.getElementById(CHANGE_INPUT_ID);
input.setAttribute("type", "password");
}
function test_inputChangesTypeHandler(evt) {
gBrowser.removeEventListener(evt.type, test_inputChangesTypeHandler, false);
is(evt.target.id, FORM1_ID,
evt.type + " event targets correct form element (changed type)");
gDoc.defaultView.setTimeout(completeTest, 0);
}
function completeTest() {
ok(true, "Test completed");
gDoc.removeEventListener("DOMFormHasPassword", unexpectedContentEvent, false);
gBrowser.removeCurrentTab();
finish();
}
});

View File

@ -1,87 +1,99 @@
const HTML_NS = "http://www.w3.org/1999/xhtml";
const consts = {
HTML_NS: "http://www.w3.org/1999/xhtml",
const INPUT_ID = "input1";
const FORM1_ID = "form1";
const FORM2_ID = "form2";
const CHANGE_INPUT_ID = "input2";
const BODY_INPUT_ID = "input3";
INPUT_ID: "input1",
FORM1_ID: "form1",
FORM2_ID: "form2",
CHANGE_INPUT_ID: "input2",
BODY_INPUT_ID: "input3",
};
function test() {
waitForExplicitFinish();
let tab = gBrowser.selectedTab =
gBrowser.addTab("data:text/html;charset=utf-8," +
"<html><body>" +
"<form id='" + FORM1_ID + "'><input id='" + CHANGE_INPUT_ID + "'></form>" +
"<form id='" + FORM2_ID + "'></form>" +
"</body></html>");
tab.linkedBrowser.addEventListener("load", tabLoad, true);
function task(consts) {
let resolve;
let promise = new Promise(r => { resolve = r; });
function unexpectedContentEvent(evt) {
ok(false, "Received a " + evt.type + " event on content");
}
var gDoc = null;
addEventListener("load", tabLoad, true);
function tabLoad() {
removeEventListener("load", tabLoad, true);
gDoc = content.document;
// These events shouldn't escape to content.
gDoc.addEventListener("DOMInputPasswordAdded", unexpectedContentEvent, false);
gDoc.defaultView.setTimeout(test_inputAdd, 0);
}
function test_inputAdd() {
addEventListener("DOMInputPasswordAdded", test_inputAddHandler, false);
let input = gDoc.createElementNS(consts.HTML_NS, "input");
input.setAttribute("type", "password");
input.setAttribute("id", consts.INPUT_ID);
input.setAttribute("data-test", "unique-attribute");
gDoc.getElementById(consts.FORM1_ID).appendChild(input);
info("Done appending the input element");
}
function test_inputAddHandler(evt) {
removeEventListener(evt.type, test_inputAddHandler, false);
is(evt.target.id, consts.INPUT_ID,
evt.type + " event targets correct input element (added password element)");
gDoc.defaultView.setTimeout(test_inputAddOutsideForm, 0);
}
function test_inputAddOutsideForm() {
addEventListener("DOMInputPasswordAdded", test_inputAddOutsideFormHandler, false);
let input = gDoc.createElementNS(consts.HTML_NS, "input");
input.setAttribute("type", "password");
input.setAttribute("id", consts.BODY_INPUT_ID);
input.setAttribute("data-test", "unique-attribute");
gDoc.body.appendChild(input);
info("Done appending the input element to the body");
}
function test_inputAddOutsideFormHandler(evt) {
removeEventListener(evt.type, test_inputAddOutsideFormHandler, false);
is(evt.target.id, consts.BODY_INPUT_ID,
evt.type + " event targets correct input element (added password element outside form)");
gDoc.defaultView.setTimeout(test_inputChangesType, 0);
}
function test_inputChangesType() {
addEventListener("DOMInputPasswordAdded", test_inputChangesTypeHandler, false);
let input = gDoc.getElementById(consts.CHANGE_INPUT_ID);
input.setAttribute("type", "password");
}
function test_inputChangesTypeHandler(evt) {
removeEventListener(evt.type, test_inputChangesTypeHandler, false);
is(evt.target.id, consts.CHANGE_INPUT_ID,
evt.type + " event targets correct input element (changed type)");
gDoc.defaultView.setTimeout(completeTest, 0);
}
function completeTest() {
ok(true, "Test completed");
gDoc.removeEventListener("DOMInputPasswordAdded", unexpectedContentEvent, false);
resolve();
}
return promise;
}
function unexpectedContentEvent(evt) {
ok(false, "Received a " + evt.type + " event on content");
}
var gDoc = null;
function tabLoad() {
let tab = gBrowser.selectedTab;
tab.linkedBrowser.removeEventListener("load", tabLoad, true);
gDoc = gBrowser.selectedBrowser.contentDocument;
// These events shouldn't escape to content.
gDoc.addEventListener("DOMInputPasswordAdded", unexpectedContentEvent, false);
gDoc.defaultView.setTimeout(test_inputAdd, 0);
}
function test_inputAdd() {
gBrowser.addEventListener("DOMInputPasswordAdded", test_inputAddHandler, false);
let input = gDoc.createElementNS(HTML_NS, "input");
input.setAttribute("type", "password");
input.setAttribute("id", INPUT_ID);
input.setAttribute("data-test", "unique-attribute");
gDoc.getElementById(FORM1_ID).appendChild(input);
info("Done appending the input element");
}
function test_inputAddHandler(evt) {
gBrowser.removeEventListener(evt.type, test_inputAddHandler, false);
is(evt.target.id, INPUT_ID,
evt.type + " event targets correct input element (added password element)");
gDoc.defaultView.setTimeout(test_inputAddOutsideForm, 0);
}
function test_inputAddOutsideForm() {
gBrowser.addEventListener("DOMInputPasswordAdded", test_inputAddOutsideFormHandler, false);
let input = gDoc.createElementNS(HTML_NS, "input");
input.setAttribute("type", "password");
input.setAttribute("id", BODY_INPUT_ID);
input.setAttribute("data-test", "unique-attribute");
gDoc.body.appendChild(input);
info("Done appending the input element to the body");
}
function test_inputAddOutsideFormHandler(evt) {
gBrowser.removeEventListener(evt.type, test_inputAddOutsideFormHandler, false);
is(evt.target.id, BODY_INPUT_ID,
evt.type + " event targets correct input element (added password element outside form)");
gDoc.defaultView.setTimeout(test_inputChangesType, 0);
}
function test_inputChangesType() {
gBrowser.addEventListener("DOMInputPasswordAdded", test_inputChangesTypeHandler, false);
let input = gDoc.getElementById(CHANGE_INPUT_ID);
input.setAttribute("type", "password");
}
function test_inputChangesTypeHandler(evt) {
gBrowser.removeEventListener(evt.type, test_inputChangesTypeHandler, false);
is(evt.target.id, CHANGE_INPUT_ID,
evt.type + " event targets correct input element (changed type)");
gDoc.defaultView.setTimeout(completeTest, 0);
}
function completeTest() {
ok(true, "Test completed");
gDoc.removeEventListener("DOMInputPasswordAdded", unexpectedContentEvent, false);
add_task(function* () {
let tab = gBrowser.selectedTab = gBrowser.addTab();
let promise = ContentTask.spawn(tab.linkedBrowser, consts, task);
tab.linkedBrowser.loadURI("data:text/html;charset=utf-8," +
"<html><body>" +
"<form id='" + consts.FORM1_ID + "'>" +
"<input id='" + consts.CHANGE_INPUT_ID + "'></form>" +
"<form id='" + consts.FORM2_ID + "'></form>" +
"</body></html>");
yield promise;
gBrowser.removeCurrentTab();
finish();
}
});

View File

@ -2,15 +2,7 @@
// Test whether setting a new property in InstallTrigger then persists to other
// page loads
function loadURI(aUri, aCallback) {
gBrowser.selectedBrowser.addEventListener("load", function() {
if (gBrowser.selectedBrowser.currentURI.spec != aUri)
return;
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
aCallback();
}, true);
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, aUri).then(aCallback);
gBrowser.loadURI(aUri);
}

View File

@ -5,20 +5,25 @@ function test() {
gBrowser.selectedTab = gBrowser.addTab();
function loadListener() {
gBrowser.selectedBrowser.removeEventListener("load", loadListener, true);
gBrowser.contentWindow.addEventListener("PageLoaded", page_loaded, false);
}
ContentTask.spawn(gBrowser.selectedBrowser, TESTROOT + "enabled.html", function (url) {
return new Promise(resolve => {
function page_loaded() {
content.removeEventListener("PageLoaded", page_loaded, false);
resolve(content.document.getElementById("enabled").textContent);
}
gBrowser.selectedBrowser.addEventListener("load", loadListener, true);
gBrowser.loadURI(TESTROOT + "enabled.html");
}
function page_loaded() {
gBrowser.contentWindow.removeEventListener("PageLoaded", page_loaded, false);
var doc = gBrowser.contentDocument;
is(doc.getElementById("enabled").textContent, "true", "installTrigger should have been enabled");
gBrowser.removeCurrentTab();
finish();
function load_listener() {
removeEventListener("load", load_listener, true);
content.addEventListener("PageLoaded", page_loaded, false);
}
addEventListener("load", load_listener, true);
content.location.href = url;
});
}).then(text => {
is(text, "true", "installTrigger should have been enabled");
gBrowser.removeCurrentTab();
finish();
});
}

View File

@ -7,21 +7,26 @@ function test() {
gBrowser.selectedTab = gBrowser.addTab();
function loadListener() {
gBrowser.selectedBrowser.removeEventListener("load", loadListener, true);
gBrowser.contentWindow.addEventListener("PageLoaded", page_loaded, false);
}
ContentTask.spawn(gBrowser.selectedBrowser, TESTROOT + "enabled.html", function (url) {
return new Promise(resolve => {
function page_loaded() {
content.removeEventListener("PageLoaded", page_loaded, false);
resolve(content.document.getElementById("enabled").textContent);
}
gBrowser.selectedBrowser.addEventListener("load", loadListener, true);
gBrowser.loadURI(TESTROOT + "enabled.html");
}
function page_loaded() {
gBrowser.contentWindow.removeEventListener("PageLoaded", page_loaded, false);
Services.prefs.clearUserPref("xpinstall.enabled");
var doc = gBrowser.contentDocument;
is(doc.getElementById("enabled").textContent, "false", "installTrigger should have not been enabled");
gBrowser.removeCurrentTab();
finish();
function load_listener() {
removeEventListener("load", load_listener, true);
content.addEventListener("PageLoaded", page_loaded, false);
}
addEventListener("load", load_listener, true);
content.location.href = url;
});
}).then(text => {
is(text, "false", "installTrigger should have not been enabled");
Services.prefs.clearUserPref("xpinstall.enabled");
gBrowser.removeCurrentTab();
finish();
});
}

View File

@ -13,13 +13,28 @@ function test() {
}));
gBrowser.selectedTab = gBrowser.addTab();
function loadListener() {
gBrowser.selectedBrowser.removeEventListener("load", loadListener, true);
gBrowser.contentWindow.addEventListener("InstallTriggered", page_loaded, false);
}
ContentTask.spawn(gBrowser.selectedBrowser, TESTROOT + "installtrigger.html?" + triggers, url => {
return new Promise(resolve => {
function page_loaded() {
content.removeEventListener("PageLoaded", page_loaded, false);
resolve(content.document.getElementById("return").textContent);
}
gBrowser.selectedBrowser.addEventListener("load", loadListener, true);
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
function load_listener() {
removeEventListener("load", load_listener, true);
content.addEventListener("InstallTriggered", page_loaded, false);
}
addEventListener("load", load_listener, true);
content.location.href = url;
});
}).then(text => {
is(text, "false", "installTrigger should have not been enabled");
Services.prefs.clearUserPref("xpinstall.enabled");
gBrowser.removeCurrentTab();
Harness.finish();
});
}
function install_disabled(installInfo) {
@ -35,14 +50,3 @@ function confirm_install(window) {
ok(false, "Should never see an install confirmation dialog");
return false;
}
function page_loaded() {
gBrowser.contentWindow.removeEventListener("InstallTriggered", page_loaded, false);
Services.prefs.clearUserPref("xpinstall.enabled");
var doc = gBrowser.contentDocument;
is(doc.getElementById("return").textContent, "false", "installTrigger should have not been enabled");
gBrowser.removeCurrentTab();
Harness.finish();
}
// ----------------------------------------------------------------------------

View File

@ -34,8 +34,9 @@ function finish_test(count) {
info("Checking if the browser is still offline...");
let tab = gBrowser.selectedTab;
tab.linkedBrowser.addEventListener("DOMContentLoaded", function errorLoad() {
tab.linkedBrowser.removeEventListener("DOMContentLoaded", errorLoad, true);
ContentTask.spawn(tab.linkedBrowser, null, () => {
return ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", true);
}).then(() => {
let url = tab.linkedBrowser.contentDocument.documentURI;
info("loaded: " + url);
if (/^about:neterror\?e=netOffline/.test(url)) {
@ -44,7 +45,7 @@ function finish_test(count) {
gBrowser.removeCurrentTab();
Harness.finish();
}
}, true);
});
tab.linkedBrowser.loadURI("http://example.com/");
}