Bug 1310318 - Part 2: Test access to canvas drawWindow() with permission
MozReview-Commit-ID: 4ee3pRfduIj
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/file_to_drawWindow.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<head>
+ <meta charset="utf-8">
+</head>
+<body style="background: #ff9">
+
+</body>
+</html>
--- a/toolkit/components/extensions/test/mochitest/mochitest-common.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest-common.ini
@@ -1,16 +1,17 @@
[DEFAULT]
support-files =
chrome_cleanup_script.js
head.js
file_mixed.html
head_webrequest.js
file_csp.html
file_csp.html^headers^
+ file_to_drawWindow.html
file_WebRequest_page3.html
file_webNavigation_clientRedirect.html
file_webNavigation_clientRedirect_httpHeaders.html
file_webNavigation_clientRedirect_httpHeaders.html^headers^
file_webNavigation_frameClientRedirect.html
file_webNavigation_frameRedirect.html
file_webNavigation_manualSubframe.html
file_webNavigation_manualSubframe_page1.html
@@ -47,16 +48,17 @@ skip-if = os == 'android' # Android does
[test_ext_geturl.html]
[test_ext_background_canvas.html]
[test_ext_content_security_policy.html]
[test_ext_contentscript.html]
[test_ext_contentscript_api_injection.html]
[test_ext_contentscript_context.html]
[test_ext_contentscript_create_iframe.html]
[test_ext_contentscript_devtools_metadata.html]
+[test_ext_contentscript_drawWindow.html]
[test_ext_contentscript_exporthelpers.html]
[test_ext_contentscript_incognito.html]
skip-if = os == 'android' # Android does not multiple windows.
[test_ext_contentscript_css.html]
[test_ext_contentscript_about_blank.html]
[test_ext_contentscript_permission.html]
skip-if = os == 'android' # Android does not support tabs API. Bug 1260250
[test_ext_contentscript_teardown.html]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/test_ext_contentscript_drawWindow.html
@@ -0,0 +1,56 @@
+<!doctype html>
+<html>
+<head>
+ <title>Test content script access to canvas drawWindow()</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<script>
+"use strict";
+
+add_task(function* test_drawWindow() {
+ const permissions = [
+ "<all_urls>",
+ ];
+
+ const content_scripts = [{
+ matches: ["https://example.org/*"],
+ js: ["content_script.js"],
+ }];
+
+ const files = {
+ "content_script.js": () => {
+ const canvas = document.createElement("canvas");
+ const ctx = canvas.getContext("2d");
+ try {
+ ctx.drawWindow(window, 0, 0, 10, 10, "red");
+ const {data} = ctx.getImageData(0, 0, 10, 10);
+ browser.test.sendMessage("success", data.slice(0, 3).join());
+ } catch (e) {
+ browser.test.sendMessage("error", e.message);
+ }
+ },
+ };
+
+ const first = ExtensionTestUtils.loadExtension({manifest: {permissions, content_scripts}, files});
+ const second = ExtensionTestUtils.loadExtension({manifest: {content_scripts}, files});
+
+ yield first.startup();
+ yield second.startup();
+
+ const win = window.open("https://example.org/tests/toolkit/components/extensions/test/mochitest/file_to_drawWindow.html");
+
+ const colour = yield first.awaitMessage("success");
+ is(colour, "255,255,153", "drawWindow() call was successful: #ff9 == rgb(255,255,153)");
+
+ const error = yield second.awaitMessage("error");
+ is(error, "ctx.drawWindow is not a function", "drawWindow() method not awailable without permission");
+
+ win.close();
+ yield first.unload();
+ yield second.unload();
+});
+
+</script>