| Index: chrome/test/data/extensions/api_test/clipboard/extension_no_permission/test.js
|
| diff --git a/chrome/test/data/extensions/api_test/clipboard/extension_no_permission/test.js b/chrome/test/data/extensions/api_test/clipboard/extension_no_permission/test.js
|
| index 2264f07ad9e82e8df45a24334b758bd5c2dd88ac..45d38f78dff494b1d782a485d9d3a491a1c2446c 100644
|
| --- a/chrome/test/data/extensions/api_test/clipboard/extension_no_permission/test.js
|
| +++ b/chrome/test/data/extensions/api_test/clipboard/extension_no_permission/test.js
|
| @@ -5,32 +5,37 @@
|
| // Clipboard permission test for Chrome.
|
| // browser_tests.exe --gtest_filter=ClipboardApiTest.ExtensionNoPermission
|
|
|
| -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") succeeded');
|
| - },
|
| - 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;
|
| +
|
| +function testDomCopy() {
|
| + if (document.execCommand('copy'))
|
| + chrome.test.succeed();
|
| + else
|
| + chrome.test.fail('execCommand("copy") failed');
|
| +}
|
| +
|
| +function testDomPaste() {
|
| + if (document.execCommand('paste'))
|
| + chrome.test.fail('execCommand("paste") succeeded');
|
| + else
|
| + chrome.test.succeed();
|
| +}
|
| +
|
| +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) {
|
| // 'copy' should always succeed regardless of the clipboardWrite permission,
|
| @@ -42,3 +47,66 @@ function testDone(result) {
|
| else
|
| chrome.test.fail();
|
| }
|
| +
|
| +function testExecuteScriptCopyPaste(baseUrl) {
|
| + var tabUrl = baseUrl + '/test_file.html';
|
| + function runScript(tabId) {
|
| + chrome.tabs.executeScript(tabId, {file: 'content_script.js'},
|
| + chrome.test.callbackPass(function() {
|
| + chrome.tabs.sendMessage(tabId, "run",
|
| + chrome.test.callbackPass(function(result) {
|
| + chrome.tabs.remove(tabId);
|
| + chrome.test.assertEq('', result);
|
| + }));
|
| + }));
|
| + }
|
| +
|
| + 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') {
|
| + runScript(newTab.id);
|
| + done();
|
| + }
|
| + });
|
| + }));
|
| +}
|
| +
|
| +function testContentScriptCopyPaste(baseUrl) {
|
| + var tabUrl = baseUrl + '/test_file_with_body.html';
|
| + function runScript(tabId) {
|
| + chrome.tabs.sendMessage(tabId, "run",
|
| + chrome.test.callbackPass(function(result) {
|
| + chrome.tabs.remove(tabId);
|
| + chrome.test.assertEq('', result);
|
| + }));
|
| + }
|
| +
|
| + chrome.tabs.create({url: tabUrl}, chrome.test.callbackPass(function(newTab) {
|
| + var done = chrome.test.listenForever(chrome.tabs.onUpdated,
|
| + function(_, info, updatedTab) {
|
| + if (updatedTab.id == newTab.id && info.status == 'complete') {
|
| + runScript(newTab.id);
|
| + done();
|
| + }
|
| + });
|
| + }));
|
| +}
|
| +
|
| +function bindTest(test, param) {
|
| + var result = test.bind(null, param);
|
| + result.generatedName = test.name;
|
| + return result;
|
| +}
|
| +
|
| +chrome.test.getConfig(function(config) {
|
| + var baseUrl = 'http://localhost:' + config.testServer.port + '/extensions';
|
| + chrome.test.runTests([
|
| + testDomCopy,
|
| + testDomPaste,
|
| + testCopyInIframe,
|
| + testPasteInIframe,
|
| + bindTest(testExecuteScriptCopyPaste, baseUrl),
|
| + bindTest(testContentScriptCopyPaste, baseUrl)
|
| + ]);
|
| +});
|
|
|