Bug 1532514 - Update sinon to v7.2.7. r=markh

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Edouard Oger 2019-03-12 19:32:40 +00:00
parent b72a1a06b5
commit d391c790bc
64 changed files with 32011 additions and 12131 deletions

View file

@ -323,7 +323,7 @@ testing/mochitest/MochiKit/**
testing/mochitest/tests/MochiKit-1.4.2/**
testing/mochitest/tests/SimpleTest/**
testing/modules/ajv-4.1.1.js
testing/modules/sinon-2.3.2.js
testing/modules/sinon-7.2.7.js
# octothorpe used for pref file comment causes parsing error
testing/mozbase/mozprofile/tests/files/prefs_with_comments.js
testing/talos/talos/scripts/jszip.min.js

View file

@ -14,6 +14,8 @@
* correctly prevent default events, and follows the correct code path.
*/
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
var gTests = [
{
@ -181,18 +183,11 @@ var gTestWin = null;
// The test currently running.
var gCurrentTest = null;
var sandbox;
function test() {
waitForExplicitFinish();
/* global sinon */
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
sandbox = sinon.sandbox.create();
registerCleanupFunction(function() {
sandbox.restore();
delete window.sinon;
sinon.restore();
});
gTestWin = openDialog(location, "", "chrome,all,dialog=no", "about:blank");
@ -250,7 +245,7 @@ function setupTestBrowserWindow() {
// Replace methods.
gReplacedMethods.forEach(function(methodName) {
let targetObj = methodName == "getShortcutOrURIAndPostData" ? UrlbarUtils : gTestWin;
sandbox.stub(targetObj, methodName).returnsArg(0);
sinon.stub(targetObj, methodName).returnsArg(0);
});
// Inject links in content.
@ -286,7 +281,7 @@ function runNextTest() {
}
// Move to next target.
sandbox.resetHistory();
sinon.resetHistory();
let target = gCurrentTest.targets.shift();
info(gCurrentTest.desc + ": testing " + target);

View file

@ -1,11 +1,7 @@
"use strict";
/* global sinon, UIState */
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
registerCleanupFunction(function() {
delete window.sinon;
});
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
/* global UIState */
const lastModifiedFixture = 1507655615.87; // Approx Oct 10th 2017
const mockTargets = [
@ -255,7 +251,7 @@ add_task(async function sendToDevice_syncNotReady_other_states() {
// Open a tab that's sendable.
await BrowserTestUtils.withNewTab("http://example.com/", async () => {
await promiseSyncReady();
const sandbox = sinon.sandbox.create();
const sandbox = sinon.createSandbox();
sandbox.stub(gSync, "syncReady").get(() => false);
sandbox.stub(UIState, "get").returns({ status: UIState.STATUS_NOT_VERIFIED });
sandbox.stub(gSync, "isSendableURI").returns(true);
@ -311,7 +307,7 @@ add_task(async function sendToDevice_syncNotReady_configured() {
// Open a tab that's sendable.
await BrowserTestUtils.withNewTab("http://example.com/", async () => {
await promiseSyncReady();
const sandbox = sinon.sandbox.create();
const sandbox = sinon.createSandbox();
const syncReady = sandbox.stub(gSync, "syncReady").get(() => false);
const hasSyncedThisSession = sandbox.stub(Weave.Service.clientsEngine, "hasSyncedThisSession").get(() => false);
sandbox.stub(UIState, "get").returns({ status: UIState.STATUS_SIGNED_IN });
@ -455,7 +451,7 @@ add_task(async function sendToDevice_noDevices() {
// Open a tab that's sendable.
await BrowserTestUtils.withNewTab("http://example.com/", async () => {
await promiseSyncReady();
const sandbox = sinon.sandbox.create();
const sandbox = sinon.createSandbox();
sandbox.stub(gSync, "syncReady").get(() => true);
sandbox.stub(Weave.Service.clientsEngine, "hasSyncedThisSession").get(() => true);
sandbox.stub(Weave.Service.clientsEngine, "fxaDevices").get(() => []);
@ -521,7 +517,7 @@ add_task(async function sendToDevice_devices() {
// Open a tab that's sendable.
await BrowserTestUtils.withNewTab("http://example.com/", async () => {
await promiseSyncReady();
const sandbox = sinon.sandbox.create();
const sandbox = sinon.createSandbox();
sandbox.stub(gSync, "syncReady").get(() => true);
sandbox.stub(Weave.Service.clientsEngine, "hasSyncedThisSession").get(() => true);
sandbox.stub(UIState, "get").returns({ status: UIState.STATUS_SIGNED_IN });
@ -587,7 +583,7 @@ add_task(async function sendToDevice_title() {
await BrowserTestUtils.withNewTab("http://example.com/a", async otherBrowser => {
await BrowserTestUtils.withNewTab("http://example.com/b", async () => {
await promiseSyncReady();
const sandbox = sinon.sandbox.create();
const sandbox = sinon.createSandbox();
sandbox.stub(gSync, "syncReady").get(() => true);
sandbox.stub(Weave.Service.clientsEngine, "hasSyncedThisSession").get(() => true);
sandbox.stub(UIState, "get").returns({ status: UIState.STATUS_SIGNED_IN });
@ -644,7 +640,7 @@ add_task(async function sendToDevice_inUrlbar() {
// Open a tab that's sendable.
await BrowserTestUtils.withNewTab("http://example.com/", async () => {
await promiseSyncReady();
const sandbox = sinon.sandbox.create();
const sandbox = sinon.createSandbox();
sandbox.stub(gSync, "syncReady").get(() => true);
sandbox.stub(Weave.Service.clientsEngine, "hasSyncedThisSession").get(() => true);
sandbox.stub(UIState, "get").returns({ status: UIState.STATUS_SIGNED_IN });

View file

@ -4,8 +4,7 @@
"use strict";
/* global sinon */
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
const URL = "http://example.org/";
@ -38,7 +37,6 @@ let stub = sinon.stub(BrowserPageActions.shareURL, "_sharingService").get(() =>
registerCleanupFunction(async function() {
stub.restore();
delete window.sinon;
await EventUtils.synthesizeNativeMouseMove(document.documentElement, 0, 0);
await PlacesUtils.history.clear();
});

View file

@ -3,8 +3,7 @@
"use strict";
/* global sinon */
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
const TEST_URL = getRootDirectory(gTestPath) + "browser_page_action_menu_share_win.html";
@ -22,7 +21,6 @@ let stub = sinon.stub(BrowserPageActions.shareURL, "_windowsUIUtils").get(() =>
registerCleanupFunction(async function() {
stub.restore();
delete window.sinon;
});
add_task(async function shareURL() {

View file

@ -1,11 +1,5 @@
/* global sinon */
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
ChromeUtils.import("resource://services-sync/UIState.jsm", this);
registerCleanupFunction(function() {
delete window.sinon;
});
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
function promiseSyncReady() {
let service = Cc["@mozilla.org/weave/service;1"]
@ -16,7 +10,7 @@ function promiseSyncReady() {
function setupSendTabMocks({ syncReady = true, fxaDevices = null,
state = UIState.STATUS_SIGNED_IN, isSendableURI = true }) {
const sandbox = sinon.sandbox.create();
const sandbox = sinon.createSandbox();
sandbox.stub(gSync, "syncReady").get(() => syncReady);
if (fxaDevices) {
// Clone fxaDevices because it gets sorted in-place.

View file

@ -1,13 +1,8 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
/* global sinon */
"use strict";
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
registerCleanupFunction(() => {
delete window.sinon;
});
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
ChromeUtils.defineModuleGetter(this, "ExtensionSettingsStore",
"resource://gre/modules/ExtensionSettingsStore.jsm");
@ -127,7 +122,7 @@ add_task(async function testExtensionControlledPopup() {
// Ensure the panel isn't open.
ok(onObserverAdded.called, "Observing the event");
onObserverAdded.reset();
onObserverAdded.resetHistory();
ok(!onObserverRemoved.called, "Observing the event");
ok(!beforeDisableAddon.called, "Settings have not been restored");
ok(panel.getAttribute("panelopen") != "true", "The panel is closed");
@ -140,7 +135,7 @@ add_task(async function testExtensionControlledPopup() {
ok(!onObserverAdded.called, "Only one observer has been registered");
ok(onObserverRemoved.called, "The observer was removed");
onObserverRemoved.reset();
onObserverRemoved.resetHistory();
ok(!beforeDisableAddon.called, "Settings have not been restored");
is(panel.getAttribute("panelopen"), "true", "The panel is open");
is(popupnotification.hidden, false, "The popup content is visible");
@ -167,7 +162,7 @@ add_task(async function testExtensionControlledPopup() {
// Force add the observer again to keep changes.
await popup.addObserver(id);
ok(onObserverAdded.called, "The observer was added again");
onObserverAdded.reset();
onObserverAdded.resetHistory();
ok(!onObserverRemoved.called, "The observer is still registered");
is(await popup.userHasConfirmed(id), false, "The user has not confirmed");
@ -180,7 +175,7 @@ add_task(async function testExtensionControlledPopup() {
// The observer is removed, but the notification is saved.
ok(!onObserverAdded.called, "The observer wasn't added");
ok(onObserverRemoved.called, "The observer was removed");
onObserverRemoved.reset();
onObserverRemoved.resetHistory();
is(await popup.userHasConfirmed(id), true, "The user has confirmed");
is(addon.userDisabled, false, "The extension is still enabled");
@ -198,7 +193,7 @@ add_task(async function testExtensionControlledPopup() {
// Force add the observer again to restore changes.
await popup.addObserver(id);
ok(onObserverAdded.called, "The observer was added a third time");
onObserverAdded.reset();
onObserverAdded.resetHistory();
ok(!onObserverRemoved.called, "The observer is still active");
ok(!beforeDisableAddon.called, "We haven't disabled the add-on yet");
is(await popup.userHasConfirmed(id), false, "The user has not confirmed");

View file

@ -1,6 +1,5 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
/* global sinon */
"use strict";

View file

@ -4,7 +4,7 @@ support-files =
!/browser/extensions/formautofill/content/editCreditCard.xhtml
../../../../../browser/extensions/formautofill/content/autofillEditForms.js
../../../../../browser/extensions/formautofill/skin/shared/editDialog-shared.css
../../../../../testing/modules/sinon-2.3.2.js
../../../../../testing/modules/sinon-7.2.7.js
# paymentRequest.xhtml is needed for `importDialogDependencies` so that the relative paths of
# formautofill/edit*.xhtml work from the *-form elements in paymentRequest.xhtml.
../../res/paymentRequest.xhtml

View file

@ -8,7 +8,7 @@ Test the PaymentStateSubscriberMixin
<title>Test the PaymentStateSubscriberMixin</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<script src="sinon-2.3.2.js"></script>
<script src="sinon-7.2.7.js"></script>
<script src="payments_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>

View file

@ -10,7 +10,7 @@ Test the PaymentsStore
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<script src="sinon-2.3.2.js"></script>
<script src="sinon-7.2.7.js"></script>
<script src="payments_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>

View file

@ -9,7 +9,7 @@ Test the accepted-cards element
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<script src="sinon-2.3.2.js"></script>
<script src="sinon-7.2.7.js"></script>
<script src="payments_common.js"></script>
<script src="../../res/unprivileged-fallbacks.js"></script>

View file

@ -9,7 +9,7 @@ Test the address-form element
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<script src="sinon-2.3.2.js"></script>
<script src="sinon-7.2.7.js"></script>
<script src="payments_common.js"></script>
<script src="../../res/unprivileged-fallbacks.js"></script>
<script src="autofillEditForms.js"></script>

View file

@ -9,7 +9,7 @@ Test the basic-card-form element
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<script src="sinon-2.3.2.js"></script>
<script src="sinon-7.2.7.js"></script>
<script src="payments_common.js"></script>
<script src="../../res/unprivileged-fallbacks.js"></script>
<script src="autofillEditForms.js"></script>

View file

@ -9,7 +9,7 @@ Test the payment-dialog custom element
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script src="sinon-2.3.2.js"></script>
<script src="sinon-7.2.7.js"></script>
<script src="payments_common.js"></script>
<script src="../../res/unprivileged-fallbacks.js"></script>
<script src="autofillEditForms.js"></script>

View file

@ -1,16 +1,2 @@
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
// ================================================
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/releases/v2.3.2/
var {
clearInterval,
clearTimeout,
setInterval,
setIntervalWithTarget,
setTimeout,
setTimeoutWithTarget,
} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
/* globals sinon */
// ================================================
var {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");

View file

@ -1,13 +1,11 @@
"use strict";
/* global sinon */
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
const sandbox = sinon.sandbox.create();
const sandbox = sinon.createSandbox();
registerCleanupFunction(async function() {
sandbox.restore();
delete window.sinon;
await PlacesUtils.bookmarks.eraseEverything();
await PlacesUtils.history.clear();
});

View file

@ -4,10 +4,9 @@
"use strict";
/* global sinon */
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
const sandbox = sinon.sandbox.create();
const sandbox = sinon.createSandbox();
const TAG_NAME = "testTag";
var bookmarks;
@ -16,7 +15,6 @@ var bookmarkId;
add_task(async function setup() {
registerCleanupFunction(async function() {
sandbox.restore();
delete window.sinon;
await PlacesUtils.bookmarks.eraseEverything();
await PlacesUtils.history.clear();
});

View file

@ -1,10 +1,4 @@
// ================================================
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/releases/v2.3.2/
const {setTimeout, clearTimeout, setInterval, clearInterval} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
/* globals sinon */
// ================================================
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
/* eslint-disable mozilla/use-chromeutils-generateqi */

View file

@ -1,6 +1,5 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* global sinon */
"use strict";
@ -8,10 +7,7 @@ const {UIState} = ChromeUtils.import("resource://services-sync/UIState.jsm", {})
const {FxAccountsPairingFlow} = ChromeUtils.import("resource://gre/modules/FxAccountsPairing.jsm", {});
// Use sinon for mocking.
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
registerCleanupFunction(() => {
delete window.sinon; // test fails with this reference left behind.
});
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
let flowCounter = 0;
@ -37,7 +33,7 @@ add_task(async function setup() {
});
add_task(async function testShowsQRCode() {
await runWithPairingDialog(async (win, sinon) => {
await runWithPairingDialog(async (win) => {
let doc = win.document;
let qrContainer = doc.getElementById("qrContainer");
let qrWrapper = doc.getElementById("qrWrapper");
@ -59,7 +55,7 @@ add_task(async function testShowsQRCode() {
add_task(async function testCantShowQrCode() {
const origStart = FxAccountsPairingFlow.start;
FxAccountsPairingFlow.start = async () => { throw new Error("boom"); };
await runWithPairingDialog(async (win, sinon) => {
await runWithPairingDialog(async (win) => {
let doc = win.document;
let qrWrapper = doc.getElementById("qrWrapper");
@ -76,7 +72,7 @@ add_task(async function testCantShowQrCode() {
});
add_task(async function testSwitchToWebContent() {
await runWithPairingDialog(async (win, sinon) => {
await runWithPairingDialog(async (win) => {
let doc = win.document;
let qrWrapper = doc.getElementById("qrWrapper");
@ -91,7 +87,7 @@ add_task(async function testSwitchToWebContent() {
});
add_task(async function testError() {
await runWithPairingDialog(async (win, sinon) => {
await runWithPairingDialog(async (win) => {
let doc = win.document;
let qrWrapper = doc.getElementById("qrWrapper");
@ -120,11 +116,9 @@ async function runWithPairingDialog(test) {
let win = await promiseSubDialogLoaded;
let ss = sinon.sandbox.create();
await test(win);
await test(win, ss);
ss.restore();
sinon.restore();
BrowserTestUtils.removeTab(gBrowser.selectedTab);
}

View file

@ -1,6 +1,5 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* global sinon */
"use strict";
@ -14,11 +13,7 @@ var fxAccountsCommon = {};
ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js", fxAccountsCommon);
// Use sinon for mocking.
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
registerCleanupFunction(() => {
delete window.sinon; // test fails with this reference left behind.
});
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
add_task(async function setup() {
// Sync start-up will interfere with our tests, don't let UIState send UI updates.
@ -42,7 +37,7 @@ add_task(async function setup() {
});
add_task(async function testDisconnectUI() {
await runTestWithSanitizeDialog(async (win, sinon) => {
await runTestWithSanitizeDialog(async (win) => {
let doc = win.document;
let butDisconnect = doc.getElementById("butDisconnect");
let butDeleteSync = doc.getElementById("deleteRemoteSyncData");
@ -92,7 +87,7 @@ add_task(async function testDisconnectUI() {
});
add_task(async function testDisconnectNoSanitize() {
await runTestWithSanitizeDialog(async (win, sinon) => {
await runTestWithSanitizeDialog(async (win) => {
let doc = win.document;
let butDisconnect = doc.getElementById("butDisconnect");
@ -130,7 +125,7 @@ add_task(async function testDisconnectNoSanitize() {
});
add_task(async function testSanitizeSync() {
await runTestWithSanitizeDialog(async (win, sinon) => {
await runTestWithSanitizeDialog(async (win) => {
let doc = win.document;
let butDisconnect = doc.getElementById("butDisconnect");
let butDeleteSync = doc.getElementById("deleteRemoteSyncData");
@ -196,7 +191,7 @@ add_task(async function testSanitizeSync() {
});
add_task(async function testSanitizeBrowser() {
await runTestWithSanitizeDialog(async (win, sinon) => {
await runTestWithSanitizeDialog(async (win) => {
let doc = win.document;
// The dialog should have the main UI visible.
@ -232,7 +227,7 @@ add_task(async function testDisconnectAlreadyRunning() {
SyncDisconnectInternal.promiseDisconnectFinished =
new Promise(resolve => resolveExisting = resolve);
await runTestWithSanitizeDialog(async (win, sinon) => {
await runTestWithSanitizeDialog(async (win) => {
let doc = win.document;
// The dialog should have "waiting" visible.
Assert.equal(doc.getElementById("deleteOptionsContent").hidden, true);
@ -261,11 +256,9 @@ async function runTestWithSanitizeDialog(test) {
let win = await promiseSubDialogLoaded;
let ss = sinon.sandbox.create();
await test(win);
await test(win, ss);
ss.restore();
sinon.restore();
BrowserTestUtils.removeTab(gBrowser.selectedTab);
}

View file

@ -62,16 +62,25 @@ const FIXTURE = [
},
];
let originalSyncedTabsInternal = null;
const {SyncedTabs} = ChromeUtils.import("resource://services-sync/SyncedTabs.jsm");
async function testClean() {
let syncedTabsDeckComponent = window.SidebarUI.browser.contentWindow.syncedTabsDeckComponent;
syncedTabsDeckComponent._getSignedInUser.restore();
SyncedTabs._internal.getTabClients.restore();
SyncedTabs._internal = originalSyncedTabsInternal;
function setupSyncedTabsStubs({
signedInUser = {verified: true},
loginFailed = false,
isConfiguredToSyncTabs = true,
hasSyncedThisSession = true,
tabClients = Cu.cloneInto(FIXTURE, {}),
} = {}) {
sinon.stub(SidebarUI.browser.contentWindow.syncedTabsDeckComponent, "_getSignedInUser").resolves(signedInUser);
sinon.stub(SyncedTabs._internal, "getTabClients").resolves(tabClients);
sinon.stub(SyncedTabs._internal, "syncTabs").resolves();
sinon.stub(SyncedTabs._internal, "loginFailed").value(loginFailed);
sinon.stub(SyncedTabs._internal, "isConfiguredToSyncTabs").value(isConfiguredToSyncTabs);
sinon.stub(SyncedTabs._internal, "hasSyncedThisSession").value(hasSyncedThisSession);
}
async function testClean() {
sinon.restore();
await new Promise(resolve => {
window.SidebarUI.browser.contentWindow.addEventListener("unload", function() {
resolve();
@ -89,16 +98,7 @@ add_task(async function testSyncedTabsSidebarList() {
Assert.ok(syncedTabsDeckComponent, "component exists");
originalSyncedTabsInternal = SyncedTabs._internal;
SyncedTabs._internal = {
isConfiguredToSyncTabs: true,
hasSyncedThisSession: true,
getTabClients() { return Promise.resolve([]); },
syncTabs() { return Promise.resolve(); },
};
sinon.stub(syncedTabsDeckComponent, "_getSignedInUser", () => Promise.resolve({verified: true}));
sinon.stub(SyncedTabs._internal, "getTabClients", () => Promise.resolve(Cu.cloneInto(FIXTURE, {})));
setupSyncedTabsStubs();
await syncedTabsDeckComponent.updatePanel();
// This is a hacky way of waiting for the view to render. The view renders
@ -140,27 +140,17 @@ add_task(async function testSyncedTabsSidebarFilteredList() {
Assert.ok(syncedTabsDeckComponent, "component exists");
originalSyncedTabsInternal = SyncedTabs._internal;
SyncedTabs._internal = {
isConfiguredToSyncTabs: true,
hasSyncedThisSession: true,
getTabClients() { return Promise.resolve([]); },
syncTabs() { return Promise.resolve(); },
};
sinon.stub(syncedTabsDeckComponent, "_getSignedInUser", () => Promise.resolve({verified: true}));
sinon.stub(SyncedTabs._internal, "getTabClients", () => Promise.resolve(Cu.cloneInto(FIXTURE, {})));
setupSyncedTabsStubs();
await syncedTabsDeckComponent.updatePanel();
// This is a hacky way of waiting for the view to render. The view renders
// after the following promise (a different instance of which is triggered
// in updatePanel) resolves, so we wait for it here as well
await syncedTabsDeckComponent.tabListComponent._store.getData();
let filterInput = syncedTabsDeckComponent._window.document.querySelector(".tabsFilter");
filterInput.value = "filter text";
filterInput.blur();
// This is a hacky way of waiting for the view to render. The view renders
// after the following promise (a different instance of which is triggered
// in updatePanel) resolves, so we wait for it here as well
await syncedTabsDeckComponent.tabListComponent._store.getData("filter text");
let selectedPanel = syncedTabsDeckComponent.container.querySelector(".sync-state.selected");
@ -193,74 +183,110 @@ add_task(async function testSyncedTabsSidebarFilteredList() {
add_task(testClean);
add_task(async function testSyncedTabsSidebarStatus() {
let account = null;
await SidebarUI.show("viewTabsSidebar");
let syncedTabsDeckComponent = window.SidebarUI.browser.contentWindow.syncedTabsDeckComponent;
originalSyncedTabsInternal = SyncedTabs._internal;
SyncedTabs._internal = {
Assert.ok(syncedTabsDeckComponent, "component exists");
setupSyncedTabsStubs({
signedInUser: Promise.reject("Test error"),
loginFailed: false,
isConfiguredToSyncTabs: false,
hasSyncedThisSession: false,
getTabClients() {},
syncTabs() { return Promise.resolve(); },
};
Assert.ok(syncedTabsDeckComponent, "component exists");
sinon.spy(syncedTabsDeckComponent, "updatePanel");
sinon.spy(syncedTabsDeckComponent, "observe");
sinon.stub(syncedTabsDeckComponent, "_getSignedInUser", () => Promise.reject("Test error"));
tabClients: [],
});
await syncedTabsDeckComponent.updatePanel();
let selectedPanel = syncedTabsDeckComponent.container.querySelector(".sync-state.selected");
Assert.ok(selectedPanel.classList.contains("notAuthedInfo"),
"not-authed panel is selected on auth error");
sinon.restore();
syncedTabsDeckComponent._getSignedInUser.restore();
sinon.stub(syncedTabsDeckComponent, "_getSignedInUser", () => Promise.resolve(account));
setupSyncedTabsStubs({
signedInUser: null,
loginFailed: false,
isConfiguredToSyncTabs: false,
hasSyncedThisSession: false,
tabClients: [],
});
await syncedTabsDeckComponent.updatePanel();
selectedPanel = syncedTabsDeckComponent.container.querySelector(".sync-state.selected");
Assert.ok(selectedPanel.classList.contains("notAuthedInfo"),
"not-authed panel is selected");
sinon.restore();
account = {verified: false};
setupSyncedTabsStubs({
signedInUser: {verified: false},
loginFailed: false,
isConfiguredToSyncTabs: false,
hasSyncedThisSession: false,
tabClients: [],
});
await syncedTabsDeckComponent.updatePanel();
selectedPanel = syncedTabsDeckComponent.container.querySelector(".sync-state.selected");
Assert.ok(selectedPanel.classList.contains("unverified"),
"unverified panel is selected");
sinon.restore();
SyncedTabs._internal.loginFailed = true;
account = {verified: true};
setupSyncedTabsStubs({
signedInUser: {verified: true},
loginFailed: true,
isConfiguredToSyncTabs: false,
hasSyncedThisSession: false,
tabClients: [],
});
await syncedTabsDeckComponent.updatePanel();
selectedPanel = syncedTabsDeckComponent.container.querySelector(".sync-state.selected");
Assert.ok(selectedPanel.classList.contains("reauth"),
"reauth panel is selected");
SyncedTabs._internal.loginFailed = false;
sinon.restore();
account = {verified: true};
setupSyncedTabsStubs({
signedInUser: {verified: true},
loginFailed: false,
isConfiguredToSyncTabs: false,
hasSyncedThisSession: false,
tabClients: [],
});
await syncedTabsDeckComponent.updatePanel();
selectedPanel = syncedTabsDeckComponent.container.querySelector(".sync-state.selected");
Assert.ok(selectedPanel.classList.contains("tabs-disabled"),
"tabs disabled panel is selected");
sinon.restore();
SyncedTabs._internal.isConfiguredToSyncTabs = true;
setupSyncedTabsStubs({
signedInUser: {verified: true},
loginFailed: false,
isConfiguredToSyncTabs: true,
hasSyncedThisSession: false,
tabClients: [],
});
await syncedTabsDeckComponent.updatePanel();
selectedPanel = syncedTabsDeckComponent.container.querySelector(".sync-state.selected");
Assert.ok(selectedPanel.classList.contains("tabs-fetching"),
"tabs fetch panel is selected");
sinon.restore();
SyncedTabs._internal.hasSyncedThisSession = true;
sinon.stub(SyncedTabs._internal, "getTabClients", () => Promise.resolve([]));
setupSyncedTabsStubs({
signedInUser: {verified: true},
loginFailed: false,
isConfiguredToSyncTabs: true,
hasSyncedThisSession: true,
tabClients: [],
});
await syncedTabsDeckComponent.updatePanel();
selectedPanel = syncedTabsDeckComponent.container.querySelector(".sync-state.selected");
Assert.ok(selectedPanel.classList.contains("singleDeviceInfo"),
"tabs fetch panel is selected");
sinon.restore();
SyncedTabs._internal.getTabClients.restore();
sinon.stub(SyncedTabs._internal, "getTabClients", () => Promise.resolve([{id: "mock"}]));
setupSyncedTabsStubs({
signedInUser: {verified: true},
loginFailed: false,
isConfiguredToSyncTabs: true,
hasSyncedThisSession: true,
tabClients: [{id: "mock"}],
});
await syncedTabsDeckComponent.updatePanel();
selectedPanel = syncedTabsDeckComponent.container.querySelector(".sync-state.selected");
Assert.ok(selectedPanel.classList.contains("tabs-container"),
@ -275,16 +301,7 @@ add_task(async function testSyncedTabsSidebarContextMenu() {
Assert.ok(syncedTabsDeckComponent, "component exists");
originalSyncedTabsInternal = SyncedTabs._internal;
SyncedTabs._internal = {
isConfiguredToSyncTabs: true,
hasSyncedThisSession: true,
getTabClients() { return Promise.resolve([]); },
syncTabs() { return Promise.resolve(); },
};
sinon.stub(syncedTabsDeckComponent, "_getSignedInUser", () => Promise.resolve({verified: true}));
sinon.stub(SyncedTabs._internal, "getTabClients", () => Promise.resolve(Cu.cloneInto(FIXTURE, {})));
setupSyncedTabsStubs();
await syncedTabsDeckComponent.updatePanel();
// This is a hacky way of waiting for the view to render. The view renders

View file

@ -1,13 +1,3 @@
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/docs/
/* global sinon */
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
registerCleanupFunction(async function() {
// Cleanup window or the test runner will throw an error
delete window.sinon;
});
var {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");

View file

@ -1,16 +1,9 @@
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
var {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
XPCOMUtils.defineLazyGetter(this, "FxAccountsCommon", function() {
return ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js", {});
});
do_get_profile(); // fxa needs a profile directory for storage.
// ================================================
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/releases/v2.3.2/
var {clearInterval, clearTimeout, setInterval, setIntervalWithTarget, setTimeout, setTimeoutWithTarget} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
/* globals sinon */
// ================================================

View file

@ -17,7 +17,7 @@ add_task(async function testInitUninit() {
let view = {render: sinon.spy(), destroy: sinon.spy(), container: {}};
ViewMock.returns(view);
sinon.stub(SyncedTabs, "syncTabs", () => Promise.resolve());
sinon.stub(SyncedTabs, "syncTabs").callsFake(() => Promise.resolve());
sinon.spy(deckStore, "on");
sinon.stub(deckStore, "setPanels");
@ -85,7 +85,7 @@ add_task(async function testObserver() {
let view = {render: sinon.spy(), destroy: sinon.spy(), container: {}};
ViewMock.returns(view);
sinon.stub(SyncedTabs, "syncTabs", () => Promise.resolve());
sinon.stub(SyncedTabs, "syncTabs").callsFake(() => Promise.resolve());
sinon.spy(deckStore, "on");
sinon.stub(deckStore, "setPanels");
@ -162,7 +162,7 @@ add_task(async function testPanelStatus() {
});
let account = null;
sinon.stub(fxAccounts, "getSignedInUser", () => Promise.resolve(account));
sinon.stub(fxAccounts, "getSignedInUser").callsFake(() => Promise.resolve(account));
let result = await component.getPanelStatus();
Assert.equal(result, component.PANELS.NOT_AUTHED_INFO);
@ -191,7 +191,7 @@ add_task(async function testPanelStatus() {
SyncedTabsMock.hasSyncedThisSession = true;
let clients = [];
sinon.stub(SyncedTabsMock, "getTabClients", () => Promise.resolve(clients));
sinon.stub(SyncedTabsMock, "getTabClients").callsFake(() => Promise.resolve(clients));
result = await component.getPanelStatus();
Assert.equal(result, component.PANELS.SINGLE_DEVICE_INFO);
@ -200,11 +200,11 @@ add_task(async function testPanelStatus() {
Assert.equal(result, component.PANELS.TABS_CONTAINER);
fxAccounts.getSignedInUser.restore();
sinon.stub(fxAccounts, "getSignedInUser", () => Promise.reject("err"));
sinon.stub(fxAccounts, "getSignedInUser").callsFake(() => Promise.reject("err"));
result = await component.getPanelStatus();
Assert.equal(result, component.PANELS.NOT_AUTHED_INFO);
sinon.stub(component, "getPanelStatus", () => Promise.resolve("mock-panelId"));
sinon.stub(component, "getPanelStatus").callsFake(() => Promise.resolve("mock-panelId"));
sinon.spy(deckStore, "selectPanel");
await component.updatePanel();
Assert.ok(deckStore.selectPanel.calledWith("mock-panelId"));

View file

@ -43,7 +43,7 @@ add_task(async function testGetDataEmpty() {
let store = new SyncedTabsListStore(SyncedTabs);
let spy = sinon.spy();
sinon.stub(SyncedTabs, "getTabClients", () => {
sinon.stub(SyncedTabs, "getTabClients").callsFake(() => {
return Promise.resolve([]);
});
store.on("change", spy);
@ -77,7 +77,7 @@ add_task(async function testRowSelectionWithoutFilter() {
let store = new SyncedTabsListStore(SyncedTabs);
let spy = sinon.spy();
sinon.stub(SyncedTabs, "getTabClients", () => {
sinon.stub(SyncedTabs, "getTabClients").callsFake(() => {
return Promise.resolve(FIXTURE);
});
@ -128,7 +128,7 @@ add_task(async function testToggleBranches() {
let store = new SyncedTabsListStore(SyncedTabs);
let spy = sinon.spy();
sinon.stub(SyncedTabs, "getTabClients", () => {
sinon.stub(SyncedTabs, "getTabClients").callsFake(() => {
return Promise.resolve(FIXTURE);
});
@ -162,7 +162,7 @@ add_task(async function testRowSelectionWithFilter() {
let store = new SyncedTabsListStore(SyncedTabs);
let spy = sinon.spy();
sinon.stub(SyncedTabs, "getTabClients", () => {
sinon.stub(SyncedTabs, "getTabClients").callsFake(() => {
return Promise.resolve(FIXTURE);
});
@ -196,7 +196,7 @@ add_task(async function testFilterAndClearFilter() {
let store = new SyncedTabsListStore(SyncedTabs);
let spy = sinon.spy();
sinon.stub(SyncedTabs, "getTabClients", () => {
sinon.stub(SyncedTabs, "getTabClients").callsFake(() => {
return Promise.resolve(FIXTURE);
});
store.on("change", spy);
@ -230,7 +230,7 @@ add_task(async function testFocusBlurInput() {
let store = new SyncedTabsListStore(SyncedTabs);
let spy = sinon.spy();
sinon.stub(SyncedTabs, "getTabClients", () => {
sinon.stub(SyncedTabs, "getTabClients").callsFake(() => {
return Promise.resolve(FIXTURE);
});
store.on("change", spy);

View file

@ -3,14 +3,5 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
// ================================================
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/releases/v2.3.2/
/* exported sinon */
var {clearInterval, clearTimeout, setInterval, setIntervalWithTarget, setTimeout, setTimeoutWithTarget} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
/* globals sinon */
// ================================================
var {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
var gProfD = do_get_profile().QueryInterface(Ci.nsIFile);

View file

@ -104,7 +104,7 @@ async function withNewWindow(callback) {
}
add_task(async function setup() {
sandbox = sinon.sandbox.create();
sandbox = sinon.createSandbox();
fakeController = new UrlbarController({
browserWindow: window,

View file

@ -8,7 +8,7 @@
// original search query.
add_task(async function setup() {
sandbox = sinon.sandbox.create();
sandbox = sinon.createSandbox();
registerCleanupFunction(async () => {
sandbox.restore();

View file

@ -31,7 +31,7 @@ const REMOTE_TAB = {
};
add_task(async function setup() {
sandbox = sinon.sandbox.create();
sandbox = sinon.createSandbox();
let originalSyncedTabsInternal = SyncedTabs._internal;
SyncedTabs._internal = {
@ -54,7 +54,7 @@ add_task(async function setup() {
["services.sync.syncedTabs.showRemoteTabs", true],
]});
sandbox.stub(SyncedTabs._internal, "getTabClients", () => Promise.resolve(Cu.cloneInto([REMOTE_TAB], {})));
sandbox.stub(SyncedTabs._internal, "getTabClients").callsFake(() => Promise.resolve(Cu.cloneInto([REMOTE_TAB], {})));
registerCleanupFunction(async () => {
sandbox.restore();

View file

@ -25,9 +25,4 @@ Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/browser/components/urlbar/tests/browser/head-common.js",
this);
/* global sinon */
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
registerCleanupFunction(function() {
delete window.sinon;
});
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");

View file

@ -25,15 +25,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarResult: "resource:///modules/UrlbarResult.jsm",
UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.jsm",
});
// ================================================
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/releases/v2.3.2/
// Sinon needs Timer.jsm for setTimeout etc.
var {clearInterval, clearTimeout, setInterval, setIntervalWithTarget, setTimeout, setTimeoutWithTarget} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
/* globals sinon */
// ================================================
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
/**
* @param {string} searchString The search string to insert into the context.

View file

@ -31,7 +31,7 @@ function assertContextMatches(context, expectedValues) {
}
add_task(function setup() {
sandbox = sinon.sandbox.create();
sandbox = sinon.createSandbox();
fPM = {
startQuery: sandbox.stub(),

View file

@ -14,7 +14,7 @@ const {PlacesUIUtils} = ChromeUtils.import("resource:///modules/PlacesUIUtils.js
let sandbox;
add_task(function setup() {
sandbox = sinon.sandbox.create();
sandbox = sinon.createSandbox();
});
add_task(function test_addToUrlbarHistory() {

View file

@ -12,6 +12,7 @@ var {AddonTestUtils, MockAsyncShutdown} = ChromeUtils.import("resource://testing
var {ExtensionTestUtils} = ChromeUtils.import("resource://testing-common/ExtensionXPCShellUtils.jsm");
var {FileTestUtils} = ChromeUtils.import("resource://testing-common/FileTestUtils.jsm");
var {MockDocument} = ChromeUtils.import("resource://testing-common/MockDocument.jsm");
var {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
var {TestUtils} = ChromeUtils.import("resource://testing-common/TestUtils.jsm");
ChromeUtils.defineModuleGetter(this, "AddonManager",
@ -58,21 +59,6 @@ region-name-tw = Taiwan
do_get_profile();
// ================================================
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/releases/v2.3.2/
var {
clearInterval,
clearTimeout,
setInterval,
setIntervalWithTarget,
setTimeout,
setTimeoutWithTarget,
} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
/* globals sinon */
// ================================================
const EXTENSION_ID = "formautofill@mozilla.org";
AddonTestUtils.init(this);

View file

@ -47,7 +47,7 @@ add_task(async function test_activeStatus_observe() {
// _active != _computeStatus() => Need to trigger _onStatusChanged
formAutofillParent._computeStatus.returns(false);
formAutofillParent._onStatusChanged.reset();
formAutofillParent._onStatusChanged.resetHistory();
formAutofillParent.observe(null, "nsPref:changed", "extensions.formautofill.addresses.enabled");
formAutofillParent.observe(null, "nsPref:changed", "extensions.formautofill.creditCards.enabled");
Assert.equal(formAutofillParent._onStatusChanged.called, true);
@ -55,14 +55,14 @@ add_task(async function test_activeStatus_observe() {
// profile changed => Need to trigger _onStatusChanged
await Promise.all(["add", "update", "remove", "reconcile"].map(async event => {
formAutofillParent._computeStatus.returns(!formAutofillParent._active);
formAutofillParent._onStatusChanged.reset();
formAutofillParent._onStatusChanged.resetHistory();
await formAutofillParent.observe(null, "formautofill-storage-changed", event);
Assert.equal(formAutofillParent._onStatusChanged.called, true);
}));
// profile metadata updated => No need to trigger _onStatusChanged
formAutofillParent._computeStatus.returns(!formAutofillParent._active);
formAutofillParent._onStatusChanged.reset();
formAutofillParent._onStatusChanged.resetHistory();
await formAutofillParent.observe(null, "formautofill-storage-changed", "notifyUsed");
Assert.equal(formAutofillParent._onStatusChanged.called, false);
});

View file

@ -41,14 +41,14 @@ add_task(async function test_loadDataState() {
Assert.equal(metadata.id, "data/US");
Assert.ok(metadata.alternative_names,
"US alternative names should be loaded from extension");
AddressDataLoader._loadScripts.reset();
AddressDataLoader._loadScripts.resetHistory();
// Load data without country
let newMetadata = FormAutofillUtils.getCountryAddressData();
// _loadScripts should not be called
sinon.assert.notCalled(AddressDataLoader._loadScripts);
Assert.deepEqual(metadata, newMetadata, "metadata should be US if country is not specified");
AddressDataLoader._loadScripts.reset();
AddressDataLoader._loadScripts.resetHistory();
// Load level 1 data that does not exist
let undefinedMetadata = FormAutofillUtils.getCountryAddressData("US", "CA");
@ -57,7 +57,7 @@ add_task(async function test_loadDataState() {
Assert.equal(undefinedMetadata, undefined, "metadata should be undefined");
Assert.ok(AddressDataLoader._dataLoaded.level1.has("US"),
"level 1 state array should be set even there's no valid metadata");
AddressDataLoader._loadScripts.reset();
AddressDataLoader._loadScripts.resetHistory();
// Load level 1 data again
undefinedMetadata = FormAutofillUtils.getCountryAddressData("US", "AS");

View file

@ -5,6 +5,8 @@
"use strict";
const {setTimeout, clearTimeout} = ChromeUtils.import("resource://gre/modules/Timer.jsm", {});
var FormAutofillHandler, OSKeyStore;
add_task(async function setup() {
({FormAutofillHandler} = ChromeUtils.import("resource://formautofill/FormAutofillHandler.jsm"));

View file

@ -180,7 +180,7 @@ add_task(async function test_getRecords_creditCards() {
clonedRecord["cc-number-encrypted"] = await OSKeyStore.encrypt(record["cc-number"]);
return clonedRecord;
}));
sinon.stub(collection, "getAll", () =>
sinon.stub(collection, "getAll").callsFake(() =>
Promise.resolve([Object.assign({}, encryptedCCRecords[0]), Object.assign({}, encryptedCCRecords[1])]));
let testCases = [

View file

@ -527,7 +527,7 @@ add_task(async function autofill_disabled() {
Services.prefs.setBoolPref("extensions.formautofill.creditCards.enabled", false);
FormAutofillContent.formSubmitted(form, null);
Assert.equal(FormAutofillContent._onFormSubmit.called, false);
FormAutofillContent._onFormSubmit.reset();
FormAutofillContent._onFormSubmit.resetHistory();
// "_onFormSubmit" should be called as usual.
Services.prefs.clearUserPref("extensions.formautofill.addresses.enabled");
@ -536,7 +536,7 @@ add_task(async function autofill_disabled() {
Assert.equal(FormAutofillContent._onFormSubmit.called, true);
Assert.notDeepEqual(FormAutofillContent._onFormSubmit.args[0][0].address, []);
Assert.notDeepEqual(FormAutofillContent._onFormSubmit.args[0][0].creditCard, []);
FormAutofillContent._onFormSubmit.reset();
FormAutofillContent._onFormSubmit.resetHistory();
// "address" should be empty if "addresses" pref is disabled.
Services.prefs.setBoolPref("extensions.formautofill.addresses.enabled", false);
@ -544,7 +544,7 @@ add_task(async function autofill_disabled() {
Assert.equal(FormAutofillContent._onFormSubmit.called, true);
Assert.deepEqual(FormAutofillContent._onFormSubmit.args[0][0].address, []);
Assert.notDeepEqual(FormAutofillContent._onFormSubmit.args[0][0].creditCard, []);
FormAutofillContent._onFormSubmit.reset();
FormAutofillContent._onFormSubmit.resetHistory();
Services.prefs.clearUserPref("extensions.formautofill.addresses.enabled");
// "creditCard" should be empty if "creditCards" pref is disabled.
@ -553,7 +553,7 @@ add_task(async function autofill_disabled() {
Assert.deepEqual(FormAutofillContent._onFormSubmit.called, true);
Assert.notDeepEqual(FormAutofillContent._onFormSubmit.args[0][0].address, []);
Assert.deepEqual(FormAutofillContent._onFormSubmit.args[0][0].creditCard, []);
FormAutofillContent._onFormSubmit.reset();
FormAutofillContent._onFormSubmit.resetHistory();
Services.prefs.clearUserPref("extensions.formautofill.creditCards.enabled");
FormAutofillContent._onFormSubmit.restore();

View file

@ -34,7 +34,7 @@ add_task(async function test_profileSavedFieldNames_observe() {
});
// profile metadata updated => no need to trigger updateValidFields
formAutofillParent._updateSavedFieldNames.reset();
formAutofillParent._updateSavedFieldNames.resetHistory();
formAutofillParent.observe(null, "formautofill-storage-changed", "notifyUsed");
Assert.equal(formAutofillParent._updateSavedFieldNames.called, false);
});

View file

@ -16,6 +16,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
URLBAR_SELECTED_RESULT_TYPES: "resource:///modules/BrowserUsageTelemetry.jsm",
URLBAR_SELECTED_RESULT_METHODS: "resource:///modules/BrowserUsageTelemetry.jsm",
});
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
function assertSearchTelemetryEmpty(search_hist) {
const scalars = TelemetryTestUtils.getProcessScalars("parent", true, false);
@ -58,9 +59,6 @@ function assertHistogramResults(histograms, type, index, method) {
add_task(async function setup() {
/* global sinon */
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
await SpecialPowers.pushPrefEnv({
set: [
// Disable search suggestions in the urlbar.
@ -108,7 +106,7 @@ add_task(async function setup() {
],
};
const sandbox = sinon.sandbox.create();
const sandbox = sinon.createSandbox();
let originalSyncedTabsInternal = SyncedTabs._internal;
SyncedTabs._internal = {
@ -137,7 +135,6 @@ add_task(async function setup() {
await PlacesUtils.history.clear();
await PlacesUtils.bookmarks.eraseEverything();
Services.telemetry.setEventRecordingEnabled("navigation", false);
delete window.sinon;
});
});

View file

@ -10,6 +10,7 @@ Test that Accordion renders correctly.
<meta charset="utf-8">
<title>Accordion component test</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="resource://testing-common/sinon-7.2.7.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<link rel="stylesheet" href="chrome://devtools/skin/light-theme.css" type="text/css">
</head>
@ -24,7 +25,6 @@ Test that Accordion renders correctly.
window.onload = async function() {
try {
const { button, div } = require("devtools/client/shared/vendor/react-dom-factories");
const sinon = require("resource://testing-common/sinon-2.3.2.js");
const React = browserRequire("devtools/client/shared/vendor/react");
const {
Simulate,

View file

@ -6,12 +6,3 @@
/* eslint no-unused-vars: [2, {"vars": "local"}] */
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
const Services = require("Services");
// ================================================
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/releases/v2.3.2/
const {setTimeout, clearTimeout, setInterval, clearInterval} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
/* globals sinon */
// ================================================

View file

@ -2695,7 +2695,7 @@ pref("csp.overrule_about_uris_without_csp_whitelist", false);
pref("csp.skip_about_page_has_csp_assert", false);
// assertion flag will be set to false after fixing Bug 1473549
pref("security.allow_eval_with_system_principal", false);
pref("security.uris_using_eval_with_system_principal", "autocomplete.xml,redux.js,react-redux.js,content-task.js,content-task.js,tree.xml,dialog.xml,preferencesbindings.js,wizard.xml,lodash.js,jszip.js,ajv-4.1.1.js,updates.js,setup,jsol.js,parent_utils.js,chrometask_chromescript");
pref("security.uris_using_eval_with_system_principal", "autocomplete.xml,redux.js,react-redux.js,content-task.js,content-task.js,tree.xml,dialog.xml,preferencesbindings.js,wizard.xml,lodash.js,jszip.js,sinon-7.2.7.js,ajv-4.1.1.js,updates.js,setup,jsol.js,parent_utils.js,chrometask_chromescript");
#endif
// Default Content Security Policy to apply to signed contents.

View file

@ -3,10 +3,7 @@
const {Async} = ChromeUtils.import("resource://services-common/async.js");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
// Sinon seems to require setTimeout.
const {setTimeout, clearTimeout, setInterval, clearInterval} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
/* globals sinon */
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
function makeArray(length) {
// Start at 1 so that we can just divide by yieldEvery to get the expected

View file

@ -8,6 +8,7 @@
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
var {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
(function initFxAccountsTestingInfrastructure() {
do_get_profile();
@ -17,11 +18,3 @@ var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ns.initTestLogging("Trace");
}).call(this);
// ================================================
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/releases/v2.3.2/
var {clearInterval, clearTimeout, setInterval, setIntervalWithTarget, setTimeout, setTimeoutWithTarget} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
/* globals sinon */
// ================================================

View file

@ -7,6 +7,7 @@ const {ON_PROFILE_CHANGE_NOTIFICATION, log} = ChromeUtils.import("resource://gre
const {FxAccountsProfileClient} = ChromeUtils.import("resource://gre/modules/FxAccountsProfileClient.jsm");
const {FxAccountsProfile} = ChromeUtils.import("resource://gre/modules/FxAccountsProfile.jsm");
const {PromiseUtils} = ChromeUtils.import("resource://gre/modules/PromiseUtils.jsm");
const {setTimeout} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
let mockClient = function(fxa) {
let options = {

View file

@ -14,6 +14,7 @@ var {AddonTestUtils, MockAsyncShutdown} = ChromeUtils.import("resource://testing
var {Async} = ChromeUtils.import("resource://services-common/async.js");
var {CommonUtils} = ChromeUtils.import("resource://services-common/utils.js");
var {PlacesTestUtils} = ChromeUtils.import("resource://testing-common/PlacesTestUtils.jsm");
var {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
var {SerializableSet, Svc, Utils, getChromeWindow} = ChromeUtils.import("resource://services-sync/util.js");
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
var {PlacesUtils} = ChromeUtils.import("resource://gre/modules/PlacesUtils.jsm");
@ -33,14 +34,6 @@ add_task(async function head_setup() {
}
});
// ================================================
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/releases/v2.3.2/
var {clearInterval, clearTimeout, setInterval, setIntervalWithTarget, setTimeout, setTimeoutWithTarget} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
/* globals sinon */
// ================================================
XPCOMUtils.defineLazyGetter(this, "SyncPingSchema", function() {
let ns = {};
ChromeUtils.import("resource://gre/modules/FileUtils.jsm", ns);

View file

@ -1584,7 +1584,7 @@ add_task(async function test_command_sync() {
await engine.sendCommand("wipeAll", []);
await engine._tracker.addChangedID(engine.localID);
const getClientFxaDeviceId = sinon.stub(engine, "getClientFxaDeviceId", (id) => "fxa-" + id);
const getClientFxaDeviceId = sinon.stub(engine, "getClientFxaDeviceId").callsFake((id) => "fxa-" + id);
const engineMock = sinon.mock(engine);
let _notifyCollectionChanged = engineMock.expects("_notifyCollectionChanged")
.withArgs(["fxa-" + remoteId, "fxa-" + remoteId2]);
@ -1796,7 +1796,7 @@ add_task(async function device_disconnected_notification_updates_known_stale_cli
Services.obs.notifyObservers(null, "fxaccounts:device_disconnected",
JSON.stringify({ isLocalDevice: false }));
ok(spyUpdate.calledOnce, "updateKnownStaleClients should be called");
spyUpdate.reset();
spyUpdate.resetHistory();
Services.obs.notifyObservers(null, "fxaccounts:device_disconnected",
JSON.stringify({ isLocalDevice: true }));
@ -1811,7 +1811,7 @@ add_task(async function update_known_stale_clients() {
const stubRemoteClients = sinon.stub(engine._store, "_remoteClients").get(() => {
return clients;
});
const stubFetchFxADevices = sinon.stub(engine, "_fetchFxADevices", () => {
const stubFetchFxADevices = sinon.stub(engine, "_fetchFxADevices").callsFake(() => {
engine._knownStaleFxADeviceIds = ["fxa-one", "fxa-two"];
});
@ -1835,7 +1835,7 @@ add_task(async function test_create_record_command_limit() {
const fakeLimit = 4 * 1024;
let maxSizeStub = sinon.stub(Service,
"getMemcacheMaxRecordPayloadSize", () => fakeLimit);
"getMemcacheMaxRecordPayloadSize").callsFake(() => fakeLimit);
let user = server.user("foo");
let remoteId = Utils.makeGUID();

View file

@ -1,6 +1,5 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* global sinon */
"use strict";

View file

@ -112,7 +112,7 @@ add_task(async function test_createRecord() {
// actual max we can fit.
equal(record.tabs.length, 2672);
let maxSizeStub = sinon.stub(Service, "getMemcacheMaxRecordPayloadSize", () => 512 * 1024);
let maxSizeStub = sinon.stub(Service, "getMemcacheMaxRecordPayloadSize").callsFake(() => 512 * 1024);
try {
numtabs = 5400;
_("Modify the max record payload size and create a big record");

View file

@ -16,7 +16,7 @@ add_task(async function test_isReady_unconfigured() {
// Does not trigger a refresh of the state since services.sync.username is undefined
ok(!UIState.isReady());
ok(!refreshState.called);
refreshState.reset();
refreshState.resetHistory();
// On subsequent calls, only return true
ok(UIState.isReady());
@ -34,7 +34,7 @@ add_task(async function test_isReady_signedin() {
// On the first call, returns false and triggers a refresh of the state
ok(!UIState.isReady());
ok(refreshState.calledOnce);
refreshState.reset();
refreshState.resetHistory();
// On subsequent calls, only return true
ok(UIState.isReady());
@ -240,7 +240,7 @@ add_task(async function test_observer_refreshState() {
Services.obs.notifyObservers(null, topic);
await uiUpdateObserved;
ok(refreshState.calledOnce);
refreshState.reset();
refreshState.resetHistory();
}
refreshState.restore();

22
testing/modules/Sinon.jsm Normal file
View file

@ -0,0 +1,22 @@
"use strict";
var EXPORTED_SYMBOLS = ["sinon"];
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
// ================================================
// Load mocking/stubbing library sinon
// docs: http://sinonjs.org/releases/v7.2.7/
const {clearInterval, clearTimeout, setInterval, setIntervalWithTarget, setTimeout, setTimeoutWithTarget} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
// eslint-disable-next-line no-unused-vars
const global = {
clearInterval,
clearTimeout,
setInterval,
setIntervalWithTarget,
setTimeout,
setTimeoutWithTarget,
};
Services.scriptloader.loadSubScript("resource://testing-common/sinon-7.2.7.js", this);
const sinon = global.sinon;
// ================================================

View file

@ -15,7 +15,8 @@ TESTING_JS_MODULES += [
'CoverageUtils.jsm',
'FileTestUtils.jsm',
'MockRegistrar.jsm',
'sinon-2.3.2.js',
'sinon-7.2.7.js',
'Sinon.jsm',
'StructuredLog.jsm',
'TestUtils.jsm',
]

File diff suppressed because one or more lines are too long

31787
testing/modules/sinon-7.2.7.js Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,9 +1,2 @@
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
// ================================================
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/releases/v2.3.2/
var {clearInterval, clearTimeout, setInterval, setIntervalWithTarget, setTimeout, setTimeoutWithTarget} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
/* global sinon */
// ================================================
var {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");

View file

@ -80,7 +80,7 @@ add_task(async function testDoNotTrack() {
add_task(async function testExperiments() {
const active = {name: "active", expired: false};
const expired = {name: "expired", expired: true};
const getAll = sinon.stub(PreferenceExperiments, "getAll", async () => [active, expired]);
const getAll = sinon.stub(PreferenceExperiments, "getAll").callsFake(async () => [active, expired]);
const experiments = await ClientEnvironment.experiments;
Assert.deepEqual(

View file

@ -140,10 +140,7 @@ async function withMockActionSandboxManagers(actions, testFunction) {
sinon.stub(managers[action.name], "runAsyncCallback");
}
const loadActionSandboxManagers = sinon.stub(RecipeRunner, "loadActionSandboxManagers")
.resolves(managers);
await testFunction(managers);
loadActionSandboxManagers.restore();
for (const manager of Object.values(managers)) {
manager.removeHold("testing");
@ -359,9 +356,8 @@ decorate_task(
withStub(RecipeRunner, "enable"),
withStub(RecipeRunner, "disable"),
withStub(CleanupManager, "addCleanupHandler"),
withStub(AddonStudies, "stop"),
async function testPrefWatching(runStub, enableStub, disableStub, addCleanupHandlerStub, stopStub) {
async function testPrefWatching(runStub, enableStub, disableStub, addCleanupHandlerStub) {
await RecipeRunner.init();
is(enableStub.callCount, 1, "Enable should be called initially");
is(disableStub.callCount, 0, "Disable should not be called initially");

View file

@ -245,10 +245,10 @@ decorate_task(
{ value: "branch0", ratio: 1 },
{ value: "branch1", ratio: 2 },
];
const sandbox = sinon.sandbox.create();
const sandbox = sinon.createSandbox();
let result;
try {
sandbox.stub(ClientEnvironment, "userId", { get: () => "fake-id" });
sandbox.stub(ClientEnvironment, "userId").get(() => "fake-id");
result = await action.chooseBranch("exp-slug", branches);
} finally {
sandbox.restore();

View file

@ -14,21 +14,13 @@ const CryptoHash = Components.Constructor("@mozilla.org/security/hash;1",
const FileInputStream = Components.Constructor("@mozilla.org/network/file-input-stream;1",
"nsIFileInputStream", "init");
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/docs/
/* global sinon */
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
const {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");
// Make sinon assertions fail in a way that mochitest understands
sinon.assert.fail = function(message) {
ok(false, message);
};
registerCleanupFunction(async function() {
// Cleanup window or the test runner will throw an error
delete window.sinon;
});
// Prep Telemetry to receive events from tests
TelemetryEvents.init();

View file

@ -1,12 +1,4 @@
"use strict";
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
// ================================================
// Load mocking/stubbing library, sinon
// docs: http://sinonjs.org/releases/v2.3.2/
/* exported sinon */
var {clearInterval, clearTimeout, setInterval, setIntervalWithTarget, setTimeout, setTimeoutWithTarget} = ChromeUtils.import("resource://gre/modules/Timer.jsm");
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
/* globals sinon */
// ================================================
var {sinon} = ChromeUtils.import("resource://testing-common/Sinon.jsm");

View file

@ -23,7 +23,7 @@ add_task(withMockApiServer(async function test_getApiUrl(serverUrl) {
add_task(withMockApiServer(async function test_getApiUrlSlashes(serverUrl, preferences) {
const fakeResponse = new MockResponse(JSON.stringify({"test-endpoint": `${serverUrl}/test/`}));
const mockGet = sinon.stub(NormandyApi, "get", async () => fakeResponse);
const mockGet = sinon.stub(NormandyApi, "get").callsFake(async () => fakeResponse);
// without slash
{
@ -32,7 +32,7 @@ add_task(withMockApiServer(async function test_getApiUrlSlashes(serverUrl, prefe
const endpoint = await NormandyApi.getApiUrl("test-endpoint");
equal(endpoint, `${serverUrl}/test/`);
ok(mockGet.calledWithExactly(`${serverUrl}/api/v1/`), "trailing slash was added");
mockGet.reset();
mockGet.resetHistory();
}
// with slash
@ -42,7 +42,7 @@ add_task(withMockApiServer(async function test_getApiUrlSlashes(serverUrl, prefe
const endpoint = await NormandyApi.getApiUrl("test-endpoint");
equal(endpoint, `${serverUrl}/test/`);
ok(mockGet.calledWithExactly(`${serverUrl}/api/v1/`), "existing trailing slash was preserved");
mockGet.reset();
mockGet.resetHistory();
}
NormandyApi.clearIndexCache();