--- a/services/common/async.js
+++ b/services/common/async.js
@@ -1,20 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef MERGED_COMPARTMENT
-
this.EXPORTED_SYMBOLS = ["Async"];
var {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
-#endif
-
// Constants for makeSyncCallback, waitForSyncCallback.
const CB_READY = {};
const CB_COMPLETE = {};
const CB_FAIL = {};
const REASON_ERROR = Ci.mozIStorageStatementCallback.REASON_ERROR;
Cu.import("resource://gre/modules/Services.jsm");
--- a/services/common/bagheeraclient.js
+++ b/services/common/bagheeraclient.js
@@ -4,29 +4,25 @@
/**
* This file contains a client API for the Bagheera data storage service.
*
* Information about Bagheera is available at
* https://github.com/mozilla-metrics/bagheera
*/
-#ifndef MERGED_COMPARTMENT
-
"use strict";
this.EXPORTED_SYMBOLS = [
"BagheeraClient",
"BagheeraClientRequestResult",
];
var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
-#endif
-
Cu.import("resource://gre/modules/Promise.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-common/rest.js");
Cu.import("resource://services-common/utils.js");
/**
* Represents the result of a Bagheera request.
--- a/services/common/moz.build
+++ b/services/common/moz.build
@@ -9,47 +9,44 @@ with Files('**'):
TEST_DIRS += ['tests']
EXTRA_COMPONENTS += [
'servicesComponents.manifest',
]
EXTRA_JS_MODULES['services-common'] += [
+ 'async.js',
'logmanager.js',
'moz-kinto-client.js',
+ 'observers.js',
+ 'rest.js',
'stringbundle.js',
'utils.js',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android' or CONFIG['MOZ_B2GDROID']:
EXTRA_JS_MODULES['services-common'] += [
'hawkclient.js',
'hawkrequest.js',
'tokenserverclient.js',
]
TESTING_JS_MODULES.services.common += [
'modules-testing/storageserver.js',
]
if CONFIG['MOZ_SERVICES_HEALTHREPORT']:
- EXTRA_PP_JS_MODULES['services-common'] += [
+ EXTRA_JS_MODULES['services-common'] += [
'bagheeraclient.js',
]
TESTING_JS_MODULES.services.common += [
'modules-testing/bagheeraserver.js',
]
-EXTRA_PP_JS_MODULES['services-common'] += [
- 'async.js',
- 'observers.js',
- 'rest.js',
-]
-
TESTING_JS_MODULES.services.common += [
'modules-testing/logging.js',
'modules-testing/utils.js',
]
JS_PREFERENCE_FILES += [
'services-common.js',
]
--- a/services/common/observers.js
+++ b/services/common/observers.js
@@ -1,23 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef MERGED_COMPARTMENT
-
this.EXPORTED_SYMBOLS = ["Observers"];
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cr = Components.results;
var Cu = Components.utils;
-#endif
-
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
/**
* A service for adding, removing and notifying observers of notifications.
* Wraps the nsIObserverService interface.
*
* @version 0.2
*/
--- a/services/common/rest.js
+++ b/services/common/rest.js
@@ -1,24 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef MERGED_COMPARTMENT
-
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
this.EXPORTED_SYMBOLS = [
"RESTRequest",
"RESTResponse",
"TokenAuthenticatedRESTRequest",
];
-#endif
-
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-common/utils.js");
XPCOMUtils.defineLazyModuleGetter(this, "CryptoUtils",
--- a/services/common/tests/unit/test_bagheera_client.js
+++ b/services/common/tests/unit/test_bagheera_client.js
@@ -88,17 +88,17 @@ add_task(function* test_unicode_payload(
p = server.getDocument("foo", "baz");
Assert.equal(p.test, EXPECTED);
let deferred = Promise.defer();
server.stop(() => deferred.resolve());
yield deferred.promise;
});
-add_task(function test_post_delete_multiple_obsolete_documents () {
+add_task(function* test_post_delete_multiple_obsolete_documents () {
let [client, server] = getClientAndServer();
let namespace = "foo";
let documents = [
[namespace, "one", "{v:1}"],
[namespace, "two", "{v:2}"],
[namespace, "three", "{v:3}"],
[namespace, "four", "{v:4}"],
];
--- a/services/common/tests/unit/test_hawkclient.js
+++ b/services/common/tests/unit/test_hawkclient.js
@@ -39,17 +39,17 @@ add_task(function test_updateClockOffset
// error, so checking strict equality will likely fail.
//
// localtimeOffsetMsec is how many milliseconds to add to the local clock so
// that it agrees with the server. We are one hour ahead of the server, so
// our offset should be -1 hour.
do_check_true(Math.abs(client.localtimeOffsetMsec + HOUR_MS) <= SECOND_MS);
});
-add_task(function test_authenticated_get_request() {
+add_task(function* test_authenticated_get_request() {
let message = "{\"msg\": \"Great Success!\"}";
let method = "GET";
let server = httpd_setup({"/foo": (request, response) => {
do_check_true(request.hasHeader("Authorization"));
response.setStatusLine(request.httpVersion, 200, "OK");
response.bodyOutputStream.write(message, message.length);
@@ -61,17 +61,17 @@ add_task(function test_authenticated_get
let response = yield client.request("/foo", method, TEST_CREDS);
let result = JSON.parse(response.body);
do_check_eq("Great Success!", result.msg);
yield deferredStop(server);
});
-function check_authenticated_request(method) {
+function* check_authenticated_request(method) {
let server = httpd_setup({"/foo": (request, response) => {
do_check_true(request.hasHeader("Authorization"));
response.setStatusLine(request.httpVersion, 200, "OK");
response.setHeader("Content-Type", "application/json");
response.bodyOutputStream.writeFrom(request.bodyInputStream, request.bodyInputStream.available());
}
});
@@ -93,17 +93,17 @@ add_task(function test_authenticated_pos
add_task(function test_authenticated_put_request() {
check_authenticated_request("PUT");
});
add_task(function test_authenticated_patch_request() {
check_authenticated_request("PATCH");
});
-add_task(function test_credentials_optional() {
+add_task(function* test_credentials_optional() {
let method = "GET";
let server = httpd_setup({
"/foo": (request, response) => {
do_check_false(request.hasHeader("Authorization"));
let message = JSON.stringify({msg: "you're in the friend zone"});
response.setStatusLine(request.httpVersion, 200, "OK");
response.setHeader("Content-Type", "application/json");
@@ -113,17 +113,17 @@ add_task(function test_credentials_optio
let client = new HawkClient(server.baseURI);
let result = yield client.request("/foo", method); // credentials undefined
do_check_eq(JSON.parse(result.body).msg, "you're in the friend zone");
yield deferredStop(server);
});
-add_task(function test_server_error() {
+add_task(function* test_server_error() {
let message = "Ohai!";
let method = "GET";
let server = httpd_setup({"/foo": (request, response) => {
response.setStatusLine(request.httpVersion, 418, "I am a Teapot");
response.bodyOutputStream.write(message, message.length);
}
});
@@ -136,17 +136,17 @@ add_task(function test_server_error() {
} catch(err) {
do_check_eq(418, err.code);
do_check_eq("I am a Teapot", err.message);
}
yield deferredStop(server);
});
-add_task(function test_server_error_json() {
+add_task(function* test_server_error_json() {
let message = JSON.stringify({error: "Cannot get ye flask."});
let method = "GET";
let server = httpd_setup({"/foo": (request, response) => {
response.setStatusLine(request.httpVersion, 400, "What wouldst thou deau?");
response.bodyOutputStream.write(message, message.length);
}
});
@@ -158,17 +158,17 @@ add_task(function test_server_error_json
do_throw("Expected an error");
} catch(err) {
do_check_eq("Cannot get ye flask.", err.error);
}
yield deferredStop(server);
});
-add_task(function test_offset_after_request() {
+add_task(function* test_offset_after_request() {
let message = "Ohai!";
let method = "GET";
let server = httpd_setup({"/foo": (request, response) => {
response.setStatusLine(request.httpVersion, 200, "OK");
response.bodyOutputStream.write(message, message.length);
}
});
@@ -181,17 +181,17 @@ add_task(function test_offset_after_requ
let response = yield client.request("/foo", method, TEST_CREDS);
// Should be about an hour off
do_check_true(Math.abs(client.localtimeOffsetMsec + HOUR_MS) < SECOND_MS);
yield deferredStop(server);
});
-add_task(function test_offset_in_hawk_header() {
+add_task(function* test_offset_in_hawk_header() {
let message = "Ohai!";
let method = "GET";
let server = httpd_setup({
"/first": function(request, response) {
response.setStatusLine(request.httpVersion, 200, "OK");
response.bodyOutputStream.write(message, message.length);
},
@@ -228,17 +228,17 @@ add_task(function test_offset_in_hawk_he
// After the first server response, our offset is updated to -12 hours.
// We should be safely in the window, now.
do_check_true(Math.abs(client.localtimeOffsetMsec + 12 * HOUR_MS) < MINUTE_MS);
yield client.request("/second", method, TEST_CREDS);
yield deferredStop(server);
});
-add_task(function test_2xx_success() {
+add_task(function* test_2xx_success() {
// Just to ensure that we're not biased toward 200 OK for success
let credentials = {
id: "eyJleHBpcmVzIjogMTM2NTAxMDg5OC4x",
key: "qTZf4ZFpAMpMoeSsX3zVRjiqmNs=",
algorithm: "sha256"
};
let method = "GET";
@@ -252,17 +252,17 @@ add_task(function test_2xx_success() {
let response = yield client.request("/foo", method, credentials);
// Shouldn't be any content in a 202
do_check_eq(response.body, "");
yield deferredStop(server);
});
-add_task(function test_retry_request_on_fail() {
+add_task(function* test_retry_request_on_fail() {
let attempts = 0;
let credentials = {
id: "eyJleHBpcmVzIjogMTM2NTAxMDg5OC4x",
key: "qTZf4ZFpAMpMoeSsX3zVRjiqmNs=",
algorithm: "sha256"
};
let method = "GET";
@@ -307,17 +307,17 @@ add_task(function test_retry_request_on_
// Request will have bad timestamp; client will retry once
let response = yield client.request("/maybe", method, credentials);
do_check_eq(response.body, "i love you!!!");
yield deferredStop(server);
});
-add_task(function test_multiple_401_retry_once() {
+add_task(function* test_multiple_401_retry_once() {
// Like test_retry_request_on_fail, but always return a 401
// and ensure that the client only retries once.
let attempts = 0;
let credentials = {
id: "eyJleHBpcmVzIjogMTM2NTAxMDg5OC4x",
key: "qTZf4ZFpAMpMoeSsX3zVRjiqmNs=",
algorithm: "sha256"
};
@@ -356,17 +356,17 @@ add_task(function test_multiple_401_retr
} catch (err) {
do_check_eq(err.code, 401);
}
do_check_eq(attempts, 2);
yield deferredStop(server);
});
-add_task(function test_500_no_retry() {
+add_task(function* test_500_no_retry() {
// If we get a 500 error, the client should not retry (as it would with a
// 401)
let credentials = {
id: "eyJleHBpcmVzIjogMTM2NTAxMDg5OC4x",
key: "qTZf4ZFpAMpMoeSsX3zVRjiqmNs=",
algorithm: "sha256"
};
let method = "GET";
@@ -396,17 +396,17 @@ add_task(function test_500_no_retry() {
do_throw("Expected an error");
} catch(err) {
do_check_eq(err.code, 500);
}
yield deferredStop(server);
});
-add_task(function test_401_then_500() {
+add_task(function* test_401_then_500() {
// Like test_multiple_401_retry_once, but return a 500 to the
// second request, ensuring that the promise is properly rejected
// in client.request.
let attempts = 0;
let credentials = {
id: "eyJleHBpcmVzIjogMTM2NTAxMDg5OC4x",
key: "qTZf4ZFpAMpMoeSsX3zVRjiqmNs=",
algorithm: "sha256"
@@ -460,17 +460,17 @@ add_task(function test_401_then_500() {
} catch(err) {
do_check_eq(err.code, 500);
}
do_check_eq(attempts, 2);
yield deferredStop(server);
});
-add_task(function throw_if_not_json_body() {
+add_task(function* throw_if_not_json_body() {
let client = new HawkClient("https://example.com");
try {
yield client.request("/bogus", "GET", {}, "I am not json");
do_throw("Expected an error");
} catch(err) {
do_check_true(!!err.message);
}
});