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

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

Issue 604443003: Adds more webview tests to app_shell_browsertests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « extensions/extensions.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 embedder = {}; 5 var embedder = {};
6 6
7 // TODO(lfg) Move these functions to a common js. 7 // TODO(lfg) Move these functions to a common js.
8 window.runTest = function(testName) { 8 window.runTest = function(testName) {
9 if (!embedder.test.testList[testName]) { 9 if (!embedder.test.testList[testName]) {
10 window.console.warn('Incorrect testName: ' + testName); 10 window.console.warn('Incorrect testName: ' + testName);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 chrome.test.sendMessage('TEST_FAILED'); 43 chrome.test.sendMessage('TEST_FAILED');
44 }; 44 };
45 45
46 embedder.test.succeed = function() { 46 embedder.test.succeed = function() {
47 chrome.test.sendMessage('TEST_PASSED'); 47 chrome.test.sendMessage('TEST_PASSED');
48 }; 48 };
49 49
50 50
51 // Tests begin. 51 // Tests begin.
52 52
53 // This test verifies that the allowtransparency property cannot be changed
54 // once set. The attribute can only be deleted.
55 function testAllowTransparencyAttribute() {
56 var webview = document.createElement('webview');
57 webview.src = 'data:text/html,webview test';
58 webview.allowtransparency = true;
59
60 webview.addEventListener('loadstop', function(e) {
61 embedder.test.assertTrue(webview.hasAttribute('allowtransparency'));
62 webview.allowtransparency = false;
63 embedder.test.assertTrue(webview.allowtransparency);
64 embedder.test.assertTrue(webview.hasAttribute('allowtransparency'));
65 webview.removeAttribute('allowtransparency');
66 embedder.test.assertFalse(webview.allowtransparency);
67 embedder.test.succeed();
68 });
69
70 document.body.appendChild(webview);
71 }
72
53 function testAPIMethodExistence() { 73 function testAPIMethodExistence() {
54 var apiMethodsToCheck = [ 74 var apiMethodsToCheck = [
55 'back', 75 'back',
56 'find', 76 'find',
57 'forward', 77 'forward',
58 'canGoBack', 78 'canGoBack',
59 'canGoForward', 79 'canGoForward',
60 'clearData', 80 'clearData',
61 'getProcessId', 81 'getProcessId',
62 'getZoom', 82 'getZoom',
(...skipping 21 matching lines...) Expand all
84 // Check contentWindow. 104 // Check contentWindow.
85 embedder.test.assertEq('object', typeof webview.contentWindow); 105 embedder.test.assertEq('object', typeof webview.contentWindow);
86 embedder.test.assertEq('function', 106 embedder.test.assertEq('function',
87 typeof webview.contentWindow.postMessage); 107 typeof webview.contentWindow.postMessage);
88 embedder.test.succeed(); 108 embedder.test.succeed();
89 }); 109 });
90 webview.setAttribute('src', 'data:text/html,webview check api'); 110 webview.setAttribute('src', 'data:text/html,webview check api');
91 document.body.appendChild(webview); 111 document.body.appendChild(webview);
92 } 112 }
93 113
114 // Makes sure 'sizechanged' event is fired only if autosize attribute is
115 // specified.
116 // After loading <webview> without autosize attribute and a size, say size1,
117 // we set autosize attribute and new min size with size2. We would get (only
118 // one) sizechanged event with size1 as old size and size2 as new size.
119 function testAutosizeAfterNavigation() {
120 var webview = document.createElement('webview');
121
122 var step = 1;
123 var sizeChangeHandler = function(e) {
124 switch (step) {
125 case 1:
126 // This would be triggered after we set autosize attribute.
127 embedder.test.assertEq(50, e.oldWidth);
128 embedder.test.assertEq(100, e.oldHeight);
129 embedder.test.assertTrue(e.newWidth >= 60 && e.newWidth <= 70);
130 embedder.test.assertTrue(e.newHeight >= 110 && e.newHeight <= 120);
131
132 // Remove autosize attribute and expect webview to return to its
133 // original size.
134 webview.removeAttribute('autosize');
135 break;
136 case 2:
137 // Expect 50x100.
138 embedder.test.assertEq(50, e.newWidth);
139 embedder.test.assertEq(100, e.newHeight);
140
141 embedder.test.succeed();
142 break;
143 default:
144 window.console.log('Unexpected sizechanged event, step = ' + step);
145 embedder.test.fail();
146 break;
147 }
148
149 ++step;
150 };
151
152 webview.addEventListener('sizechanged', sizeChangeHandler);
153
154 webview.addEventListener('loadstop', function(e) {
155 webview.setAttribute('autosize', true);
156 webview.setAttribute('minwidth', 60);
157 webview.setAttribute('maxwidth', 70);
158 webview.setAttribute('minheight', 110);
159 webview.setAttribute('maxheight', 120);
160 });
161
162 webview.style.width = '50px';
163 webview.style.height = '100px';
164 webview.setAttribute('src', 'data:text/html,webview test sizechanged event');
165 document.body.appendChild(webview);
166 }
167
168 // This test verifies that if a browser plugin is in autosize mode before
169 // navigation then the guest starts auto-sized.
170 function testAutosizeBeforeNavigation() {
171 var webview = document.createElement('webview');
172
173 webview.setAttribute('autosize', 'true');
174 webview.setAttribute('minwidth', 200);
175 webview.setAttribute('maxwidth', 210);
176 webview.setAttribute('minheight', 100);
177 webview.setAttribute('maxheight', 110);
178
179 webview.addEventListener('sizechanged', function(e) {
180 embedder.test.assertEq(0, e.oldWidth);
181 embedder.test.assertEq(0, e.oldHeight);
182 embedder.test.assertTrue(e.newWidth >= 200 && e.newWidth <= 210);
183 embedder.test.assertTrue(e.newHeight >= 100 && e.newHeight <= 110);
184 embedder.test.succeed();
185 });
186
187 webview.setAttribute('src', 'data:text/html,webview test sizechanged event');
188 document.body.appendChild(webview);
189 }
190
191 // This test verifies that a lengthy page with autosize enabled will report
192 // the correct height in the sizechanged event.
193 function testAutosizeHeight() {
194 var webview = document.createElement('webview');
195
196 webview.autosize = true;
197 webview.minwidth = 200;
198 webview.maxwidth = 210;
199 webview.minheight = 40;
200 webview.maxheight = 200;
201
202 var step = 1;
203 webview.addEventListener('sizechanged', function(e) {
204 switch (step) {
205 case 1:
206 embedder.test.assertEq(0, e.oldHeight);
207 embedder.test.assertEq(200, e.newHeight);
208 // Change the maxheight to verify that we see the change.
209 webview.maxheight = 50;
210 break;
211 case 2:
212 embedder.test.assertEq(200, e.oldHeight);
213 embedder.test.assertEq(50, e.newHeight);
214 embedder.test.succeed();
215 break;
216 default:
217 window.console.log('Unexpected sizechanged event, step = ' + step);
218 embedder.test.fail();
219 break;
220 }
221 ++step;
222 });
223
224 webview.src = 'data:text/html,' +
225 'a<br/>b<br/>c<br/>d<br/>e<br/>f<br/>' +
226 'a<br/>b<br/>c<br/>d<br/>e<br/>f<br/>' +
227 'a<br/>b<br/>c<br/>d<br/>e<br/>f<br/>' +
228 'a<br/>b<br/>c<br/>d<br/>e<br/>f<br/>' +
229 'a<br/>b<br/>c<br/>d<br/>e<br/>f<br/>';
230 document.body.appendChild(webview);
231 }
232
233 // This test verifies that all autosize attributes can be removed
234 // without crashing the plugin, or throwing errors.
235 function testAutosizeRemoveAttributes() {
236 var webview = document.createElement('webview');
237
238 var step = 1;
239 var sizeChangeHandler = function(e) {
240 switch (step) {
241 case 1:
242 // This is the sizechanged event for autosize.
243
244 // Remove attributes.
245 webview.removeAttribute('minwidth');
246 webview.removeAttribute('maxwidth');
247 webview.removeAttribute('minheight');
248 webview.removeAttribute('maxheight');
249 webview.removeAttribute('autosize');
250
251 // We'd get one more sizechanged event after we turn off
252 // autosize.
253 webview.style.width = '500px';
254 webview.style.height = '500px';
255 break;
256 case 2:
257 embedder.test.succeed();
258 break;
259 }
260
261 ++step;
262 };
263
264 webview.addEventListener('loadstop', function(e) {
265 webview.minwidth = 300;
266 webview.maxwidth = 700;
267 webview.minheight = 600;
268 webview.maxheight = 400;
269 webview.autosize = true;
270 });
271
272 webview.addEventListener('sizechanged', sizeChangeHandler);
273
274 webview.style.width = '640px';
275 webview.style.height = '480px';
276 webview.setAttribute('src', 'data:text/html,webview check autosize');
277 document.body.appendChild(webview);
278 }
279
280 // This test verifies that autosize works when some of the parameters are unset.
281 function testAutosizeWithPartialAttributes() {
282 window.console.log('testAutosizeWithPartialAttributes');
283 var webview = document.createElement('webview');
284
285 var step = 1;
286 var sizeChangeHandler = function(e) {
287 window.console.log('sizeChangeHandler, new: ' +
288 e.newWidth + ' X ' + e.newHeight);
289 switch (step) {
290 case 1:
291 // Expect 300x200.
292 embedder.test.assertEq(300, e.newWidth);
293 embedder.test.assertEq(200, e.newHeight);
294
295 // Change the min size to cause a relayout.
296 webview.minwidth = 500;
297 break;
298 case 2:
299 embedder.test.assertTrue(e.newWidth >= webview.minwidth);
300 embedder.test.assertTrue(e.newWidth <= webview.maxwidth);
301
302 // Tests when minwidth > maxwidth, minwidth = maxwidth.
303 // i.e. minwidth is essentially 700.
304 webview.minwidth = 800;
305 break;
306 case 3:
307 // Expect 700X?
308 embedder.test.assertEq(700, e.newWidth);
309 embedder.test.assertTrue(e.newHeight >= 200);
310 embedder.test.assertTrue(e.newHeight <= 600);
311
312 embedder.test.succeed();
313 break;
314 default:
315 window.console.log('Unexpected sizechanged event, step = ' + step);
316 embedder.test.fail();
317 break;
318 }
319
320 ++step;
321 };
322
323 webview.addEventListener('sizechanged', sizeChangeHandler);
324
325 webview.addEventListener('loadstop', function(e) {
326 webview.minwidth = 300;
327 webview.maxwidth = 700;
328 webview.minheight = 200;
329 webview.maxheight = 600;
330 webview.autosize = true;
331 });
332
333 webview.style.width = '640px';
334 webview.style.height = '480px';
335 webview.setAttribute('src', 'data:text/html,webview check autosize');
336 document.body.appendChild(webview);
337 }
338
339
340 // Tests end.
341
94 embedder.test.testList = { 342 embedder.test.testList = {
95 'testAPIMethodExistence': testAPIMethodExistence 343 'testAllowTransparencyAttribute': testAllowTransparencyAttribute,
344 'testAPIMethodExistence': testAPIMethodExistence,
345 'testAutosizeAfterNavigation': testAutosizeAfterNavigation,
346 'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation,
347 'testAutosizeHeight': testAutosizeHeight,
348 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes,
349 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes
96 }; 350 };
97 351
98 onload = function() { 352 onload = function() {
99 chrome.test.sendMessage('LAUNCHED'); 353 chrome.test.sendMessage('LAUNCHED');
100 }; 354 };
OLDNEW
« no previous file with comments | « extensions/extensions.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698