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

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

Issue 498513002: Respect the clipboardRead and clipboardWrite permissions in content scripts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address more comments Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Clipboard permission test for Chrome. 5 // Clipboard permission test for Chrome.
6 // browser_tests.exe --gtest_filter=ClipboardApiTest.ExtensionNoPermission 6 // browser_tests.exe --gtest_filter=ClipboardApiTest.ExtensionNoPermission
7 7
8 chrome.test.runTests([ 8 // TODO(kalman): Consolidate this test script with the other clipboard tests.
9 function domCopy() { 9
10 if (document.execCommand('copy')) 10 var pass = chrome.test.callbackPass;
11 chrome.test.succeed(); 11
12 else 12 function testDomCopy() {
13 chrome.test.fail('execCommand("copy") failed'); 13 if (document.execCommand('copy'))
14 }, 14 chrome.test.succeed();
15 function domPaste() { 15 else
16 if (!document.execCommand('paste')) 16 chrome.test.fail('execCommand("copy") failed');
17 chrome.test.succeed(); 17 }
18 else 18
19 chrome.test.fail('execCommand("paste") succeeded'); 19 function testDomPaste() {
20 }, 20 if (document.execCommand('paste'))
21 function copyInIframe() { 21 chrome.test.fail('execCommand("paste") succeeded');
22 var ifr = document.createElement('iframe'); 22 else
23 document.body.appendChild(ifr); 23 chrome.test.succeed();
24 window.command = 'copy'; 24 }
25 ifr.contentDocument.write('<script src="iframe.js"></script>'); 25
26 }, 26 function testCopyInIframe() {
27 function pasteInIframe() { 27 var ifr = document.createElement('iframe');
28 var ifr = document.createElement('iframe'); 28 document.body.appendChild(ifr);
29 document.body.appendChild(ifr); 29 window.command = 'copy';
30 window.command = 'paste'; 30 ifr.contentDocument.write('<script src="iframe.js"></script>');
31 ifr.contentDocument.write('<script src="iframe.js"></script>'); 31 }
32 } 32
33 ]); 33 function testPasteInIframe() {
34 var ifr = document.createElement('iframe');
35 document.body.appendChild(ifr);
36 window.command = 'paste';
37 ifr.contentDocument.write('<script src="iframe.js"></script>');
38 }
34 39
35 function testDone(result) { 40 function testDone(result) {
36 // 'copy' should always succeed regardless of the clipboardWrite permission, 41 // 'copy' should always succeed regardless of the clipboardWrite permission,
37 // for backwards compatibility. 'paste' should always fail because the 42 // for backwards compatibility. 'paste' should always fail because the
38 // extension doesn't have clipboardRead. 43 // extension doesn't have clipboardRead.
39 var expected = window.command === 'copy'; 44 var expected = window.command === 'copy';
40 if (result === expected) 45 if (result === expected)
41 chrome.test.succeed(); 46 chrome.test.succeed();
42 else 47 else
43 chrome.test.fail(); 48 chrome.test.fail();
44 } 49 }
50
51 function testExecuteScriptCopyPaste(baseUrl) {
52 var tabUrl = baseUrl + '/test_file.html';
53 function runScript(tabId) {
54 chrome.tabs.executeScript(tabId, {file: 'content_script.js'},
55 chrome.test.callbackPass(function() {
56 chrome.tabs.sendMessage(tabId, "run",
57 chrome.test.callbackPass(function(result) {
58 chrome.tabs.remove(tabId);
59 chrome.test.assertEq('', result);
60 }));
61 }));
62 }
63
64 chrome.tabs.create({url: tabUrl}, pass(function(newTab) {
65 var done = chrome.test.listenForever(chrome.tabs.onUpdated,
66 function(_, info, updatedTab) {
67 if (updatedTab.id == newTab.id && info.status == 'complete') {
68 runScript(newTab.id);
69 done();
70 }
71 });
72 }));
73 }
74
75 function testContentScriptCopyPaste(baseUrl) {
76 var tabUrl = baseUrl + '/test_file_with_body.html';
77 function runScript(tabId) {
78 chrome.tabs.sendMessage(tabId, "run",
79 chrome.test.callbackPass(function(result) {
80 chrome.tabs.remove(tabId);
81 chrome.test.assertEq('', result);
82 }));
83 }
84
85 chrome.tabs.create({url: tabUrl}, chrome.test.callbackPass(function(newTab) {
86 var done = chrome.test.listenForever(chrome.tabs.onUpdated,
87 function(_, info, updatedTab) {
88 if (updatedTab.id == newTab.id && info.status == 'complete') {
89 runScript(newTab.id);
90 done();
91 }
92 });
93 }));
94 }
95
96 function bindTest(test, param) {
97 var result = test.bind(null, param);
98 result.generatedName = test.name;
99 return result;
100 }
101
102 chrome.test.getConfig(function(config) {
103 var baseUrl = 'http://localhost:' + config.testServer.port + '/extensions';
104 chrome.test.runTests([
105 testDomCopy,
106 testDomPaste,
107 testCopyInIframe,
108 testPasteInIframe,
109 bindTest(testExecuteScriptCopyPaste, baseUrl),
110 bindTest(testContentScriptCopyPaste, baseUrl)
111 ]);
112 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698