equal(context, mockSendingContext, "Should forward the original context");
equal(
message.command, "fxaccounts:login", "Should include the incoming command"
);
equal(message.messageId, "1234", "Should include the message ID");
equal(
message.data.error.message, "Error: oops", "Should convert the error message to a string"
);
notStrictEqual(
message.data.error.stack, null, "Should include the stack for JS error rejections"
);
});
let channel = new FxAccountsWebChannel({
channel_id: WEBCHANNEL_ID,
content_uri: URL_STRING,
helpers: {
openSyncPreferences(browser, entryPoint) {
equal(
entryPoint, "fxa:verification_complete", "Should forward incoming message data to the helper"
); thrownew TypeError("splines not reticulated");
},
},
});
channel._channel.send = (message, context) => {
equal(context, mockSendingContext, "Should forward the original context");
equal(
message.command, "fxaccounts:sync_preferences", "Should include the incoming command"
);
equal(message.messageId, "5678", "Should include the message ID");
equal(
message.data.error.message, "TypeError: splines not reticulated", "Should convert the exception to a string"
);
notStrictEqual(
message.data.error.stack, null, "Should include the stack for JS exceptions"
);
add_test(function test_error_message_remove_profile_path() { const errors = {
windows: {
err: new Error( "Win error 183 during operation rename on file C:\\Users\\Some Computer\\AppData\\Roaming\\" + "Mozilla\\Firefox\\Profiles\\dbzjmzxa.default\\signedInUser.json (Cannot create a file)"
),
expected: "Error: Win error 183 during operation rename on file C:[REDACTED]signedInUser.json (Cannot create a file)",
},
unix: {
err: new Error( "Unix error 28 during operation write on file /Users/someuser/Library/Application Support/" + "Firefox/Profiles/dbzjmzxa.default-release-7/signedInUser.json (No space left on device)"
),
expected: "Error: Unix error 28 during operation write on file [REDACTED]signedInUser.json (No space left on device)",
},
netpath: {
err: new Error( "Win error 32 during operation rename on file \\\\SVC.LOC\\HOMEDIRS$\\USERNAME\\Mozilla\\" + "Firefox\\Profiles\\dbzjmzxa.default-release-7\\signedInUser.json (No space left on device)"
),
expected: "Error: Win error 32 during operation rename on file [REDACTED]signedInUser.json (No space left on device)",
},
mount: {
err: new Error( "Win error 649 during operation rename on file C:\\SnapVolumes\\MountPoints\\" + "{9e399ec5-0000-0000-0000-100000000000}\\SVROOT\\Users\\username\\AppData\\Roaming\\Mozilla\\Firefox\\" + "Profiles\\dbzjmzxa.default-release\\signedInUser.json (The create operation failed)"
),
expected: "Error: Win error 649 during operation rename on file C:[REDACTED]signedInUser.json " + "(The create operation failed)",
},
}; const mockMessage = {
command: "fxaccounts:sync_preferences",
messageId: "1234",
}; const channel = new FxAccountsWebChannel({
channel_id: WEBCHANNEL_ID,
content_uri: URL_STRING,
});
let testNum = 0; const toTest = Object.keys(errors).length; for (const key in errors) {
let error = errors[key];
channel._channel.send = message => {
equal(
message.data.error.message,
error.expected, "Should remove the profile path from the error message"
);
testNum++; if (testNum === toTest) {
run_next_test();
}
};
channel._sendError(error.err, mockMessage, mockSendingContext);
}
});
add_task(async function test_helpers_login_without_customize_sync() {
let helpers = new FxAccountsWebChannelHelpers({
fxAccounts: {
getSignedInUser() { return Promise.resolve(null);
},
_internal: {
setSignedInUser(accountData) { returnnew Promise(resolve => { // ensure fxAccounts is informed of the new user being signed in. Assert.equal(accountData.email, "testuser@testuser.com");
// verifiedCanLinkAccount should be stripped in the data. Assert.equal(false, "verifiedCanLinkAccount" in accountData);
add_task(async function test_helpers_login_with_customize_sync() {
let helpers = new FxAccountsWebChannelHelpers({
fxAccounts: {
_internal: {
setSignedInUser(accountData) { returnnew Promise(resolve => { // ensure fxAccounts is informed of the new user being signed in. Assert.equal(accountData.email, "testuser@testuser.com");
// customizeSync should be stripped in the data. Assert.equal(false, "customizeSync" in accountData);
add_task(
{ skip_if: () => CLIENT_IS_THUNDERBIRD },
async function test_helpers_login_with_customize_sync_and_declined_engines() {
ensureOauthNotConfigured();
let configured = false;
let helpers = new FxAccountsWebChannelHelpers({
fxAccounts: {
_internal: {
setSignedInUser(accountData) { returnnew Promise(resolve => { // ensure fxAccounts is informed of the new user being signed in. Assert.equal(accountData.email, "testuser@testuser.com");
// customizeSync should be stripped in the data. Assert.equal(false, "customizeSync" in accountData); Assert.equal(false, "services" in accountData);
resolve();
});
},
},
getSignedInUser() { return Promise.resolve(null);
},
telemetry: {
recordConnection: sinon.spy(),
},
},
weaveXPCOM: {
whenLoaded() {},
Weave: {
Service: {
configure() {
configured = true;
},
},
},
},
});
// ensure fxAccounts is informed of the new user being signed in.
equal(accountData.email, "testuser@testuser.com");
// services should be stripped in the data.
ok(!("services" in accountData)); // credit cards was offered but not declined.
equal(Services.prefs.getBoolPref("services.sync.engine.creditcards"), true); // addresses was offered and explicitely declined.
equal(Services.prefs.getBoolPref("services.sync.engine.addresses"), false);
ok(configured);
});
const accountData = await setSignedInUserCalled; // ensure fxAccounts is informed of the new user being signed in.
equal(accountData.email, "testuser@testuser.com");
for (let name of allEngines) { Assert.ok(!Services.prefs.prefHasUserValue("services.sync.engine." + name));
} Assert.ok(configured);
});
await helpers.login({
uid: "auid",
email: "testuser@testuser.com",
verifiedCanLinkAccount: true,
services: {
first_only: { x: 10 }, // this data is not in the update below.
sync: { important: true },
},
});
Assert.deepEqual(JSON.parse(accountData.requestedServices), {
first_only: { x: 10 },
sync: { important: true },
}); // A second "login" message without the services.
await helpers.login({
uid: "auid",
email: "testuser@testuser.com",
verifiedCanLinkAccount: true,
services: { // the service is mentioned, but data is empty, so it's the old version of the data we want.
sync: {}, // a new service we never saw before, but we still want it. new: { name: "opted in" }, // not in original, but we want in the final.
},
}); // the version with the data should remain. Assert.deepEqual(JSON.parse(accountData.requestedServices), {
first_only: { x: 10 },
sync: { important: true }, new: { name: "opted in" },
});
resetOauthConfig();
});
add_test(function test_helpers_open_sync_preferences() {
let helpers = new FxAccountsWebChannelHelpers({
fxAccounts: {},
});
ensureOauthNotConfigured();
Services.prefs.setBoolPref( "services.sync.engine.creditcards.available", true
); // Not defining "services.sync.engine.addresses.available" on purpose.
let fxaStatus = await helpers.getFxaStatus("sync", mockSendingContext);
ok(!!fxaStatus);
ok(!!fxaStatus.signedInUser); // in the non-oauth flows we only expect "extra" engines.
deepEqual(fxaStatus.capabilities.engines, ["creditcards"]);
resetOauthConfig();
});
add_task(
async function test_helpers_shouldAllowFxaStatus_sync_service_not_private_browsing() {
let wasCalled = {
isPrivateBrowsingMode: false,
};
let helpers = new FxAccountsWebChannelHelpers({});
add_task(
async function test_helpers_shouldAllowFxaStatus_desktop_context_not_private_browsing() {
let wasCalled = {
isPrivateBrowsingMode: false,
};
let helpers = new FxAccountsWebChannelHelpers({});
add_task(
async function test_helpers_shouldAllowFxaStatus_oauth_service_not_private_browsing() {
let wasCalled = {
isPrivateBrowsingMode: false,
};
let helpers = new FxAccountsWebChannelHelpers({});
add_task(
async function test_helpers_shouldAllowFxaStatus_no_service_not_private_browsing() {
let wasCalled = {
isPrivateBrowsingMode: false,
};
let helpers = new FxAccountsWebChannelHelpers({});
add_task(
async function test_helpers_shouldAllowFxaStatus_sync_service_private_browsing() {
let wasCalled = {
isPrivateBrowsingMode: false,
};
let helpers = new FxAccountsWebChannelHelpers({});
add_task(
async function test_helpers_shouldAllowFxaStatus_desktop_context_private_browsing() {
let wasCalled = {
isPrivateBrowsingMode: false,
};
let helpers = new FxAccountsWebChannelHelpers({});
add_task(
async function test_helpers_shouldAllowFxaStatus_oauth_service_private_browsing() {
let wasCalled = {
isPrivateBrowsingMode: false,
};
let helpers = new FxAccountsWebChannelHelpers({});
add_task(
async function test_helpers_shouldAllowFxaStatus_oauth_service_pairing_private_browsing() {
let wasCalled = {
isPrivateBrowsingMode: false,
};
let helpers = new FxAccountsWebChannelHelpers({});
add_task(
async function test_helpers_shouldAllowFxaStatus_no_service_private_browsing() {
let wasCalled = {
isPrivateBrowsingMode: false,
};
let helpers = new FxAccountsWebChannelHelpers({});
add_task(async function test_helpers_isPrivateBrowsingMode_private_browsing() {
let wasCalled = {
isBrowserPrivate: false,
};
let helpers = new FxAccountsWebChannelHelpers({
privateBrowsingUtils: {
isBrowserPrivate(browser) {
wasCalled.isBrowserPrivate = true; Assert.equal(
browser,
mockSendingContext.browsingContext.top.embedderElement
); returntrue;
},
},
});
let isPrivateBrowsingMode = helpers.isPrivateBrowsingMode(mockSendingContext); Assert.ok(isPrivateBrowsingMode); Assert.ok(wasCalled.isBrowserPrivate);
});
add_task(async function test_helpers_isPrivateBrowsingMode_private_browsing() {
let wasCalled = {
isBrowserPrivate: false,
};
let helpers = new FxAccountsWebChannelHelpers({
privateBrowsingUtils: {
isBrowserPrivate(browser) {
wasCalled.isBrowserPrivate = true; Assert.equal(
browser,
mockSendingContext.browsingContext.top.embedderElement
); returnfalse;
},
},
});
let isPrivateBrowsingMode = helpers.isPrivateBrowsingMode(mockSendingContext); Assert.ok(!isPrivateBrowsingMode); Assert.ok(wasCalled.isBrowserPrivate);
});
add_task(async function test_helpers_change_password() {
let wasCalled = {
updateUserAccountData: false,
updateDeviceRegistration: false,
};
let helpers = new FxAccountsWebChannelHelpers({
fxAccounts: {
_internal: {
updateUserAccountData(credentials) { returnnew Promise(resolve => { Assert.ok(credentials.hasOwnProperty("email")); Assert.ok(credentials.hasOwnProperty("uid")); Assert.ok(credentials.hasOwnProperty("unwrapBKey")); Assert.ok(credentials.hasOwnProperty("device")); Assert.equal(null, credentials.device); Assert.equal(null, credentials.encryptedSendTabKeys); // "foo" isn't a field known by storage, so should be dropped. Assert.ok(!credentials.hasOwnProperty("foo"));
wasCalled.updateUserAccountData = true;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.