зеркало из https://github.com/mozilla/gecko-dev.git
Bug 606353 - Improve and harden history sync tests. r=rnewman
This commit is contained in:
Родитель
034dbc550a
Коммит
5f992ae26d
|
@ -102,7 +102,7 @@ function test_locally_changed_keys() {
|
|||
|
||||
// Upload keys.
|
||||
CollectionKeys.generateNewKeys();
|
||||
serverKeys = CollectionKeys.asWBO("crypto", "keys");
|
||||
let serverKeys = CollectionKeys.asWBO("crypto", "keys");
|
||||
serverKeys.encrypt(Weave.Service.syncKeyBundle);
|
||||
do_check_true(serverKeys.upload(Weave.Service.cryptoKeysURL).success);
|
||||
|
||||
|
@ -123,10 +123,9 @@ function test_locally_changed_keys() {
|
|||
// Let's create some server side history records.
|
||||
let liveKeys = CollectionKeys.keyForCollection("history");
|
||||
_("Keys now: " + liveKeys.keyPair);
|
||||
let nextHistory = {}
|
||||
let visitType = Ci.nsINavHistoryService.TRANSITION_LINK;
|
||||
for (var i = 0; i < 5; i++) {
|
||||
let id = 'record-no-' + i;
|
||||
let id = 'record-no--' + i;
|
||||
let modified = Date.now()/1000 - 60*(i+10);
|
||||
|
||||
let w = new CryptoWrapper("history", "id");
|
||||
|
@ -135,7 +134,7 @@ function test_locally_changed_keys() {
|
|||
histUri: "http://foo/bar?" + id,
|
||||
title: id,
|
||||
sortindex: i,
|
||||
visits: [{date: (modified - 5), type: visitType}],
|
||||
visits: [{date: (modified - 5) * 1000000, type: visitType}],
|
||||
deleted: false};
|
||||
w.encrypt();
|
||||
|
||||
|
@ -144,7 +143,9 @@ function test_locally_changed_keys() {
|
|||
hmac: w.hmac});
|
||||
wbo.modified = modified;
|
||||
history.wbos[id] = wbo;
|
||||
server.registerPathHandler("/1.0/johndoe/storage/history/record-no-" + i, upd("history", wbo.handler()));
|
||||
server.registerPathHandler(
|
||||
"/1.0/johndoe/storage/history/record-no--" + i,
|
||||
upd("history", wbo.handler()));
|
||||
}
|
||||
|
||||
collections.history = Date.now()/1000;
|
||||
|
@ -152,8 +153,8 @@ function test_locally_changed_keys() {
|
|||
_("Old key time: " + old_key_time);
|
||||
|
||||
// Check that we can decrypt one.
|
||||
let rec = new CryptoWrapper("history", "record-no-0");
|
||||
rec.fetch(Weave.Service.storageURL + "history/record-no-0");
|
||||
let rec = new CryptoWrapper("history", "record-no--0");
|
||||
rec.fetch(Weave.Service.storageURL + "history/record-no--0");
|
||||
_(JSON.stringify(rec));
|
||||
do_check_true(!!rec.decrypt());
|
||||
|
||||
|
@ -165,12 +166,6 @@ function test_locally_changed_keys() {
|
|||
|
||||
do_check_eq(hmacErrorCount, 0);
|
||||
|
||||
// Add some data.
|
||||
for (let k in nextHistory) {
|
||||
nextHistory[k].modified += 1000;
|
||||
history.wbos[k] = nextHistory[k];
|
||||
}
|
||||
|
||||
_("HMAC error count: " + hmacErrorCount);
|
||||
// Now syncing should succeed, after one HMAC error.
|
||||
Weave.Service.sync();
|
||||
|
@ -178,17 +173,18 @@ function test_locally_changed_keys() {
|
|||
_("Keys now: " + CollectionKeys.keyForCollection("history").keyPair);
|
||||
|
||||
// And look! We downloaded history!
|
||||
do_check_true(Engines.get("history")._store.urlExists("http://foo/bar?record-no-0"));
|
||||
do_check_true(Engines.get("history")._store.urlExists("http://foo/bar?record-no-1"));
|
||||
do_check_true(Engines.get("history")._store.urlExists("http://foo/bar?record-no-2"));
|
||||
do_check_true(Engines.get("history")._store.urlExists("http://foo/bar?record-no-3"));
|
||||
do_check_true(Engines.get("history")._store.urlExists("http://foo/bar?record-no-4"));
|
||||
let store = Engines.get("history")._store;
|
||||
do_check_true(store.urlExists("http://foo/bar?record-no--0"));
|
||||
do_check_true(store.urlExists("http://foo/bar?record-no--1"));
|
||||
do_check_true(store.urlExists("http://foo/bar?record-no--2"));
|
||||
do_check_true(store.urlExists("http://foo/bar?record-no--3"));
|
||||
do_check_true(store.urlExists("http://foo/bar?record-no--4"));
|
||||
do_check_eq(hmacErrorCount, 1);
|
||||
|
||||
_("Busting some new server values.");
|
||||
// Now what happens if we corrupt the HMAC on the server?
|
||||
for (var i = 5; i < 10; i++) {
|
||||
let id = 'record-no-' + i;
|
||||
let id = 'record-no--' + i;
|
||||
let modified = 1 + (Date.now()/1000);
|
||||
|
||||
let w = new CryptoWrapper("history", "id");
|
||||
|
@ -197,7 +193,7 @@ function test_locally_changed_keys() {
|
|||
histUri: "http://foo/bar?" + id,
|
||||
title: id,
|
||||
sortindex: i,
|
||||
visits: [{date: (modified - 5), type: visitType}],
|
||||
visits: [{date: (modified - 5 ) * 1000000, type: visitType}],
|
||||
deleted: false};
|
||||
w.encrypt();
|
||||
w.hmac = w.hmac.toUpperCase();
|
||||
|
@ -207,7 +203,9 @@ function test_locally_changed_keys() {
|
|||
hmac: w.hmac});
|
||||
wbo.modified = modified;
|
||||
history.wbos[id] = wbo;
|
||||
server.registerPathHandler("/1.0/johndoe/storage/history/record-no-" + i, upd("history", wbo.handler()));
|
||||
server.registerPathHandler(
|
||||
"/1.0/johndoe/storage/history/record-no--" + i,
|
||||
upd("history", wbo.handler()));
|
||||
}
|
||||
collections.history = Date.now()/1000;
|
||||
|
||||
|
@ -223,11 +221,11 @@ function test_locally_changed_keys() {
|
|||
_("Server keys have been updated, and we skipped over 5 more HMAC errors without adjusting history.");
|
||||
do_check_true(collections.crypto > old_key_time);
|
||||
do_check_eq(hmacErrorCount, 6);
|
||||
do_check_false(Engines.get("history")._store.urlExists("http://foo/bar?record-no-5"));
|
||||
do_check_false(Engines.get("history")._store.urlExists("http://foo/bar?record-no-6"));
|
||||
do_check_false(Engines.get("history")._store.urlExists("http://foo/bar?record-no-7"));
|
||||
do_check_false(Engines.get("history")._store.urlExists("http://foo/bar?record-no-8"));
|
||||
do_check_false(Engines.get("history")._store.urlExists("http://foo/bar?record-no-9"));
|
||||
do_check_false(store.urlExists("http://foo/bar?record-no--5"));
|
||||
do_check_false(store.urlExists("http://foo/bar?record-no--6"));
|
||||
do_check_false(store.urlExists("http://foo/bar?record-no--7"));
|
||||
do_check_false(store.urlExists("http://foo/bar?record-no--8"));
|
||||
do_check_false(store.urlExists("http://foo/bar?record-no--9"));
|
||||
|
||||
// Clean up.
|
||||
Weave.Service.startOver();
|
||||
|
|
|
@ -35,14 +35,14 @@ function test_processIncoming_mobile_history_batched() {
|
|||
// 10 minutes old.
|
||||
let visitType = Ci.nsINavHistoryService.TRANSITION_LINK;
|
||||
for (var i = 0; i < 234; i++) {
|
||||
let id = 'record-no-' + i;
|
||||
let id = 'record-no' + ("00" + i).slice(-3);
|
||||
let modified = Date.now()/1000 - 60*(i+10);
|
||||
let payload = encryptPayload({
|
||||
id: id,
|
||||
histUri: "http://foo/bar?" + id,
|
||||
title: id,
|
||||
sortindex: i,
|
||||
visits: [{date: (modified - 5), type: visitType}],
|
||||
visits: [{date: (modified - 5) * 1000000, type: visitType}],
|
||||
deleted: false});
|
||||
|
||||
let wbo = new ServerWBO(id, payload);
|
||||
|
@ -128,6 +128,7 @@ function test_processIncoming_mobile_history_batched() {
|
|||
}
|
||||
|
||||
} finally {
|
||||
Svc.History.removeAllPages();
|
||||
server.stop(do_test_finished);
|
||||
Svc.Prefs.resetBranch("");
|
||||
Records.clearCache();
|
||||
|
|
|
@ -63,8 +63,14 @@ function ensureThrows(func) {
|
|||
}
|
||||
|
||||
function run_test() {
|
||||
_("Verify that we've got an empty store to work with.");
|
||||
initTestLogging("Trace");
|
||||
|
||||
let store = new HistoryEngine()._store;
|
||||
function applyEnsureNoFailures(records) {
|
||||
do_check_eq(store.applyIncomingBatch(records).length, 0);
|
||||
}
|
||||
|
||||
_("Verify that we've got an empty store to work with.");
|
||||
do_check_eq([id for (id in store.getAllIDs())].length, 0);
|
||||
|
||||
let fxuri, fxguid, tburi, tbguid;
|
||||
|
@ -105,9 +111,12 @@ function run_test() {
|
|||
do_check_eq(queryres[1].title, "Hol Dir Firefox!");
|
||||
next();
|
||||
}));
|
||||
store.update({histUri: record.histUri,
|
||||
title: "Hol Dir Firefox!",
|
||||
visits: [record.visits[0], secondvisit]});
|
||||
applyEnsureNoFailures([
|
||||
{id: fxguid,
|
||||
histUri: record.histUri,
|
||||
title: "Hol Dir Firefox!",
|
||||
visits: [record.visits[0], secondvisit]}
|
||||
]);
|
||||
|
||||
}, function (next) {
|
||||
|
||||
|
@ -122,22 +131,26 @@ function run_test() {
|
|||
do_check_eq(queryres[0].title, "The bird is the word!");
|
||||
next();
|
||||
}));
|
||||
store.create({id: tbguid,
|
||||
histUri: tburi.spec,
|
||||
title: "The bird is the word!",
|
||||
visits: [{date: TIMESTAMP3,
|
||||
type: Ci.nsINavHistoryService.TRANSITION_TYPED}]});
|
||||
applyEnsureNoFailures([
|
||||
{id: tbguid,
|
||||
histUri: tburi.spec,
|
||||
title: "The bird is the word!",
|
||||
visits: [{date: TIMESTAMP3,
|
||||
type: Ci.nsINavHistoryService.TRANSITION_TYPED}]}
|
||||
]);
|
||||
|
||||
}, function (next) {
|
||||
|
||||
_("Make sure we handle a null title gracefully (it can happen in some cases, e.g. for resource:// URLs)");
|
||||
let resguid = Utils.makeGUID();
|
||||
let resuri = Utils.makeURI("unknown://title");
|
||||
store.create({id: resguid,
|
||||
histUri: resuri.spec,
|
||||
title: null,
|
||||
visits: [{date: TIMESTAMP3,
|
||||
type: Ci.nsINavHistoryService.TRANSITION_TYPED}]});
|
||||
applyEnsureNoFailures([
|
||||
{id: resguid,
|
||||
histUri: resuri.spec,
|
||||
title: null,
|
||||
visits: [{date: TIMESTAMP3,
|
||||
type: Ci.nsINavHistoryService.TRANSITION_TYPED}]}
|
||||
]);
|
||||
do_check_eq([id for (id in store.getAllIDs())].length, 3);
|
||||
let queryres = queryHistoryVisits(resuri);
|
||||
do_check_eq(queryres.length, 1);
|
||||
|
@ -155,21 +168,81 @@ function run_test() {
|
|||
let result = Utils.queryAsync(stmt);
|
||||
do_check_eq([id for (id in store.getAllIDs())].length, 4);
|
||||
|
||||
_("Make sure we report records with invalid URIs.");
|
||||
let invalid_uri_guid = Utils.makeGUID();
|
||||
let failed = store.applyIncomingBatch([{
|
||||
id: invalid_uri_guid,
|
||||
histUri: ":::::::::::::::",
|
||||
title: "Doesn't have a valid URI",
|
||||
visits: [{date: TIMESTAMP3,
|
||||
type: Ci.nsINavHistoryService.TRANSITION_EMBED}]}
|
||||
]);
|
||||
do_check_eq(failed.length, 1);
|
||||
do_check_eq(failed[0], invalid_uri_guid);
|
||||
|
||||
_("Make sure we handle records with invalid GUIDs gracefully (ignore).");
|
||||
applyEnsureNoFailures([
|
||||
{id: "invalid",
|
||||
histUri: "http://invalid.guid/",
|
||||
title: "Doesn't have a valid GUID",
|
||||
visits: [{date: TIMESTAMP3,
|
||||
type: Ci.nsINavHistoryService.TRANSITION_EMBED}]}
|
||||
]);
|
||||
|
||||
_("Make sure we report records with invalid visits, gracefully handle non-integer dates.");
|
||||
let no_date_visit_guid = Utils.makeGUID();
|
||||
let no_type_visit_guid = Utils.makeGUID();
|
||||
let invalid_type_visit_guid = Utils.makeGUID();
|
||||
let non_integer_visit_guid = Utils.makeGUID();
|
||||
failed = store.applyIncomingBatch([
|
||||
{id: no_date_visit_guid,
|
||||
histUri: "http://no.date.visit/",
|
||||
title: "Visit has no date",
|
||||
visits: [{date: TIMESTAMP3}]},
|
||||
{id: no_type_visit_guid,
|
||||
histUri: "http://no.type.visit/",
|
||||
title: "Visit has no type",
|
||||
visits: [{type: Ci.nsINavHistoryService.TRANSITION_EMBED}]},
|
||||
{id: invalid_type_visit_guid,
|
||||
histUri: "http://invalid.type.visit/",
|
||||
title: "Visit has invalid type",
|
||||
visits: [{date: TIMESTAMP3,
|
||||
type: Ci.nsINavHistoryService.TRANSITION_LINK - 1}]},
|
||||
{id: non_integer_visit_guid,
|
||||
histUri: "http://non.integer.visit/",
|
||||
title: "Visit has non-integer date",
|
||||
visits: [{date: 1234.567,
|
||||
type: Ci.nsINavHistoryService.TRANSITION_EMBED}]}
|
||||
]);
|
||||
do_check_eq(failed.length, 3);
|
||||
failed.sort();
|
||||
let expected = [no_date_visit_guid,
|
||||
no_type_visit_guid,
|
||||
invalid_type_visit_guid].sort();
|
||||
for (let i = 0; i < expected.length; i++) {
|
||||
do_check_eq(failed[i], expected[i]);
|
||||
}
|
||||
|
||||
_("Make sure we handle records with javascript: URLs gracefully.");
|
||||
store.create({id: Utils.makeGUID(),
|
||||
histUri: "javascript:''",
|
||||
title: "javascript:''",
|
||||
visits: [{date: TIMESTAMP3,
|
||||
type: Ci.nsINavHistoryService.TRANSITION_EMBED}]});
|
||||
applyEnsureNoFailures([
|
||||
{id: Utils.makeGUID(),
|
||||
histUri: "javascript:''",
|
||||
title: "javascript:''",
|
||||
visits: [{date: TIMESTAMP3,
|
||||
type: Ci.nsINavHistoryService.TRANSITION_EMBED}]}
|
||||
]);
|
||||
|
||||
_("Make sure we handle records without any visits gracefully.");
|
||||
store.create({id: Utils.makeGUID(),
|
||||
histUri: "http://getfirebug.com",
|
||||
title: "Get Firebug!",
|
||||
visits: []});
|
||||
applyEnsureNoFailures([
|
||||
{id: Utils.makeGUID(),
|
||||
histUri: "http://getfirebug.com",
|
||||
title: "Get Firebug!",
|
||||
visits: []}
|
||||
]);
|
||||
|
||||
_("Remove a record from the store.");
|
||||
store.remove({id: fxguid});
|
||||
_("Remove an existent record and a non-existent from the store.");
|
||||
applyEnsureNoFailures([{id: fxguid, deleted: true},
|
||||
{id: Utils.makeGUID(), deleted: true}]);
|
||||
do_check_false(store.itemExists(fxguid));
|
||||
let queryres = queryHistoryVisits(fxuri);
|
||||
do_check_eq(queryres.length, 0);
|
||||
|
|
Загрузка…
Ссылка в новой задаче