| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 allTests = [ | 5 var allTests = [ |
| 6 function testHitTestInDesktop() { | 6 function testHitTestInDesktop() { |
| 7 var url = 'data:text/html,<!doctype html>' + | 7 var url = 'data:text/html,<!doctype html>' + |
| 8 encodeURI('<button>Click Me</button>'); | 8 encodeURI('<button>Click Me</button>'); |
| 9 var didHitTest = false; | 9 var didHitTest = false; |
| 10 chrome.automation.getDesktop(function(desktop) { | 10 chrome.automation.getDesktop(function(desktop) { |
| 11 chrome.tabs.create({url: url}); | 11 chrome.tabs.create({url: url}); |
| 12 | 12 |
| 13 desktop.addEventListener('loadComplete', function(event) { | 13 desktop.addEventListener('loadComplete', function(event) { |
| 14 if (didHitTest) | 14 if (didHitTest) |
| 15 return; | 15 return; |
| 16 if (event.target.url.indexOf('data:') >= 0) { | 16 if (event.target.url.indexOf('data:') >= 0) { |
| 17 var button = desktop.find({ attributes: { name: 'Click Me' } }); | 17 var button = desktop.find({ attributes: { name: 'Click Me' } }); |
| 18 if (button) { | 18 if (button) { |
| 19 didHitTest = true; | 19 didHitTest = true; |
| 20 button.addEventListener(EventType.ALERT, function() { | 20 button.addEventListener(EventType.ALERT, function() { |
| 21 chrome.test.succeed(); | 21 chrome.test.succeed(); |
| 22 }, true); | 22 }, true); |
| 23 var cx = Math.floor( | 23 var cx = button.location.left + button.location.width / 2; |
| 24 button.location.left + button.location.width / 2); | 24 var cy = button.location.top + button.location.height / 2; |
| 25 var cy = Math.floor( | |
| 26 button.location.top + button.location.height / 2); | |
| 27 desktop.hitTest(cx, cy, EventType.ALERT); | 25 desktop.hitTest(cx, cy, EventType.ALERT); |
| 28 } | 26 } |
| 29 } | 27 } |
| 30 }, false); | 28 }, false); |
| 31 }); | 29 }); |
| 32 }, | 30 }, |
| 33 ]; | 31 ]; |
| 34 | 32 |
| 35 chrome.test.runTests(allTests); | 33 chrome.test.runTests(allTests); |
| OLD | NEW |