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 | Cu.import("resource://services-sync/constants.js"); |
michael@0 | 5 | Cu.import("resource://services-sync/resource.js"); |
michael@0 | 6 | Cu.import("resource://services-sync/service.js"); |
michael@0 | 7 | Cu.import("resource://services-sync/util.js"); |
michael@0 | 8 | Cu.import("resource://testing-common/services/sync/utils.js"); |
michael@0 | 9 | |
michael@0 | 10 | // Tracking info/collections. |
michael@0 | 11 | let collectionsHelper = track_collections_helper(); |
michael@0 | 12 | let collections = collectionsHelper.collections; |
michael@0 | 13 | |
michael@0 | 14 | let meta_global; |
michael@0 | 15 | let server; |
michael@0 | 16 | |
michael@0 | 17 | let expectedUA; |
michael@0 | 18 | let ua; |
michael@0 | 19 | function uaHandler(f) { |
michael@0 | 20 | return function(request, response) { |
michael@0 | 21 | ua = request.getHeader("User-Agent"); |
michael@0 | 22 | return f(request, response); |
michael@0 | 23 | }; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | function run_test() { |
michael@0 | 27 | Log.repository.rootLogger.addAppender(new Log.DumpAppender()); |
michael@0 | 28 | meta_global = new ServerWBO('global'); |
michael@0 | 29 | server = httpd_setup({ |
michael@0 | 30 | "/1.1/johndoe/info/collections": uaHandler(collectionsHelper.handler), |
michael@0 | 31 | "/1.1/johndoe/storage/meta/global": uaHandler(meta_global.handler()), |
michael@0 | 32 | }); |
michael@0 | 33 | |
michael@0 | 34 | ensureLegacyIdentityManager(); |
michael@0 | 35 | setBasicCredentials("johndoe", "ilovejane"); |
michael@0 | 36 | Service.serverURL = server.baseURI + "/"; |
michael@0 | 37 | Service.clusterURL = server.baseURI + "/"; |
michael@0 | 38 | _("Server URL: " + server.baseURI); |
michael@0 | 39 | |
michael@0 | 40 | expectedUA = Services.appinfo.name + "/" + Services.appinfo.version + |
michael@0 | 41 | " FxSync/" + WEAVE_VERSION + "." + |
michael@0 | 42 | Services.appinfo.appBuildID; |
michael@0 | 43 | |
michael@0 | 44 | run_next_test(); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | add_test(function test_fetchInfo() { |
michael@0 | 48 | _("Testing _fetchInfo."); |
michael@0 | 49 | Service._fetchInfo(); |
michael@0 | 50 | _("User-Agent: " + ua); |
michael@0 | 51 | do_check_eq(ua, expectedUA + ".desktop"); |
michael@0 | 52 | ua = ""; |
michael@0 | 53 | run_next_test(); |
michael@0 | 54 | }); |
michael@0 | 55 | |
michael@0 | 56 | add_test(function test_desktop_post() { |
michael@0 | 57 | _("Testing direct Resource POST."); |
michael@0 | 58 | let r = new AsyncResource(server.baseURI + "/1.1/johndoe/storage/meta/global"); |
michael@0 | 59 | r.post("foo=bar", function (error, content) { |
michael@0 | 60 | _("User-Agent: " + ua); |
michael@0 | 61 | do_check_eq(ua, expectedUA + ".desktop"); |
michael@0 | 62 | ua = ""; |
michael@0 | 63 | run_next_test(); |
michael@0 | 64 | }); |
michael@0 | 65 | }); |
michael@0 | 66 | |
michael@0 | 67 | add_test(function test_desktop_get() { |
michael@0 | 68 | _("Testing async."); |
michael@0 | 69 | Svc.Prefs.set("client.type", "desktop"); |
michael@0 | 70 | let r = new AsyncResource(server.baseURI + "/1.1/johndoe/storage/meta/global"); |
michael@0 | 71 | r.get(function(error, content) { |
michael@0 | 72 | _("User-Agent: " + ua); |
michael@0 | 73 | do_check_eq(ua, expectedUA + ".desktop"); |
michael@0 | 74 | ua = ""; |
michael@0 | 75 | run_next_test(); |
michael@0 | 76 | }); |
michael@0 | 77 | }); |
michael@0 | 78 | |
michael@0 | 79 | add_test(function test_mobile_get() { |
michael@0 | 80 | _("Testing mobile."); |
michael@0 | 81 | Svc.Prefs.set("client.type", "mobile"); |
michael@0 | 82 | let r = new AsyncResource(server.baseURI + "/1.1/johndoe/storage/meta/global"); |
michael@0 | 83 | r.get(function (error, content) { |
michael@0 | 84 | _("User-Agent: " + ua); |
michael@0 | 85 | do_check_eq(ua, expectedUA + ".mobile"); |
michael@0 | 86 | ua = ""; |
michael@0 | 87 | run_next_test(); |
michael@0 | 88 | }); |
michael@0 | 89 | }); |
michael@0 | 90 | |
michael@0 | 91 | add_test(function tear_down() { |
michael@0 | 92 | server.stop(run_next_test); |
michael@0 | 93 | }); |
michael@0 | 94 |