OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 callbackPass = chrome.test.callbackPass; | 5 var callbackPass = chrome.test.callbackPass; |
6 var callbackFail = chrome.test.callbackFail; | 6 var callbackFail = chrome.test.callbackFail; |
7 var defaultFuzzFactor = 1; | 7 var defaultFuzzFactor = 1; |
8 | 8 |
9 function assertFuzzyEq(expected, actual, fuzzFactor, message) { | 9 function assertFuzzyEq(expected, actual, fuzzFactor, message) { |
10 if (!message) { | 10 if (!message) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 callback(win); | 42 callback(win); |
43 return; | 43 return; |
44 } | 44 } |
45 | 45 |
46 window.addEventListener('load', callbackPass(function() { | 46 window.addEventListener('load', callbackPass(function() { |
47 window.removeEventListener('load', arguments.callee); | 47 window.removeEventListener('load', arguments.callee); |
48 callback(win); | 48 callback(win); |
49 })); | 49 })); |
50 } | 50 } |
51 | 51 |
52 function assertConstraintsUnspecified(win) { | |
53 chrome.test.assertEq(null, win.innerBounds.minWidth); | |
54 chrome.test.assertEq(null, win.innerBounds.minHeight); | |
55 chrome.test.assertEq(null, win.innerBounds.maxWidth); | |
56 chrome.test.assertEq(null, win.innerBounds.maxHeight); | |
57 chrome.test.assertEq(null, win.outerBounds.minWidth); | |
58 chrome.test.assertEq(null, win.outerBounds.minHeight); | |
59 chrome.test.assertEq(null, win.outerBounds.maxWidth); | |
60 chrome.test.assertEq(null, win.outerBounds.maxHeight); | |
61 } | |
62 | |
63 function assertBoundsConsistent(win) { | |
64 chrome.test.assertTrue(win.innerBounds.left >= win.outerBounds.left); | |
65 chrome.test.assertTrue(win.innerBounds.top >= win.outerBounds.top); | |
66 chrome.test.assertTrue(win.innerBounds.width <= win.outerBounds.width); | |
67 chrome.test.assertTrue(win.innerBounds.height <= win.outerBounds.height); | |
68 | |
69 if (win.innerBounds.minWidth === null) | |
70 chrome.test.assertEq(null, win.outerBounds.minWidth); | |
71 else | |
72 chrome.test.assertTrue( | |
73 win.innerBounds.minWidth <= win.outerBounds.minWidth); | |
74 | |
75 if (win.innerBounds.minHeight === null) | |
76 chrome.test.assertEq(null, win.outerBounds.minHeight); | |
77 else | |
78 chrome.test.assertTrue( | |
79 win.innerBounds.minHeight <= win.outerBounds.minHeight); | |
80 | |
81 if (win.innerBounds.maxWidth === null) | |
82 chrome.test.assertEq(null, win.outerBounds.maxWidth); | |
83 else | |
84 chrome.test.assertTrue( | |
85 win.innerBounds.maxWidth <= win.outerBounds.maxWidth); | |
86 | |
87 if (win.innerBounds.maxHeight === null) | |
88 chrome.test.assertEq(null, win.outerBounds.maxHeight); | |
89 else | |
90 chrome.test.assertTrue( | |
91 win.innerBounds.maxHeight <= win.outerBounds.maxHeight); | |
92 } | |
93 | |
94 function testConflictingBoundsProperty(propertyName) { | |
95 var innerBounds = {}; | |
96 var outerBounds = {}; | |
97 innerBounds[propertyName] = 20; | |
98 outerBounds[propertyName] = 20; | |
99 chrome.app.window.create('test.html', { | |
100 innerBounds: innerBounds, | |
101 outerBounds: outerBounds | |
102 }, callbackFail('The ' + propertyName + ' property cannot be specified for ' + | |
103 'both inner and outer bounds.') | |
104 ); | |
105 } | |
106 | |
52 function testCreate() { | 107 function testCreate() { |
53 chrome.test.runTests([ | 108 chrome.test.runTests([ |
54 function basic() { | 109 function basic() { |
55 chrome.app.window.create('test.html', | 110 chrome.app.window.create('test.html', |
56 {id: 'testId'}, | 111 {id: 'testId'}, |
57 callbackPass(function(win) { | 112 callbackPass(function(win) { |
58 chrome.test.assertEq(typeof win.contentWindow.window, 'object'); | 113 chrome.test.assertEq(typeof win.contentWindow.window, 'object'); |
59 chrome.test.assertTrue( | 114 chrome.test.assertTrue( |
60 typeof win.contentWindow.document !== 'undefined'); | 115 typeof win.contentWindow.document !== 'undefined'); |
61 chrome.test.assertFalse( | 116 chrome.test.assertFalse( |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 }, callbackPass(function(win) { | 201 }, callbackPass(function(win) { |
147 var w = win.contentWindow; | 202 var w = win.contentWindow; |
148 assertFuzzyEq(400, w.innerWidth, defaultFuzzFactor); | 203 assertFuzzyEq(400, w.innerWidth, defaultFuzzFactor); |
149 assertFuzzyEq(450, w.innerHeight, defaultFuzzFactor); | 204 assertFuzzyEq(450, w.innerHeight, defaultFuzzFactor); |
150 w.close(); | 205 w.close(); |
151 })); | 206 })); |
152 } | 207 } |
153 ]); | 208 ]); |
154 } | 209 } |
155 | 210 |
211 function testInitialBounds() { | |
212 chrome.test.runTests([ | |
213 function testNoOptions() { | |
214 chrome.app.window.create('test.html', { | |
215 }, callbackPass(function(win) { | |
216 chrome.test.assertTrue(win != null); | |
217 chrome.test.assertTrue(win.innerBounds.width > 0); | |
218 chrome.test.assertTrue(win.innerBounds.height > 0); | |
219 chrome.test.assertTrue(win.outerBounds.width > 0); | |
220 chrome.test.assertTrue(win.outerBounds.height > 0); | |
221 assertConstraintsUnspecified(win); | |
222 assertBoundsConsistent(win); | |
223 win.close(); | |
224 })); | |
225 }, | |
226 function testInnerBoundsOnly() { | |
227 var innerBounds = { | |
228 left: 150, | |
229 top: 100, | |
230 width: 400, | |
231 height: 300 | |
232 }; | |
233 chrome.app.window.create('test.html', { | |
234 innerBounds: innerBounds | |
235 }, callbackPass(function(win) { | |
236 chrome.test.assertTrue(win != null); | |
237 chrome.test.assertEq(innerBounds.left, win.innerBounds.left); | |
238 chrome.test.assertEq(innerBounds.top, win.innerBounds.top); | |
239 chrome.test.assertEq(innerBounds.width, win.innerBounds.width); | |
240 chrome.test.assertEq(innerBounds.height, win.innerBounds.height); | |
241 assertBoundsConsistent(win); | |
242 assertConstraintsUnspecified(win); | |
243 win.close(); | |
244 })); | |
245 }, | |
246 function testOuterBoundsOnly() { | |
247 var outerBounds = { | |
248 left: 150, | |
249 top: 100, | |
250 width: 400, | |
251 height: 300 | |
252 }; | |
253 chrome.app.window.create('test.html', { | |
254 outerBounds: outerBounds | |
255 }, callbackPass(function(win) { | |
256 chrome.test.assertTrue(win != null); | |
257 chrome.test.assertEq(outerBounds.left, win.outerBounds.left); | |
258 chrome.test.assertEq(outerBounds.top, win.outerBounds.top); | |
259 chrome.test.assertEq(outerBounds.width, win.outerBounds.width); | |
260 chrome.test.assertEq(outerBounds.height, win.outerBounds.height); | |
261 assertBoundsConsistent(win); | |
262 assertConstraintsUnspecified(win); | |
263 win.close(); | |
264 })); | |
265 }, | |
266 function testFrameless() { | |
267 var outerBounds = { | |
268 left: 150, | |
269 top: 100, | |
270 width: 400, | |
271 height: 300 | |
272 }; | |
273 chrome.app.window.create('test.html', { | |
274 outerBounds: outerBounds, | |
275 frame: 'none' | |
276 }, callbackPass(function(win) { | |
277 chrome.test.assertTrue(win != null); | |
278 chrome.test.assertEq(outerBounds.left, win.outerBounds.left); | |
279 chrome.test.assertEq(outerBounds.top, win.outerBounds.top); | |
280 chrome.test.assertEq(outerBounds.width, win.outerBounds.width); | |
281 chrome.test.assertEq(outerBounds.height, win.outerBounds.height); | |
282 chrome.test.assertEq(outerBounds.left, win.innerBounds.left); | |
283 chrome.test.assertEq(outerBounds.top, win.innerBounds.top); | |
284 chrome.test.assertEq(outerBounds.width, win.innerBounds.width); | |
285 chrome.test.assertEq(outerBounds.height, win.innerBounds.height); | |
286 assertConstraintsUnspecified(win); | |
287 win.close(); | |
288 })); | |
289 }, | |
290 function testInnerSizeAndOuterPos() { | |
291 var innerBounds = { | |
292 width: 400, | |
293 height: 300 | |
294 }; | |
295 var outerBounds = { | |
296 left: 150, | |
297 top: 100 | |
298 }; | |
299 chrome.app.window.create('test.html', { | |
300 innerBounds: innerBounds, | |
301 outerBounds: outerBounds | |
302 }, callbackPass(function(win) { | |
303 chrome.test.assertTrue(win != null); | |
304 chrome.test.assertEq(outerBounds.left, win.outerBounds.left); | |
305 chrome.test.assertEq(outerBounds.top, win.outerBounds.top); | |
306 chrome.test.assertEq(innerBounds.width, win.innerBounds.width); | |
307 chrome.test.assertEq(innerBounds.height, win.innerBounds.height); | |
308 assertBoundsConsistent(win); | |
309 assertConstraintsUnspecified(win); | |
310 win.close(); | |
311 })); | |
312 }, | |
313 function testInnerAndOuterBoundsEdgeCase() { | |
314 var innerBounds = { | |
315 left: 150, | |
316 height: 300 | |
317 }; | |
318 var outerBounds = { | |
319 width: 400, | |
320 top: 100 | |
321 }; | |
322 chrome.app.window.create('test.html', { | |
323 innerBounds: innerBounds, | |
324 outerBounds: outerBounds | |
325 }, callbackPass(function(win) { | |
326 chrome.test.assertTrue(win != null); | |
327 chrome.test.assertEq(innerBounds.left, win.innerBounds.left); | |
328 chrome.test.assertEq(innerBounds.height, win.innerBounds.height); | |
329 chrome.test.assertEq(outerBounds.top, win.outerBounds.top); | |
330 chrome.test.assertEq(outerBounds.width, win.outerBounds.width); | |
331 assertBoundsConsistent(win); | |
332 assertConstraintsUnspecified(win); | |
333 win.close(); | |
334 })); | |
335 }, | |
336 function testPositionOnly() { | |
337 var outerBounds = { | |
338 left: 150, | |
339 top: 100 | |
340 }; | |
341 chrome.app.window.create('test.html', { | |
342 outerBounds: outerBounds | |
343 }, callbackPass(function(win) { | |
344 chrome.test.assertTrue(win != null); | |
345 chrome.test.assertEq(outerBounds.left, win.outerBounds.left); | |
346 chrome.test.assertEq(outerBounds.top, win.outerBounds.top); | |
347 chrome.test.assertTrue(win.innerBounds.width > 0); | |
348 chrome.test.assertTrue(win.innerBounds.height > 0); | |
349 chrome.test.assertTrue(win.outerBounds.width > 0); | |
350 chrome.test.assertTrue(win.outerBounds.height > 0); | |
351 assertBoundsConsistent(win); | |
352 assertConstraintsUnspecified(win); | |
353 win.close(); | |
354 })); | |
355 }, | |
356 function testSizeOnly() { | |
357 var outerBounds = { | |
358 width: 500, | |
359 height: 400 | |
360 }; | |
361 chrome.app.window.create('test.html', { | |
362 outerBounds: outerBounds | |
363 }, callbackPass(function(win) { | |
364 chrome.test.assertTrue(win != null); | |
365 chrome.test.assertEq(outerBounds.width, win.outerBounds.width); | |
366 chrome.test.assertEq(outerBounds.height, win.outerBounds.height); | |
367 assertBoundsConsistent(win); | |
368 assertConstraintsUnspecified(win); | |
369 win.close(); | |
370 })); | |
371 }, | |
372 function testConflictingProperties() { | |
373 testConflictingBoundsProperty("width"); | |
374 testConflictingBoundsProperty("height"); | |
375 testConflictingBoundsProperty("left"); | |
376 testConflictingBoundsProperty("top"); | |
377 testConflictingBoundsProperty("minWidth"); | |
378 testConflictingBoundsProperty("minHeight"); | |
379 testConflictingBoundsProperty("maxWidth"); | |
380 testConflictingBoundsProperty("maxHeight"); | |
381 } | |
382 ]); | |
383 } | |
384 | |
385 function testInitialBoundsInStable() { | |
386 chrome.test.runTests([ | |
387 function testInnerBounds() { | |
388 var innerBounds = { | |
389 width: 600, | |
390 height: 400 | |
391 }; | |
392 chrome.app.window.create('test.html', { | |
393 innerBounds: innerBounds | |
394 }, callbackFail('innerBounds and outerBounds are only available in'+ | |
395 ' dev channel.') | |
396 ); | |
397 }, | |
398 function testOuterBounds() { | |
399 var outerBounds = { | |
400 width: 600, | |
401 height: 400 | |
402 }; | |
403 chrome.app.window.create('test.html', { | |
404 outerBounds: outerBounds | |
405 }, callbackFail('innerBounds and outerBounds are only available in'+ | |
406 ' dev channel.') | |
407 ); | |
408 } | |
409 ]); | |
410 } | |
411 | |
412 function testInitialConstraints() { | |
413 chrome.test.runTests([ | |
414 function testMaxInnerConstraints() { | |
415 var innerBounds = { | |
416 width: 800, | |
417 height: 600, | |
418 maxWidth: 500, | |
419 maxHeight: 400 | |
420 }; | |
421 chrome.app.window.create('test.html', { | |
422 innerBounds: innerBounds | |
423 }, callbackPass(function(win) { | |
424 chrome.test.assertTrue(win != null); | |
425 chrome.test.assertEq(innerBounds.maxWidth, win.innerBounds.width); | |
426 chrome.test.assertEq(innerBounds.maxHeight, win.innerBounds.height); | |
427 chrome.test.assertEq(innerBounds.maxWidth, win.innerBounds.maxWidth); | |
428 chrome.test.assertEq(innerBounds.maxHeight, win.innerBounds.maxHeight); | |
429 assertBoundsConsistent(win); | |
430 win.close(); | |
431 })); | |
432 }, | |
433 function testMinInnerConstraints() { | |
434 var innerBounds = { | |
435 width: 100, | |
436 height: 100, | |
437 minWidth: 300, | |
438 minHeight: 200 | |
439 }; | |
440 chrome.app.window.create('test.html', { | |
441 innerBounds: innerBounds | |
442 }, callbackPass(function(win) { | |
443 chrome.test.assertTrue(win != null); | |
444 chrome.test.assertEq(innerBounds.minWidth, win.innerBounds.width); | |
445 chrome.test.assertEq(innerBounds.minHeight, win.innerBounds.height); | |
446 chrome.test.assertEq(innerBounds.minWidth, win.innerBounds.minWidth); | |
447 chrome.test.assertEq(innerBounds.minHeight, win.innerBounds.minHeight); | |
448 assertBoundsConsistent(win); | |
449 win.close(); | |
450 })); | |
451 }, | |
452 function testMaxOuterConstraints() { | |
453 var outerBounds = { | |
454 width: 800, | |
455 height: 600, | |
456 maxWidth: 500, | |
457 maxHeight: 400 | |
458 }; | |
459 chrome.app.window.create('test.html', { | |
460 outerBounds: outerBounds | |
461 }, callbackPass(function(win) { | |
462 chrome.test.assertTrue(win != null); | |
463 chrome.test.assertEq(outerBounds.maxWidth, win.outerBounds.width); | |
464 chrome.test.assertEq(outerBounds.maxHeight, win.outerBounds.height); | |
465 chrome.test.assertEq(outerBounds.maxWidth, win.outerBounds.maxWidth); | |
466 chrome.test.assertEq(outerBounds.maxHeight, win.outerBounds.maxHeight); | |
467 assertBoundsConsistent(win); | |
468 win.close(); | |
469 })); | |
470 }, | |
471 function testMinOuterConstraints() { | |
472 var outerBounds = { | |
473 width: 100, | |
474 height: 100, | |
475 minWidth: 300, | |
476 minHeight: 200 | |
477 }; | |
478 chrome.app.window.create('test.html', { | |
479 outerBounds: outerBounds | |
480 }, callbackPass(function(win) { | |
481 chrome.test.assertTrue(win != null); | |
482 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.width); | |
483 chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.height); | |
484 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.minWidth); | |
485 chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.minHeight); | |
486 assertBoundsConsistent(win); | |
487 win.close(); | |
488 })); | |
489 }, | |
490 function testMixedConstraints() { | |
491 var innerBounds = { | |
492 width: 100, | |
493 minHeight: 300 | |
494 }; | |
495 var outerBounds = { | |
496 height: 100, | |
497 minWidth: 400, | |
498 }; | |
499 chrome.app.window.create('test.html', { | |
500 innerBounds: innerBounds, | |
501 outerBounds: outerBounds | |
502 }, callbackPass(function(win) { | |
503 chrome.test.assertTrue(win != null); | |
504 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.width); | |
505 chrome.test.assertEq(innerBounds.minHeight, win.innerBounds.height); | |
506 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.minWidth); | |
507 chrome.test.assertEq(innerBounds.minHeight, win.innerBounds.minHeight); | |
508 assertBoundsConsistent(win); | |
509 win.close(); | |
510 })); | |
511 }, | |
512 function testBadConstraints() { | |
513 var outerBounds = { | |
514 width: 500, | |
515 height: 400, | |
516 minWidth: 800, | |
517 minHeight: 700, | |
518 maxWidth: 300, | |
519 maxHeight: 200 | |
520 }; | |
521 chrome.app.window.create('test.html', { | |
522 outerBounds: outerBounds | |
523 }, callbackPass(function(win) { | |
524 chrome.test.assertTrue(win != null); | |
525 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.width); | |
526 chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.height); | |
527 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.minWidth); | |
528 chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.minHeight); | |
529 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.maxWidth); | |
530 chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.maxHeight); | |
531 assertBoundsConsistent(win); | |
532 win.close(); | |
533 })); | |
534 }, | |
535 ]); | |
536 } | |
537 | |
benwells
2014/03/05 02:33:30
These tests are awesome, hopefully they won't suff
| |
156 function testSingleton() { | 538 function testSingleton() { |
157 chrome.test.runTests([ | 539 chrome.test.runTests([ |
158 function noParameterWithId() { | 540 function noParameterWithId() { |
159 chrome.app.window.create( | 541 chrome.app.window.create( |
160 'test.html', { id: 'singleton-id' }, | 542 'test.html', { id: 'singleton-id' }, |
161 callbackPass(function(win) { | 543 callbackPass(function(win) { |
162 var w = win.contentWindow; | 544 var w = win.contentWindow; |
163 | 545 |
164 chrome.app.window.create( | 546 chrome.app.window.create( |
165 'test.html', { id: 'singleton-id' }, | 547 'test.html', { id: 'singleton-id' }, |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 callbackFail('frameOptions is only available in dev channel.')); | 1051 callbackFail('frameOptions is only available in dev channel.')); |
670 } | 1052 } |
671 ]); | 1053 ]); |
672 } | 1054 } |
673 | 1055 |
674 chrome.app.runtime.onLaunched.addListener(function() { | 1056 chrome.app.runtime.onLaunched.addListener(function() { |
675 chrome.test.sendMessage('Launched', function(reply) { | 1057 chrome.test.sendMessage('Launched', function(reply) { |
676 window[reply](); | 1058 window[reply](); |
677 }); | 1059 }); |
678 }); | 1060 }); |
OLD | NEW |