Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/test/data/extensions/platform_apps/windows_api_bounds/main.js

Issue 11369039: Add setBounds method and browsertest for get/set bounds to app window API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 boundsEqual(b1, b2, slop) {
10 if (!b1 || !b2) {
11 console.error("boundsEqual: got null bounds");
12 window.close();
13 return false;
14 }
15 if (!slop)
16 slop = 0;
17 return (closeEnough(b1.left, b2.left, slop) &&
18 closeEnough(b1.top, b2.top, slop) &&
19 closeEnough(b1.width, b2.width, slop) &&
20 closeEnough(b1.height, b2.height, slop));
21 }
22
23 function waitForBounds(expectedBounds, callback) {
24 function checkBounds() {
25 var bounds = chrome.app.window.current().getBounds();
26 if (!bounds) {
27 console.error("getBounds returned null!");
28 window.close();
29 return;
30 }
31 if (boundsEqual(bounds, expectedBounds, slop)) {
32 callback();
33 } else {
34 // TODO(asargent) - change this to just listen for the bounds change event
35 // once that's supported.
36 setTimeout(checkBounds, 50);
37 }
38 }
39 checkBounds();
40 }
41
42 var slop = 0;
43
44 chrome.test.sendMessage("ready", function(response) {
45 slop = parseInt(response);
46 waitForBounds({left:100, top:200, width:300, height:400}, function() {
47 var newBounds = {left:50, top:100, width:150, height:200};
48 chrome.app.window.current().setBounds(newBounds);
49 waitForBounds(newBounds, function(){
50 chrome.test.sendMessage("success");
51 });
52 });
53 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698