Index: chrome/test/data/extensions/api_test/automation/tests/tabs/document_selection.js |
diff --git a/chrome/test/data/extensions/api_test/automation/tests/tabs/document_selection.js b/chrome/test/data/extensions/api_test/automation/tests/tabs/document_selection.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e049050b128a69be9a6c1f6db00724f608ff29b5 |
--- /dev/null |
+++ b/chrome/test/data/extensions/api_test/automation/tests/tabs/document_selection.js |
@@ -0,0 +1,66 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+var EventType = chrome.automation.EventType; |
+var RoleType = chrome.automation.RoleType; |
+var html = "<head><title>testdoc</title></head>" + |
+ '<p>para1</p><input type="text" id="textField" value="hello world">'; |
+ |
+var allTests = [ |
+ function testInitialSelectionNotSet() { |
+ assertEq(undefined, rootNode.anchorObject); |
+ assertEq(undefined, rootNode.anchorOffset); |
+ assertEq(undefined, rootNode.focusObject); |
+ assertEq(undefined, rootNode.focusOffset); |
+ chrome.test.succeed(); |
+ }, |
+ |
+ function selectOutsideTextField() { |
+ var textNode = rootNode.find({role: RoleType.paragraph}).firstChild; |
+ assertTrue(!!textNode); |
+ chrome.automation.setDocumentSelection({anchorObject: textNode, |
+ anchorOffset: 0, |
+ focusObject: textNode, |
+ focusOffset: 3}); |
+ listenOnce(rootNode, EventType.textSelectionChanged, function(evt) { |
+ assertEq(textNode, rootNode.anchorObject); |
+ assertEq(0, rootNode.anchorOffset); |
+ assertEq(textNode, rootNode.focusObject); |
+ assertEq(3, rootNode.focusOffset); |
+ chrome.test.succeed(); |
+ }); |
+ }, |
+ |
+ function selectInTextField() { |
+ var textField = rootNode.find({role: RoleType.textField}); |
+ assertTrue(!!textField); |
+ textField.focus(); |
+ listenOnce(rootNode, EventType.textSelectionChanged, function(evt) { |
+ assertTrue(evt.target === rootNode || evt.target === textField); |
+ assertEq(textField, rootNode.anchorObject); |
+ assertEq(0, rootNode.anchorOffset); |
+ assertEq(textField, rootNode.focusObject); |
+ assertEq(0, rootNode.focusOffset); |
+ // Wait for another text selection change event. There's one for |
+ // the document root and one for the text field. |
+ listenOnce(rootNode, EventType.textSelectionChanged, function() { |
+ assertTrue(evt.target === rootNode || evt.target === textField); |
+ assertTrue(evt.target === rootNode || evt.target === textField); |
+ chrome.automation.setDocumentSelection({anchorObject: textField, |
+ anchorOffset: 1, |
+ focusObject: textField, |
+ focusOffset: 3}); |
+ listenOnce(rootNode, EventType.textSelectionChanged, function(evt) { |
+ assertEq(textField, rootNode.anchorObject); |
+ assertEq(1, rootNode.anchorOffset); |
+ assertEq(textField, rootNode.focusObject); |
+ assertEq(3, rootNode.focusOffset); |
+ chrome.test.succeed(); |
+ }); |
+ }); |
+ }); |
+ }, |
+]; |
+ |
+setUpAndRunTests(allTests, 'document_selection.html'); |