Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: chrome/test/data/extensions/platform_apps/web_view/main.js

Issue 12326168: Move <webview> API to chrome layer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var util = {}; 5 var util = {};
6 6
7 // Creates a <webview> tag in document.body and returns the reference to it. 7 // Creates a <webview> tag in document.body and returns the reference to it.
8 // It also sets a dummy src. The dummy src is significant because this makes 8 // It also sets a dummy src. The dummy src is significant because this makes
9 // sure that the <object> shim is created (asynchronously at this point) for the 9 // sure that the <object> shim is created (asynchronously at this point) for the
10 // <webview> tag. This makes the <webview> tag ready for add/removeEventListener 10 // <webview> tag. This makes the <webview> tag ready for add/removeEventListener
11 // calls. 11 // calls.
12 util.createWebViewTagInDOM = function(partitionName) { 12 util.createWebViewTagInDOM = function() {
13 var webview = document.createElement('webview'); 13 var webview = document.createElement('webview');
14 webview.style.width = '300px'; 14 webview.style.width = '300px';
15 webview.style.height = '200px'; 15 webview.style.height = '200px';
16 document.body.appendChild(webview);
16 var urlDummy = 'data:text/html,<body>Initial dummy guest</body>'; 17 var urlDummy = 'data:text/html,<body>Initial dummy guest</body>';
17 webview.setAttribute('src', urlDummy); 18 webview.setAttribute('src', urlDummy);
18 webview.setAttribute('partition', partitionName);
19 document.body.appendChild(webview);
20 return webview; 19 return webview;
21 }; 20 };
22 21
23 onload = function() { 22 onload = function() {
24 chrome.test.runTests([ 23 chrome.test.runTests([
25 function webView() { 24 function webView() {
26 var webview = document.querySelector('webview'); 25 var webview = document.querySelector('webview');
27 // Since we can't currently inspect the page loaded inside the <webview>, 26 // Since we can't currently inspect the page loaded inside the <webview>,
28 // the only way we can check that the shim is working is by changing the 27 // the only way we can check that the shim is working is by changing the
29 // size and seeing if the shim updates the size of the DOM. 28 // size and seeing if the shim updates the size of the DOM.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 'canGoBack', 62 'canGoBack',
64 'canGoForward', 63 'canGoForward',
65 'forward', 64 'forward',
66 'getProcessId', 65 'getProcessId',
67 'go', 66 'go',
68 'reload', 67 'reload',
69 'stop', 68 'stop',
70 'terminate' 69 'terminate'
71 ]; 70 ];
72 var webview = document.createElement('webview'); 71 var webview = document.createElement('webview');
73 webview.setAttribute('partition', arguments.callee.name);
74 webview.addEventListener('loadstop', function(e) { 72 webview.addEventListener('loadstop', function(e) {
75 for (var i = 0; i < apiMethodsToCheck.length; ++i) { 73 for (var i = 0; i < apiMethodsToCheck.length; ++i) {
76 chrome.test.assertEq('function', 74 chrome.test.assertEq('function',
77 typeof webview[apiMethodsToCheck[i]]); 75 typeof webview[apiMethodsToCheck[i]]);
78 } 76 }
79 77
80 // Check contentWindow. 78 // Check contentWindow.
81 chrome.test.assertEq('object', typeof webview.contentWindow); 79 chrome.test.assertEq('object', typeof webview.contentWindow);
82 chrome.test.assertEq('function', 80 chrome.test.assertEq('function',
83 typeof webview.contentWindow.postMessage); 81 typeof webview.contentWindow.postMessage);
82
84 chrome.test.succeed(); 83 chrome.test.succeed();
85 }); 84 });
86 webview.setAttribute('src', 'data:text/html,webview check api'); 85 webview.setAttribute('src', 'data:text/html,webview check api');
87 document.body.appendChild(webview); 86 document.body.appendChild(webview);
88 }, 87 },
89 88
90 function webViewEventName() { 89 function webViewEventName() {
91 var webview = document.createElement('webview'); 90 var webview = document.createElement('webview');
92 webview.setAttribute('partition', arguments.callee.name); 91 webview.setAttribute('src', 'data:text/html,webview check api');
92 document.body.appendChild(webview);
93 93
94 webview.addEventListener('loadstart', function(evt) { 94 webview.addEventListener('loadstart', function(evt) {
95 chrome.test.assertEq('loadstart', evt.type); 95 chrome.test.assertEq('loadstart', evt.type);
96 }); 96 });
97 97
98 webview.addEventListener('loadstop', function(evt) { 98 webview.addEventListener('loadstop', function(evt) {
99 chrome.test.assertEq('loadstop', evt.type); 99 chrome.test.assertEq('loadstop', evt.type);
100 webview.terminate(); 100 webview.terminate();
101 }); 101 });
102 102
103 webview.addEventListener('exit', function(evt) { 103 webview.addEventListener('exit', function(evt) {
104 chrome.test.assertEq('exit', evt.type); 104 chrome.test.assertEq('exit', evt.type);
105 chrome.test.succeed(); 105 chrome.test.succeed();
106 }); 106 });
107 107
108 webview.setAttribute('src', 'data:text/html,trigger navigation'); 108 webview.setAttribute('src', 'data:text/html,trigger navigation');
109 document.body.appendChild(webview);
110 }, 109 },
111 110
112 // This test registers two listeners on an event (loadcommit) and removes 111 // This test registers two listeners on an event (loadcommit) and removes
113 // the <webview> tag when the first listener fires. 112 // the <webview> tag when the first listener fires.
114 // Current expected behavior is that the second event listener will still 113 // Current expected behavior is that the second event listener will still
115 // fire without crashing. 114 // fire without crashing.
116 function webviewDestroyOnEventListener() { 115 function webviewDestroyOnEventListener() {
117 var webview = util.createWebViewTagInDOM(arguments.callee.name); 116 var webview = util.createWebViewTagInDOM();
118 var url = 'data:text/html,<body>Destroy test</body>'; 117 var url = 'data:text/html,<body>Destroy test</body>';
119 118
120 var loadCommitCount = 0; 119 var loadCommitCount = 0;
121 function loadCommitCommon(e) { 120 function loadCommitCommon(e) {
122 chrome.test.assertEq('loadcommit', e.type); 121 chrome.test.assertEq('loadcommit', e.type);
123 if (url != e.url) 122 if (url != e.url)
124 return; 123 return;
125 ++loadCommitCount; 124 ++loadCommitCount;
126 if (loadCommitCount == 1) { 125 if (loadCommitCount == 1) {
126 webview.parentNode.removeChild(webview);
127 webview = null;
127 setTimeout(function() { 128 setTimeout(function() {
128 chrome.test.succeed(); 129 chrome.test.succeed();
129 }, 0); 130 }, 0);
130 } else if (loadCommitCount > 2) { 131 } else if (loadCommitCount > 2) {
131 chrome.test.fail(); 132 chrome.test.fail();
132 } 133 }
133 }; 134 };
134 135
135 // The test starts from here, by setting the src to |url|. 136 // The test starts from here, by setting the src to |url|.
136 webview.addEventListener('loadcommit', function(e) { 137 webview.addEventListener('loadcommit', function(e) {
137 webview.parentNode.removeChild(webview);
138 loadCommitCommon(e); 138 loadCommitCommon(e);
139 }); 139 });
140 webview.addEventListener('loadcommit', function(e) { 140 webview.addEventListener('loadcommit', function(e) {
141 loadCommitCommon(e); 141 loadCommitCommon(e);
142 }); 142 });
143 webview.setAttribute('src', url); 143 webview.setAttribute('src', url);
144 }, 144 },
145 145
146 // This test registers two event listeners on a same event (loadcommit). 146 // This test registers two event listeners on a same event (loadcommit).
147 // Each of the listener tries to change some properties on the event param, 147 // Each of the listener tries to change some properties on the event param,
148 // which should not be possible. 148 // which should not be possible.
149 function cannotMutateEventName() { 149 function cannotMutateEventName() {
150 var webview = util.createWebViewTagInDOM(arguments.callee.name); 150 var webview = util.createWebViewTagInDOM();
151 var url = 'data:text/html,<body>Two</body>'; 151 var url = 'data:text/html,<body>Two</body>';
152 152
153 var loadCommitACalled = false; 153 var loadCommitACalled = false;
154 var loadCommitBCalled = false; 154 var loadCommitBCalled = false;
155 155
156 var maybeFinishTest = function(e) { 156 var maybeFinishTest = function(e) {
157 if (loadCommitACalled && loadCommitBCalled) { 157 if (loadCommitACalled && loadCommitBCalled) {
158 chrome.test.assertEq('loadcommit', e.type); 158 chrome.test.assertEq('loadcommit', e.type);
159 chrome.test.succeed(); 159 chrome.test.succeed();
160 } 160 }
(...skipping 27 matching lines...) Expand all
188 // on the <webview> tag. 188 // on the <webview> tag.
189 webview.addEventListener('loadcommit', onLoadCommitA); 189 webview.addEventListener('loadcommit', onLoadCommitA);
190 webview.addEventListener('loadcommit', onLoadCommitB); 190 webview.addEventListener('loadcommit', onLoadCommitB);
191 webview.setAttribute('src', url); 191 webview.setAttribute('src', url);
192 }, 192 },
193 193
194 // This test verifies that setting the partition attribute after the src has 194 // This test verifies that setting the partition attribute after the src has
195 // been set raises an exception. 195 // been set raises an exception.
196 function partitionRaisesException() { 196 function partitionRaisesException() {
197 var webview = document.createElement('webview'); 197 var webview = document.createElement('webview');
198 webview.setAttribute('partition', arguments.callee.name);
199 webview.setAttribute('src', 'data:text/html,trigger navigation'); 198 webview.setAttribute('src', 'data:text/html,trigger navigation');
200 document.body.appendChild(webview); 199 document.body.appendChild(webview);
201 setTimeout(function() { 200 setTimeout(function() {
202 try { 201 try {
203 webview.partition = 'illegal'; 202 webview.partition = 'illegal';
204 chrome.test.fail(); 203 chrome.test.fail();
205 } catch (e) { 204 } catch (e) {
206 chrome.test.succeed(); 205 chrome.test.succeed();
207 } 206 }
208 }, 0); 207 }, 0);
209 }, 208 },
210 209
210 // This test verifies that executeScript is able to inject script into a
211 // guest and receives a response.
211 function webViewExecuteScript() { 212 function webViewExecuteScript() {
212 var webview = document.createElement('webview'); 213 var webview = document.createElement('webview');
213 webview.setAttribute('partition', arguments.callee.name); 214 webview.addEventListener('loadstop', function(e) {
214 webview.addEventListener('loadstop', function() {
215 webview.executeScript( 215 webview.executeScript(
216 {code:'document.body.style.backgroundColor = "red";'}, 216 {code:"document.body.offsetWidth"},
217 function(results) { 217 function(result) {
218 chrome.test.assertEq(1, results.length); 218 console.log(result);
219 chrome.test.assertEq('red', results[0]); 219 //chrome.test.assertEq('red', result);
220 chrome.test.succeed(); 220 chrome.test.succeed();
221 }); 221 });
222 }); 222 });
223 webview.setAttribute('src', 'data:text/html,trigger navigation'); 223 var urlDummy = 'data:text/html,<body>Initial dummy guest</body>';
224 webview.setAttribute('src', urlDummy);
224 document.body.appendChild(webview); 225 document.body.appendChild(webview);
225 },
226
227 // This test calls terminate() on guest after it has already been
228 // terminated. This makes sure we ignore the call gracefully.
229 function webViewTerminateAfterExitDoesntCrash() {
230 var webview = document.createElement('webview');
231 webview.setAttribute('partition', arguments.callee.name);
232 var loadstopSucceedsTest = false;
233 webview.addEventListener('loadstop', function(evt) {
234 chrome.test.assertEq('loadstop', evt.type);
235 if (loadstopSucceedsTest) {
236 chrome.test.succeed();
237 return;
238 }
239
240 webview.terminate();
241 });
242
243 webview.addEventListener('exit', function(evt) {
244 chrome.test.assertEq('exit', evt.type);
245 // Call terminate again.
246 webview.terminate();
247 // Load another page. The test would pass when loadstop is called on
248 // this second page. This would hopefully catch if call to
249 // webview.terminate() caused a browser crash.
250 setTimeout(function() {
251 loadstopSucceedsTest = true;
252 webview.setAttribute('src', 'data:text/html,test second page');
253 }, 0);
254 });
255
256 webview.setAttribute('src', 'data:text/html,test terminate() crash.');
257 document.body.appendChild(webview);
258 },
259
260 // This test verifies that assigning the src attribute the same value it had
261 // prior to a crash spawns off a new guest process.
262 function webViewAssignSrcAfterCrash() {
263 var webview = document.createElement('webview');
264 webview.setAttribute('partition', arguments.callee.name);
265 var terminated = false;
266 webview.addEventListener('loadstop', function(evt) {
267 if (!terminated) {
268 webview.terminate();
269 return;
270 }
271 // The guest has recovered after being terminated.
272 chrome.test.succeed();
273 });
274 webview.addEventListener('exit', function(evt) {
275 terminated = true;
276 webview.setAttribute('src', 'data:text/html,test page');
277 });
278 webview.setAttribute('src', 'data:text/html,test page');
279 document.body.appendChild(webview);
280 },
281
282 // This test verifies that <webview> restores the src attribute if it is
283 // removed after navigation.
284 function webViewRemoveSrcAttribute() {
285 var dataUrl = 'data:text/html,test page';
286 var webview = document.createElement('webview');
287 webview.setAttribute('partition', arguments.callee.name);
288 var terminated = false;
289 webview.addEventListener('loadstop', function(evt) {
290 webview.removeAttribute('src');
291 setTimeout(function() {
292 chrome.test.assertEq(dataUrl, webview.getAttribute('src'));
293 chrome.test.succeed();
294 }, 0);
295 });
296 webview.setAttribute('src', dataUrl);
297 document.body.appendChild(webview);
298 },
299
300 function browserPluginObjectInstantiationIsNotAllowed() {
301 var container = document.getElementById('object-container');
302 if (!container) {
303 chrome.test.fail('Container for object not found.');
304 return;
305 }
306 container.innerHTML = '<object type="application/browser-plugin"' +
307 ' id="object-plugin"' +
308 ' src="data:text/html,<body>You should not see this</body>">' +
309 '</object>';
310 var objectElement = document.getElementById('object-plugin');
311 // Check that bindings are not registered.
312 chrome.test.assertTrue(objectElement.canGoBack === undefined);
313 chrome.test.succeed();
314 } 226 }
315 ]); 227 ]);
316 }; 228 };
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/web_view.js ('k') | content/browser/browser_plugin/browser_plugin_guest_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698