2011-04-07 13:55:02 -07:00
|
|
|
Cu.import("resource://services-sync/constants.js");
|
|
|
|
Cu.import("resource://services-sync/resource.js");
|
|
|
|
Cu.import("resource://services-sync/service.js");
|
|
|
|
|
|
|
|
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({
|
2011-04-08 14:52:08 -07:00
|
|
|
"/1.1/johndoe/info/collections": uaHandler(collectionsHelper.handler),
|
|
|
|
"/1.1/johndoe/storage/meta/global": uaHandler(meta_global.handler()),
|
2011-04-07 13:55:02 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
Weave.Service.serverURL = "http://localhost:8080/";
|
|
|
|
Weave.Service.clusterURL = "http://localhost:8080/";
|
|
|
|
Weave.Service.username = "johndoe";
|
|
|
|
Weave.Service.password = "ilovejane";
|
|
|
|
|
2011-05-19 18:08:07 -07:00
|
|
|
let expectedUA = Services.appinfo.name + "/" + Services.appinfo.version +
|
|
|
|
" FxSync/" + WEAVE_VERSION + "." +
|
|
|
|
Services.appinfo.appBuildID;
|
2011-04-07 13:55:02 -07:00
|
|
|
|
|
|
|
function test_fetchInfo(next) {
|
|
|
|
_("Testing _fetchInfo.");
|
|
|
|
Weave.Service._fetchInfo();
|
|
|
|
_("User-Agent: " + ua);
|
|
|
|
do_check_eq(ua, expectedUA + ".desktop");
|
|
|
|
ua = "";
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_desktop_post(next) {
|
|
|
|
_("Testing direct Resource POST.");
|
2011-04-08 14:52:08 -07:00
|
|
|
let r = new AsyncResource("http://localhost:8080/1.1/johndoe/storage/meta/global");
|
2011-04-07 13:55:02 -07:00
|
|
|
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");
|
2011-04-08 14:52:08 -07:00
|
|
|
let r = new AsyncResource("http://localhost:8080/1.1/johndoe/storage/meta/global");
|
2011-04-07 13:55:02 -07:00
|
|
|
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");
|
2011-04-08 14:52:08 -07:00
|
|
|
let r = new AsyncResource("http://localhost:8080/1.1/johndoe/storage/meta/global");
|
2011-04-07 13:55:02 -07:00
|
|
|
r.get(function (error, content) {
|
|
|
|
_("User-Agent: " + ua);
|
|
|
|
do_check_eq(ua, expectedUA + ".mobile");
|
|
|
|
ua = "";
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-08-26 10:25:42 -07:00
|
|
|
Async.chain(
|
2011-04-07 13:55:02 -07:00
|
|
|
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();
|
|
|
|
}
|