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

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

Issue 23691039: Reland attempt 2: Improve <webview> autosize: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Relax checking width/height since bunch of removeAttribute() and style.width assignments are not at… Created 7 years, 3 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
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 var embedder = {}; 6 var embedder = {};
7 embedder.baseGuestURL = ''; 7 embedder.baseGuestURL = '';
8 embedder.emptyGuestURL = ''; 8 embedder.emptyGuestURL = '';
9 embedder.windowOpenGuestURL = ''; 9 embedder.windowOpenGuestURL = '';
10 embedder.noReferrerGuestURL = ''; 10 embedder.noReferrerGuestURL = '';
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 document.body.appendChild(webview); 163 document.body.appendChild(webview);
164 } 164 }
165 165
166 // This test verifies that autosize works when some of the parameters are unset. 166 // This test verifies that autosize works when some of the parameters are unset.
167 function testAutosizeWithPartialAttributes() { 167 function testAutosizeWithPartialAttributes() {
168 window.console.log('testAutosizeWithPartialAttributes'); 168 window.console.log('testAutosizeWithPartialAttributes');
169 var webview = document.createElement('webview'); 169 var webview = document.createElement('webview');
170 170
171 var step = 1; 171 var step = 1;
172 var sizeChangeHandler = function(e) { 172 var sizeChangeHandler = function(e) {
173 window.console.log('sizeChangeHandler, new: ' +
174 e.newWidth + ' X ' + e.newHeight);
173 switch (step) { 175 switch (step) {
174 case 1: 176 case 1:
175 // Expect 300x200. 177 // Expect 300x200.
176 embedder.test.assertEq(300, e.newWidth); 178 embedder.test.assertEq(300, e.newWidth);
177 embedder.test.assertEq(200, e.newHeight); 179 embedder.test.assertEq(200, e.newHeight);
178 180
179 // Remove an autosize attribute and verify that it causes relayout. 181 // Change the min size to cause a relayout.
180 webview.minwidth = null; 182 webview.minwidth = 500;
181 break; 183 break;
182 case 2: 184 case 2:
183 // Expect 640x? 185 embedder.test.assertTrue(e.newWidth >= webview.minwidth);
184 embedder.test.assertEq(640, e.newWidth); 186 embedder.test.assertTrue(e.newWidth <= webview.maxwidth);
185 187
186 // Tests when minwidth > maxwidth, minwidth = maxwidth. 188 // Tests when minwidth > maxwidth, minwidth = maxwidth.
187 webview.maxheight = null; 189 // i.e. minwidth is essentially 700.
188 webview.minwidth = 800; 190 webview.minwidth = 800;
189 webview.minheight = 800;
190 break; 191 break;
191 case 3: 192 case 3:
192 // Expect 700X480 193 // Expect 700X?
193 embedder.test.assertEq(700, e.newWidth); 194 embedder.test.assertEq(700, e.newWidth);
194 embedder.test.assertEq(480, e.newHeight); 195 embedder.test.assertTrue(e.newHeight >= 200);
195 196 embedder.test.assertTrue(e.newHeight <= 600);
196 // Remove maxwidth and make sure the size returns to plugin size.
197 webview.removeAttribute('maxwidth');
198 break;
199 case 4:
200 // Expect original size, 640x480.
201 embedder.test.assertEq(640, e.newWidth);
202 embedder.test.assertEq(480, e.newHeight);
203 197
204 embedder.test.succeed(); 198 embedder.test.succeed();
205 break; 199 break;
206 default: 200 default:
207 window.console.log('Unexpected sizechanged event, step = ' + step); 201 window.console.log('Unexpected sizechanged event, step = ' + step);
208 embedder.test.fail(); 202 embedder.test.fail();
209 break; 203 break;
210 } 204 }
211 205
212 ++step; 206 ++step;
(...skipping 24 matching lines...) Expand all
237 var sizeChangeHandler = function(e) { 231 var sizeChangeHandler = function(e) {
238 switch (step) { 232 switch (step) {
239 case 1: 233 case 1:
240 // This is the sizechanged event for autosize. 234 // This is the sizechanged event for autosize.
241 235
242 // Remove attributes. 236 // Remove attributes.
243 webview.removeAttribute('minwidth'); 237 webview.removeAttribute('minwidth');
244 webview.removeAttribute('maxwidth'); 238 webview.removeAttribute('maxwidth');
245 webview.removeAttribute('minheight'); 239 webview.removeAttribute('minheight');
246 webview.removeAttribute('maxheight'); 240 webview.removeAttribute('maxheight');
241 webview.removeAttribute('autosize');
242
243 // We'd get one more sizechanged event after we turn off
244 // autosize.
245 webview.style.width = '500px';
246 webview.style.height = '500px';
247 break; 247 break;
248 case 2: 248 case 2:
249 // Expect plugin to return to its original size.
250 embedder.test.assertEq(640, e.newWidth);
251 embedder.test.assertEq(480, e.newHeight);
252
253 embedder.test.succeed(); 249 embedder.test.succeed();
254 break; 250 break;
255 default:
256 window.console.log('Unexpected sizechanged event, step = ' + step);
257 embedder.test.fail();
258 break;
259 } 251 }
260 252
261 ++step; 253 ++step;
262 }; 254 };
263 255
264 webview.addEventListener('loadstop', function(e) { 256 webview.addEventListener('loadstop', function(e) {
265 webview.minwidth = 300; 257 webview.minwidth = 300;
266 webview.maxwidth = 700; 258 webview.maxwidth = 700;
267 webview.minheight = 600; 259 webview.minheight = 600;
268 webview.maxheight = 400; 260 webview.maxheight = 400;
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation, 1033 'testRemoveWebviewAfterNavigation': testRemoveWebviewAfterNavigation,
1042 'testResizeWebviewResizesContent': testResizeWebviewResizesContent 1034 'testResizeWebviewResizesContent': testResizeWebviewResizesContent
1043 }; 1035 };
1044 1036
1045 onload = function() { 1037 onload = function() {
1046 chrome.test.getConfig(function(config) { 1038 chrome.test.getConfig(function(config) {
1047 embedder.setUp_(config); 1039 embedder.setUp_(config);
1048 chrome.test.sendMessage("Launched"); 1040 chrome.test.sendMessage("Launched");
1049 }); 1041 });
1050 }; 1042 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698