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
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.
14 // The window reference of the embedder to send post message reply.
15 var embedderWindowChannel = null;
16 var embedderTestName = '';
18 var notifyEmbedder = function(msg_array) {
19 embedderWindowChannel.postMessage(JSON.stringify(msg_array), '*');
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']);
30 if (data[0] == 'end-of-line') {
31 window.getSelection().empty();
32 var testinput = document.getElementById('testinput');
33 var length = testinput.value.length;
35 testinput.selectionStart = length;
39 window.addEventListener('message', onPostMessageReceived, false);
41 window.addEventListener('load', function(e) {
42 document.getElementById('testinput').addEventListener('keyup',
44 var response = 'caret-position-' + this.selectionStart;
45 notifyEmbedder([response, embedderTestName]);
52 <div>This is a guest that verifies edit commands are sent.</div>
53 <input id='testinput' type="text" value="test">