Commit 5bc25455 authored by Shane Caraveo's avatar Shane Caraveo
Browse files

Bug 1551744 move webrequest modules into extension component r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D31168

--HG--
rename : toolkit/modules/tests/browser/dummy_page.html => toolkit/components/extensions/test/xpcshell/data/dummy_page.html
rename : toolkit/modules/tests/browser/file_WebRequest_page2.html => toolkit/components/extensions/test/xpcshell/data/file_WebRequest_page2.html
rename : toolkit/modules/tests/browser/file_image_bad.png => toolkit/components/extensions/test/xpcshell/data/file_image_bad.png
rename : toolkit/modules/tests/browser/file_image_good.png => toolkit/components/extensions/test/xpcshell/data/file_image_good.png
rename : toolkit/modules/tests/browser/file_image_bad.png => toolkit/components/extensions/test/xpcshell/data/file_image_redirect.png
rename : toolkit/modules/tests/browser/file_script_bad.js => toolkit/components/extensions/test/xpcshell/data/file_script_bad.js
rename : toolkit/modules/tests/browser/file_script_good.js => toolkit/components/extensions/test/xpcshell/data/file_script_good.js
rename : toolkit/modules/tests/browser/file_script_redirect.js => toolkit/components/extensions/test/xpcshell/data/file_script_redirect.js
rename : toolkit/modules/tests/browser/file_script_xhr.js => toolkit/components/extensions/test/xpcshell/data/file_script_xhr.js
rename : toolkit/modules/tests/browser/file_style_bad.css => toolkit/components/extensions/test/xpcshell/data/file_style_bad.css
rename : toolkit/modules/tests/browser/file_style_good.css => toolkit/components/extensions/test/xpcshell/data/file_style_good.css
rename : toolkit/modules/tests/browser/file_style_bad.css => toolkit/components/extensions/test/xpcshell/data/file_style_redirect.css
rename : toolkit/modules/tests/browser/browser_WebRequest_ancestors.js => toolkit/components/extensions/test/xpcshell/test_webRequest_ancestors.js
rename : toolkit/modules/tests/browser/browser_WebRequest_cookies.js => toolkit/components/extensions/test/xpcshell/test_webRequest_cookies.js
rename : toolkit/modules/tests/browser/browser_WebRequest_filtering.js => toolkit/components/extensions/test/xpcshell/test_webRequest_filtering.js
rename : toolkit/modules/addons/SecurityInfo.jsm => toolkit/components/extensions/webrequest/SecurityInfo.jsm
rename : toolkit/modules/addons/WebRequest.jsm => toolkit/components/extensions/webrequest/WebRequest.jsm
rename : toolkit/modules/addons/WebRequestCommon.jsm => toolkit/components/extensions/webrequest/WebRequestCommon.jsm
rename : toolkit/modules/addons/WebRequestContent.js => toolkit/components/extensions/webrequest/WebRequestContent.js
rename : toolkit/modules/addons/WebRequestUpload.jsm => toolkit/components/extensions/webrequest/WebRequestUpload.jsm
extra : moz-landing-system : lando
parent b3e2863b
"use strict";
var request = new XMLHttpRequest();
request.open("get", "http://example.com/browser/toolkit/modules/tests/browser/xhr_resource", false);
request.send();
"use strict";
// This test requires an XMLHttpRequest constructor which isn't
// associated with a window.
const {XMLHttpRequest} = Cu.Sandbox(window, {wantGlobalProperties: ["XMLHttpRequest"]});
var {WebRequest} = ChromeUtils.import("resource://gre/modules/WebRequest.jsm");
var {PromiseUtils} = ChromeUtils.import("resource://gre/modules/PromiseUtils.jsm");
const server = createHttpServer({hosts: ["example.com"]});
server.registerDirectory("/data/", do_get_file("data"));
add_task(async function test_ancestors_exist() {
let deferred = PromiseUtils.defer();
function onBeforeRequest(details) {
......@@ -15,11 +14,11 @@ add_task(async function test_ancestors_exist() {
deferred.resolve();
}
WebRequest.onBeforeRequest.addListener(onBeforeRequest, {urls: new MatchPatternSet(["http://mochi.test/test/*"])}, ["blocking"]);
WebRequest.onBeforeRequest.addListener(onBeforeRequest, {urls: new MatchPatternSet(["http://example.com/*"])}, ["blocking"]);
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://mochi.test:8888/test/");
let contentPage = await ExtensionTestUtils.loadContentPage("http://example.com/data/file_sample.html");
await deferred.promise;
BrowserTestUtils.removeTab(tab);
await contentPage.close();
WebRequest.onBeforeRequest.removeListener(onBeforeRequest);
});
......@@ -47,7 +46,7 @@ add_task(async function test_ancestors_null() {
});
}
await fetch("http://mochi.test:8888/test/");
await fetch("http://example.com/data/file_sample.html");
await deferred.promise;
WebRequest.onBeforeRequest.removeListener(onBeforeRequest);
......
......@@ -2,8 +2,22 @@
var {WebRequest} = ChromeUtils.import("resource://gre/modules/WebRequest.jsm");
const BASE = "http://example.com/browser/toolkit/modules/tests/browser";
const URL = BASE + "/WebRequest_dynamic.sjs";
const server = createHttpServer({hosts: ["example.com"]});
server.registerPathHandler("/", (request, response) => {
response.setStatusLine(request.httpVersion, 200, "OK");
if (request.hasHeader("Cookie")) {
let value = request.getHeader("Cookie");
if (value == "blinky=1") {
response.setHeader("Set-Cookie", "dinky=1", false);
}
response.write("cookie-present");
} else {
response.setHeader("Set-Cookie", "foopy=1", false);
response.write("cookie-not-present");
}
});
const URL = "http://example.com/";
var countBefore = 0;
var countAfter = 0;
......@@ -21,7 +35,7 @@ function onBeforeSendHeaders(details) {
for (let {name, value} of details.requestHeaders) {
info(`Saw header ${name} '${value}'`);
if (name == "Cookie") {
is(value, "foopy=1", "Cookie is correct");
equal(value, "foopy=1", "Cookie is correct");
headers.push({name, value: "blinky=1"});
found = true;
} else {
......@@ -29,6 +43,7 @@ function onBeforeSendHeaders(details) {
}
}
ok(found, "Saw cookie header");
equal(countBefore, 1, "onBeforeSendHeaders hit once");
return {requestHeaders: headers};
}
......@@ -44,37 +59,27 @@ function onResponseStarted(details) {
let found = false;
for (let {name, value} of details.responseHeaders) {
info(`Saw header ${name} '${value}'`);
if (name == "Set-Cookie") {
is(value, "dinky=1", "Cookie is correct");
if (name == "set-cookie") {
equal(value, "dinky=1", "Cookie is correct");
found = true;
}
}
ok(found, "Saw cookie header");
equal(countAfter, 1, "onResponseStarted hit once");
}
add_task(async function filter_urls() {
// First load the URL so that we set cookie foopy=1.
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, URL);
await waitForLoad();
gBrowser.removeCurrentTab();
let contentPage = await ExtensionTestUtils.loadContentPage(URL);
await contentPage.close();
// Now load with WebRequest set up.
WebRequest.onBeforeSendHeaders.addListener(onBeforeSendHeaders, null, ["blocking"]);
WebRequest.onResponseStarted.addListener(onResponseStarted, null);
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, URL);
WebRequest.onBeforeSendHeaders.addListener(onBeforeSendHeaders, null, ["blocking", "requestHeaders"]);
WebRequest.onResponseStarted.addListener(onResponseStarted, null, ["responseHeaders"]);
await waitForLoad();
gBrowser.removeCurrentTab();
contentPage = await ExtensionTestUtils.loadContentPage(URL);
await contentPage.close();
WebRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders);
WebRequest.onResponseStarted.removeListener(onResponseStarted);
is(countBefore, 1, "onBeforeSendHeaders hit once");
is(countAfter, 1, "onResponseStarted hit once");
});
function waitForLoad(browser = gBrowser.selectedBrowser) {
return BrowserTestUtils.browserLoaded(browser);
}
......@@ -2,7 +2,10 @@
var {WebRequest} = ChromeUtils.import("resource://gre/modules/WebRequest.jsm");
const BASE = "http://example.com/browser/toolkit/modules/tests/browser";
const server = createHttpServer({hosts: ["example.com"]});
server.registerDirectory("/data/", do_get_file("data"));
const BASE = "http://example.com/data/";
const URL = BASE + "/file_WebRequest_page2.html";
var requested = [];
......@@ -53,12 +56,12 @@ function compareLists(list1, list2, kind) {
removeDupes(list1);
list2.sort();
removeDupes(list2);
is(String(list1), String(list2), `${kind} URLs correct`);
equal(String(list1), String(list2), `${kind} URLs correct`);
}
add_task(async function setup() {
// Disable rcwn to make cache behavior deterministic.
await SpecialPowers.pushPrefEnv({set: [["network.http.rcwn.enabled", false]]});
Services.prefs.setBoolPref("network.http.rcwn.enabled", false);
});
add_task(async function filter_urls() {
......@@ -68,11 +71,8 @@ add_task(async function filter_urls() {
WebRequest.onBeforeSendHeaders.addListener(onBeforeSendHeaders, filter, ["blocking"]);
WebRequest.onResponseStarted.addListener(onResponseStarted, filter);
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, URL);
await waitForLoad();
gBrowser.removeCurrentTab();
let contentPage = await ExtensionTestUtils.loadContentPage(URL);
await contentPage.close();
compareLists(requested, expected_urls, "requested");
compareLists(sendHeaders, expected_urls, "sendHeaders");
......@@ -90,11 +90,8 @@ add_task(async function filter_types() {
WebRequest.onBeforeSendHeaders.addListener(onBeforeSendHeaders, filter, ["blocking"]);
WebRequest.onResponseStarted.addListener(onResponseStarted, filter);
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, URL);
await waitForLoad();
gBrowser.removeCurrentTab();
let contentPage = await ExtensionTestUtils.loadContentPage(URL);
await contentPage.close();
compareLists(requested, expected_urls, "requested");
compareLists(sendHeaders, expected_urls, "sendHeaders");
......@@ -104,7 +101,3 @@ add_task(async function filter_types() {
WebRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders);
WebRequest.onResponseStarted.removeListener(onResponseStarted);
});
function waitForLoad(browser = gBrowser.selectedBrowser) {
return BrowserTestUtils.browserLoaded(browser);
}
......@@ -181,6 +181,9 @@ skip-if = os == "android" # incognito not supported on android
[test_proxy_scripts_deprecated.js]
[test_proxy_scripts_results.js]
[test_proxy_userContextId.js]
[test_webRequest_ancestors.js]
[test_webRequest_cookies.js]
[test_webRequest_filtering.js]
[test_ext_brokenlinks.js]
[test_ext_performance_counters.js]
skip-if = appname == "thunderbird" || os == "android"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment