Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / data / extensions / platform_apps / window_api / test.js
blob1092bbdbec15df7811b8dcff7d258da2439fc644
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
3 // found in the LICENSE file.
5 var callbackPass = chrome.test.callbackPass;
6 var callbackFail = chrome.test.callbackFail;
7 var defaultFuzzFactor = 1;
9 function assertFuzzyEq(expected, actual, fuzzFactor, message) {
10   if (!message) {
11     message = "Expected: " + expected + "; actual: " + actual + "; "
12                + "fuzzyFactor: " + fuzzFactor;
13   }
15   chrome.test.assertTrue(actual - fuzzFactor <= expected
16                          && actual + fuzzFactor >= expected, message);
18   if (actual != expected) {
19     console.log("FUZZ: a factor of " + Math.abs(actual - expected) +
20                 "has been used.");
21   }
24 // This helper will verify that |check| returns true. If it does not, it will do
25 // a trip to the event loop and will try again until |check| returns true. At
26 // which points |callback| will be called.
27 // NOTE: if the test fails, it will timeout.
28 function eventLoopCheck(check, callback) {
29   if (check()) {
30     callback();
31   } else {
32     setTimeout(callbackPass(function() { eventLoopCheck(check, callback); }));
33   }
36 // This help function will call the callback when the window passed to it will
37 // be loaded. The callback will have the AppWindow passed as a parameter.
38 function waitForLoad(win, callback) {
39   var window = win.contentWindow;
41   if (window.document.readyState == 'complete') {
42     callback(win);
43     return;
44   }
46   window.addEventListener('load', callbackPass(function() {
47     window.removeEventListener('load', arguments.callee);
48     callback(win);
49   }));
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);
63 function assertBoundsConsistent(win) {
64   // Ensure that the inner and outer bounds are consistent. Since platforms
65   // have different frame padding, we cannot check the sizes precisely.
66   // It is a reasonable assumption that all platforms will have a title bar at
67   // the top of the window.
68   chrome.test.assertTrue(win.innerBounds.left >= win.outerBounds.left);
69   chrome.test.assertTrue(win.innerBounds.top > win.outerBounds.top);
70   chrome.test.assertTrue(win.innerBounds.width <= win.outerBounds.width);
71   chrome.test.assertTrue(win.innerBounds.height < win.outerBounds.height);
73   if (win.innerBounds.minWidth === null)
74     chrome.test.assertEq(null, win.outerBounds.minWidth);
75   else
76     chrome.test.assertTrue(
77         win.innerBounds.minWidth <= win.outerBounds.minWidth);
79   if (win.innerBounds.minHeight === null)
80     chrome.test.assertEq(null, win.outerBounds.minHeight);
81   else
82     chrome.test.assertTrue(
83         win.innerBounds.minHeight < win.outerBounds.minHeight);
85   if (win.innerBounds.maxWidth === null)
86     chrome.test.assertEq(null, win.outerBounds.maxWidth);
87   else
88     chrome.test.assertTrue(
89         win.innerBounds.maxWidth <= win.outerBounds.maxWidth);
91   if (win.innerBounds.maxHeight === null)
92     chrome.test.assertEq(null, win.outerBounds.maxHeight);
93   else
94     chrome.test.assertTrue(
95         win.innerBounds.maxHeight < win.outerBounds.maxHeight);
98 function testConflictingBoundsProperty(propertyName) {
99   var innerBounds = {};
100   var outerBounds = {};
101   innerBounds[propertyName] = 20;
102   outerBounds[propertyName] = 20;
103   chrome.app.window.create('test.html', {
104     innerBounds: innerBounds,
105     outerBounds: outerBounds
106   }, callbackFail('The ' + propertyName + ' property cannot be specified for ' +
107                   'both inner and outer bounds.')
108   );
111 function assertBoundsEq(expectedBounds, actualBounds) {
112   chrome.test.assertEq(expectedBounds.left, actualBounds.left);
113   chrome.test.assertEq(expectedBounds.top, actualBounds.top);
114   chrome.test.assertEq(expectedBounds.width, actualBounds.width);
115   chrome.test.assertEq(expectedBounds.height, actualBounds.height);
118 function assertConstraintsEq(expectedConstraints, actualConstraints) {
119   chrome.test.assertEq(expectedConstraints.minWidth,
120                        actualConstraints.minWidth);
121   chrome.test.assertEq(expectedConstraints.minHeight,
122                        actualConstraints.minHeight);
123   chrome.test.assertEq(expectedConstraints.maxWidth,
124                        actualConstraints.maxWidth);
125   chrome.test.assertEq(expectedConstraints.maxHeight,
126                        actualConstraints.maxHeight);
129 function runSetBoundsTest(boundsType, initialState, changeFields,
130                           expectedBounds, hasConstraints) {
131   var createOptions = {};
132   createOptions[boundsType] = initialState;
133   chrome.app.window.create('test.html', createOptions, callbackPass(
134   function(win) {
135     // Change the bounds.
136     if (typeof(changeFields.left) !== 'undefined' &&
137         typeof(changeFields.top) !== 'undefined') {
138       win[boundsType].setPosition(changeFields.left, changeFields.top);
139     } else if (typeof(changeFields.left) !== 'undefined')
140       win[boundsType].left = changeFields.left;
141     else if (typeof(changeFields.top) !== 'undefined')
142       win[boundsType].top = changeFields.top;
144     if (typeof(changeFields.width) !== 'undefined' &&
145         typeof(changeFields.height) !== 'undefined') {
146       win[boundsType].setSize(changeFields.width, changeFields.height);
147     } else if (typeof(changeFields.width) !== 'undefined')
148       win[boundsType].width = changeFields.width;
149     else if (typeof(changeFields.height) !== 'undefined')
150       win[boundsType].height = changeFields.height;
152     // Dummy call to wait for bounds to be changed in the browser.
153     chrome.test.waitForRoundTrip('msg', callbackPass(function(msg) {
154       assertBoundsConsistent(win);
155       assertBoundsEq(expectedBounds, win[boundsType]);
156       if (!hasConstraints)
157         assertConstraintsUnspecified(win);
158       win.close();
159     }));
160   }));
163 function runSetConstraintsTest(boundsType, initialState, changeFields,
164                                expectedConstraints, expectedBounds) {
165   var createOptions = {};
166   createOptions[boundsType] = initialState;
167   chrome.app.window.create('test.html', createOptions, callbackPass(
168   function(win) {
169     assertConstraintsEq(initialState, win[boundsType]);
171     // Change the constraints.
172     if (typeof(changeFields.minWidth) !== 'undefined' &&
173         typeof(changeFields.minHeight) !== 'undefined') {
174       win[boundsType].setMinimumSize(changeFields.minWidth,
175                                      changeFields.minHeight);
176     } else if (typeof(changeFields.minWidth) !== 'undefined')
177       win[boundsType].minWidth = changeFields.minWidth;
178     else if (typeof(changeFields.minHeight) !== 'undefined')
179       win[boundsType].minHeight = changeFields.minHeight;
181     if (typeof(changeFields.maxWidth) !== 'undefined' &&
182         typeof(changeFields.maxHeight) !== 'undefined') {
183       win[boundsType].setMaximumSize(changeFields.maxWidth,
184                                      changeFields.maxHeight);
185     } else if (typeof(changeFields.maxWidth) !== 'undefined')
186       win[boundsType].maxWidth = changeFields.maxWidth;
187     else if (typeof(changeFields.maxHeight) !== 'undefined')
188       win[boundsType].maxHeight = changeFields.maxHeight;
190     // Dummy call to wait for the constraints to be changed in the browser.
191     chrome.test.waitForRoundTrip('msg', callbackPass(function(msg) {
192       assertBoundsConsistent(win);
193       assertConstraintsEq(expectedConstraints, win[boundsType]);
194       if (expectedBounds) {
195         chrome.test.assertEq(expectedBounds.width, win[boundsType].width);
196         chrome.test.assertEq(expectedBounds.height, win[boundsType].height);
197       }
198       win.close();
199     }));
200   }));
203 function testCreate() {
204   chrome.test.runTests([
205     function basic() {
206       chrome.app.window.create('test.html',
207                                {id: 'testId'},
208                                callbackPass(function(win) {
209         chrome.test.assertEq(typeof win.contentWindow.window, 'object');
210         chrome.test.assertTrue(
211           typeof win.contentWindow.document !== 'undefined');
212         chrome.test.assertFalse(
213           'about:blank' === win.contentWindow.location.href);
214         var cw = win.contentWindow.chrome.app.window.current();
215         chrome.test.assertEq(cw, win);
216         chrome.test.assertEq('testId', cw.id);
217         win.contentWindow.close();
218       }))
219     },
221     function badWindow() {
222       chrome.app.window.create('404.html', callbackPass(function(win) {
223         chrome.test.assertTrue(typeof win === 'undefined');
224         // TODO(mlamouri): because |win| is not defined, we can not close that
225         // window...
226       }));
227     },
229     function loadEvent() {
230       chrome.app.window.create('test.html', callbackPass(function(win) {
231         win.contentWindow.onload = callbackPass(function() {
232           chrome.test.assertEq(document.readyState, 'complete');
233           win.contentWindow.close();
234         });
235       }));
236     },
238     function multiWindow() {
239       chrome.test.assertTrue(null === chrome.app.window.current());
240       chrome.app.window.create('test.html',
241                                {id: 'testId1'},
242                                callbackPass(function(win1) {
243         chrome.app.window.create('test.html',
244                                  {id: 'testId2'},
245                                  callbackPass(function(win2) {
246           var cw1 = win1.contentWindow.chrome.app.window.current();
247           var cw2 = win2.contentWindow.chrome.app.window.current();
248           chrome.test.assertEq('testId1', cw1.id);
249           chrome.test.assertEq('testId2', cw2.id);
250           chrome.test.assertTrue(cw1 === win1);
251           chrome.test.assertTrue(cw2 === win2);
252           chrome.test.assertFalse(cw1 === cw2);
253           win1.contentWindow.close();
254           win2.contentWindow.close();
255         }));
256       }));
257     },
259     function hiddenAndNormal() {
260       chrome.app.window.create('test.html',
261                                {hidden: true},
262                                callbackPass(function(win1) {
263         chrome.app.window.create('test.html',
264                                  {hidden: false},
265                                  callbackPass(function(win2) {
266           win1.contentWindow.close();
267           win2.contentWindow.close();
268         }));
269       }));
270     }
271   ]);
274 function testDeprecatedBounds() {
275   chrome.test.runTests([
276     function contentSize() {
277       var options = { bounds: { left: 0, top: 0, width: 250, height: 200 } };
278       chrome.app.window.create('test.html', options, callbackPass(
279       function(win) {
280         var bounds = win.getBounds();
281         chrome.test.assertEq(options.bounds.width, bounds.width);
282         chrome.test.assertEq(options.bounds.height, bounds.height);
283         chrome.test.assertEq(options.bounds.width, win.innerBounds.width);
284         chrome.test.assertEq(options.bounds.height, win.innerBounds.height);
285         win.close();
286       }));
287     },
289     function windowPosition() {
290       var options = { bounds: { left: 0, top: 0, left: 250, top: 200 } };
291       chrome.app.window.create('test.html', options, callbackPass(
292       function(win) {
293         var bounds = win.getBounds();
294         chrome.test.assertEq(options.bounds.left, bounds.left);
295         chrome.test.assertEq(options.bounds.top, bounds.top);
296         chrome.test.assertEq(options.bounds.left, win.outerBounds.left);
297         chrome.test.assertEq(options.bounds.top, win.outerBounds.top);
298         win.close();
299       }));
300     },
302     function minSize() {
303       var options = {
304         bounds: { left: 0, top: 0, width: 250, height: 250 },
305         minWidth: 400, minHeight: 450
306       };
307       chrome.app.window.create('test.html', options, callbackPass(
308       function(win) {
309         var bounds = win.getBounds();
310         chrome.test.assertEq(options.minWidth, bounds.width);
311         chrome.test.assertEq(options.minHeight, bounds.height);
312         win.close();
313       }));
314     },
316     function maxSize() {
317       var options = {
318         bounds: { left: 0, top: 0, width: 250, height: 250 },
319         maxWidth: 200, maxHeight: 150
320       };
321       chrome.app.window.create('test.html', options, callbackPass(
322       function(win) {
323         var bounds = win.getBounds();
324         chrome.test.assertEq(options.maxWidth, bounds.width);
325         chrome.test.assertEq(options.maxHeight, bounds.height);
326         win.close();
327       }));
328     },
330     function minAndMaxSize() {
331       var options = {
332         bounds: { left: 0, top: 0, width: 250, height: 250 },
333         minWidth: 400, minHeight: 450,
334         maxWidth: 200, maxHeight: 150
335       };
336       chrome.app.window.create('test.html', options, callbackPass(
337       function(win) {
338         var bounds = win.getBounds();
339         chrome.test.assertEq(options.minWidth, bounds.width);
340         chrome.test.assertEq(options.minHeight, bounds.height);
341         win.close();
342       }));
343     },
345     function simpleSetBounds() {
346       chrome.app.window.create('test.html', {
347         bounds: { left: 0, top: 0, width: 250, height: 200 }
348       }, callbackPass(function(win) {
349         var newBounds = {width: 400, height: 450};
350         win.setBounds(newBounds);
351         chrome.test.waitForRoundTrip('msg', callbackPass(function() {
352           var bounds = win.getBounds();
353           chrome.test.assertEq(newBounds.width, bounds.width);
354           chrome.test.assertEq(newBounds.height, bounds.height);
355           win.close();
356         }));
357       }));
358     },
360     function heightOnlySetBounds() {
361       chrome.app.window.create('test.html', {
362         bounds: { left: 0, top: 0, width: 300, height: 256 }
363       }, callbackPass(function(win) {
364         win.setBounds({ height: 300 });
365         chrome.test.waitForRoundTrip('msg', callbackPass(function() {
366           var bounds = win.getBounds();
367           chrome.test.assertEq(300, bounds.width);
368           chrome.test.assertEq(300, bounds.height);
369           win.close();
370         }));
371       }));
372     },
373   ]);
376 function testInitialBounds() {
377   chrome.test.runTests([
378     function testNoOptions() {
379       chrome.app.window.create('test.html', {
380       }, callbackPass(function(win) {
381         chrome.test.assertTrue(win != null);
382         chrome.test.assertTrue(win.innerBounds.width > 0);
383         chrome.test.assertTrue(win.innerBounds.height > 0);
384         chrome.test.assertTrue(win.outerBounds.width > 0);
385         chrome.test.assertTrue(win.outerBounds.height > 0);
386         assertConstraintsUnspecified(win);
387         assertBoundsConsistent(win);
388         win.close();
389       }));
390     },
392     function testInnerBoundsOnly() {
393       var innerBounds = {
394         left: 150,
395         top: 100,
396         width: 400,
397         height: 300
398       };
399       chrome.app.window.create('test.html', {
400         innerBounds: innerBounds
401       }, callbackPass(function(win) {
402         chrome.test.assertTrue(win != null);
403         assertBoundsEq(innerBounds, win.innerBounds);
404         assertBoundsConsistent(win);
405         assertConstraintsUnspecified(win);
406         win.close();
407       }));
408     },
410     function testOuterBoundsOnly() {
411       var outerBounds = {
412         left: 150,
413         top: 100,
414         width: 400,
415         height: 300
416       };
417       chrome.app.window.create('test.html', {
418         outerBounds: outerBounds
419       }, callbackPass(function(win) {
420         chrome.test.assertTrue(win != null);
421         assertBoundsEq(outerBounds, win.outerBounds);
422         assertBoundsConsistent(win);
423         assertConstraintsUnspecified(win);
424         win.close();
425       }));
426     },
428     function testFrameless() {
429       var outerBounds = {
430         left: 150,
431         top: 100,
432         width: 400,
433         height: 300
434       };
435       chrome.app.window.create('test.html', {
436         outerBounds: outerBounds,
437         frame: 'none'
438       }, callbackPass(function(win) {
439         chrome.test.assertTrue(win != null);
440         assertBoundsEq(outerBounds, win.outerBounds);
441         assertBoundsEq(outerBounds, win.innerBounds);
442         assertConstraintsUnspecified(win);
443         win.close();
444       }));
445     },
447     function testInnerSizeAndOuterPos() {
448       var innerBounds = {
449         width: 400,
450         height: 300
451       };
452       var outerBounds = {
453         left: 150,
454         top: 100
455       };
456       chrome.app.window.create('test.html', {
457         innerBounds: innerBounds,
458         outerBounds: outerBounds
459       }, callbackPass(function(win) {
460         chrome.test.assertTrue(win != null);
461         chrome.test.assertEq(outerBounds.left, win.outerBounds.left);
462         chrome.test.assertEq(outerBounds.top, win.outerBounds.top);
463         chrome.test.assertEq(innerBounds.width, win.innerBounds.width);
464         chrome.test.assertEq(innerBounds.height, win.innerBounds.height);
465         assertBoundsConsistent(win);
466         assertConstraintsUnspecified(win);
467         win.close();
468       }));
469     },
471     function testInnerAndOuterBoundsEdgeCase() {
472       var innerBounds = {
473         left: 150,
474         height: 300
475       };
476       var outerBounds = {
477         width: 400,
478         top: 100
479       };
480       chrome.app.window.create('test.html', {
481         innerBounds: innerBounds,
482         outerBounds: outerBounds
483       }, callbackPass(function(win) {
484         chrome.test.assertTrue(win != null);
485         chrome.test.assertEq(innerBounds.left, win.innerBounds.left);
486         chrome.test.assertEq(innerBounds.height, win.innerBounds.height);
487         chrome.test.assertEq(outerBounds.top, win.outerBounds.top);
488         chrome.test.assertEq(outerBounds.width, win.outerBounds.width);
489         assertBoundsConsistent(win);
490         assertConstraintsUnspecified(win);
491         win.close();
492       }));
493     },
495     function testPositionOnly() {
496       var outerBounds = {
497         left: 150,
498         top: 100
499       };
500       chrome.app.window.create('test.html', {
501         outerBounds: outerBounds
502       }, callbackPass(function(win) {
503         chrome.test.assertTrue(win != null);
504         chrome.test.assertEq(outerBounds.left, win.outerBounds.left);
505         chrome.test.assertEq(outerBounds.top, win.outerBounds.top);
506         chrome.test.assertTrue(win.innerBounds.width > 0);
507         chrome.test.assertTrue(win.innerBounds.height > 0);
508         chrome.test.assertTrue(win.outerBounds.width > 0);
509         chrome.test.assertTrue(win.outerBounds.height > 0);
510         assertBoundsConsistent(win);
511         assertConstraintsUnspecified(win);
512         win.close();
513       }));
514     },
516     function testSizeOnly() {
517       var outerBounds = {
518         width: 500,
519         height: 400
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.width, win.outerBounds.width);
526         chrome.test.assertEq(outerBounds.height, win.outerBounds.height);
527         assertBoundsConsistent(win);
528         assertConstraintsUnspecified(win);
529         win.close();
530       }));
531     },
533     function testConflictingProperties() {
534       testConflictingBoundsProperty("width");
535       testConflictingBoundsProperty("height");
536       testConflictingBoundsProperty("left");
537       testConflictingBoundsProperty("top");
538       testConflictingBoundsProperty("minWidth");
539       testConflictingBoundsProperty("minHeight");
540       testConflictingBoundsProperty("maxWidth");
541       testConflictingBoundsProperty("maxHeight");
542     }
543   ]);
546 function testInitialConstraints() {
547   chrome.test.runTests([
548     function testMaxInnerConstraints() {
549       var innerBounds = {
550         width: 800,
551         height: 600,
552         maxWidth: 500,
553         maxHeight: 400
554       };
555       chrome.app.window.create('test.html', {
556         innerBounds: innerBounds
557       }, callbackPass(function(win) {
558         chrome.test.assertTrue(win != null);
559         chrome.test.assertEq(innerBounds.maxWidth, win.innerBounds.width);
560         chrome.test.assertEq(innerBounds.maxHeight, win.innerBounds.height);
561         chrome.test.assertEq(innerBounds.maxWidth, win.innerBounds.maxWidth);
562         chrome.test.assertEq(innerBounds.maxHeight, win.innerBounds.maxHeight);
563         assertBoundsConsistent(win);
564         win.close();
565       }));
566     },
568     function testMinInnerConstraints() {
569       var innerBounds = {
570         width: 100,
571         height: 100,
572         minWidth: 300,
573         minHeight: 200
574       };
575       chrome.app.window.create('test.html', {
576         innerBounds: innerBounds
577       }, callbackPass(function(win) {
578         chrome.test.assertTrue(win != null);
579         chrome.test.assertEq(innerBounds.minWidth, win.innerBounds.width);
580         chrome.test.assertEq(innerBounds.minHeight, win.innerBounds.height);
581         chrome.test.assertEq(innerBounds.minWidth, win.innerBounds.minWidth);
582         chrome.test.assertEq(innerBounds.minHeight, win.innerBounds.minHeight);
583         assertBoundsConsistent(win);
584         win.close();
585       }));
586     },
588     function testMaxOuterConstraints() {
589       var outerBounds = {
590         width: 800,
591         height: 600,
592         maxWidth: 500,
593         maxHeight: 400
594       };
595       chrome.app.window.create('test.html', {
596         outerBounds: outerBounds
597       }, callbackPass(function(win) {
598         chrome.test.assertTrue(win != null);
599         chrome.test.assertEq(outerBounds.maxWidth, win.outerBounds.width);
600         chrome.test.assertEq(outerBounds.maxHeight, win.outerBounds.height);
601         chrome.test.assertEq(outerBounds.maxWidth, win.outerBounds.maxWidth);
602         chrome.test.assertEq(outerBounds.maxHeight, win.outerBounds.maxHeight);
603         assertBoundsConsistent(win);
604         win.close();
605       }));
606     },
608     function testMinOuterConstraints() {
609       var outerBounds = {
610         width: 100,
611         height: 100,
612         minWidth: 300,
613         minHeight: 200
614       };
615       chrome.app.window.create('test.html', {
616         outerBounds: outerBounds
617       }, callbackPass(function(win) {
618         chrome.test.assertTrue(win != null);
619         chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.width);
620         chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.height);
621         chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.minWidth);
622         chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.minHeight);
623         assertBoundsConsistent(win);
624         win.close();
625       }));
626     },
628     function testMixedConstraints() {
629       var innerBounds = {
630         width: 100,
631         minHeight: 300
632       };
633       var outerBounds = {
634         height: 100,
635         minWidth: 400,
636       };
637       chrome.app.window.create('test.html', {
638         innerBounds: innerBounds,
639         outerBounds: outerBounds
640       }, callbackPass(function(win) {
641         chrome.test.assertTrue(win != null);
642         chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.width);
643         chrome.test.assertEq(innerBounds.minHeight, win.innerBounds.height);
644         chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.minWidth);
645         chrome.test.assertEq(innerBounds.minHeight, win.innerBounds.minHeight);
646         assertBoundsConsistent(win);
647         win.close();
648       }));
649     },
651     function testBadConstraints() {
652       var outerBounds = {
653         width: 500,
654         height: 400,
655         minWidth: 800,
656         minHeight: 700,
657         maxWidth: 300,
658         maxHeight: 200
659       };
660       chrome.app.window.create('test.html', {
661         outerBounds: outerBounds
662       }, callbackPass(function(win) {
663         chrome.test.assertTrue(win != null);
664         chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.width);
665         chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.height);
666         chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.minWidth);
667         chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.minHeight);
668         chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.maxWidth);
669         chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.maxHeight);
670         assertBoundsConsistent(win);
671         win.close();
672       }));
673     },
675     function testFrameless() {
676       var outerBounds = {
677         minWidth: 50,
678         minHeight: 50,
679         maxWidth: 800,
680         maxHeight: 800
681       };
682       chrome.app.window.create('test.html', {
683         outerBounds: outerBounds,
684         frame: 'none'
685       }, callbackPass(function(win) {
686         chrome.test.assertTrue(win != null);
687         assertConstraintsEq(outerBounds, win.outerBounds);
688         assertConstraintsEq(outerBounds, win.innerBounds);
689         win.close();
690       }));
691     }
692   ]);
695 function testSetBounds() {
696   chrome.test.runTests([
697     function testLeft() {
698       var init = { left: 150, top: 100, width: 300, height: 200 };
699       var change = { left: 189 };
700       var expected = { left: 189, top: 100, width: 300, height: 200 };
701       runSetBoundsTest('innerBounds', init, change, expected);
702       runSetBoundsTest('outerBounds', init, change, expected);
703     },
705     function testLeftNull() {
706       var init = { left: 150, top: 100, width: 300, height: 200 };
707       var change = { left: null };
708       runSetBoundsTest('innerBounds', init, change, init);
709       runSetBoundsTest('outerBounds', init, change, init);
710     },
712     function testTop() {
713       var init = { left: 150, top: 100, width: 300, height: 200 };
714       var change = { top: 167 };
715       var expected = { left: 150, top: 167, width: 300, height: 200 };
716       runSetBoundsTest('innerBounds', init, change, expected);
717       runSetBoundsTest('outerBounds', init, change, expected);
718     },
720     function testTopNull() {
721       var init = { left: 150, top: 100, width: 300, height: 200 };
722       var change = { top: null };
723       runSetBoundsTest('innerBounds', init, change, init);
724       runSetBoundsTest('outerBounds', init, change, init);
725     },
727     function testWidth() {
728       var init = { left: 150, top: 100, width: 300, height: 200 };
729       var change = { width: 245 };
730       var expected = { left: 150, top: 100, width: 245, height: 200 };
731       runSetBoundsTest('innerBounds', init, change, expected);
732       runSetBoundsTest('outerBounds', init, change, expected);
733     },
735     function testWidthNull() {
736       var init = { left: 150, top: 100, width: 300, height: 200 };
737       var change = { width: null };
738       runSetBoundsTest('innerBounds', init, change, init);
739       runSetBoundsTest('outerBounds', init, change, init);
740     },
742     function testHeight() {
743       var init = { left: 150, top: 100, width: 300, height: 200 };
744       var change = { height: 196 };
745       var expected = { left: 150, top: 100, width: 300, height: 196 };
746       runSetBoundsTest('innerBounds', init, change, expected);
747       runSetBoundsTest('outerBounds', init, change, expected);
748     },
750     function testHeightNull() {
751       var init = { left: 150, top: 100, width: 300, height: 200 };
752       var change = { height: null };
753       runSetBoundsTest('innerBounds', init, change, init);
754       runSetBoundsTest('outerBounds', init, change, init);
755     },
757     function testPosition() {
758       var init = { left: 150, top: 100, width: 300, height: 200 };
759       var change = { left: 162, top: 112 };
760       var expected = { left: 162, top: 112, width: 300, height: 200 };
761       runSetBoundsTest('innerBounds', init, change, expected);
762       runSetBoundsTest('outerBounds', init, change, expected);
763     },
765     function testPositionNull() {
766       var init = { left: 150, top: 100, width: 300, height: 200 };
767       var change = { left: null, top: null };
768       runSetBoundsTest('innerBounds', init, change, init);
769       runSetBoundsTest('outerBounds', init, change, init);
770     },
772     function testSize() {
773       var init = { left: 150, top: 100, width: 300, height: 200 };
774       var change = { width: 306, height: 216 };
775       var expected = { left: 150, top: 100, width: 306, height: 216 };
776       runSetBoundsTest('innerBounds', init, change, expected);
777       runSetBoundsTest('outerBounds', init, change, expected);
778     },
780     function testSizeNull() {
781       var init = { left: 150, top: 100, width: 300, height: 200 };
782       var change = { width: null, height: null };
783       runSetBoundsTest('innerBounds', init, change, init);
784       runSetBoundsTest('outerBounds', init, change, init);
785     },
787     function testMinSize() {
788       var init = { left: 150, top: 100, width: 300, height: 200,
789                    minWidth: 235, minHeight: 170 };
790       var change = { width: 50, height: 60 };
791       var expected = { left: 150, top: 100, width: 235, height: 170 };
792       runSetBoundsTest('innerBounds', init, change, expected, true);
793       runSetBoundsTest('outerBounds', init, change, expected, true);
794     },
796     function testMaxSize() {
797       var init = { left: 150, top: 100, width: 300, height: 200,
798                    maxWidth: 330, maxHeight: 230 };
799       var change = { width: 400, height: 300 };
800       var expected = { left: 150, top: 100, width: 330, height: 230 };
801       runSetBoundsTest('innerBounds', init, change, expected, true);
802       runSetBoundsTest('outerBounds', init, change, expected, true);
803     },
805     function testMinAndMaxSize() {
806       var init = { left: 150, top: 100, width: 300, height: 200,
807                    minWidth: 120, minHeight: 170,
808                    maxWidth: 330, maxHeight: 230 };
809       var change = { width: 225, height: 195 };
810       var expected = { left: 150, top: 100, width: 225, height: 195 };
811       runSetBoundsTest('innerBounds', init, change, expected, true);
812       runSetBoundsTest('outerBounds', init, change, expected, true);
813     },
814   ]);
817 function testSetSizeConstraints() {
818   chrome.test.runTests([
819     function testMinWidth() {
820       var init = { minWidth: 300, minHeight: 200,
821                    maxWidth: 350, maxHeight: 250 };
822       var change = { minWidth: 111 };
823       var expected = { minWidth: 111, minHeight: 200,
824                        maxWidth: 350, maxHeight: 250 };
825       runSetConstraintsTest('innerBounds', init, change, expected);
826       runSetConstraintsTest('outerBounds', init, change, expected);
827     },
829     function testClearMinWidth() {
830       var init = { minWidth: 300, minHeight: 200,
831                    maxWidth: 350, maxHeight: 250 };
832       var change = { minWidth: null };
833       var expected = { minWidth: null, minHeight: 200,
834                        maxWidth: 350, maxHeight: 250 };
835       runSetConstraintsTest('innerBounds', init, change, expected);
836       runSetConstraintsTest('outerBounds', init, change, expected);
837     },
839     function testMaxWidth() {
840       var init = { minWidth: 300, minHeight: 200,
841                    maxWidth: 350, maxHeight: 250 };
842       var change = { maxWidth: 347 };
843       var expected = { minWidth: 300, minHeight: 200,
844                        maxWidth: 347, maxHeight: 250 };
845       runSetConstraintsTest('innerBounds', init, change, expected);
846       runSetConstraintsTest('outerBounds', init, change, expected);
847     },
849     function testClearMaxWidth() {
850       var init = { minWidth: 300, minHeight: 200,
851                    maxWidth: 350, maxHeight: 250 };
852       var change = { maxWidth: null };
853       var expected = { minWidth: 300, minHeight: 200,
854                        maxWidth: null, maxHeight: 250 };
855       runSetConstraintsTest('innerBounds', init, change, expected);
856       runSetConstraintsTest('outerBounds', init, change, expected);
857     },
859     function testMinHeight() {
860       var init = { minWidth: 300, minHeight: 200,
861                    maxWidth: 350, maxHeight: 250 };
862       var change = { minHeight: 198 };
863       var expected = { minWidth: 300, minHeight: 198,
864                        maxWidth: 350, maxHeight: 250 };
865       runSetConstraintsTest('innerBounds', init, change, expected);
866       runSetConstraintsTest('outerBounds', init, change, expected);
867     },
869     function testClearMinHeight() {
870       var init = { minWidth: 300, minHeight: 200,
871                    maxWidth: 350, maxHeight: 250 };
872       var change = { minHeight: null };
873       var expected = { minWidth: 300, minHeight: null,
874                        maxWidth: 350, maxHeight: 250 };
875       runSetConstraintsTest('innerBounds', init, change, expected);
876       runSetConstraintsTest('outerBounds', init, change, expected);
877     },
879     function testMaxHeight() {
880       var init = { minWidth: 300, minHeight: 200,
881                    maxWidth: 350, maxHeight: 250 };
882       var change = { maxHeight: 278 };
883       var expected = { minWidth: 300, minHeight: 200,
884                        maxWidth: 350, maxHeight: 278 };
885       runSetConstraintsTest('innerBounds', init, change, expected);
886       runSetConstraintsTest('outerBounds', init, change, expected);
887     },
889     function testClearMaxHeight() {
890       var init = { minWidth: 300, minHeight: 200,
891                    maxWidth: 350, maxHeight: 250 };
892       var change = { maxHeight: null };
893       var expected = { minWidth: 300, minHeight: 200,
894                        maxWidth: 350, maxHeight: null };
895       runSetConstraintsTest('innerBounds', init, change, expected);
896       runSetConstraintsTest('outerBounds', init, change, expected);
897     },
899     function testSetMinSize() {
900       // This test expects the bounds to be changed.
901       var init = { width: 225, height: 125,
902                    minWidth: null, minHeight: null,
903                    maxWidth: null, maxHeight: null };
904       var change = { minWidth: 235, minHeight: 135 };
905       var expected = { width: 235, height: 135,
906                        minWidth: 235, minHeight: 135,
907                        maxWidth: null, maxHeight: null };
908       runSetConstraintsTest('innerBounds', init, change, expected, expected);
909       runSetConstraintsTest('outerBounds', init, change, expected, expected);
910     },
912     function testSetMaxSize() {
913       // This test expects the bounds to be changed.
914       var init = { width: 225, height: 125,
915                    minWidth: null, minHeight: null,
916                    maxWidth: null, maxHeight: null };
917       var change = { maxWidth: 198, maxHeight: 107 };
918       var expected = { width: 198, height: 107,
919                        minWidth: null, minHeight: null,
920                        maxWidth: 198, maxHeight: 107 };
921       runSetConstraintsTest('innerBounds', init, change, expected, expected);
922       runSetConstraintsTest('outerBounds', init, change, expected, expected);
923     },
925     function testChangeMinAndMaxSize() {
926       var init = { width: 325, height: 225,
927                    minWidth: 300, minHeight: 200,
928                    maxWidth: 350, maxHeight: 250 };
929       var change = { minWidth: 287, minHeight: 198,
930                      maxWidth: 334, maxHeight: 278 };
931       runSetConstraintsTest('innerBounds', init, change, change, init);
932       runSetConstraintsTest('outerBounds', init, change, change, init);
933     },
935     function testClearMinAndMaxSize() {
936       var init = { width: 325, height: 225,
937                    minWidth: 300, minHeight: 200,
938                    maxWidth: 350, maxHeight: 250 };
939       var change = { minWidth: null, minHeight: null,
940                      maxWidth: null, maxHeight: null };
941       runSetConstraintsTest('innerBounds', init, change, change, init);
942       runSetConstraintsTest('outerBounds', init, change, change, init);
943     },
945     function testClearConstraints() {
946       // This checks that bounds are not clipped once constraints are removed.
947       var createOptions = {
948         innerBounds: {
949           width: 325, height: 225,
950           minWidth: 300, minHeight: 200,
951           maxWidth: 350, maxHeight: 250
952         }
953       };
954       chrome.app.window.create('test.html', createOptions, callbackPass(
955       function(win) {
956         win.innerBounds.setMinimumSize(null, null);
957         win.innerBounds.setMaximumSize(null, null);
959         // Set the size smaller than the initial min.
960         win.innerBounds.setSize(234, 198);
962         // Dummy call to wait for bounds to be changed in the browser.
963         chrome.test.waitForRoundTrip('msg', callbackPass(function(msg) {
964           chrome.test.assertEq(234, win.innerBounds.width);
965           chrome.test.assertEq(198, win.innerBounds.height);
967           // Set the size larger than the initial max.
968           win.innerBounds.setSize(361, 278);
970           chrome.test.waitForRoundTrip('msg', callbackPass(function(msg) {
971             chrome.test.assertEq(361, win.innerBounds.width);
972             chrome.test.assertEq(278, win.innerBounds.height);
973             win.close();
974           }));
975         }));
976       }));
977     },
979     function testMinWidthLargerThanMaxWidth() {
980       var init = { width: 102, height: 103,
981                    minWidth: 100, minHeight: 101,
982                    maxWidth: 104, maxHeight: 105 };
983       var change = { minWidth: 200 };
984       var expected = { minWidth: 200, minHeight: 101,
985                        maxWidth: 200, maxHeight: 105 };
986       runSetConstraintsTest('innerBounds', init, change, expected);
987     },
989     function testMinHeightLargerThanMaxHeight() {
990       var init = { width: 102, height: 103,
991                    minWidth: 100, minHeight: 101,
992                    maxWidth: 104, maxHeight: 105 };
993       var change = { minHeight: 200 };
994       var expected = { minWidth: 100, minHeight: 200,
995                        maxWidth: 104, maxHeight: 200 };
996       runSetConstraintsTest('innerBounds', init, change, expected);
997     },
999     function testMaxWidthSmallerThanMinWidth() {
1000       var init = { width: 102, height: 103,
1001                    minWidth: 100, minHeight: 101,
1002                    maxWidth: 104, maxHeight: 105 };
1003       var change = { maxWidth: 50 };
1004       var expected = { minWidth: 100, minHeight: 101,
1005                        maxWidth: 100, maxHeight: 105 };
1006       runSetConstraintsTest('innerBounds', init, change, expected);
1007     },
1009     function testMaxHeightSmallerThanMinHeight() {
1010       var init = { width: 102, height: 103,
1011                    minWidth: 100, minHeight: 101,
1012                    maxWidth: 104, maxHeight: 105 };
1013       var change = { maxHeight: 50 };
1014       var expected = { minWidth: 100, minHeight: 101,
1015                        maxWidth: 104, maxHeight: 101 };
1016       runSetConstraintsTest('innerBounds', init, change, expected);
1017     },
1018   ]);
1021 function testSingleton() {
1022   chrome.test.runTests([
1023     function noParameterWithId() {
1024       chrome.app.window.create(
1025         'test.html', { id: 'singleton-id' },
1026         callbackPass(function(win) {
1027           var w = win.contentWindow;
1029           chrome.app.window.create(
1030             'test.html', { id: 'singleton-id' },
1031             callbackPass(function(win) {
1032               var w2 = win.contentWindow;
1033               chrome.test.assertTrue(w === w2);
1035               w.close();
1036               w2.close();
1037             })
1038           );
1039         })
1040       );
1041     },
1042   ]);
1045 function testCloseEvent() {
1046   chrome.test.runTests([
1047     function basic() {
1048       chrome.app.window.create('test.html', callbackPass(function(win) {
1049         win.onClosed.addListener(callbackPass(function() {
1050           // Mission accomplished.
1051         }));
1052         win.contentWindow.close();
1053       }));
1054     }
1055   ]);
1058 function testMaximize() {
1059   chrome.test.runTests([
1060     function basic() {
1061       chrome.app.window.create('test.html',
1062                                { innerBounds: {width: 200, height: 200} },
1063         callbackPass(function(win) {
1064           // TODO(mlamouri): we should be able to use onMaximized here but to
1065           // make that happen we need to make sure the event is not fired when
1066           // .maximize() is called but when the maximizing is finished.
1067           // See crbug.com/316091
1068           function isWindowMaximized() {
1069             return win.contentWindow.outerHeight == screen.availHeight &&
1070                    win.contentWindow.outerWidth == screen.availWidth;
1071           }
1073           eventLoopCheck(isWindowMaximized, function() {
1074             win.close();
1075           });
1077           win.maximize();
1078         })
1079       );
1080     },
1082     function nonResizableWindow() {
1083       chrome.app.window.create('test.html',
1084                                { innerBounds: {width: 200, height: 200},
1085                                  resizable: false },
1086         callbackPass(function(win) {
1087           // TODO(mlamouri): we should be able to use onMaximized here but to
1088           // make that happen we need to make sure the event is not fired when
1089           // .maximize() is called but when the maximizing is finished.
1090           // See crbug.com/316091
1091           function isWindowMaximized() {
1092             return win.contentWindow.outerHeight == screen.availHeight &&
1093                    win.contentWindow.outerWidth == screen.availWidth;
1094           }
1096           eventLoopCheck(isWindowMaximized, function() {
1097             win.close();
1098           });
1100           win.maximize();
1101         })
1102       );
1103     },
1104   ]);
1107 function testMinimize() {
1108   chrome.test.runTests([
1109     function basic() {
1110       chrome.app.window.create('test.html',
1111                                { innerBounds: {width: 200, height: 200} },
1112         callbackPass(function(win) {
1113           function isWindowMinimized() {
1114             return win.isMinimized();
1115           }
1117           win.minimize();
1118           eventLoopCheck(isWindowMinimized, function() {
1119             win.close();
1120           });
1121         })
1122       );
1123     },
1125     function checkSizeAfterRestore() {
1126       var bounds = { width: 200, height: 200,
1127                      minWidth: 200, minHeight: 200,
1128                      maxWidth: 200, maxHeight: 200 };
1129       chrome.app.window.create('test.html', { innerBounds: bounds },
1130         callbackPass(function(win) {
1131           function isWindowMinimized() {
1132             return win.isMinimized();
1133           }
1135           function sizeIsSame() {
1136             return bounds.width == win.innerBounds.width &&
1137                    bounds.height == win.innerBounds.height;
1138           }
1140           win.minimize();
1141           eventLoopCheck(isWindowMinimized, function() {
1142             win.restore();
1143             eventLoopCheck(sizeIsSame, function() {
1144               win.close();
1145             });
1146           });
1147         })
1148       );
1149     },
1150   ]);
1153 function testRestore() {
1154   chrome.test.runTests([
1155     function basic() {
1156       chrome.app.window.create('test.html',
1157                                { innerBounds: {width: 200, height: 200} },
1158         callbackPass(function(win) {
1159           var oldWidth = win.contentWindow.innerWidth;
1160           var oldHeight = win.contentWindow.innerHeight;
1162           // TODO(mlamouri): we should be able to use onMaximized here but to
1163           // make that happen we need to make sure the event is not fired when
1164           // .maximize() is called but when the maximizing is finished.
1165           // See crbug.com/316091
1166           function isWindowMaximized() {
1167             return win.contentWindow.outerHeight == screen.availHeight &&
1168                    win.contentWindow.outerWidth == screen.availWidth;
1169           }
1170           function isWindowRestored() {
1171             return win.contentWindow.innerHeight == oldHeight &&
1172                    win.contentWindow.innerWidth == oldWidth;
1173           }
1175           eventLoopCheck(isWindowMaximized, function() {
1176             eventLoopCheck(isWindowRestored, function() {
1177               win.close();
1178             });
1180             win.restore();
1181           });
1183           win.maximize();
1184         })
1185       );
1186     }
1187   ]);
1190 function testRestoreAfterClose() {
1191   chrome.test.runTests([
1192     function restoredBoundsLowerThanNewMinSize() {
1193       chrome.app.window.create('test.html', {
1194         innerBounds: {
1195           width: 100, height: 150,
1196           minWidth: 200, minHeight: 250,
1197           maxWidth: 200, maxHeight: 250
1198         },
1199         id: 'test-id'
1200       }, callbackPass(function(win) {
1201         var w = win.contentWindow;
1202         assertFuzzyEq(200, w.innerWidth, defaultFuzzFactor);
1203         assertFuzzyEq(250, w.innerHeight, defaultFuzzFactor);
1205         win.onClosed.addListener(callbackPass(function() {
1206           chrome.app.window.create('test.html', {
1207             innerBounds: {
1208               width: 500, height: 550,
1209               minWidth: 400, minHeight: 450,
1210               maxWidth: 600, maxHeight: 650
1211             },
1212             id: 'test-id'
1213           }, callbackPass(function(win) {
1214             var w = win.contentWindow;
1215             assertFuzzyEq(400, w.innerWidth, defaultFuzzFactor);
1216             assertFuzzyEq(450, w.innerHeight, defaultFuzzFactor);
1217             w.close();
1218           }));
1219         }));
1221         w.close();
1222       }));
1223     }
1224   ]);
1227 function testRestoreAfterGeometryCacheChange() {
1228   chrome.test.runTests([
1229     function restorePositionAndSize() {
1230       chrome.app.window.create('test.html', {
1231         outerBounds: { left: 200, top: 200 },
1232         innerBounds: { width: 200, height: 200 },
1233         id: 'test-ra',
1234       }, callbackPass(function(win) { waitForLoad(win, function(win) {
1235         var w = win.contentWindow;
1236         chrome.test.assertEq(200, w.screenX);
1237         chrome.test.assertEq(200, w.screenY);
1238         chrome.test.assertEq(200, w.innerHeight);
1239         chrome.test.assertEq(200, w.innerWidth);
1241         w.resizeTo(300, 300);
1242         w.moveTo(100, 100);
1244         chrome.app.window.create('test.html', {
1245           outerBounds: { left: 200, top: 200, width: 200, height: 200 },
1246           id: 'test-rb', frame: 'none'
1247         }, callbackPass(function(win2) { waitForLoad(win2, function(win2) {
1248           var w2 = win2.contentWindow;
1249           chrome.test.assertEq(200, w2.screenX);
1250           chrome.test.assertEq(200, w2.screenY);
1251           chrome.test.assertEq(200, w2.innerWidth);
1252           chrome.test.assertEq(200, w2.innerHeight);
1254           w2.resizeTo(100, 100);
1255           w2.moveTo(300, 300);
1257           chrome.test.sendMessage('ListenGeometryChange', function(reply) {
1258             win.onClosed.addListener(callbackPass(function() {
1259               chrome.app.window.create('test.html', {
1260                 id: 'test-ra'
1261               }, callbackPass(function(win) { waitForLoad(win, function(win) {
1262                 var w = win.contentWindow;
1263                 chrome.test.assertEq(100, w.screenX);
1264                 chrome.test.assertEq(100, w.screenY);
1265                 chrome.test.assertEq(300, w.outerWidth);
1266                 chrome.test.assertEq(300, w.outerHeight);
1267               })}));
1268             }));
1270             win2.onClosed.addListener(callbackPass(function() {
1271               chrome.app.window.create('test.html', {
1272                 id: 'test-rb', frame: 'none'
1273               },callbackPass(function(win2) { waitForLoad(win2, function(win2) {
1274                 var w = win2.contentWindow;
1275                 chrome.test.assertEq(300, w.screenX);
1276                 chrome.test.assertEq(300, w.screenY);
1277                 chrome.test.assertEq(100, w.outerWidth);
1278                 chrome.test.assertEq(100, w.outerHeight);
1279               })}));
1280             }));
1282             win.close();
1283             win2.close();
1284           });
1285         })}));
1286       })}));
1287     },
1288   ]);
1291 function testFrameColors() {
1292   chrome.test.runTests([
1293     function testWithNoColor() {
1294       chrome.app.window.create('test.html', callbackPass(function(win) {
1295         chrome.test.assertEq(false, win.hasFrameColor);
1296         win.close();
1297       }));
1298     },
1300     function testWithFrameNone() {
1301       chrome.app.window.create('test.html', {
1302         frame: 'none'
1303       },
1304       callbackPass(function(win) {
1305         chrome.test.assertEq(false, win.hasFrameColor);
1306         win.close();
1307       }));
1308     },
1310     function testWithBlack() {
1311       chrome.app.window.create('test.html', {
1312         frame: {
1313           type: 'chrome',
1314           color: '#000000'
1315         }
1316       },
1317       callbackPass(function(win) {
1318         chrome.test.assertEq(true, win.hasFrameColor);
1319         chrome.test.assertEq(0x000000, win.activeFrameColor);
1320         chrome.test.assertEq(0x000000, win.inactiveFrameColor);
1321         win.close();
1322       }));
1323     },
1325     function testWithWhite() {
1326       chrome.app.window.create('test.html', {
1327         frame: {
1328           color: '#FFFFFF'
1329         }
1330       },
1331       callbackPass(function(win) {
1332         chrome.test.assertEq(true, win.hasFrameColor);
1333         chrome.test.assertEq(0xFFFFFF, win.activeFrameColor);
1334         chrome.test.assertEq(0xFFFFFF, win.inactiveFrameColor);
1335         win.close();
1336       }));
1337     },
1339     function testWithActiveInactive() {
1340       chrome.app.window.create('test.html', {
1341         frame: {
1342           type: 'chrome',
1343           color: '#000000',
1344           inactiveColor: '#FFFFFF'
1345         }
1346       },
1347       callbackPass(function(win) {
1348         chrome.test.assertEq(true, win.hasFrameColor);
1349         chrome.test.assertEq(0x000000, win.activeFrameColor);
1350         chrome.test.assertEq(0xFFFFFF, win.inactiveFrameColor);
1351         win.close();
1352       }));
1353     },
1355     function testWithWhiteShorthand() {
1356       chrome.app.window.create('test.html', {
1357         frame: {
1358           color: '#FFF'
1359         }
1360       },
1361       callbackPass(function(win) {
1362         chrome.test.assertEq(true, win.hasFrameColor);
1363         chrome.test.assertEq(0xFFFFFF, win.activeFrameColor);
1364         chrome.test.assertEq(0xFFFFFF, win.inactiveFrameColor);
1365         win.close();
1366       }));
1367     },
1369     function testWithFrameNoneAndColor() {
1370       chrome.app.window.create('test.html', {
1371         frame: {
1372           type: 'none',
1373           color: '#FFF'
1374         }
1375       },
1376       callbackFail('Windows with no frame cannot have a color.'));
1377     },
1379     function testWithInactiveColorAndNoColor() {
1380       chrome.app.window.create('test.html', {
1381         frame: {
1382           inactiveColor: '#FFF'
1383         }
1384       },
1385       callbackFail('frame.inactiveColor must be used with frame.color.'));
1386     },
1388      function testWithInvalidColor() {
1389       chrome.app.window.create('test.html', {
1390         frame: {
1391           color: 'DontWorryBeHappy'
1392         }
1393       },
1394       callbackFail('The color specification could not be parsed.'));
1395     }
1396   ]);
1399 function testVisibleOnAllWorkspaces() {
1400   chrome.test.runTests([
1401     function setAndUnsetVisibleOnAllWorkspaces() {
1402       chrome.app.window.create('test.html', {
1403         visibleOnAllWorkspaces: true
1404       }, callbackPass(function(win) {
1405         win.setVisibleOnAllWorkspaces(false);
1406         win.setVisibleOnAllWorkspaces(true);
1407         chrome.test.sendMessage(
1408             'WaitForRoundTrip', callbackPass(function(reply) {}));
1409       }));
1410     },
1411   ]);
1414 chrome.app.runtime.onLaunched.addListener(function() {
1415   chrome.test.sendMessage('Launched', function(reply) {
1416     window[reply]();
1417   });