Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 function closeEnough(actual, expected, maxAllowedDifference) { | |
| 6 return Math.abs(actual - expected) < maxAllowedDifference; | |
| 7 } | |
| 8 | |
| 9 function waitForBounds(expectedBounds, callback) { | |
| 10 function checkBounds() { | |
| 11 var bounds = chrome.app.window.current().getBounds(); | |
| 12 if (closeEnough(bounds.left, expectedBounds.left, slop) && | |
| 13 closeEnough(bounds.top, expectedBounds.top, slop) && | |
| 14 closeEnough(bounds.width, expectedBounds.width, slop) && | |
| 15 closeEnough(bounds.height, expectedBounds.height, slop)) { | |
| 16 callback(); | |
| 17 } else { | |
| 18 setTimeout(checkBounds, 50); | |
|
jeremya
2012/11/02 05:06:41
Can you add a TODO here to rewrite when bounds cha
asargent_no_longer_on_chrome
2012/11/09 20:25:35
Done.
| |
| 19 } | |
| 20 } | |
| 21 checkBounds(); | |
| 22 } | |
| 23 | |
| 24 var slop = 0; | |
| 25 | |
| 26 chrome.test.sendMessage("ready", function(response) { | |
| 27 slop = parseInt(response); | |
| 28 waitForBounds({left:100, top:200, width:300, height:400}, function() { | |
| 29 var newBounds = {left:50, top:100, width:150, height:200}; | |
| 30 chrome.app.window.current().setBounds(newBounds); | |
| 31 waitForBounds(newBounds, function(){ | |
| 32 chrome.test.sendMessage("success"); | |
| 33 }); | |
| 34 }); | |
| 35 }); | |
| OLD | NEW |