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
3 // found in the LICENSE file.
5 // Clipboard permission test for Chrome.
6 // browser_tests.exe --gtest_filter=ClipboardApiTest.Extension
8 // TODO(kalman): Consolidate this test script with the other clipboard tests.
10 function testDomCopy() {
11 if (document.execCommand('copy'))
12 chrome.test.succeed();
14 chrome.test.fail('execCommand("copy") failed');
17 function testDomPaste() {
18 if (document.execCommand('paste'))
19 chrome.test.succeed();
21 chrome.test.fail('execCommand("paste") failed');
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>');
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>');
38 function testDone(result) {
40 chrome.test.succeed();
45 function testExecuteScriptCopyPaste(baseUrl) {
46 var tabUrl = baseUrl + '/test_file.html';
47 function runScript(tabId) {
48 chrome.tabs.executeScript(tabId, {file: 'content_script.js'},
49 chrome.test.callbackPass(function() {
50 chrome.tabs.sendMessage(tabId, "run",
51 chrome.test.callbackPass(function(result) {
52 chrome.tabs.remove(tabId);
53 chrome.test.assertEq('', result);
58 chrome.tabs.create({url: tabUrl}, chrome.test.callbackPass(function(newTab) {
59 var done = chrome.test.listenForever(chrome.tabs.onUpdated,
60 function(_, info, updatedTab) {
61 if (updatedTab.id == newTab.id && info.status == 'complete') {
69 function testContentScriptCopyPaste(baseUrl) {
70 var tabUrl = baseUrl + '/test_file_with_body.html';
71 function runScript(tabId) {
72 chrome.tabs.sendMessage(tabId, "run",
73 chrome.test.callbackPass(function(result) {
74 chrome.tabs.remove(tabId);
75 chrome.test.assertEq('', result);
79 chrome.tabs.create({url: tabUrl}, chrome.test.callbackPass(function(newTab) {
80 var done = chrome.test.listenForever(chrome.tabs.onUpdated,
81 function(_, info, updatedTab) {
82 if (updatedTab.id == newTab.id && info.status == 'complete') {
90 function bindTest(test, param) {
91 var result = test.bind(null, param);
92 result.generatedName = test.name;
96 chrome.test.getConfig(function(config) {
97 var baseUrl = 'http://localhost:' + config.testServer.port + '/extensions';
98 chrome.test.runTests([
103 bindTest(testExecuteScriptCopyPaste, baseUrl),
104 bindTest(testContentScriptCopyPaste, baseUrl)