summaryrefslogtreecommitdiff
path: root/services/sync/tests/unit/test_service_wipeServer.js
diff options
context:
space:
mode:
authorPale Moon <git-repo@palemoon.org>2016-09-01 13:39:08 +0200
committerPale Moon <git-repo@palemoon.org>2016-09-01 13:39:08 +0200
commit3d8ce1a11a7347cc94a937719c4bc8df46fb8d14 (patch)
tree8c26ca375a6312751c00a27e1653fb6f189f0463 /services/sync/tests/unit/test_service_wipeServer.js
parente449bdb1ec3a82f204bffdd9c3c54069d086eee3 (diff)
downloadpalemoon-gre-3d8ce1a11a7347cc94a937719c4bc8df46fb8d14.tar.gz
Base import of Tycho code (warning: huge commit)
Diffstat (limited to 'services/sync/tests/unit/test_service_wipeServer.js')
-rw-r--r--services/sync/tests/unit/test_service_wipeServer.js67
1 files changed, 40 insertions, 27 deletions
diff --git a/services/sync/tests/unit/test_service_wipeServer.js b/services/sync/tests/unit/test_service_wipeServer.js
index e03f6caf0..3fc45cf86 100644
--- a/services/sync/tests/unit/test_service_wipeServer.js
+++ b/services/sync/tests/unit/test_service_wipeServer.js
@@ -7,6 +7,9 @@ Cu.import("resource://testing-common/services/sync/utils.js");
Svc.DefaultPrefs.set("registerEngines", "");
Cu.import("resource://services-sync/service.js");
+// configure the identity we use for this test.
+identityConfig = makeIdentityConfig({username: "johndoe"});
+
function FakeCollection() {
this.deleted = false;
}
@@ -28,13 +31,13 @@ FakeCollection.prototype = {
}
};
-function setUpTestFixtures() {
+function setUpTestFixtures(server) {
let cryptoService = new FakeCryptoService();
- Service.serverURL = TEST_SERVER_URL;
- Service.clusterURL = TEST_CLUSTER_URL;
+ Service.serverURL = server.baseURI + "/";
+ Service.clusterURL = server.baseURI + "/";
- setBasicCredentials("johndoe", null, "aabcdeabcdeabcdeabcdeabcde");
+ yield configureIdentity(identityConfig);
}
@@ -43,7 +46,13 @@ function run_test() {
run_next_test();
}
-add_test(function test_wipeServer_list_success() {
+function promiseStopServer(server) {
+ let deferred = Promise.defer();
+ server.stop(deferred.resolve);
+ return deferred.promise;
+}
+
+add_identity_test(this, function test_wipeServer_list_success() {
_("Service.wipeServer() deletes collections given as argument.");
let steam_coll = new FakeCollection();
@@ -56,8 +65,8 @@ add_test(function test_wipeServer_list_success() {
});
try {
- setUpTestFixtures();
- new SyncTestingInfrastructure("johndoe", "irrelevant", "irrelevant");
+ yield setUpTestFixtures(server);
+ new SyncTestingInfrastructure(server, "johndoe", "irrelevant", "irrelevant");
_("Confirm initial environment.");
do_check_false(steam_coll.deleted);
@@ -72,12 +81,12 @@ add_test(function test_wipeServer_list_success() {
do_check_true(diesel_coll.deleted);
} finally {
- server.stop(run_next_test);
+ yield promiseStopServer(server);
Svc.Prefs.resetBranch("");
}
});
-add_test(function test_wipeServer_list_503() {
+add_identity_test(this, function test_wipeServer_list_503() {
_("Service.wipeServer() deletes collections given as argument.");
let steam_coll = new FakeCollection();
@@ -90,8 +99,8 @@ add_test(function test_wipeServer_list_503() {
});
try {
- setUpTestFixtures();
- new SyncTestingInfrastructure("johndoe", "irrelevant", "irrelevant");
+ yield setUpTestFixtures(server);
+ new SyncTestingInfrastructure(server, "johndoe", "irrelevant", "irrelevant");
_("Confirm initial environment.");
do_check_false(steam_coll.deleted);
@@ -113,12 +122,12 @@ add_test(function test_wipeServer_list_503() {
do_check_false(diesel_coll.deleted);
} finally {
- server.stop(run_next_test);
+ yield promiseStopServer(server);
Svc.Prefs.resetBranch("");
}
});
-add_test(function test_wipeServer_all_success() {
+add_identity_test(this, function test_wipeServer_all_success() {
_("Service.wipeServer() deletes all the things.");
/**
@@ -136,19 +145,19 @@ add_test(function test_wipeServer_all_success() {
let server = httpd_setup({
"/1.1/johndoe/storage": storageHandler
});
- setUpTestFixtures();
+ yield setUpTestFixtures(server);
_("Try deletion.");
- new SyncTestingInfrastructure("johndoe", "irrelevant", "irrelevant");
+ new SyncTestingInfrastructure(server, "johndoe", "irrelevant", "irrelevant");
let returnedTimestamp = Service.wipeServer();
do_check_true(deleted);
do_check_eq(returnedTimestamp, serverTimestamp);
- server.stop(run_next_test);
+ yield promiseStopServer(server);
Svc.Prefs.resetBranch("");
});
-add_test(function test_wipeServer_all_404() {
+add_identity_test(this, function test_wipeServer_all_404() {
_("Service.wipeServer() accepts a 404.");
/**
@@ -168,19 +177,19 @@ add_test(function test_wipeServer_all_404() {
let server = httpd_setup({
"/1.1/johndoe/storage": storageHandler
});
- setUpTestFixtures();
+ yield setUpTestFixtures(server);
_("Try deletion.");
- new SyncTestingInfrastructure("johndoe", "irrelevant", "irrelevant");
+ new SyncTestingInfrastructure(server, "johndoe", "irrelevant", "irrelevant");
let returnedTimestamp = Service.wipeServer();
do_check_true(deleted);
do_check_eq(returnedTimestamp, serverTimestamp);
- server.stop(run_next_test);
+ yield promiseStopServer(server);
Svc.Prefs.resetBranch("");
});
-add_test(function test_wipeServer_all_503() {
+add_identity_test(this, function test_wipeServer_all_503() {
_("Service.wipeServer() throws if it encounters a non-200/404 response.");
/**
@@ -195,12 +204,12 @@ add_test(function test_wipeServer_all_503() {
let server = httpd_setup({
"/1.1/johndoe/storage": storageHandler
});
- setUpTestFixtures();
+ yield setUpTestFixtures(server);
_("Try deletion.");
let error;
try {
- new SyncTestingInfrastructure("johndoe", "irrelevant", "irrelevant");
+ new SyncTestingInfrastructure(server, "johndoe", "irrelevant", "irrelevant");
Service.wipeServer();
do_throw("Should have thrown!");
} catch (ex) {
@@ -208,13 +217,17 @@ add_test(function test_wipeServer_all_503() {
}
do_check_eq(error.status, 503);
- server.stop(run_next_test);
+ yield promiseStopServer(server);
Svc.Prefs.resetBranch("");
});
-add_test(function test_wipeServer_all_connectionRefused() {
+add_identity_test(this, function test_wipeServer_all_connectionRefused() {
_("Service.wipeServer() throws if it encounters a network problem.");
- setUpTestFixtures();
+ let server = httpd_setup({});
+ yield setUpTestFixtures(server);
+
+ Service.serverURL = "http://localhost:4352/";
+ Service.clusterURL = "http://localhost:4352/";
_("Try deletion.");
try {
@@ -224,6 +237,6 @@ add_test(function test_wipeServer_all_connectionRefused() {
do_check_eq(ex.result, Cr.NS_ERROR_CONNECTION_REFUSED);
}
- run_next_test();
Svc.Prefs.resetBranch("");
+ yield promiseStopServer(server);
});