Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / extensions / test / data / web_view / display_none_set_src / main.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 var LOG = function(msg) {
6   window.console.log(msg);
7 };
8
9 var failTest = function() {
10   chrome.test.sendMessage('WebViewTest.FAILURE');
11 };
12
13 var waitingForLoadstop = false;
14
15 var startTest = function() {
16   var webview = document.createElement('webview');
17   webview.style.display = 'none';
18   document.body.appendChild(webview);
19
20   var onLoadstop = function(e) {
21     if (waitingForLoadstop) {
22       chrome.test.sendMessage('WebViewTest.PASSED');
23     }
24   };
25   webview.addEventListener('loadstop', onLoadstop);
26
27   chrome.test.sendMessage('LAUNCHED');
28 };
29
30 window.onAppCommand = function(command) {
31   LOG('onAppCommand: ' + command);
32   switch (command) {
33     case 'navigate-guest':
34       window.console.log('navigate-guest command');
35       document.querySelector('webview').src =
36           'data:text/html,<body>Guest</body>';
37       break;
38     case 'show-guest':
39       waitingForLoadstop = true;
40       document.querySelector('webview').style.display = '';
41       break;
42     case 'hide-guest':
43       document.querySelector('webview').style.display = 'none';
44       break;
45     default:
46       failTest();
47       break;
48   }
49 };
50
51 window.onload = startTest;