| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 EventType = chrome.automation.EventType; | 5 var EventType = chrome.automation.EventType; |
| 6 var RoleType = chrome.automation.RoleType; | 6 var RoleType = chrome.automation.RoleType; |
| 7 var html = "<head><title>testdoc</title></head>" + | 7 var html = "<head><title>testdoc</title></head>" + |
| 8 '<p>para1</p><input type="text" id="textField" value="hello world">'; | 8 '<p>para1</p><input type="text" id="textField" value="hello world">'; |
| 9 | 9 |
| 10 var allTests = [ | 10 var allTests = [ |
| 11 function testInitialSelectionNotSet() { | 11 function testInitialSelectionNotSet() { |
| 12 assertEq(undefined, rootNode.anchorObject); | 12 assertEq(undefined, rootNode.anchorObject); |
| 13 assertEq(undefined, rootNode.anchorOffset); | 13 assertEq(undefined, rootNode.anchorOffset); |
| 14 assertEq(undefined, rootNode.focusObject); | 14 assertEq(undefined, rootNode.focusObject); |
| 15 assertEq(undefined, rootNode.focusOffset); | 15 assertEq(undefined, rootNode.focusOffset); |
| 16 chrome.test.succeed(); | 16 chrome.test.succeed(); |
| 17 }, | 17 }, |
| 18 | 18 |
| 19 function selectOutsideTextField() { | 19 function selectOutsideTextField() { |
| 20 var textNode = rootNode.find({role: RoleType.PARAGRAPH}).firstChild; | 20 var textNode = rootNode.find({role: RoleType.paragraph}).firstChild; |
| 21 assertTrue(!!textNode); | 21 assertTrue(!!textNode); |
| 22 chrome.automation.setDocumentSelection({anchorObject: textNode, | 22 chrome.automation.setDocumentSelection({anchorObject: textNode, |
| 23 anchorOffset: 0, | 23 anchorOffset: 0, |
| 24 focusObject: textNode, | 24 focusObject: textNode, |
| 25 focusOffset: 3}); | 25 focusOffset: 3}); |
| 26 listenOnce(rootNode, EventType.DOCUMENT_SELECTION_CHANGED, function(evt) { | 26 listenOnce(rootNode, EventType.documentSelectionChanged, function(evt) { |
| 27 assertEq(textNode, rootNode.anchorObject); | 27 assertEq(textNode, rootNode.anchorObject); |
| 28 assertEq(0, rootNode.anchorOffset); | 28 assertEq(0, rootNode.anchorOffset); |
| 29 assertEq(textNode, rootNode.focusObject); | 29 assertEq(textNode, rootNode.focusObject); |
| 30 assertEq(3, rootNode.focusOffset); | 30 assertEq(3, rootNode.focusOffset); |
| 31 chrome.test.succeed(); | 31 chrome.test.succeed(); |
| 32 }); | 32 }); |
| 33 }, | 33 }, |
| 34 | 34 |
| 35 function selectInTextField() { | 35 function selectInTextField() { |
| 36 var textField = rootNode.find({role: RoleType.TEXT_FIELD}); | 36 var textField = rootNode.find({role: RoleType.textField}); |
| 37 assertTrue(!!textField); | 37 assertTrue(!!textField); |
| 38 textField.focus(); | 38 textField.focus(); |
| 39 listenOnce(textField, EventType.TEXT_SELECTION_CHANGED, function(evt) { | 39 listenOnce(textField, EventType.textSelectionChanged, function(evt) { |
| 40 listenOnce(rootNode, EventType.DOCUMENT_SELECTION_CHANGED, function(evt) { | 40 listenOnce(rootNode, EventType.documentSelectionChanged, function(evt) { |
| 41 assertTrue(evt.target === rootNode); | 41 assertTrue(evt.target === rootNode); |
| 42 assertEq(textField, rootNode.anchorObject); | 42 assertEq(textField, rootNode.anchorObject); |
| 43 assertEq(0, rootNode.anchorOffset); | 43 assertEq(0, rootNode.anchorOffset); |
| 44 assertEq(textField, rootNode.focusObject); | 44 assertEq(textField, rootNode.focusObject); |
| 45 assertEq(0, rootNode.focusOffset); | 45 assertEq(0, rootNode.focusOffset); |
| 46 chrome.automation.setDocumentSelection({anchorObject: textField, | 46 chrome.automation.setDocumentSelection({anchorObject: textField, |
| 47 anchorOffset: 1, | 47 anchorOffset: 1, |
| 48 focusObject: textField, | 48 focusObject: textField, |
| 49 focusOffset: 3}); | 49 focusOffset: 3}); |
| 50 listenOnce(rootNode, EventType.DOCUMENT_SELECTION_CHANGED, | 50 listenOnce(rootNode, EventType.documentSelectionChanged, |
| 51 function(evt) { | 51 function(evt) { |
| 52 assertEq(textField, rootNode.anchorObject); | 52 assertEq(textField, rootNode.anchorObject); |
| 53 assertEq(1, rootNode.anchorOffset); | 53 assertEq(1, rootNode.anchorOffset); |
| 54 assertEq(textField, rootNode.focusObject); | 54 assertEq(textField, rootNode.focusObject); |
| 55 assertEq(3, rootNode.focusOffset); | 55 assertEq(3, rootNode.focusOffset); |
| 56 chrome.test.succeed(); | 56 chrome.test.succeed(); |
| 57 }); | 57 }); |
| 58 }); | 58 }); |
| 59 }); | 59 }); |
| 60 }, | 60 }, |
| 61 ]; | 61 ]; |
| 62 | 62 |
| 63 setUpAndRunTests(allTests, 'document_selection.html'); | 63 setUpAndRunTests(allTests, 'document_selection.html'); |
| OLD | NEW |