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() { | 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") failed'); | 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 testContentScriptCopyPaste(tabUrl) { |
| 27 function runContentScript(tabId) { |
| 28 var done = chrome.test.listenForever(chrome.runtime.onMessage, |
| 29 function(message, sender) { |
| 30 if (sender.tab.id == tabId) { |
| 31 chrome.tabs.remove(sender.tab.id); |
| 32 chrome.test.assertEq('', message); |
| 33 done(); |
| 34 chrome.test.succeed(); |
| 35 } |
| 36 }); |
| 37 chrome.tabs.executeScript(tabId, {file: 'content_script.js'}); |
20 } | 38 } |
21 ]); | |
22 | 39 |
| 40 chrome.tabs.create({url: tabUrl}, pass(function(newTab) { |
| 41 var done = chrome.test.listenForever(chrome.tabs.onUpdated, |
| 42 function(_, info, updatedTab) { |
| 43 if (updatedTab.id == newTab.id && info.status == 'complete') { |
| 44 runContentScript(newTab.id); |
| 45 done(); |
| 46 } |
| 47 }); |
| 48 })); |
| 49 } |
| 50 |
| 51 chrome.test.getConfig(function(config) { |
| 52 var tabUrl = 'http://localhost:' + config.testServer.port + |
| 53 '/extensions/test_file.html'; |
| 54 chrome.test.runTests([ |
| 55 testDomCopy, |
| 56 testDomPaste, |
| 57 testContentScriptCopyPaste.bind(null, tabUrl) |
| 58 ]); |
| 59 }) |
OLD | NEW |