Chromium Code Reviews| Index: chrome/test/data/extensions/platform_apps/windows_api_bounds/main.js |
| diff --git a/chrome/test/data/extensions/platform_apps/windows_api_bounds/main.js b/chrome/test/data/extensions/platform_apps/windows_api_bounds/main.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c69beb88f306ab5a98f1f94b9bc611c0dc4bd054 |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/platform_apps/windows_api_bounds/main.js |
| @@ -0,0 +1,35 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +function closeEnough(actual, expected, maxAllowedDifference) { |
| + return Math.abs(actual - expected) < maxAllowedDifference; |
| +} |
| + |
| +function waitForBounds(expectedBounds, callback) { |
| + function checkBounds() { |
| + var bounds = chrome.app.window.current().getBounds(); |
| + if (closeEnough(bounds.left, expectedBounds.left, slop) && |
| + closeEnough(bounds.top, expectedBounds.top, slop) && |
| + closeEnough(bounds.width, expectedBounds.width, slop) && |
| + closeEnough(bounds.height, expectedBounds.height, slop)) { |
| + callback(); |
| + } else { |
| + 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.
|
| + } |
| + } |
| + checkBounds(); |
| +} |
| + |
| +var slop = 0; |
| + |
| +chrome.test.sendMessage("ready", function(response) { |
| + slop = parseInt(response); |
| + waitForBounds({left:100, top:200, width:300, height:400}, function() { |
| + var newBounds = {left:50, top:100, width:150, height:200}; |
| + chrome.app.window.current().setBounds(newBounds); |
| + waitForBounds(newBounds, function(){ |
| + chrome.test.sendMessage("success"); |
| + }); |
| + }); |
| +}); |