Bug 1326225 - Fix un-imported fetch use in NormandyApi.jsm r=Gijs

See https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Mochitest#How_do_I_test_issues_which_only_show_up_when_tests_are_run_across_domains.3F
for info on how the test server was set up for testing that fetch was
used correctly.

r=Gijs

MozReview-Commit-ID: CNH6SQ6gEGU

--HG--
extra : rebase_source : 1f2025c91cf38fa89b69d7732a5959cafe73192f
This commit is contained in:
Mythmon 2017-01-03 09:41:51 -08:00
Родитель 960f182e2f
Коммит 42a716eedd
6 изменённых файлов: 36 добавлений и 3 удалений

Просмотреть файл

@ -10,6 +10,7 @@ Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/CanonicalJSON.jsm");
Cu.import("resource://gre/modules/Log.jsm");
Cu.importGlobalProperties(["fetch"]); /* globals fetch */
this.EXPORTED_SYMBOLS = ["NormandyApi"];

Просмотреть файл

@ -8,6 +8,7 @@ module.exports = {
is: false,
isnot: false,
ok: false,
SpecialPowers: false,
},
rules: {
"spaced-comment": 2,

Просмотреть файл

@ -3,4 +3,6 @@
[browser_EventEmitter.js]
[browser_Storage.js]
[browser_Heartbeat.js]
skip-if = true # bug 1325409
[browser_NormandyApi.js]
support-files =
test_server.sjs

Просмотреть файл

@ -0,0 +1,21 @@
"use strict";
const {utils: Cu} = Components;
Cu.import("resource://shield-recipe-client/lib/NormandyApi.jsm", this);
add_task(function* () {
// Point the add-on to the test server.
yield SpecialPowers.pushPrefEnv({
set: [
[
"extensions.shield-recipe-client.api_url",
"http://mochi.test:8888/browser/browser/extensions/shield-recipe-client/test",
]
]
})
// Test that NormandyApi can fetch from the test server.
const response = yield NormandyApi.get("test_server.sjs");
const data = yield response.json();
Assert.deepEqual(data, {test: "data"}, "NormandyApi returned incorrect server data.");
});

Просмотреть файл

@ -0,0 +1,8 @@
function handleRequest(request, response) {
// Allow cross-origin, so you can XHR to it!
response.setHeader("Access-Control-Allow-Origin", "*", false);
// Avoid confusing cache behaviors
response.setHeader("Cache-Control", "no-cache", false);
response.setHeader("Content-Type", "application/json", false);
response.write(JSON.stringify({test: "data"}))
}

Просмотреть файл

@ -304,8 +304,8 @@ user_pref("browser.search.countryCode", "US");
user_pref("browser.search.geoSpecificDefaults", false);
// Make sure self support doesn't hit the network.
user_pref("browser.selfsupport.url", "https://%(server)s/selfsupport-dummy/");
user_pref("extensions.shield-recipe-client.api_url", "https://%(server)s/selfsupport-dummy/");
user_pref("browser.selfsupport.url", "https://example.com/selfsupport-dummy/");
user_pref("extensions.shield-recipe-client.api_url", "https://example.com/selfsupport-dummy/");
user_pref("media.eme.enabled", true);