OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 EventType = chrome.automation.EventType; | |
6 var RoleType = chrome.automation.RoleType; | |
7 var html = "<head><title>testdoc</title></head>" + | |
8 '<p>para1</p><input type="text" id="textField" value="hello world">'; | |
9 | |
10 var allTests = [ | |
11 function selectOutsideTextField() { | |
12 runWithDocument(html, function(document) { | |
13 var textNode = document.find({role: RoleType.paragraph}).firstChild; | |
14 assertTrue(!!textNode); | |
15 chrome.automation.setSelection(textNode, 0, textNode, 3); | |
16 listenOnce(document, EventType.textSelectionChanged, function(evt) { | |
17 assertEq(textNode, document.anchorObject); | |
18 assertEq(0, document.anchorOffset); | |
19 assertEq(textNode, document.focusObject); | |
20 assertEq(3, document.focusOffset); | |
21 chrome.test.succeed(); | |
22 }); | |
23 }); | |
24 }, | |
25 | |
26 function selectInTextField() { | |
27 runWithDocument(html, function(document) { | |
28 var textField = document.find({role: RoleType.textField}); | |
29 assertTrue(!!textField); | |
David Tseng
2015/09/23 17:57:41
nit: assertNotNullNorUndefined
| |
30 textField.focus(); | |
31 listenOnce(document, EventType.textSelectionChanged, function() { | |
David Tseng
2015/09/23 17:57:42
Can you verify the event param's target as you exp
| |
32 assertEq(textField, document.anchorObject); | |
33 assertEq(0, document.anchorOffset); | |
34 assertEq(textField, document.focusObject); | |
35 assertEq(0, document.focusOffset); | |
36 // Wait for another text selection change event. There's one for | |
David Tseng
2015/09/23 17:57:41
Is this potentially flakey?
| |
37 // the document root and one for the text field. | |
38 listenOnce(document, EventType.textSelectionChanged, function() { | |
David Tseng
2015/09/23 17:57:42
Ditto; vierfy event target.
| |
39 chrome.automation.setSelection(textField, 1, textField, 3); | |
40 listenOnce(document, EventType.textSelectionChanged, function(evt) { | |
David Tseng
2015/09/23 17:57:42
Ditto.
| |
41 assertEq(textField, document.anchorObject); | |
42 assertEq(1, document.anchorOffset); | |
43 assertEq(textField, document.focusObject); | |
44 assertEq(3, document.focusOffset); | |
45 chrome.test.succeed(); | |
46 }); | |
47 }); | |
48 }); | |
49 }); | |
50 }, | |
51 | |
52 function testInitialSelectionNotSet() { | |
53 runWithDocument(html, function(document) { | |
David Tseng
2015/09/23 17:57:42
document here as a param looks pretty weird since
| |
54 assertEq(undefined, document.anchorrObject); | |
David Tseng
2015/09/23 17:57:41
Typo? s/anchorr/anchor
| |
55 assertEq(undefined, document.anchorOffset); | |
56 assertEq(undefined, document.focusObject); | |
57 assertEq(undefined, document.focusOffset); | |
58 chrome.test.succeed(); | |
59 }); | |
60 } | |
61 ]; | |
62 | |
63 setupAndRunTests(allTests); | |
OLD | NEW |