OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 var assertTrue = chrome.test.assertTrue; |
| 6 |
| 7 var EventType = chrome.automation.EventType; |
| 8 |
| 9 // These tests are run with a device scale factor of 2.0, but all of the |
| 10 // coordinates we get from the automation API should be with no device |
| 11 // scale factor applied. |
| 12 // |
| 13 // Note that internally, the device scale factor is applied to web trees, |
| 14 // but not to the desktop tree, so we want to make sure that that's properly |
| 15 // taken into account when converting from relative coordinates to global |
| 16 // device-independent coordinates. |
| 17 var allTests = [ |
| 18 function testLocationInWebView() { |
| 19 rootNode.addEventListener(EventType.LOAD_COMPLETE, function() { |
| 20 var firstButton = rootNode.find({ attributes: { name: 'First' } }); |
| 21 var secondButton = rootNode.find({ attributes: { name: 'Second' } }); |
| 22 if (firstButton && secondButton) { |
| 23 var firstRect = firstButton.location; |
| 24 var secondRect = secondButton.location; |
| 25 |
| 26 // The first button should be at (50, 150) with a size of (200, 100). |
| 27 // Allow one pixel off for rounding errors. |
| 28 assertTrue(Math.abs(firstRect.left - 50) <= 1); |
| 29 assertTrue(Math.abs(firstRect.top - 150) <= 1); |
| 30 assertTrue(Math.abs(firstRect.width - 200) <= 1); |
| 31 assertTrue(Math.abs(firstRect.height - 100) <= 1); |
| 32 |
| 33 // The second button should be exactly 225 x 25 pixels offset from |
| 34 // the first button. |
| 35 assertTrue(Math.abs(secondRect.left - firstRect.left - 225) <= 1); |
| 36 assertTrue(Math.abs(secondRect.top - firstRect.top - 25) <= 1); |
| 37 assertTrue(Math.abs(secondRect.width - 200) <= 1); |
| 38 assertTrue(Math.abs(secondRect.height - 100) <= 1); |
| 39 chrome.test.succeed(); |
| 40 } |
| 41 }, false); |
| 42 |
| 43 chrome.app.window.create('buttons.html', { |
| 44 'innerBounds': { |
| 45 'left': 50, |
| 46 'top': 150, |
| 47 'width': 400, |
| 48 'height': 400 |
| 49 } |
| 50 }); |
| 51 } |
| 52 ]; |
| 53 |
| 54 chrome.automation.getDesktop(function(rootNodeArg) { |
| 55 window.rootNode = rootNodeArg; |
| 56 chrome.test.runTests(allTests); |
| 57 }); |
OLD | NEW |