зеркало из https://github.com/mozilla/gecko-dev.git
Bug 980182 - more about:accounts tests. r=ttaubert
This commit is contained in:
Родитель
afa1491838
Коммит
42fd902243
|
@ -83,6 +83,8 @@ support-files =
|
|||
skip-if = (os == "linux" || os == "mac") && debug # bug 970052, bug 970053
|
||||
[browser_aboutAccounts.js]
|
||||
skip-if = os == "linux" # Bug 958026
|
||||
support-files =
|
||||
content_aboutAccounts.js
|
||||
[browser_aboutHealthReport.js]
|
||||
skip-if = os == "linux" # Bug 924307
|
||||
[browser_aboutHome.js]
|
||||
|
|
|
@ -9,22 +9,32 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
|||
XPCOMUtils.defineLazyModuleGetter(this, "fxAccounts",
|
||||
"resource://gre/modules/FxAccounts.jsm");
|
||||
|
||||
const CHROME_BASE = "chrome://mochitests/content/browser/browser/base/content/test/general/";
|
||||
// Preference helpers.
|
||||
let changedPrefs = new Set();
|
||||
|
||||
function setPref(name, value) {
|
||||
changedPrefs.add(name);
|
||||
Services.prefs.setCharPref(name, value);
|
||||
}
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
// Ensure we don't pollute prefs for next tests.
|
||||
Services.prefs.clearUserPref("identity.fxaccounts.remote.uri");
|
||||
for (let name of changedPrefs) {
|
||||
Services.prefs.clearUserPref(name);
|
||||
}
|
||||
});
|
||||
|
||||
let gTests = [
|
||||
|
||||
{
|
||||
desc: "Test the remote commands",
|
||||
setup: function ()
|
||||
{
|
||||
Services.prefs.setCharPref("identity.fxaccounts.remote.uri",
|
||||
"https://example.com/browser/browser/base/content/test/general/accounts_testRemoteCommands.html");
|
||||
},
|
||||
run: function ()
|
||||
teardown: () => gBrowser.removeCurrentTab(),
|
||||
run: function* ()
|
||||
{
|
||||
setPref("identity.fxaccounts.remote.uri",
|
||||
"https://example.com/browser/browser/base/content/test/general/accounts_testRemoteCommands.html");
|
||||
yield promiseNewTabLoadEvent("about:accounts");
|
||||
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let results = 0;
|
||||
|
@ -50,7 +60,55 @@ let gTests = [
|
|||
return deferred.promise.then(() => fxAccounts.signOut());
|
||||
}
|
||||
},
|
||||
{
|
||||
desc: "Test action=signin",
|
||||
teardown: () => gBrowser.removeCurrentTab(),
|
||||
run: function* ()
|
||||
{
|
||||
const expected_url = "https://example.com/?is_sign_in";
|
||||
setPref("identity.fxaccounts.remote.signin.uri", expected_url);
|
||||
let [tab, url] = yield promiseNewTabWithIframeLoadEvent("about:accounts?action=signin");
|
||||
is(url, expected_url, "action=signin got the expected URL");
|
||||
}
|
||||
},
|
||||
{
|
||||
desc: "Test action=signup",
|
||||
teardown: () => gBrowser.removeCurrentTab(),
|
||||
run: function* ()
|
||||
{
|
||||
const expected_url = "https://example.com/?is_sign_up";
|
||||
setPref("identity.fxaccounts.remote.uri", expected_url);
|
||||
let [tab, url] = yield promiseNewTabWithIframeLoadEvent("about:accounts?action=signup");
|
||||
is(url, expected_url, "action=signup got the expected URL");
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "Test action=reauth",
|
||||
teardown: function* () {
|
||||
gBrowser.removeCurrentTab();
|
||||
yield fxAccounts.signOut();
|
||||
},
|
||||
run: function* ()
|
||||
{
|
||||
const expected_url = "https://example.com/?is_force_auth";
|
||||
setPref("identity.fxaccounts.remote.force_auth.uri", expected_url);
|
||||
let userData = {
|
||||
email: "foo@example.com",
|
||||
uid: "1234@lcip.org",
|
||||
assertion: "foobar",
|
||||
sessionToken: "dead",
|
||||
kA: "beef",
|
||||
kB: "cafe",
|
||||
verified: true
|
||||
};
|
||||
|
||||
yield fxAccounts.setSignedInUser(userData);
|
||||
let [tab, url] = yield promiseNewTabWithIframeLoadEvent("about:accounts?action=reauth");
|
||||
// The current user will be appended to the url
|
||||
let expected = expected_url + "&email=foo%40example.com";
|
||||
is(url, expected, "action=reauth got the expected URL");
|
||||
},
|
||||
},
|
||||
|
||||
]; // gTests
|
||||
|
||||
|
@ -61,13 +119,11 @@ function test()
|
|||
Task.spawn(function () {
|
||||
for (let test of gTests) {
|
||||
info(test.desc);
|
||||
test.setup();
|
||||
|
||||
yield promiseNewTabLoadEvent("about:accounts");
|
||||
|
||||
yield test.run();
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
try {
|
||||
yield test.run();
|
||||
} finally {
|
||||
yield test.teardown();
|
||||
}
|
||||
}
|
||||
|
||||
finish();
|
||||
|
@ -79,14 +135,32 @@ function promiseNewTabLoadEvent(aUrl)
|
|||
let deferred = Promise.defer();
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(aUrl);
|
||||
let browser = tab.linkedBrowser;
|
||||
let mm = browser.messageManager;
|
||||
|
||||
browser.addEventListener("load", function onLoad(event) {
|
||||
let iframe = browser.contentDocument.getElementById("remote");
|
||||
if (iframe && event.target == iframe.contentDocument) {
|
||||
browser.removeEventListener("load", onLoad, true);
|
||||
deferred.resolve();
|
||||
}
|
||||
}, true);
|
||||
|
||||
// give it an e10s-friendly content script to help with our tests.
|
||||
mm.loadFrameScript(CHROME_BASE + "content_aboutAccounts.js", true);
|
||||
// and wait for it to tell us about the load.
|
||||
mm.addMessageListener("test:document:load", function onLoad() {
|
||||
mm.removeMessageListener("test:document:load", onLoad);
|
||||
deferred.resolve(tab);
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Returns a promise which is resolved with the iframe's URL after a new
|
||||
// tab is created and the iframe in that tab loads.
|
||||
function promiseNewTabWithIframeLoadEvent(aUrl) {
|
||||
let deferred = Promise.defer();
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(aUrl);
|
||||
let browser = tab.linkedBrowser;
|
||||
let mm = browser.messageManager;
|
||||
|
||||
// give it an e10s-friendly content script to help with our tests.
|
||||
mm.loadFrameScript(CHROME_BASE + "content_aboutAccounts.js", true);
|
||||
// and wait for it to tell us about the iframe load.
|
||||
mm.addMessageListener("test:iframe:load", function onFrameLoad(message) {
|
||||
mm.removeMessageListener("test:iframe:load", onFrameLoad);
|
||||
deferred.resolve([tab, message.data.url]);
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
// This file is loaded as a "content script" for browser_aboutAccounts tests
|
||||
"use strict";
|
||||
|
||||
addEventListener("DOMContentLoaded", function domContentLoaded(event) {
|
||||
removeEventListener("DOMContentLoaded", domContentLoaded);
|
||||
sendAsyncMessage("test:document:load");
|
||||
let iframe = content.document.getElementById("remote");
|
||||
iframe.addEventListener("load", function iframeLoaded(event) {
|
||||
if (iframe.contentWindow.location.href == "about:blank" ||
|
||||
event.target != iframe) {
|
||||
return;
|
||||
}
|
||||
iframe.removeEventListener("load", iframeLoaded, true);
|
||||
sendAsyncMessage("test:iframe:load", {url: iframe.getAttribute("src")});
|
||||
}, true);
|
||||
});
|
Загрузка…
Ссылка в новой задаче