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

Side by Side Diff: chrome/test/data/extensions/api_test/clipboard/extension/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 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.Extension 6 // browser_tests.exe --gtest_filter=ClipboardApiTest.Extension
7 7
8 chrome.test.runTests([ 8 // TODO(kalman): Consolidate this test script with the other clipboard tests.
9 function domCopy() {
10 if (document.execCommand('copy'))
11 chrome.test.succeed();
12 else
13 chrome.test.fail('execCommand("copy") failed');
14 },
15 function domPaste() {
16 if (document.execCommand('paste'))
17 chrome.test.succeed();
18 else
19 chrome.test.fail('execCommand("paste") failed');
20 },
21 function copyInIframe() {
22 var ifr = document.createElement('iframe');
23 document.body.appendChild(ifr);
24 window.command = 'copy';
25 ifr.contentDocument.write('<script src="iframe.js"></script>');
26 },
27 function pasteInIframe() {
28 var ifr = document.createElement('iframe');
29 document.body.appendChild(ifr);
30 window.command = 'paste';
31 ifr.contentDocument.write('<script src="iframe.js"></script>');
32 }
33 ]);
34 9
10 function testDomCopy() {
11 if (document.execCommand('copy'))
12 chrome.test.succeed();
13 else
14 chrome.test.fail('execCommand("copy") failed');
15 }
16
17 function testDomPaste() {
18 if (document.execCommand('paste'))
19 chrome.test.succeed();
20 else
21 chrome.test.fail('execCommand("paste") failed');
22 }
23
24 function testCopyInIframe() {
25 var ifr = document.createElement('iframe');
26 document.body.appendChild(ifr);
27 window.command = 'copy';
28 ifr.contentDocument.write('<script src="iframe.js"></script>');
29 }
30
31 function testPasteInIframe() {
32 var ifr = document.createElement('iframe');
33 document.body.appendChild(ifr);
34 window.command = 'paste';
35 ifr.contentDocument.write('<script src="iframe.js"></script>');
36 }
35 37
36 function testDone(result) { 38 function testDone(result) {
37 if (result) 39 if (result)
38 chrome.test.succeed(); 40 chrome.test.succeed();
39 else 41 else
40 chrome.test.fail(); 42 chrome.test.fail();
41 } 43 }
44
45 function testExecuteScriptCopyPaste(tabUrl) {
46 function runScript(tabId) {
47 var done = chrome.test.listenForever(chrome.runtime.onMessage,
48 function(message, sender) {
49 if (sender.tab.id == tabId) {
50 chrome.tabs.remove(sender.tab.id);
51 chrome.test.assertEq('', message);
52 done();
53 chrome.test.succeed();
54 }
55 });
56 chrome.tabs.executeScript(tabId, {file: 'content_script.js'});
57 }
58
59 chrome.tabs.create({url: tabUrl}, chrome.test.callbackPass(function(newTab) {
60 var done = chrome.test.listenForever(chrome.tabs.onUpdated,
61 function(_, info, updatedTab) {
62 if (updatedTab.id == newTab.id && info.status == 'complete') {
63 runScript(newTab.id);
64 done();
65 }
66 });
67 }));
68 }
69
70 chrome.test.getConfig(function(config) {
71 var tabUrl = 'http://localhost:' + config.testServer.port +
72 '/extensions/test_file.html';
73 chrome.test.runTests([
74 testDomCopy,
75 testDomPaste,
76 testCopyInIframe,
77 testPasteInIframe,
78 testExecuteScriptCopyPaste.bind(null, tabUrl)
79 ]);
80 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698