diff options
author | hanxi <hanxi@chromium.org> | 2014-10-11 03:59:54 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-11 11:00:13 +0000 |
commit | fcd89aea77ff46248d95e642977c759b121c4a3e (patch) | |
tree | 4c312e8efd9d5b6a0fc873601c2d2f43899efa36 /extensions/test | |
parent | 67387c7d05d70d6fcbce05f5db71e940cecffe84 (diff) | |
download | chromium_src-fcd89aea77ff46248d95e642977c759b121c4a3e.zip chromium_src-fcd89aea77ff46248d95e642977c759b121c4a3e.tar.gz chromium_src-fcd89aea77ff46248d95e642977c759b121c4a3e.tar.bz2 |
Adding more webview browser tests to app_shell_browsertests.
This CL includes the following tests:
- WebViewAPITest.AcceptTouchEvents
- WebViewAPITest.EmbedderVisibilityChanged
- WebViewAPITest.GuestVisibilityChanged
- WebViewAPITest.ReloadEmbedder
BUG=352293
Review URL: https://codereview.chromium.org/639693005
Cr-Commit-Position: refs/heads/master@{#299243}
Diffstat (limited to 'extensions/test')
10 files changed, 224 insertions, 0 deletions
diff --git a/extensions/test/data/web_view/accept_touch_events/guest.html b/extensions/test/data/web_view/accept_touch_events/guest.html new file mode 100644 index 0000000..1f170ff --- /dev/null +++ b/extensions/test/data/web_view/accept_touch_events/guest.html @@ -0,0 +1,15 @@ +<!doctype html> +<!-- + * Copyright 2014 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> +<html> +<head> + <script type="text/javascript" src="guest.js"></script> +</head> +<body> + Test guest. + <div id="touch-div"></div> +</body> +</html> diff --git a/extensions/test/data/web_view/accept_touch_events/guest.js b/extensions/test/data/web_view/accept_touch_events/guest.js new file mode 100644 index 0000000..bc3597e --- /dev/null +++ b/extensions/test/data/web_view/accept_touch_events/guest.js @@ -0,0 +1,51 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var LOG = function(msg) { + window.console.log(msg); +}; + +var touchDiv; +var embedder; + +function init() { + touchDiv = document.createElement('div'); + touchDiv.innerText = 'With touch'; + document.body.appendChild(touchDiv); +} + +function handler() {} + +function onAppCommand(command) { + LOG('onAppCommand, command = ' + command); + switch (command) { + case 'install-touch-handler': + touchDiv.addEventListener('touchstart', handler); + sendMessageToEmbedder('installed-touch-handler'); + break; + case 'uninstall-touch-handler': + touchDiv.removeEventListener('touchstart', handler); + sendMessageToEmbedder('uninstalled-touch-handler'); + break; + } +}; + +function sendMessageToEmbedder(message) { + if (!embedder) { + LOG('no embedder channel to send postMessage'); + return; + } + + embedder.postMessage(JSON.stringify([message]), '*'); +} + +window.addEventListener('message', function(e) { + embedder = e.source; + var data = JSON.parse(e.data); + if (data[0] == 'connect') { + sendMessageToEmbedder('connected'); + } +}); + +window.onload = init; diff --git a/extensions/test/data/web_view/accept_touch_events/main.html b/extensions/test/data/web_view/accept_touch_events/main.html new file mode 100644 index 0000000..d7227a6 --- /dev/null +++ b/extensions/test/data/web_view/accept_touch_events/main.html @@ -0,0 +1,12 @@ +<!doctype html> +<!-- + * Copyright 2014 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> +<html> +<body> + <div id="webview-tag-container"></div> + <script src="main.js"></script> +</body> +</html> diff --git a/extensions/test/data/web_view/accept_touch_events/main.js b/extensions/test/data/web_view/accept_touch_events/main.js new file mode 100644 index 0000000..a389b94 --- /dev/null +++ b/extensions/test/data/web_view/accept_touch_events/main.js @@ -0,0 +1,43 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var LOG = function(msg) { + window.console.log(msg); +}; + +var startTest = function() { + var webview = document.querySelector('webview'); + var onLoadStop = function(e) { + webview.contentWindow.postMessage(JSON.stringify(['connect']),'*'); + }; + + webview.addEventListener('loadstop', onLoadStop); + webview.addEventListener('consolemessage', function(e) { + LOG('g: ' + e.message); + }); + webview.partition = 'partition1'; + webview.src = 'guest.html'; +}; + +window.addEventListener('message', function(e) { + var data = JSON.parse(e.data); + LOG('data: ' + data); + switch (data[0]) { + case 'connected': + chrome.test.sendMessage('LAUNCHED'); + break; + case 'installed-touch-handler': + case 'uninstalled-touch-handler': + chrome.test.sendMessage(data[0]); + break; + } +}); + +chrome.test.getConfig(function(config) { + var guestURL = 'data:text/html,<html><body>foo</body></html>'; + document.querySelector('#webview-tag-container').innerHTML = + '<webview style="width: 10px; height: 10px; margin: 0; padding: 0;"' + + '></webview>'; + startTest(); +}); diff --git a/extensions/test/data/web_view/accept_touch_events/manifest.json b/extensions/test/data/web_view/accept_touch_events/manifest.json new file mode 100644 index 0000000..79c79df --- /dev/null +++ b/extensions/test/data/web_view/accept_touch_events/manifest.json @@ -0,0 +1,23 @@ +{ + "name": "<webview> touch handler registration test.", + "version": "1", + "permissions": [ + "webview" + ], + "app": { + "background": { + "scripts": ["test.js"] + } + }, + "webview": { + "partitions": [ + { + "name": "partition1", + "accessible_resources": [ + "guest.js", + "guest.html" + ] + } + ] + } +} diff --git a/extensions/test/data/web_view/accept_touch_events/test.js b/extensions/test/data/web_view/accept_touch_events/test.js new file mode 100644 index 0000000..a80d274 --- /dev/null +++ b/extensions/test/data/web_view/accept_touch_events/test.js @@ -0,0 +1,7 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +chrome.app.runtime.onLaunched.addListener(function() { + chrome.app.window.create('main.html', {}, function () {}); +}); diff --git a/extensions/test/data/web_view/visibility_changed/main.html b/extensions/test/data/web_view/visibility_changed/main.html new file mode 100644 index 0000000..d7227a6 --- /dev/null +++ b/extensions/test/data/web_view/visibility_changed/main.html @@ -0,0 +1,12 @@ +<!doctype html> +<!-- + * Copyright 2014 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> +<html> +<body> + <div id="webview-tag-container"></div> + <script src="main.js"></script> +</body> +</html> diff --git a/extensions/test/data/web_view/visibility_changed/main.js b/extensions/test/data/web_view/visibility_changed/main.js new file mode 100644 index 0000000..da02697 --- /dev/null +++ b/extensions/test/data/web_view/visibility_changed/main.js @@ -0,0 +1,42 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var LOG = function(msg) { + window.console.log(msg); +}; + +var failTest = function() { + chrome.test.sendMessage('WebViewTest.FAILURE'); +}; + +var startTest = function() { + document.querySelector('#webview-tag-container').innerHTML = + '<webview style="width: 10px; height: 10px; margin: 0; padding: 0;"' + + '></webview>'; + + var webview = document.querySelector('webview'); + var onLoadStop = function(e) { + chrome.test.sendMessage('LAUNCHED'); + }; + + webview.addEventListener('loadstop', onLoadStop); + webview.src = 'data:text/html,<body>Guest</body>'; +}; + +window.onAppCommand = function(command) { + LOG('onAppCommand: ' + command); + switch (command) { + case 'hide-guest': + document.querySelector('webview').style.display = 'none'; + break; + case 'hide-embedder': + document.body.style.display = 'none'; + break; + default: + failTest(); + break; + } +}; + +window.onload = startTest; diff --git a/extensions/test/data/web_view/visibility_changed/manifest.json b/extensions/test/data/web_view/visibility_changed/manifest.json new file mode 100644 index 0000000..585c11e --- /dev/null +++ b/extensions/test/data/web_view/visibility_changed/manifest.json @@ -0,0 +1,12 @@ +{ + "name": "<webview> visibility checking tests.", + "version": "1", + "permissions": [ + "webview" + ], + "app": { + "background": { + "scripts": ["test.js"] + } + } +} diff --git a/extensions/test/data/web_view/visibility_changed/test.js b/extensions/test/data/web_view/visibility_changed/test.js new file mode 100644 index 0000000..a80d274 --- /dev/null +++ b/extensions/test/data/web_view/visibility_changed/test.js @@ -0,0 +1,7 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +chrome.app.runtime.onLaunched.addListener(function() { + chrome.app.window.create('main.html', {}, function () {}); +}); |