| 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 testInitialSelectionNotSet() { |
| 12 assertEq(undefined, rootNode.anchorObject); |
| 13 assertEq(undefined, rootNode.anchorOffset); |
| 14 assertEq(undefined, rootNode.focusObject); |
| 15 assertEq(undefined, rootNode.focusOffset); |
| 16 chrome.test.succeed(); |
| 17 }, |
| 18 |
| 19 function selectOutsideTextField() { |
| 20 var textNode = rootNode.find({role: RoleType.paragraph}).firstChild; |
| 21 assertTrue(!!textNode); |
| 22 chrome.automation.setDocumentSelection(textNode, 0, textNode, 3); |
| 23 listenOnce(rootNode, EventType.textSelectionChanged, function(evt) { |
| 24 assertEq(textNode, rootNode.anchorObject); |
| 25 assertEq(0, rootNode.anchorOffset); |
| 26 assertEq(textNode, rootNode.focusObject); |
| 27 assertEq(3, rootNode.focusOffset); |
| 28 chrome.test.succeed(); |
| 29 }); |
| 30 }, |
| 31 |
| 32 function selectInTextField() { |
| 33 var textField = rootNode.find({role: RoleType.textField}); |
| 34 assertTrue(!!textField); |
| 35 textField.focus(); |
| 36 listenOnce(rootNode, EventType.textSelectionChanged, function(evt) { |
| 37 assertTrue(evt.target === rootNode || evt.target === textField); |
| 38 assertEq(textField, rootNode.anchorObject); |
| 39 assertEq(0, rootNode.anchorOffset); |
| 40 assertEq(textField, rootNode.focusObject); |
| 41 assertEq(0, rootNode.focusOffset); |
| 42 // Wait for another text selection change event. There's one for |
| 43 // the document root and one for the text field. |
| 44 listenOnce(rootNode, EventType.textSelectionChanged, function() { |
| 45 assertTrue(evt.target === rootNode || evt.target === textField); |
| 46 assertTrue(evt.target === rootNode || evt.target === textField); |
| 47 chrome.automation.setDocumentSelection(textField, 1, textField, 3); |
| 48 listenOnce(rootNode, EventType.textSelectionChanged, function(evt) { |
| 49 assertEq(textField, rootNode.anchorObject); |
| 50 assertEq(1, rootNode.anchorOffset); |
| 51 assertEq(textField, rootNode.focusObject); |
| 52 assertEq(3, rootNode.focusOffset); |
| 53 chrome.test.succeed(); |
| 54 }); |
| 55 }); |
| 56 }); |
| 57 }, |
| 58 ]; |
| 59 |
| 60 setUpAndRunTests(allTests, 'document_selection.html'); |
| OLD | NEW |