Part 5:
Bug 1295807 - Add unit tests for the network API. r?kmag
MozReview-Commit-ID: 1NVyyXhDT1b
--- a/toolkit/components/extensions/ProxyScript.jsm
+++ b/toolkit/components/extensions/ProxyScript.jsm
@@ -203,17 +203,17 @@ class ProxyScriptContext extends BaseCon
} catch (error) {
this.extension.emit("network-error", error);
Cu.reportError("ProxyScript: Invalid Proxy Script");
return;
}
let {FindProxyForURL} = this.sandbox_;
if (typeof FindProxyForURL != "function") {
- this.extension.emit("network-error", new Error("FindProxyForURL must be a function"));
+ this.extension.emit("network-error", new Error("FindProxyForURL must be defined as a function"));
Cu.reportError("ProxyScript: Invalid Proxy Script");
return;
}
gProxyService.registerFilter(
this.filter_ /* nsIProtocolProxyFilter aFilter */,
0 /* unsigned long aPosition */
);
--- a/toolkit/components/extensions/test/mochitest/mochitest.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest.ini
@@ -52,16 +52,17 @@ skip-if = buildapp == 'b2g' # runat != d
[test_ext_contentscript_devtools_metadata.html]
[test_ext_contentscript_exporthelpers.html]
[test_ext_contentscript_css.html]
[test_ext_contentscript_teardown.html]
skip-if = (os == 'android') # Android does not support tabs API. Bug 1260250
[test_ext_exclude_include_globs.html]
[test_ext_i18n_css.html]
[test_ext_generate.html]
+[test_ext_network.html]
[test_ext_notifications.html]
[test_ext_permission_xhr.html]
skip-if = buildapp == 'b2g' # JavaScript error: jar:remoteopenfile:///data/local/tmp/generated-extension.xpi!/content.js, line 46: NS_ERROR_ILLEGAL_VALUE:
[test_ext_runtime_connect.html]
skip-if = (os == 'android' || buildapp == 'b2g') # port.sender.tab is undefined on b2g. Bug 1258975 on android.
[test_ext_runtime_connect_twoway.html]
skip-if = (os == 'android' || buildapp == 'b2g') # port.sender.tab is undefined on b2g. Bug 1258975 on android.
[test_ext_runtime_connect2.html]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/test_ext_network.html
@@ -0,0 +1,75 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for content script contexts</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
+ <script type="text/javascript" src="head.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="text/javascript">
+"use strict";
+
+// TODO(matt): Test that registered filters run correctly when pages are loaded, and that
+// the correct additional arguments are passed to FindProxyForUrl.
+add_task(function* test_empty_proxyscript() {
+ function backgroundScript() {
+ browser.network.onProxyError.addListener(error => {
+ browser.test.assertEq("FindProxyForURL must be defined as a function", error, "Correct error message received");
+ browser.test.notifyPass("network-empty-proxy-script");
+ });
+
+ browser.network.setProxyScript("proxy_script.js");
+ }
+
+ let extension = ExtensionTestUtils.loadExtension({
+ background: `(${backgroundScript})();`,
+ manifest: {
+ "permissions": ["network"],
+ },
+ files: {
+ "proxy_script.js": `(function(){ })()`,
+ },
+ });
+
+ yield extension.startup();
+ yield extension.awaitFinish("network-empty-proxy-script");
+ yield extension.unload();
+});
+
+add_task(function* test_invalid_type_for_FindProxyForURL() {
+ function backgroundScript() {
+ browser.network.onProxyError.addListener(error => {
+ browser.test.assertEq("FindProxyForURL must be defined as a function", error, "Correct error message received");
+ browser.test.notifyPass("network-empty-proxy-script");
+ });
+
+ browser.network.setProxyScript("proxy_script.js");
+ }
+
+ function proxyScript() {
+ let FindProxyForURL = "invalid-type";
+ }
+
+ let extension = ExtensionTestUtils.loadExtension({
+ background: `(${backgroundScript})();`,
+ manifest: {
+ "permissions": ["network"],
+ },
+ files: {
+ "proxy_script.js": `(${proxyScript})()`,
+ },
+ });
+
+ yield extension.startup();
+ yield extension.awaitFinish("network-empty-proxy-script");
+ yield extension.unload();
+});
+
+</script>
+
+</body>
+</html>