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

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: fix extensions test compile 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 testContentScriptCopyPaste(tabUrl) {
52 function runContentScript(tabId) {
53 var done = chrome.test.listenForever(chrome.runtime.onMessage,
54 function(message, sender) {
55 if (sender.tab.id == tabId) {
56 chrome.tabs.remove(sender.tab.id);
57 chrome.test.assertEq('', message);
58 done();
59 chrome.test.succeed();
60 }
61 });
62 chrome.tabs.executeScript(tabId, {file: 'content_script.js'});
63 }
64
65 chrome.tabs.create({url: tabUrl}, pass(function(newTab) {
66 var done = chrome.test.listenForever(chrome.tabs.onUpdated,
67 function(_, info, updatedTab) {
68 if (updatedTab.id == newTab.id && info.status == 'complete') {
69 runContentScript(newTab.id);
70 done();
71 }
72 });
73 }));
74 }
75
76 chrome.test.getConfig(function(config) {
77 var tabUrl = 'http://localhost:' + config.testServer.port +
78 '/extensions/test_file.html';
79 chrome.test.runTests([
80 testDomCopy,
81 testDomPaste,
82 testCopyInIframe,
83 testPasteInIframe,
84 testContentScriptCopyPaste.bind(null, tabUrl)
85 ]);
86 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698