Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3424)

Unified Diff: chrome/test/data/extensions/api_test/clipboard/extension_no_permission/test.js

Issue 475883003: [wip] Respect the clipboardRead and clipboardWrite permissions in content scripts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/clipboard/extension_no_permission/test.js
diff --git a/chrome/test/data/extensions/api_test/clipboard/extension_no_permission/test.js b/chrome/test/data/extensions/api_test/clipboard/extension_no_permission/test.js
index b5650c25684c2caf0801b913dd20003eb8b3ae5e..df61f896bbced4c7ccc0401b59cc3a81846706a9 100644
--- a/chrome/test/data/extensions/api_test/clipboard/extension_no_permission/test.js
+++ b/chrome/test/data/extensions/api_test/clipboard/extension_no_permission/test.js
@@ -5,17 +5,55 @@
// Clipboard permission test for Chrome.
// browser_tests.exe --gtest_filter=ClipboardApiTest.ExtensionNoPermission
-chrome.test.runTests([
- function domCopy() {
- if (document.execCommand('copy'))
- chrome.test.succeed();
- else
- chrome.test.fail('execCommand("copy") failed');
- },
- function domPaste() {
- if (!document.execCommand('paste'))
- chrome.test.succeed();
- else
- chrome.test.fail('execCommand("paste") succeeded');
+// TODO(kalman): Consolidate this test script with the other clipboard tests.
+
+var pass = chrome.test.callbackPass;
+
+function testDomCopy() {
+ if (document.execCommand('copy'))
+ chrome.test.succeed();
+ else
+ chrome.test.fail('execCommand("copy") failed');
+}
+
+function testDomPaste() {
+ if (document.execCommand('paste'))
+ chrome.test.fail('execCommand("paste") succeeded');
+ else
+ chrome.test.succeed();
+}
+
+function testContentScriptCopyPaste(tabUrl) {
+ function runContentScript(tabId) {
+ var done = chrome.test.listenForever(chrome.runtime.onMessage,
+ function(message, sender) {
+ if (sender.tab.id == tabId) {
+ chrome.tabs.remove(sender.tab.id);
+ chrome.test.assertEq('', message);
+ done();
+ chrome.test.succeed();
+ }
+ });
+ chrome.tabs.executeScript(tabId, {file: 'content_script.js'});
}
-]);
+
+ chrome.tabs.create({url: tabUrl}, pass(function(newTab) {
+ var done = chrome.test.listenForever(chrome.tabs.onUpdated,
+ function(_, info, updatedTab) {
+ if (updatedTab.id == newTab.id && info.status == 'complete') {
+ runContentScript(newTab.id);
+ done();
+ }
+ });
+ }));
+}
+
+chrome.test.getConfig(function(config) {
+ var tabUrl = 'http://localhost:' + config.testServer.port +
+ '/extensions/test_file.html';
+ chrome.test.runTests([
+ testDomCopy,
+ testDomPaste,
+ testContentScriptCopyPaste.bind(null, tabUrl)
+ ]);
+})

Powered by Google App Engine
This is Rietveld 408576698