diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/components/extensions/test/mochitest/test_clipboard.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/extensions/test/mochitest/test_clipboard.html')
-rw-r--r-- | toolkit/components/extensions/test/mochitest/test_clipboard.html | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/toolkit/components/extensions/test/mochitest/test_clipboard.html b/toolkit/components/extensions/test/mochitest/test_clipboard.html new file mode 100644 index 000000000..900ee5f10 --- /dev/null +++ b/toolkit/components/extensions/test/mochitest/test_clipboard.html @@ -0,0 +1,140 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>clipboard permission test</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <script src="/tests/SimpleTest/SpawnTask.js"></script> + <script src="/tests/SimpleTest/ExtensionTestUtils.js"></script> + <script src="head.js"></script> + <link rel="stylesheet" href="/tests/SimpleTest/test.css"> +</head> +<body> + +<script> +"use strict"; + +function doCopy(txt) { + let field = document.createElement("textarea"); + document.body.appendChild(field); + field.value = txt; + field.select(); + return document.execCommand("copy"); +} + +add_task(function* no_permission_deny_copy() { + function backgroundScript() { + browser.test.assertEq(false, doCopy("whatever"), + "copy should be denied without permission"); + browser.test.sendMessage("ready"); + } + let extensionData = { + background: `${doCopy};(${backgroundScript})();`, + }; + let extension = ExtensionTestUtils.loadExtension(extensionData); + yield extension.startup(); + + yield extension.awaitMessage("ready"); + + yield extension.unload(); +}); + +/** Selecting text in a bg page is not possible, skip test until it's fixed. +add_task(function* with_permission_allow_copy() { + function backgroundScript() { + browser.test.onMessage.addListener(txt => { + browser.test.assertEq(true, doCopy(txt), + "copy should be allowed with permission"); + }); + browser.test.sendMessage("ready"); + } + let extensionData = { + background: `${doCopy};(${backgroundScript})();`, + manifest: { + permissions: [ + "clipboardWrite", + ], + }, + }; + let extension = ExtensionTestUtils.loadExtension(extensionData); + yield extension.startup(); + yield extension.awaitMessage("ready"); + + const DUMMY_STR = "dummy string to copy"; + yield new Promise(resolve => { + SimpleTest.waitForClipboard(DUMMY_STR, () => { + extension.sendMessage(DUMMY_STR); + }, resolve, resolve); + }); + + yield extension.unload(); +}); */ + +add_task(function* content_script_no_permission_deny_copy() { + function contentScript() { + browser.test.assertEq(false, doCopy("whatever"), + "copy should be denied without permission"); + browser.test.sendMessage("ready"); + } + let extensionData = { + manifest: { + content_scripts: [{ + js: ["contentscript.js"], + matches: ["http://mochi.test/*/file_sample.html"], + }], + }, + files: { + "contentscript.js": `${doCopy};(${contentScript})();`, + }, + }; + let extension = ExtensionTestUtils.loadExtension(extensionData); + yield extension.startup(); + + let win = window.open("file_sample.html"); + yield extension.awaitMessage("ready"); + win.close(); + + yield extension.unload(); +}); + +add_task(function* content_script_with_permission_allow_copy() { + function contentScript() { + browser.test.onMessage.addListener(txt => { + browser.test.assertEq(true, doCopy(txt), + "copy should be allowed with permission"); + }); + browser.test.sendMessage("ready"); + } + let extensionData = { + manifest: { + content_scripts: [{ + js: ["contentscript.js"], + matches: ["http://mochi.test/*/file_sample.html"], + }], + permissions: [ + "clipboardWrite", + ], + }, + files: { + "contentscript.js": `${doCopy};(${contentScript})();`, + }, + }; + let extension = ExtensionTestUtils.loadExtension(extensionData); + yield extension.startup(); + + let win = window.open("file_sample.html"); + yield extension.awaitMessage("ready"); + + const DUMMY_STR = "dummy string to copy in content script"; + yield new Promise(resolve => { + SimpleTest.waitForClipboard(DUMMY_STR, () => { + extension.sendMessage(DUMMY_STR); + }, resolve, resolve); + }); + + win.close(); + + yield extension.unload(); +}); +</script> +</body> +</html> |