Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / clipboard / extension_no_permission / content_script.js
1 // Copyright 2014 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.
4
5 // TODO(kalman): Consolidate this test script with the other clipboard tests.
6
7 function appendTextarea() {
8   return document.body.appendChild(document.createElement('textarea'));
9 }
10
11 function run() {
12   var textIn = appendTextarea();
13
14   textIn.focus();
15   textIn.value = 'foobar';
16   textIn.selectionStart = 0;
17   textIn.selectionEnd = 'foobar'.length;
18   if (document.execCommand('copy'))
19     return 'Succeeded to copy';
20
21   var textOut = appendTextarea();
22
23   textOut.focus();
24   if (document.execCommand('paste'))
25     return 'Succeeded to paste';
26   if (textOut.value == 'foobar')
27     return 'Successfully copied/pasted despite execCommand failures';
28
29   return '';
30 }
31
32 chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
33   sendResponse(run());
34 });