- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / platform_apps / web_view / edit_commands_no_menu / guest.html
1 <!--
2  * Copyright 2013 The Chromium Authors. All rights reserved.  Use of this
3  * source code is governed by a BSD-style license that can be found in the
4  * LICENSE file.
5 -->
6 <html>
7   <head>
8     <script type="text/javascript">
9       // A guest that monitors focus and edit commands.
10       // Notifies the embedder about changes in focus via postMessage.
11       // Note that the embedder has to initiate a postMessage first so that
12       // the guest has a reference to the embedder's window.
13
14       // The window reference of the embedder to send post message reply.
15       var embedderWindowChannel = null;
16       var embedderTestName = '';
17
18       var notifyEmbedder = function(msg_array) {
19         embedderWindowChannel.postMessage(JSON.stringify(msg_array), '*');
20       };
21
22       var onPostMessageReceived = function(e) {
23         embedderWindowChannel = e.source;
24         var data = JSON.parse(e.data);
25         if (data[0] == 'create-channel') {
26           embedderTestName = data[1];
27           notifyEmbedder(['channel-created']);
28           return;
29         }
30         if (data[0] == 'end-of-line') {
31           window.getSelection().empty();
32           var testinput = document.getElementById('testinput');
33           var length = testinput.value.length;
34           testinput.focus();
35           testinput.selectionStart = length;
36           return;
37         }
38       };
39       window.addEventListener('message', onPostMessageReceived, false);
40
41       window.addEventListener('load', function(e) {
42         document.getElementById('testinput').addEventListener('keyup',
43             function(e) {
44           var response = 'caret-position-' + this.selectionStart;
45           notifyEmbedder([response, embedderTestName]);
46         });
47       });
48
49     </script>
50   </head>
51   <body>
52     <div>This is a guest that verifies edit commands are sent.</div>
53     <input id='testinput' type="text" value="test">
54   </body>
55 </html>