OLD | NEW |
---|---|
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 var pass = chrome.test.callbackPass; | |
Devlin
2014/09/03 22:09:16
for the one time we use this, I'd just inline it.
Marijn Kruisselbrink
2014/09/03 23:54:07
Done.
| |
11 | |
12 function testDomCopy() { | |
13 if (document.execCommand('copy')) | |
14 chrome.test.succeed(); | |
15 else | |
16 chrome.test.fail('execCommand("copy") failed'); | |
17 } | |
18 | |
19 function testDomPaste() { | |
20 if (document.execCommand('paste')) | |
21 chrome.test.succeed(); | |
22 else | |
23 chrome.test.fail('execCommand("paste") failed'); | |
24 } | |
25 | |
26 function testCopyInIframe() { | |
27 var ifr = document.createElement('iframe'); | |
28 document.body.appendChild(ifr); | |
29 window.command = 'copy'; | |
30 ifr.contentDocument.write('<script src="iframe.js"></script>'); | |
31 } | |
32 | |
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 } | |
35 | 39 |
36 function testDone(result) { | 40 function testDone(result) { |
37 if (result) | 41 if (result) |
38 chrome.test.succeed(); | 42 chrome.test.succeed(); |
39 else | 43 else |
40 chrome.test.fail(); | 44 chrome.test.fail(); |
41 } | 45 } |
46 | |
47 function testContentScriptCopyPaste(tabUrl) { | |
48 function runContentScript(tabId) { | |
49 var done = chrome.test.listenForever(chrome.runtime.onMessage, | |
50 function(message, sender) { | |
51 if (sender.tab.id == tabId) { | |
52 chrome.tabs.remove(sender.tab.id); | |
53 chrome.test.assertEq('', message); | |
54 done(); | |
55 chrome.test.succeed(); | |
56 } | |
57 }); | |
58 chrome.tabs.executeScript(tabId, {file: 'content_script.js'}); | |
Devlin
2014/09/03 22:09:16
hmm...
Saying this injects from a content script,
Marijn Kruisselbrink
2014/09/03 23:54:07
I renamed the test/methods. But that makes it soun
Devlin
2014/09/04 19:15:10
Ideally, yes, I'd say having a content script test
Marijn Kruisselbrink
2014/09/04 23:41:11
Okay, I added tests for content scripts as well.
| |
59 } | |
60 | |
61 chrome.tabs.create({url: tabUrl}, pass(function(newTab) { | |
62 var done = chrome.test.listenForever(chrome.tabs.onUpdated, | |
63 function(_, info, updatedTab) { | |
64 if (updatedTab.id == newTab.id && info.status == 'complete') { | |
65 runContentScript(newTab.id); | |
66 done(); | |
67 } | |
68 }); | |
69 })); | |
70 } | |
71 | |
72 chrome.test.getConfig(function(config) { | |
73 var tabUrl = 'http://localhost:' + config.testServer.port + | |
74 '/extensions/test_file.html'; | |
75 chrome.test.runTests([ | |
76 testDomCopy, | |
77 testDomPaste, | |
78 testCopyInIframe, | |
79 testPasteInIframe, | |
80 testContentScriptCopyPaste.bind(null, tabUrl) | |
81 ]); | |
82 }) | |
OLD | NEW |