Skip to content

Commit

Permalink
Bug 1435296 Address xpcshell test failures from increasing timer prec…
Browse files Browse the repository at this point in the history
…ision r=baku

See the comment on "Address test failures caused by bumping timer precision to 2 ms"
for more details.

MozReview-Commit-ID: LrsucEPdZIo

--HG--
extra : rebase_source : 8147c034f7dc93f678eebc80b0afabf55729d804
  • Loading branch information
tomrittervg committed Feb 12, 2018
1 parent f928a0f commit c4edd2f
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ add_task(async function testCache() {
});

add_task(async function testCookies() {
// Above in setUpCookies we create an 'old' cookies, wait 10ms, then log a timestamp.
// Here we ask the browser to delete all cookies after the timestamp, with the intention
// that the 'old' cookie is not removed. The issue arises when the timer precision is
// low enough such that the timestamp that gets logged is the same as the 'old' cookie.
// We hardcode a precision value to ensure that there is time between the 'old' cookie
// and the timestamp generation.
Services.prefs.setBoolPref("privacy.reduceTimerPrecision", true);
Services.prefs.setIntPref("privacy.resistFingerprinting.reduceTimerPrecision.microseconds", 2000);

registerCleanupFunction(function() {
Services.prefs.clearUserPref("privacy.reduceTimerPrecision");
Services.prefs.clearUserPref("privacy.resistFingerprinting.reduceTimerPrecision.microseconds");
});

function background() {
browser.test.onMessage.addListener(async (msg, options) => {
if (msg == "removeCookies") {
Expand Down
13 changes: 13 additions & 0 deletions browser/extensions/formautofill/test/unit/test_addressRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ const MERGE_TESTCASES = [
},
];

ChromeUtils.defineModuleGetter(this, "Preferences",
"resource://gre/modules/Preferences.jsm");

let do_check_record_matches = (recordWithMeta, record) => {
for (let key in record) {
Assert.equal(recordWithMeta[key], record[key]);
Expand Down Expand Up @@ -369,6 +372,16 @@ add_task(async function test_add() {
});

add_task(async function test_update() {
// Test assumes that when an entry is saved a second time, it's last modified date will
// be different from the first. With high values of precision reduction, we execute too
// fast for that to be true.
let timerPrecision = Preferences.get("privacy.reduceTimerPrecision");
Preferences.set("privacy.reduceTimerPrecision", false);

registerCleanupFunction(function() {
Preferences.set("privacy.reduceTimerPrecision", timerPrecision);
});

let profileStorage = await initProfileStorage(TEST_STORE_FILE_NAME,
[TEST_ADDRESS_1, TEST_ADDRESS_2]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"use strict";

const {FormAutofillStorage} = ChromeUtils.import("resource://formautofill/FormAutofillStorage.jsm", {});
ChromeUtils.defineModuleGetter(this, "Preferences",
"resource://gre/modules/Preferences.jsm");

const TEST_STORE_FILE_NAME = "test-credit-card.json";
const COLLECTION_NAME = "creditCards";
Expand Down Expand Up @@ -290,6 +292,16 @@ add_task(async function test_add() {
});

add_task(async function test_update() {
// Test assumes that when an entry is saved a second time, it's last modified date will
// be different from the first. With high values of precision reduction, we execute too
// fast for that to be true.
let timerPrecision = Preferences.get("privacy.reduceTimerPrecision");
Preferences.set("privacy.reduceTimerPrecision", false);

registerCleanupFunction(function() {
Preferences.set("privacy.reduceTimerPrecision", timerPrecision);
});

let path = getTempFile(TEST_STORE_FILE_NAME).path;
await prepareTestCreditCards(path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ const { PromisesFront } = require("devtools/shared/fronts/promises");

var EventEmitter = require("devtools/shared/event-emitter");

ChromeUtils.defineModuleGetter(this, "Preferences",
"resource://gre/modules/Preferences.jsm");

add_task(function* () {
let timerPrecision = Preferences.get("privacy.reduceTimerPrecision");
Preferences.set("privacy.reduceTimerPrecision", false);

registerCleanupFunction(function () {
Preferences.set("privacy.reduceTimerPrecision", timerPrecision);
});

let client = yield startTestDebuggerServer("promises-object-test");
let chromeActors = yield getChromeActors(client);

Expand Down Expand Up @@ -63,7 +73,8 @@ function* testPromiseCreationTimestamp(client, form, makePromise) {
let creationTimestamp = grip.promiseState.creationTimestamp;

ok(start - 1 <= creationTimestamp && creationTimestamp <= end + 1,
"Expect promise creation timestamp to be within elapsed time range.");
"Expect promise creation timestamp to be within elapsed time range: " +
(start - 1) + " <= " + creationTimestamp + " <= " + (end + 1));

yield front.detach();
// Appease eslint
Expand Down
15 changes: 15 additions & 0 deletions netwerk/test/unit/test_race_cache_with_network.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ function run_test() {

let testGenerator = testSteps();
function *testSteps() {
/*
* In this test, we have a relatively low timeout of 200ms and an assertion that
* the timer works properly by checking that the time was greater than 200ms.
* With a timer precision of 100ms (for example) we will clamp downwards to 200
* and cause the assertion to fail. To resolve this, we hardcode a precision of
* 20ms.
*/
Services.prefs.setBoolPref("privacy.reduceTimerPrecision", true);
Services.prefs.setIntPref("privacy.resistFingerprinting.reduceTimerPrecision.microseconds", 20000);

registerCleanupFunction(function() {
Services.prefs.clearUserPref("privacy.reduceTimerPrecision");
Services.prefs.clearUserPref("privacy.resistFingerprinting.reduceTimerPrecision.microseconds");
});

// Initial request. Stores the response in the cache.
var channel = make_channel("http://localhost:" + PORT + "/rcwn");
channel.asyncOpen2(new ChannelListener(checkContent, null));
Expand Down
10 changes: 10 additions & 0 deletions services/fxaccounts/tests/xpcshell/test_profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ add_test(function fetchAndCacheProfile_alreadyCached() {
// Check that a new profile request within PROFILE_FRESHNESS_THRESHOLD of the
// last one doesn't kick off a new request to check the cached copy is fresh.
add_task(async function fetchAndCacheProfileAfterThreshold() {
/*
* This test was observed to cause a timeout for... any timer precision reduction.
* Even 1 us. Exact reason is still undiagnosed.
*/
Services.prefs.setBoolPref("privacy.reduceTimerPrecision", false);

registerCleanupFunction(async () => {
Services.prefs.clearUserPref("privacy.reduceTimerPrecision");
});

let numFetches = 0;
let client = mockClient(mockFxa());
client.fetchProfile = async function() {
Expand Down
8 changes: 8 additions & 0 deletions services/sync/tests/unit/test_addons_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ChromeUtils.import("resource://services-sync/addonsreconciler.js");
ChromeUtils.import("resource://services-sync/engines/addons.js");
ChromeUtils.import("resource://services-sync/service.js");
ChromeUtils.import("resource://services-sync/util.js");
ChromeUtils.defineModuleGetter(this, "Preferences", "resource://gre/modules/Preferences.jsm");

const prefs = new Preferences();
prefs.set("extensions.getAddons.get.url",
Expand Down Expand Up @@ -90,6 +91,13 @@ add_task(async function test_find_dupe() {
});

add_task(async function test_get_changed_ids() {
let timerPrecision = Preferences.get("privacy.reduceTimerPrecision");
Preferences.set("privacy.reduceTimerPrecision", false);

registerCleanupFunction(function() {
Preferences.set("privacy.reduceTimerPrecision", timerPrecision);
});

_("Ensure getChangedIDs() has the appropriate behavior.");

_("Ensure getChangedIDs() returns an empty object by default.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ add_task(async function test_search() {

Services.prefs.setIntPref("browser.download.folderList", 2);
Services.prefs.setComplexValue("browser.download.dir", nsIFile, downloadDir);
Services.prefs.setBoolPref("privacy.reduceTimerPrecision", false);

registerCleanupFunction(async () => {
Services.prefs.clearUserPref("browser.download.folderList");
Services.prefs.clearUserPref("browser.download.dir");
Services.prefs.clearUserPref("privacy.reduceTimerPrecision");
await cleanupDir(downloadDir);
await clearDownloads();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

ChromeUtils.defineModuleGetter(this, "Preferences",
"resource://gre/modules/Preferences.jsm");

add_task(async function insert_separator_notification() {
let observer = expectNotifications();
let bm = await PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_SEPARATOR,
Expand Down Expand Up @@ -108,6 +111,13 @@ add_task(async function insert_bookmark_tag_notification() {
});

add_task(async function update_bookmark_lastModified() {
let timerPrecision = Preferences.get("privacy.reduceTimerPrecision");
Preferences.set("privacy.reduceTimerPrecision", false);

registerCleanupFunction(function() {
Preferences.set("privacy.reduceTimerPrecision", timerPrecision);
});

let bm = await PlacesUtils.bookmarks.insert({ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: new URL("http://lastmod.example.com/") });
Expand Down
17 changes: 17 additions & 0 deletions toolkit/components/places/tests/bookmarks/test_keywords.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ChromeUtils.defineModuleGetter(this, "Preferences",
"resource://gre/modules/Preferences.jsm");

const URI1 = NetUtil.newURI("http://test1.mozilla.org/");
const URI2 = NetUtil.newURI("http://test2.mozilla.org/");
const URI3 = NetUtil.newURI("http://test3.mozilla.org/");
Expand Down Expand Up @@ -80,6 +83,13 @@ add_task(function test_invalid_input() {
});

add_task(async function test_addBookmarkAndKeyword() {
let timerPrecision = Preferences.get("privacy.reduceTimerPrecision");
Preferences.set("privacy.reduceTimerPrecision", false);

registerCleanupFunction(function() {
Preferences.set("privacy.reduceTimerPrecision", timerPrecision);
});

await check_keyword(URI1, null);
let fc = await foreign_count(URI1);
let observer = expectNotifications();
Expand Down Expand Up @@ -128,6 +138,13 @@ add_task(async function test_addBookmarkToURIHavingKeyword() {
});

add_task(async function test_sameKeywordDifferentURI() {
let timerPrecision = Preferences.get("privacy.reduceTimerPrecision");
Preferences.set("privacy.reduceTimerPrecision", false);

registerCleanupFunction(function() {
Preferences.set("privacy.reduceTimerPrecision", timerPrecision);
});

let fc1 = await foreign_count(URI1);
let fc2 = await foreign_count(URI2);
let observer = expectNotifications();
Expand Down
10 changes: 10 additions & 0 deletions toolkit/components/places/tests/unit/test_async_transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const rootGuid = PlacesUtils.bookmarks.rootGuid;
const menuGuid = PlacesUtils.bookmarks.menuGuid;

Components.utils.importGlobalProperties(["URL"]);
ChromeUtils.defineModuleGetter(this, "Preferences",
"resource://gre/modules/Preferences.jsm");


// Create and add bookmarks observer.
var observer = {
Expand Down Expand Up @@ -1589,6 +1592,13 @@ add_task(async function test_copy() {
await PT.clearTransactionsHistory();
}

let timerPrecision = Preferences.get("privacy.reduceTimerPrecision");
Preferences.set("privacy.reduceTimerPrecision", false);

registerCleanupFunction(function() {
Preferences.set("privacy.reduceTimerPrecision", timerPrecision);
});

// Test duplicating leafs (bookmark, separator, empty folder)
PT.NewBookmark({ url: new URL("http://test.item.duplicate"),
parentGuid: rootGuid,
Expand Down
10 changes: 10 additions & 0 deletions toolkit/components/places/tests/unit/test_keywords.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"use strict";

ChromeUtils.defineModuleGetter(this, "Preferences",
"resource://gre/modules/Preferences.jsm");

async function check_keyword(aExpectExists, aHref, aKeyword, aPostData = null) {
// Check case-insensitivity.
aKeyword = aKeyword.toUpperCase();
Expand Down Expand Up @@ -175,6 +178,13 @@ add_task(async function test_addKeyword() {
});

add_task(async function test_addBookmarkAndKeyword() {
let timerPrecision = Preferences.get("privacy.reduceTimerPrecision");
Preferences.set("privacy.reduceTimerPrecision", false);

registerCleanupFunction(function() {
Preferences.set("privacy.reduceTimerPrecision", timerPrecision);
});

await check_keyword(false, "http://example.com/", "keyword");
let fc = await foreign_count("http://example.com/");
let bookmark = await PlacesUtils.bookmarks.insert({ url: "http://example.com/",
Expand Down
9 changes: 9 additions & 0 deletions toolkit/components/places/tests/unit/test_sync_utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ChromeUtils.import("resource://gre/modules/ObjectUtils.jsm");
ChromeUtils.import("resource://gre/modules/PlacesSyncUtils.jsm");
ChromeUtils.import("resource://testing-common/httpd.js");
ChromeUtils.defineModuleGetter(this, "Preferences",
"resource://gre/modules/Preferences.jsm");
Cu.importGlobalProperties(["URLSearchParams"]);

const DESCRIPTION_ANNO = "bookmarkProperties/description";
Expand Down Expand Up @@ -2809,6 +2811,13 @@ add_task(async function test_remove_partial() {
});

add_task(async function test_migrateOldTrackerEntries() {
let timerPrecision = Preferences.get("privacy.reduceTimerPrecision");
Preferences.set("privacy.reduceTimerPrecision", false);

registerCleanupFunction(function() {
Preferences.set("privacy.reduceTimerPrecision", timerPrecision);
});

let unknownBmk = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.menuGuid,
url: "http://getfirefox.com",
Expand Down
8 changes: 8 additions & 0 deletions toolkit/components/satchel/test/unit/test_notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

ChromeUtils.defineModuleGetter(this, "setTimeout", "resource://gre/modules/Timer.jsm");
ChromeUtils.defineModuleGetter(this, "Preferences", "resource://gre/modules/Preferences.jsm");

const TestObserver = {
observed: [],
Expand Down Expand Up @@ -134,6 +135,13 @@ add_task(async function removeEntriesForName() {
});

add_task(async function removeEntriesByTimeframe() {
let timerPrecision = Preferences.get("privacy.reduceTimerPrecision");
Preferences.set("privacy.reduceTimerPrecision", false);

registerCleanupFunction(function() {
Preferences.set("privacy.reduceTimerPrecision", timerPrecision);
});

await promiseAddEntry(entry1[0], entry1[1]);
await promiseAddEntry(entry2[0], entry2[1]);

Expand Down

0 comments on commit c4edd2f

Please sign in to comment.