gecko/services/sync/tests/unit/test_resource_ua.js
Gregory Szorc 43c6e1d377 Bug 787273 - Part 6: Remove Weave export from service.js; r=rnewman
This is mostly minor cosmetic changes. Weave was being exported from
service.js for no apparent reason. It was mostly used by tests.

There was a reference to it in engines.js, which should have been caught
when the engines were associated with a service instance. engines.js now
does the right thing.

Weave is no longer exported by service.js. Tests and modules no longer
import main.js.

WeaveSvc was also renamed to Sync11Service because why not.

Weave continues to be the main public API.
2012-09-14 16:02:33 -07:00

97 lines
2.5 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/resource.js");
Cu.import("resource://services-sync/service.js");
const TEST_GET_URL = "http://localhost:8080/1.1/johndoe/storage/meta/global";
function test_resource_user_agent() {
let meta_global = new ServerWBO('global');
// Tracking info/collections.
let collectionsHelper = track_collections_helper();
let collections = collectionsHelper.collections;
let ua;
function uaHandler(f) {
return function(request, response) {
ua = request.getHeader("User-Agent");
return f(request, response);
};
}
do_test_pending();
let server = httpd_setup({
"/1.1/johndoe/info/collections": uaHandler(collectionsHelper.handler),
"/1.1/johndoe/storage/meta/global": uaHandler(meta_global.handler()),
});
setBasicCredentials("johndoe", "ilovejane");
Service.serverURL = TEST_SERVER_URL;
Service.clusterURL = TEST_CLUSTER_URL;
let expectedUA = Services.appinfo.name + "/" + Services.appinfo.version +
" FxSync/" + WEAVE_VERSION + "." +
Services.appinfo.appBuildID;
function test_fetchInfo(next) {
_("Testing _fetchInfo.");
Service._fetchInfo();
_("User-Agent: " + ua);
do_check_eq(ua, expectedUA + ".desktop");
ua = "";
next();
}
function test_desktop_post(next) {
_("Testing direct Resource POST.");
let r = new AsyncResource(TEST_GET_URL);
r.post("foo=bar", function (error, content) {
_("User-Agent: " + ua);
do_check_eq(ua, expectedUA + ".desktop");
ua = "";
next();
});
}
function test_desktop_get(next) {
_("Testing async.");
Svc.Prefs.set("client.type", "desktop");
let r = new AsyncResource(TEST_GET_URL);
r.get(function(error, content) {
_("User-Agent: " + ua);
do_check_eq(ua, expectedUA + ".desktop");
ua = "";
next();
});
}
function test_mobile_get(next) {
_("Testing mobile.");
Svc.Prefs.set("client.type", "mobile");
let r = new AsyncResource(TEST_GET_URL);
r.get(function (error, content) {
_("User-Agent: " + ua);
do_check_eq(ua, expectedUA + ".mobile");
ua = "";
next();
});
}
Async.chain(
test_fetchInfo,
test_desktop_post,
test_desktop_get,
test_mobile_get,
function (next) {
server.stop(next);
},
do_test_finished)();
}
function run_test() {
test_resource_user_agent();
}