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 // 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); |
| 72 |
| 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); |
| 78 |
| 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); |
| 84 |
| 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); |
| 90 |
| 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); |
| 96 } |
| 97 |
| 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 ); |
| 109 } |
| 110 |
52 function testCreate() { | 111 function testCreate() { |
53 chrome.test.runTests([ | 112 chrome.test.runTests([ |
54 function basic() { | 113 function basic() { |
55 chrome.app.window.create('test.html', | 114 chrome.app.window.create('test.html', |
56 {id: 'testId'}, | 115 {id: 'testId'}, |
57 callbackPass(function(win) { | 116 callbackPass(function(win) { |
58 chrome.test.assertEq(typeof win.contentWindow.window, 'object'); | 117 chrome.test.assertEq(typeof win.contentWindow.window, 'object'); |
59 chrome.test.assertTrue( | 118 chrome.test.assertTrue( |
60 typeof win.contentWindow.document !== 'undefined'); | 119 typeof win.contentWindow.document !== 'undefined'); |
61 chrome.test.assertFalse( | 120 chrome.test.assertFalse( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 var cw2 = win2.contentWindow.chrome.app.window.current(); | 155 var cw2 = win2.contentWindow.chrome.app.window.current(); |
97 chrome.test.assertEq('testId1', cw1.id); | 156 chrome.test.assertEq('testId1', cw1.id); |
98 chrome.test.assertEq('testId2', cw2.id); | 157 chrome.test.assertEq('testId2', cw2.id); |
99 chrome.test.assertTrue(cw1 === win1); | 158 chrome.test.assertTrue(cw1 === win1); |
100 chrome.test.assertTrue(cw2 === win2); | 159 chrome.test.assertTrue(cw2 === win2); |
101 chrome.test.assertFalse(cw1 === cw2); | 160 chrome.test.assertFalse(cw1 === cw2); |
102 win1.contentWindow.close(); | 161 win1.contentWindow.close(); |
103 win2.contentWindow.close(); | 162 win2.contentWindow.close(); |
104 })); | 163 })); |
105 })); | 164 })); |
106 }, | 165 } |
107 | 166 ]); |
| 167 } |
| 168 |
| 169 function testDeprecatedBounds() { |
| 170 chrome.test.runTests([ |
108 function contentSize() { | 171 function contentSize() { |
109 chrome.app.window.create('test.html', | 172 var options = { bounds: { width: 250, height: 200 } }; |
110 { bounds: { width: 250, height: 200 } }, callbackPass(function(win) { | 173 chrome.app.window.create('test.html', options, callbackPass( |
111 assertFuzzyEq(250, win.contentWindow.innerWidth, defaultFuzzFactor); | 174 function(win) { |
112 assertFuzzyEq(200, win.contentWindow.innerHeight, defaultFuzzFactor); | 175 var bounds = win.getBounds(); |
| 176 chrome.test.assertEq(options.bounds.width, bounds.width); |
| 177 chrome.test.assertEq(options.bounds.height, bounds.height); |
| 178 chrome.test.assertEq(options.bounds.width, win.innerBounds.width); |
| 179 chrome.test.assertEq(options.bounds.height, win.innerBounds.height); |
| 180 win.close(); |
| 181 })); |
| 182 }, |
| 183 |
| 184 function windowPosition() { |
| 185 var options = { bounds: { left: 250, top: 200 } }; |
| 186 chrome.app.window.create('test.html', options, callbackPass( |
| 187 function(win) { |
| 188 var bounds = win.getBounds(); |
| 189 chrome.test.assertEq(options.bounds.left, bounds.left); |
| 190 chrome.test.assertEq(options.bounds.top, bounds.top); |
| 191 chrome.test.assertEq(options.bounds.left, win.outerBounds.left); |
| 192 chrome.test.assertEq(options.bounds.top, win.outerBounds.top); |
113 win.close(); | 193 win.close(); |
114 })); | 194 })); |
115 }, | 195 }, |
116 | 196 |
117 function minSize() { | 197 function minSize() { |
118 chrome.app.window.create('test.html', { | 198 var options = { |
119 bounds: { width: 250, height: 250 }, | 199 bounds: { width: 250, height: 250 }, |
120 minWidth: 400, minHeight: 450 | 200 minWidth: 400, minHeight: 450 |
121 }, callbackPass(function(win) { | 201 }; |
122 var w = win.contentWindow; | 202 chrome.app.window.create('test.html', options, callbackPass( |
123 assertFuzzyEq(400, w.innerWidth, defaultFuzzFactor); | 203 function(win) { |
124 assertFuzzyEq(450, w.innerHeight, defaultFuzzFactor); | 204 var bounds = win.getBounds(); |
125 w.close(); | 205 chrome.test.assertEq(options.minWidth, bounds.width); |
| 206 chrome.test.assertEq(options.minHeight, bounds.height); |
| 207 win.close(); |
126 })); | 208 })); |
127 }, | 209 }, |
128 | 210 |
129 function maxSize() { | 211 function maxSize() { |
130 chrome.app.window.create('test.html', { | 212 var options = { |
131 bounds: { width: 250, height: 250 }, | 213 bounds: { width: 250, height: 250 }, |
132 maxWidth: 200, maxHeight: 150 | 214 maxWidth: 200, maxHeight: 150 |
133 }, callbackPass(function(win) { | 215 }; |
134 var w = win.contentWindow; | 216 chrome.app.window.create('test.html', options, callbackPass( |
135 assertFuzzyEq(200, w.innerWidth, defaultFuzzFactor); | 217 function(win) { |
136 assertFuzzyEq(150, w.innerHeight, defaultFuzzFactor); | 218 var bounds = win.getBounds(); |
137 w.close(); | 219 chrome.test.assertEq(options.maxWidth, bounds.width); |
| 220 chrome.test.assertEq(options.maxHeight, bounds.height); |
| 221 win.close(); |
138 })); | 222 })); |
139 }, | 223 }, |
140 | 224 |
141 function minAndMaxSize() { | 225 function minAndMaxSize() { |
142 chrome.app.window.create('test.html', { | 226 var options = { |
143 bounds: { width: 250, height: 250 }, | 227 bounds: { width: 250, height: 250 }, |
144 minWidth: 400, minHeight: 450, | 228 minWidth: 400, minHeight: 450, |
145 maxWidth: 200, maxHeight: 150 | 229 maxWidth: 200, maxHeight: 150 |
146 }, callbackPass(function(win) { | 230 }; |
147 var w = win.contentWindow; | 231 chrome.app.window.create('test.html', options, callbackPass( |
148 assertFuzzyEq(400, w.innerWidth, defaultFuzzFactor); | 232 function(win) { |
149 assertFuzzyEq(450, w.innerHeight, defaultFuzzFactor); | 233 var bounds = win.getBounds(); |
150 w.close(); | 234 chrome.test.assertEq(options.minWidth, bounds.width); |
151 })); | 235 chrome.test.assertEq(options.minHeight, bounds.height); |
| 236 win.close(); |
| 237 })); |
| 238 }, |
| 239 |
| 240 function simpleSetBounds() { |
| 241 chrome.app.window.create('test.html', |
| 242 { bounds: { width: 250, height: 200 } }, callbackPass(function(win) { |
| 243 var newBounds = {width: 400, height: 450}; |
| 244 win.setBounds(newBounds); |
| 245 chrome.test.waitForRoundTrip('msg', callbackPass(function() { |
| 246 var bounds = win.getBounds(); |
| 247 chrome.test.assertEq(newBounds.width, bounds.width); |
| 248 chrome.test.assertEq(newBounds.height, bounds.height); |
| 249 win.close(); |
| 250 })); |
| 251 })); |
| 252 }, |
| 253 |
| 254 function heightOnlySetBounds() { |
| 255 chrome.app.window.create('test.html', { |
| 256 bounds: { width: 512, height: 256 } |
| 257 }, callbackPass(function(win) { |
| 258 win.setBounds({ height: 512 }); |
| 259 chrome.test.waitForRoundTrip('msg', callbackPass(function() { |
| 260 var bounds = win.getBounds(); |
| 261 chrome.test.assertEq(512, bounds.width); |
| 262 chrome.test.assertEq(512, bounds.height); |
| 263 win.close(); |
| 264 })); |
| 265 })); |
| 266 }, |
| 267 ]); |
| 268 } |
| 269 |
| 270 function testInitialBounds() { |
| 271 chrome.test.runTests([ |
| 272 function testNoOptions() { |
| 273 chrome.app.window.create('test.html', { |
| 274 }, callbackPass(function(win) { |
| 275 chrome.test.assertTrue(win != null); |
| 276 chrome.test.assertTrue(win.innerBounds.width > 0); |
| 277 chrome.test.assertTrue(win.innerBounds.height > 0); |
| 278 chrome.test.assertTrue(win.outerBounds.width > 0); |
| 279 chrome.test.assertTrue(win.outerBounds.height > 0); |
| 280 assertConstraintsUnspecified(win); |
| 281 assertBoundsConsistent(win); |
| 282 win.close(); |
| 283 })); |
| 284 }, |
| 285 |
| 286 function testInnerBoundsOnly() { |
| 287 var innerBounds = { |
| 288 left: 150, |
| 289 top: 100, |
| 290 width: 400, |
| 291 height: 300 |
| 292 }; |
| 293 chrome.app.window.create('test.html', { |
| 294 innerBounds: innerBounds |
| 295 }, callbackPass(function(win) { |
| 296 chrome.test.assertTrue(win != null); |
| 297 chrome.test.assertEq(innerBounds.left, win.innerBounds.left); |
| 298 chrome.test.assertEq(innerBounds.top, win.innerBounds.top); |
| 299 chrome.test.assertEq(innerBounds.width, win.innerBounds.width); |
| 300 chrome.test.assertEq(innerBounds.height, win.innerBounds.height); |
| 301 assertBoundsConsistent(win); |
| 302 assertConstraintsUnspecified(win); |
| 303 win.close(); |
| 304 })); |
| 305 }, |
| 306 |
| 307 function testOuterBoundsOnly() { |
| 308 var outerBounds = { |
| 309 left: 150, |
| 310 top: 100, |
| 311 width: 400, |
| 312 height: 300 |
| 313 }; |
| 314 chrome.app.window.create('test.html', { |
| 315 outerBounds: outerBounds |
| 316 }, callbackPass(function(win) { |
| 317 chrome.test.assertTrue(win != null); |
| 318 chrome.test.assertEq(outerBounds.left, win.outerBounds.left); |
| 319 chrome.test.assertEq(outerBounds.top, win.outerBounds.top); |
| 320 chrome.test.assertEq(outerBounds.width, win.outerBounds.width); |
| 321 chrome.test.assertEq(outerBounds.height, win.outerBounds.height); |
| 322 assertBoundsConsistent(win); |
| 323 assertConstraintsUnspecified(win); |
| 324 win.close(); |
| 325 })); |
| 326 }, |
| 327 |
| 328 function testFrameless() { |
| 329 var outerBounds = { |
| 330 left: 150, |
| 331 top: 100, |
| 332 width: 400, |
| 333 height: 300 |
| 334 }; |
| 335 chrome.app.window.create('test.html', { |
| 336 outerBounds: outerBounds, |
| 337 frame: 'none' |
| 338 }, callbackPass(function(win) { |
| 339 chrome.test.assertTrue(win != null); |
| 340 chrome.test.assertEq(outerBounds.left, win.outerBounds.left); |
| 341 chrome.test.assertEq(outerBounds.top, win.outerBounds.top); |
| 342 chrome.test.assertEq(outerBounds.width, win.outerBounds.width); |
| 343 chrome.test.assertEq(outerBounds.height, win.outerBounds.height); |
| 344 chrome.test.assertEq(outerBounds.left, win.innerBounds.left); |
| 345 chrome.test.assertEq(outerBounds.top, win.innerBounds.top); |
| 346 chrome.test.assertEq(outerBounds.width, win.innerBounds.width); |
| 347 chrome.test.assertEq(outerBounds.height, win.innerBounds.height); |
| 348 assertConstraintsUnspecified(win); |
| 349 win.close(); |
| 350 })); |
| 351 }, |
| 352 |
| 353 function testInnerSizeAndOuterPos() { |
| 354 var innerBounds = { |
| 355 width: 400, |
| 356 height: 300 |
| 357 }; |
| 358 var outerBounds = { |
| 359 left: 150, |
| 360 top: 100 |
| 361 }; |
| 362 chrome.app.window.create('test.html', { |
| 363 innerBounds: innerBounds, |
| 364 outerBounds: outerBounds |
| 365 }, callbackPass(function(win) { |
| 366 chrome.test.assertTrue(win != null); |
| 367 chrome.test.assertEq(outerBounds.left, win.outerBounds.left); |
| 368 chrome.test.assertEq(outerBounds.top, win.outerBounds.top); |
| 369 chrome.test.assertEq(innerBounds.width, win.innerBounds.width); |
| 370 chrome.test.assertEq(innerBounds.height, win.innerBounds.height); |
| 371 assertBoundsConsistent(win); |
| 372 assertConstraintsUnspecified(win); |
| 373 win.close(); |
| 374 })); |
| 375 }, |
| 376 |
| 377 function testInnerAndOuterBoundsEdgeCase() { |
| 378 var innerBounds = { |
| 379 left: 150, |
| 380 height: 300 |
| 381 }; |
| 382 var outerBounds = { |
| 383 width: 400, |
| 384 top: 100 |
| 385 }; |
| 386 chrome.app.window.create('test.html', { |
| 387 innerBounds: innerBounds, |
| 388 outerBounds: outerBounds |
| 389 }, callbackPass(function(win) { |
| 390 chrome.test.assertTrue(win != null); |
| 391 chrome.test.assertEq(innerBounds.left, win.innerBounds.left); |
| 392 chrome.test.assertEq(innerBounds.height, win.innerBounds.height); |
| 393 chrome.test.assertEq(outerBounds.top, win.outerBounds.top); |
| 394 chrome.test.assertEq(outerBounds.width, win.outerBounds.width); |
| 395 assertBoundsConsistent(win); |
| 396 assertConstraintsUnspecified(win); |
| 397 win.close(); |
| 398 })); |
| 399 }, |
| 400 |
| 401 function testPositionOnly() { |
| 402 var outerBounds = { |
| 403 left: 150, |
| 404 top: 100 |
| 405 }; |
| 406 chrome.app.window.create('test.html', { |
| 407 outerBounds: outerBounds |
| 408 }, callbackPass(function(win) { |
| 409 chrome.test.assertTrue(win != null); |
| 410 chrome.test.assertEq(outerBounds.left, win.outerBounds.left); |
| 411 chrome.test.assertEq(outerBounds.top, win.outerBounds.top); |
| 412 chrome.test.assertTrue(win.innerBounds.width > 0); |
| 413 chrome.test.assertTrue(win.innerBounds.height > 0); |
| 414 chrome.test.assertTrue(win.outerBounds.width > 0); |
| 415 chrome.test.assertTrue(win.outerBounds.height > 0); |
| 416 assertBoundsConsistent(win); |
| 417 assertConstraintsUnspecified(win); |
| 418 win.close(); |
| 419 })); |
| 420 }, |
| 421 |
| 422 function testSizeOnly() { |
| 423 var outerBounds = { |
| 424 width: 500, |
| 425 height: 400 |
| 426 }; |
| 427 chrome.app.window.create('test.html', { |
| 428 outerBounds: outerBounds |
| 429 }, callbackPass(function(win) { |
| 430 chrome.test.assertTrue(win != null); |
| 431 chrome.test.assertEq(outerBounds.width, win.outerBounds.width); |
| 432 chrome.test.assertEq(outerBounds.height, win.outerBounds.height); |
| 433 assertBoundsConsistent(win); |
| 434 assertConstraintsUnspecified(win); |
| 435 win.close(); |
| 436 })); |
| 437 }, |
| 438 |
| 439 function testConflictingProperties() { |
| 440 testConflictingBoundsProperty("width"); |
| 441 testConflictingBoundsProperty("height"); |
| 442 testConflictingBoundsProperty("left"); |
| 443 testConflictingBoundsProperty("top"); |
| 444 testConflictingBoundsProperty("minWidth"); |
| 445 testConflictingBoundsProperty("minHeight"); |
| 446 testConflictingBoundsProperty("maxWidth"); |
| 447 testConflictingBoundsProperty("maxHeight"); |
152 } | 448 } |
153 ]); | 449 ]); |
| 450 } |
| 451 |
| 452 function testInitialBoundsInStable() { |
| 453 chrome.test.runTests([ |
| 454 function testInnerBounds() { |
| 455 var innerBounds = { |
| 456 width: 600, |
| 457 height: 400 |
| 458 }; |
| 459 chrome.app.window.create('test.html', { |
| 460 innerBounds: innerBounds |
| 461 }, callbackFail('innerBounds and outerBounds are only available in'+ |
| 462 ' dev channel.') |
| 463 ); |
| 464 }, |
| 465 |
| 466 function testOuterBounds() { |
| 467 var outerBounds = { |
| 468 width: 600, |
| 469 height: 400 |
| 470 }; |
| 471 chrome.app.window.create('test.html', { |
| 472 outerBounds: outerBounds |
| 473 }, callbackFail('innerBounds and outerBounds are only available in'+ |
| 474 ' dev channel.') |
| 475 ); |
| 476 } |
| 477 ]); |
| 478 } |
| 479 |
| 480 function testInitialConstraints() { |
| 481 chrome.test.runTests([ |
| 482 function testMaxInnerConstraints() { |
| 483 var innerBounds = { |
| 484 width: 800, |
| 485 height: 600, |
| 486 maxWidth: 500, |
| 487 maxHeight: 400 |
| 488 }; |
| 489 chrome.app.window.create('test.html', { |
| 490 innerBounds: innerBounds |
| 491 }, callbackPass(function(win) { |
| 492 chrome.test.assertTrue(win != null); |
| 493 chrome.test.assertEq(innerBounds.maxWidth, win.innerBounds.width); |
| 494 chrome.test.assertEq(innerBounds.maxHeight, win.innerBounds.height); |
| 495 chrome.test.assertEq(innerBounds.maxWidth, win.innerBounds.maxWidth); |
| 496 chrome.test.assertEq(innerBounds.maxHeight, win.innerBounds.maxHeight); |
| 497 assertBoundsConsistent(win); |
| 498 win.close(); |
| 499 })); |
| 500 }, |
| 501 |
| 502 function testMinInnerConstraints() { |
| 503 var innerBounds = { |
| 504 width: 100, |
| 505 height: 100, |
| 506 minWidth: 300, |
| 507 minHeight: 200 |
| 508 }; |
| 509 chrome.app.window.create('test.html', { |
| 510 innerBounds: innerBounds |
| 511 }, callbackPass(function(win) { |
| 512 chrome.test.assertTrue(win != null); |
| 513 chrome.test.assertEq(innerBounds.minWidth, win.innerBounds.width); |
| 514 chrome.test.assertEq(innerBounds.minHeight, win.innerBounds.height); |
| 515 chrome.test.assertEq(innerBounds.minWidth, win.innerBounds.minWidth); |
| 516 chrome.test.assertEq(innerBounds.minHeight, win.innerBounds.minHeight); |
| 517 assertBoundsConsistent(win); |
| 518 win.close(); |
| 519 })); |
| 520 }, |
| 521 |
| 522 function testMaxOuterConstraints() { |
| 523 var outerBounds = { |
| 524 width: 800, |
| 525 height: 600, |
| 526 maxWidth: 500, |
| 527 maxHeight: 400 |
| 528 }; |
| 529 chrome.app.window.create('test.html', { |
| 530 outerBounds: outerBounds |
| 531 }, callbackPass(function(win) { |
| 532 chrome.test.assertTrue(win != null); |
| 533 chrome.test.assertEq(outerBounds.maxWidth, win.outerBounds.width); |
| 534 chrome.test.assertEq(outerBounds.maxHeight, win.outerBounds.height); |
| 535 chrome.test.assertEq(outerBounds.maxWidth, win.outerBounds.maxWidth); |
| 536 chrome.test.assertEq(outerBounds.maxHeight, win.outerBounds.maxHeight); |
| 537 assertBoundsConsistent(win); |
| 538 win.close(); |
| 539 })); |
| 540 }, |
| 541 |
| 542 function testMinOuterConstraints() { |
| 543 var outerBounds = { |
| 544 width: 100, |
| 545 height: 100, |
| 546 minWidth: 300, |
| 547 minHeight: 200 |
| 548 }; |
| 549 chrome.app.window.create('test.html', { |
| 550 outerBounds: outerBounds |
| 551 }, callbackPass(function(win) { |
| 552 chrome.test.assertTrue(win != null); |
| 553 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.width); |
| 554 chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.height); |
| 555 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.minWidth); |
| 556 chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.minHeight); |
| 557 assertBoundsConsistent(win); |
| 558 win.close(); |
| 559 })); |
| 560 }, |
| 561 |
| 562 function testMixedConstraints() { |
| 563 var innerBounds = { |
| 564 width: 100, |
| 565 minHeight: 300 |
| 566 }; |
| 567 var outerBounds = { |
| 568 height: 100, |
| 569 minWidth: 400, |
| 570 }; |
| 571 chrome.app.window.create('test.html', { |
| 572 innerBounds: innerBounds, |
| 573 outerBounds: outerBounds |
| 574 }, callbackPass(function(win) { |
| 575 chrome.test.assertTrue(win != null); |
| 576 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.width); |
| 577 chrome.test.assertEq(innerBounds.minHeight, win.innerBounds.height); |
| 578 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.minWidth); |
| 579 chrome.test.assertEq(innerBounds.minHeight, win.innerBounds.minHeight); |
| 580 assertBoundsConsistent(win); |
| 581 win.close(); |
| 582 })); |
| 583 }, |
| 584 |
| 585 function testBadConstraints() { |
| 586 var outerBounds = { |
| 587 width: 500, |
| 588 height: 400, |
| 589 minWidth: 800, |
| 590 minHeight: 700, |
| 591 maxWidth: 300, |
| 592 maxHeight: 200 |
| 593 }; |
| 594 chrome.app.window.create('test.html', { |
| 595 outerBounds: outerBounds |
| 596 }, callbackPass(function(win) { |
| 597 chrome.test.assertTrue(win != null); |
| 598 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.width); |
| 599 chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.height); |
| 600 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.minWidth); |
| 601 chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.minHeight); |
| 602 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.maxWidth); |
| 603 chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.maxHeight); |
| 604 assertBoundsConsistent(win); |
| 605 win.close(); |
| 606 })); |
| 607 }, |
| 608 |
| 609 function testFrameless() { |
| 610 var outerBounds = { |
| 611 minWidth: 50, |
| 612 minHeight: 50, |
| 613 maxWidth: 800, |
| 614 maxHeight: 800 |
| 615 }; |
| 616 chrome.app.window.create('test.html', { |
| 617 outerBounds: outerBounds, |
| 618 frame: 'none' |
| 619 }, callbackPass(function(win) { |
| 620 chrome.test.assertTrue(win != null); |
| 621 chrome.test.assertEq(outerBounds.minWidth, win.outerBounds.minWidth); |
| 622 chrome.test.assertEq(outerBounds.minHeight, win.outerBounds.minHeight); |
| 623 chrome.test.assertEq(outerBounds.maxWidth, win.outerBounds.maxWidth); |
| 624 chrome.test.assertEq(outerBounds.maxHeight, win.outerBounds.maxHeight); |
| 625 chrome.test.assertEq(outerBounds.minWidth, win.innerBounds.minWidth); |
| 626 chrome.test.assertEq(outerBounds.minHeight, win.innerBounds.minHeight); |
| 627 chrome.test.assertEq(outerBounds.maxWidth, win.innerBounds.maxWidth); |
| 628 chrome.test.assertEq(outerBounds.maxHeight, win.innerBounds.maxHeight); |
| 629 win.close(); |
| 630 })); |
| 631 } |
| 632 ]); |
154 } | 633 } |
155 | 634 |
156 function testSingleton() { | 635 function testSingleton() { |
157 chrome.test.runTests([ | 636 chrome.test.runTests([ |
158 function noParameterWithId() { | 637 function noParameterWithId() { |
159 chrome.app.window.create( | 638 chrome.app.window.create( |
160 'test.html', { id: 'singleton-id' }, | 639 'test.html', { id: 'singleton-id' }, |
161 callbackPass(function(win) { | 640 callbackPass(function(win) { |
162 var w = win.contentWindow; | 641 var w = win.contentWindow; |
163 | 642 |
164 chrome.app.window.create( | 643 chrome.app.window.create( |
165 'test.html', { id: 'singleton-id' }, | 644 'test.html', { id: 'singleton-id' }, |
166 callbackPass(function(win) { | 645 callbackPass(function(win) { |
167 var w2 = win.contentWindow; | 646 var w2 = win.contentWindow; |
168 chrome.test.assertTrue(w === w2); | 647 chrome.test.assertTrue(w === w2); |
169 | 648 |
170 w.close(); | 649 w.close(); |
171 w2.close(); | 650 w2.close(); |
172 }) | 651 }) |
173 ); | 652 ); |
174 }) | 653 }) |
175 ); | 654 ); |
176 }, | 655 }, |
177 ]); | 656 ]); |
178 } | 657 } |
179 | 658 |
180 function testBounds() { | |
181 chrome.test.runTests([ | |
182 function simpleSetBounds() { | |
183 chrome.app.window.create('test.html', | |
184 { bounds: { width: 250, height: 200 } }, callbackPass(function(win) { | |
185 var b = win.getBounds(); | |
186 win.setBounds({width: 400, height: 450}) | |
187 // Listen to onresize here rather than win.onBoundsChanged, because | |
188 // onBoundsChanged is fired before the web contents are resized. | |
189 win.contentWindow.onresize = callbackPass(function() { | |
190 assertFuzzyEq(400, win.contentWindow.innerWidth, defaultFuzzFactor); | |
191 assertFuzzyEq(450, win.contentWindow.innerHeight, defaultFuzzFactor); | |
192 win.close(); | |
193 }); | |
194 })); | |
195 }, | |
196 | |
197 function heightOnlySetBounds() { | |
198 chrome.app.window.create('test.html', { | |
199 bounds: { width: 512, height: 256 } | |
200 }, callbackPass(function(win) { | |
201 win.setBounds({ height: 512 }); | |
202 win.contentWindow.onresize = callbackPass(function() { | |
203 assertFuzzyEq(512, win.contentWindow.innerHeight, defaultFuzzFactor); | |
204 win.close(); | |
205 }); | |
206 })); | |
207 }, | |
208 ]); | |
209 } | |
210 | |
211 function testCloseEvent() { | 659 function testCloseEvent() { |
212 chrome.test.runTests([ | 660 chrome.test.runTests([ |
213 function basic() { | 661 function basic() { |
214 chrome.app.window.create('test.html', callbackPass(function(win) { | 662 chrome.app.window.create('test.html', callbackPass(function(win) { |
215 win.onClosed.addListener(callbackPass(function() { | 663 win.onClosed.addListener(callbackPass(function() { |
216 // Mission accomplished. | 664 // Mission accomplished. |
217 })); | 665 })); |
218 win.contentWindow.close(); | 666 win.contentWindow.close(); |
219 })); | 667 })); |
220 } | 668 } |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 callbackFail('frameOptions is only available in dev channel.')); | 1122 callbackFail('frameOptions is only available in dev channel.')); |
675 } | 1123 } |
676 ]); | 1124 ]); |
677 } | 1125 } |
678 | 1126 |
679 chrome.app.runtime.onLaunched.addListener(function() { | 1127 chrome.app.runtime.onLaunched.addListener(function() { |
680 chrome.test.sendMessage('Launched', function(reply) { | 1128 chrome.test.sendMessage('Launched', function(reply) { |
681 window[reply](); | 1129 window[reply](); |
682 }); | 1130 }); |
683 }); | 1131 }); |
OLD | NEW |