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 : a492de75e4189f10371427a4f6c342a672ea57cd
This commit is contained in:
Mythmon 2017-01-03 09:41:51 -08:00
Родитель cd181bc396
Коммит 9974c78865
6 изменённых файлов: 36 добавлений и 2 удалений

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

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

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

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

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

@ -4,3 +4,6 @@
[browser_Storage.js] [browser_Storage.js]
[browser_Heartbeat.js] [browser_Heartbeat.js]
skip-if = true # bug 1325409 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"}))
}

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

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