| Index: chrome/test/data/extensions/platform_apps/web_view/shim/main.js
|
| diff --git a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
|
| index 31d1c37ffd0a7bf020f2b00eb9c6700df50f7e15..71d3c9fa4a9252dee3c9ceb7f62fca66701e413f 100644
|
| --- a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
|
| +++ b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
|
| @@ -749,6 +749,177 @@ function testPartitionRemovalAfterNavigationFails() {
|
| webview.setAttribute('src', 'data:text/html,<html><body>guest</body></html>');
|
| }
|
|
|
| +function testAddContentScript() {
|
| + var webview = document.createElement('webview');
|
| +
|
| + console.log("Step 1: call <webview>.addContentScripts.");
|
| + webview.addContentScripts(
|
| + [{"name": 'myrule',
|
| + "matches": ["http://*/extensions/*"],
|
| + "js": ["inject_comm_channel.js"],
|
| + "run_at": "document_start"}]);
|
| +
|
| + webview.addEventListener('loadstop', function() {
|
| + var msg = ['connect'];
|
| + webview.contentWindow.postMessage(JSON.stringify(msg), '*');
|
| + });
|
| +
|
| + window.addEventListener('message', function(e) {
|
| + var data = JSON.parse(e.data);
|
| + if (data == 'connected') {
|
| + console.log(
|
| + 'Step 2: A communication channel has been established with webview.');
|
| + embedder.test.succeed();
|
| + return;
|
| + }
|
| + console.log('Unexpected message: \'' + data[0] + '\'');
|
| + embedder.test.fail();
|
| + });
|
| +
|
| + webview.src = embedder.emptyGuestURL;
|
| + document.body.appendChild(webview);
|
| +}
|
| +
|
| +function testAddMultiContentScripts() {
|
| + var webview = document.createElement('webview');
|
| +
|
| + console.log("Step 1: call <webview>.addContentScripts(myrule1 & myrule2)");
|
| + webview.addContentScripts(
|
| + [{"name": 'myrule1',
|
| + "matches": ["http://*/extensions/*"],
|
| + "js": ["inject_comm_channel.js"],
|
| + "run_at": "document_start"},
|
| + {"name": 'myrule2',
|
| + "matches": ["http://*/extensions/*"],
|
| + "js": ["inject_comm_channel_2.js"],
|
| + "run_at": "document_start"}]);
|
| +
|
| + webview.addEventListener('loadstop', function() {
|
| + var msg1 = ['connect'];
|
| + webview.contentWindow.postMessage(JSON.stringify(msg1), '*');
|
| + var msg2 = ['connect_request'];
|
| + webview.contentWindow.postMessage(JSON.stringify(msg2), '*');
|
| + });
|
| +
|
| + var response_1 = false;
|
| + var response_2 = false;
|
| + window.addEventListener('message', function(e) {
|
| + var data = JSON.parse(e.data);
|
| + if (data == 'connected') {
|
| + console.log(
|
| + 'Step 2: A communication channel has been established with webview.');
|
| + response_1 = true;
|
| + if (response_1 && response_2)
|
| + embedder.test.succeed();
|
| + return;
|
| + } else if (data == 'connected_response') {
|
| + console.log(
|
| + 'Step 3: A communication channel has been established with webview.');
|
| + response_2 = true;
|
| + if (response_1 && response_2)
|
| + embedder.test.succeed();
|
| + return;
|
| + }
|
| + console.log('Unexpected message: \'' + data[0] + '\'');
|
| + embedder.test.fail();
|
| + });
|
| +
|
| + webview.src = embedder.emptyGuestURL;
|
| + document.body.appendChild(webview);
|
| +}
|
| +
|
| +function testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView() {
|
| + var webview1 = document.createElement('webview');
|
| + var webview2 = document.createElement('webview');
|
| +
|
| + console.log("Step 1: call <webview1>.addContentScripts.");
|
| + webview1.addContentScripts(
|
| + [{"name": 'myrule',
|
| + "matches": ["http://*/extensions/*"],
|
| + "js": ["inject_comm_channel.js"],
|
| + "run_at": "document_start"}]);
|
| +
|
| + webview2.addEventListener('loadstop', function() {
|
| + console.log("Step 2: webview2 requests to build communication channel.");
|
| + var msg = ['connect'];
|
| + webview2.contentWindow.postMessage(JSON.stringify(msg), '*');
|
| + setTimeout(function() {
|
| + embedder.test.succeed();
|
| + }, 2000);
|
| + });
|
| +
|
| + window.addEventListener('message', function(e) {
|
| + var data = JSON.parse(e.data);
|
| + if (data == 'connected') {
|
| + embedder.test.fail();
|
| + return;
|
| + }
|
| + console.log('Unexpected message: \'' + data[0] + '\'');
|
| + embedder.test.fail();
|
| + });
|
| +
|
| + webview1.src = embedder.emptyGuestURL;
|
| + webview2.src = embedder.emptyGuestURL;
|
| + document.body.appendChild(webview1);
|
| + document.body.appendChild(webview2);
|
| +}
|
| +
|
| +function testAddAndRemoveContentScripts() {
|
| + var webview = document.createElement('webview');
|
| +
|
| + console.log("Step 1: call <webview>.addContentScripts.");
|
| + webview.addContentScripts(
|
| + [{"name": 'myrule',
|
| + "matches": ["http://*/extensions/*"],
|
| + "js": ["inject_comm_channel.js"],
|
| + "run_at": "document_start"}]);
|
| +
|
| + var count = 0;
|
| + webview.addEventListener('loadstop', function() {
|
| + if (count == 0) {
|
| + console.log('Step 2: post message to build connect.');
|
| + var msg = ['connect'];
|
| + webview.contentWindow.postMessage(JSON.stringify(msg), '*');
|
| + count++;
|
| + } else if (count == 1) {
|
| + console.log(
|
| + 'Step 4: call <webview>.removeContentScripts and navigate.');
|
| + webview.removeContentScripts();
|
| + webview.src = embedder.emptyGuestURL;
|
| + count++;
|
| + } else if (count == 2) {
|
| + console.log('Step 5: post message to build connect again.');
|
| + var msg = ['connect'];
|
| + webview.contentWindow.postMessage(JSON.stringify(msg), '*');
|
| + setTimeout(function() {
|
| + embedder.test.succeed();
|
| + }, 2000);
|
| + }
|
| + });
|
| +
|
| + var replyCount = 0;
|
| + window.addEventListener('message', function(e) {
|
| + var data = JSON.parse(e.data);
|
| + if (data[0] == 'connected') {
|
| + console.log(
|
| + 'Step 3: A communication channel has been established with webview.');
|
| + if (replyCount == 0) {
|
| + webview.setAttribute('src', 'about:blank');
|
| + replyCount++;
|
| + return;
|
| + } else if (replyCount == 1) {
|
| + embedder.test.fail();
|
| + return;
|
| + }
|
| + }
|
| + console.log('Unexpected message: \'' + data[0] + '\'');
|
| + embedder.test.fail();
|
| + });
|
| +
|
| + webview.src = embedder.emptyGuestURL;
|
| + document.body.appendChild(webview);
|
| +}
|
| +
|
| function testExecuteScriptFail() {
|
| var webview = document.createElement('webview');
|
| document.body.appendChild(webview);
|
| @@ -2128,6 +2299,11 @@ embedder.test.testList = {
|
| 'testPartitionChangeAfterNavigation': testPartitionChangeAfterNavigation,
|
| 'testPartitionRemovalAfterNavigationFails':
|
| testPartitionRemovalAfterNavigationFails,
|
| + 'testAddContentScript': testAddContentScript,
|
| + 'testAddMultiContentScripts': testAddMultiContentScripts,
|
| + 'testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView':
|
| + testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView,
|
| + 'testAddAndRemoveContentScripts': testAddAndRemoveContentScripts,
|
| 'testExecuteScriptFail': testExecuteScriptFail,
|
| 'testExecuteScript': testExecuteScript,
|
| 'testExecuteScriptIsAbortedWhenWebViewSourceIsChanged':
|
|
|