Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/clipboard/extension/test.js |
| diff --git a/chrome/test/data/extensions/api_test/clipboard/extension/test.js b/chrome/test/data/extensions/api_test/clipboard/extension/test.js |
| index 3ee936e20dd72822eb00aa84a25633f78cfd8028..0fd8e27868ad4c62b6d6d8fbb31aa81da9d52bfd 100644 |
| --- a/chrome/test/data/extensions/api_test/clipboard/extension/test.js |
| +++ b/chrome/test/data/extensions/api_test/clipboard/extension/test.js |
| @@ -5,33 +5,37 @@ |
| // Clipboard permission test for Chrome. |
| // browser_tests.exe --gtest_filter=ClipboardApiTest.Extension |
| -chrome.test.runTests([ |
| - function domCopy() { |
| - if (document.execCommand('copy')) |
| - chrome.test.succeed(); |
| - else |
| - chrome.test.fail('execCommand("copy") failed'); |
| - }, |
| - function domPaste() { |
| - if (document.execCommand('paste')) |
| - chrome.test.succeed(); |
| - else |
| - chrome.test.fail('execCommand("paste") failed'); |
| - }, |
| - function copyInIframe() { |
| - var ifr = document.createElement('iframe'); |
| - document.body.appendChild(ifr); |
| - window.command = 'copy'; |
| - ifr.contentDocument.write('<script src="iframe.js"></script>'); |
| - }, |
| - function pasteInIframe() { |
| - var ifr = document.createElement('iframe'); |
| - document.body.appendChild(ifr); |
| - window.command = 'paste'; |
| - ifr.contentDocument.write('<script src="iframe.js"></script>'); |
| - } |
| -]); |
| +// TODO(kalman): Consolidate this test script with the other clipboard tests. |
| + |
| +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.
|
| + |
| +function testDomCopy() { |
| + if (document.execCommand('copy')) |
| + chrome.test.succeed(); |
| + else |
| + chrome.test.fail('execCommand("copy") failed'); |
| +} |
| + |
| +function testDomPaste() { |
| + if (document.execCommand('paste')) |
| + chrome.test.succeed(); |
| + else |
| + chrome.test.fail('execCommand("paste") failed'); |
| +} |
| +function testCopyInIframe() { |
| + var ifr = document.createElement('iframe'); |
| + document.body.appendChild(ifr); |
| + window.command = 'copy'; |
| + ifr.contentDocument.write('<script src="iframe.js"></script>'); |
| +} |
| + |
| +function testPasteInIframe() { |
| + var ifr = document.createElement('iframe'); |
| + document.body.appendChild(ifr); |
| + window.command = 'paste'; |
| + ifr.contentDocument.write('<script src="iframe.js"></script>'); |
| +} |
| function testDone(result) { |
| if (result) |
| @@ -39,3 +43,40 @@ function testDone(result) { |
| else |
| chrome.test.fail(); |
| } |
| + |
| +function testContentScriptCopyPaste(tabUrl) { |
| + function runContentScript(tabId) { |
| + var done = chrome.test.listenForever(chrome.runtime.onMessage, |
| + function(message, sender) { |
| + if (sender.tab.id == tabId) { |
| + chrome.tabs.remove(sender.tab.id); |
| + chrome.test.assertEq('', message); |
| + done(); |
| + chrome.test.succeed(); |
| + } |
| + }); |
| + 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.
|
| + } |
| + |
| + chrome.tabs.create({url: tabUrl}, pass(function(newTab) { |
| + var done = chrome.test.listenForever(chrome.tabs.onUpdated, |
| + function(_, info, updatedTab) { |
| + if (updatedTab.id == newTab.id && info.status == 'complete') { |
| + runContentScript(newTab.id); |
| + done(); |
| + } |
| + }); |
| + })); |
| +} |
| + |
| +chrome.test.getConfig(function(config) { |
| + var tabUrl = 'http://localhost:' + config.testServer.port + |
| + '/extensions/test_file.html'; |
| + chrome.test.runTests([ |
| + testDomCopy, |
| + testDomPaste, |
| + testCopyInIframe, |
| + testPasteInIframe, |
| + testContentScriptCopyPaste.bind(null, tabUrl) |
| + ]); |
| +}) |