2010-06-17 08:47:13 -07:00
|
|
|
Cu.import("resource://services-sync/service.js");
|
2010-08-25 15:49:45 -07:00
|
|
|
Cu.import("resource://services-sync/util.js");
|
2010-06-17 08:47:13 -07:00
|
|
|
|
|
|
|
function send(statusCode, status, body) {
|
|
|
|
return function(request, response) {
|
|
|
|
response.setStatusLine(request.httpVersion, statusCode, status);
|
|
|
|
response.bodyOutputStream.write(body, body.length);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
2010-08-02 22:37:13 -07:00
|
|
|
do_test_pending();
|
2010-06-17 08:47:13 -07:00
|
|
|
let server = httpd_setup({
|
|
|
|
"/user/1.0/johndoe": send(200, "OK", "1"),
|
2010-09-13 08:17:37 -07:00
|
|
|
"/user/1.0/janedoe": send(200, "OK", "0"),
|
|
|
|
// john@doe.com
|
2010-09-15 03:54:33 -07:00
|
|
|
"/user/1.0/7wohs32cngzuqt466q3ge7indszva4of": send(200, "OK", "0"),
|
|
|
|
// jane@doe.com
|
|
|
|
"/user/1.0/vuuf3eqgloxpxmzph27f5a6ve7gzlrms": send(200, "OK", "1")
|
2010-06-17 08:47:13 -07:00
|
|
|
});
|
|
|
|
try {
|
2010-08-25 15:49:45 -07:00
|
|
|
Service.serverURL = "http://localhost:8080/";
|
2010-06-17 08:47:13 -07:00
|
|
|
|
|
|
|
_("A 404 will be recorded as 'generic-server-error'");
|
2010-09-15 03:54:33 -07:00
|
|
|
do_check_eq(Service.checkUsername("jimdoe"), "generic-server-error");
|
|
|
|
|
|
|
|
_("Account that's available.");
|
|
|
|
do_check_eq(Service.checkAccount("john@doe.com"), "available");
|
2010-06-17 08:47:13 -07:00
|
|
|
|
2010-09-13 08:17:37 -07:00
|
|
|
_("Account that's not available.");
|
2010-09-15 03:54:33 -07:00
|
|
|
do_check_eq(Service.checkAccount("jane@doe.com"), "notAvailable");
|
2010-06-17 08:47:13 -07:00
|
|
|
|
2010-09-15 03:54:33 -07:00
|
|
|
// Backwards compat with the Firefox UI. Remove once bug 595066 has landed.
|
2010-09-13 08:17:37 -07:00
|
|
|
|
2010-09-15 03:54:33 -07:00
|
|
|
_("Account that's not available.");
|
|
|
|
do_check_eq(Service.checkUsername("johndoe"), "notAvailable");
|
|
|
|
|
|
|
|
_("Account that's available.");
|
|
|
|
do_check_eq(Service.checkUsername("janedoe"), "available");
|
2010-06-17 08:47:13 -07:00
|
|
|
|
|
|
|
} finally {
|
2010-08-25 15:49:45 -07:00
|
|
|
Svc.Prefs.resetBranch("");
|
2010-08-02 22:37:13 -07:00
|
|
|
server.stop(do_test_finished);
|
2010-06-17 08:47:13 -07:00
|
|
|
}
|
|
|
|
}
|