Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // Verify that we wipe the server if we have to regenerate keys. |
michael@0 | 5 | Cu.import("resource://services-sync/service.js"); |
michael@0 | 6 | Cu.import("resource://services-sync/util.js"); |
michael@0 | 7 | Cu.import("resource://testing-common/services/sync/utils.js"); |
michael@0 | 8 | |
michael@0 | 9 | add_identity_test(this, function test_missing_crypto_collection() { |
michael@0 | 10 | let johnHelper = track_collections_helper(); |
michael@0 | 11 | let johnU = johnHelper.with_updated_collection; |
michael@0 | 12 | let johnColls = johnHelper.collections; |
michael@0 | 13 | |
michael@0 | 14 | let empty = false; |
michael@0 | 15 | function maybe_empty(handler) { |
michael@0 | 16 | return function (request, response) { |
michael@0 | 17 | if (empty) { |
michael@0 | 18 | let body = "{}"; |
michael@0 | 19 | response.setStatusLine(request.httpVersion, 200, "OK"); |
michael@0 | 20 | response.bodyOutputStream.write(body, body.length); |
michael@0 | 21 | } else { |
michael@0 | 22 | handler(request, response); |
michael@0 | 23 | } |
michael@0 | 24 | }; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | yield configureIdentity({username: "johndoe"}); |
michael@0 | 28 | |
michael@0 | 29 | let handlers = { |
michael@0 | 30 | "/1.1/johndoe/info/collections": maybe_empty(johnHelper.handler), |
michael@0 | 31 | "/1.1/johndoe/storage/crypto/keys": johnU("crypto", new ServerWBO("keys").handler()), |
michael@0 | 32 | "/1.1/johndoe/storage/meta/global": johnU("meta", new ServerWBO("global").handler()) |
michael@0 | 33 | }; |
michael@0 | 34 | let collections = ["clients", "bookmarks", "forms", "history", |
michael@0 | 35 | "passwords", "prefs", "tabs"]; |
michael@0 | 36 | for each (let coll in collections) { |
michael@0 | 37 | handlers["/1.1/johndoe/storage/" + coll] = |
michael@0 | 38 | johnU(coll, new ServerCollection({}, true).handler()); |
michael@0 | 39 | } |
michael@0 | 40 | let server = httpd_setup(handlers); |
michael@0 | 41 | Service.serverURL = server.baseURI; |
michael@0 | 42 | |
michael@0 | 43 | try { |
michael@0 | 44 | let fresh = 0; |
michael@0 | 45 | let orig = Service._freshStart; |
michael@0 | 46 | Service._freshStart = function() { |
michael@0 | 47 | _("Called _freshStart."); |
michael@0 | 48 | orig.call(Service); |
michael@0 | 49 | fresh++; |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | _("Startup, no meta/global: freshStart called once."); |
michael@0 | 53 | Service.sync(); |
michael@0 | 54 | do_check_eq(fresh, 1); |
michael@0 | 55 | fresh = 0; |
michael@0 | 56 | |
michael@0 | 57 | _("Regular sync: no need to freshStart."); |
michael@0 | 58 | Service.sync(); |
michael@0 | 59 | do_check_eq(fresh, 0); |
michael@0 | 60 | |
michael@0 | 61 | _("Simulate a bad info/collections."); |
michael@0 | 62 | delete johnColls.crypto; |
michael@0 | 63 | Service.sync(); |
michael@0 | 64 | do_check_eq(fresh, 1); |
michael@0 | 65 | fresh = 0; |
michael@0 | 66 | |
michael@0 | 67 | _("Regular sync: no need to freshStart."); |
michael@0 | 68 | Service.sync(); |
michael@0 | 69 | do_check_eq(fresh, 0); |
michael@0 | 70 | |
michael@0 | 71 | } finally { |
michael@0 | 72 | Svc.Prefs.resetBranch(""); |
michael@0 | 73 | let deferred = Promise.defer(); |
michael@0 | 74 | server.stop(deferred.resolve); |
michael@0 | 75 | yield deferred.promise; |
michael@0 | 76 | } |
michael@0 | 77 | }); |
michael@0 | 78 | |
michael@0 | 79 | function run_test() { |
michael@0 | 80 | initTestLogging("Trace"); |
michael@0 | 81 | run_next_test(); |
michael@0 | 82 | } |