Index: chrome/test/data/extensions/api_test/automation/tests/desktop/selection.js |
diff --git a/chrome/test/data/extensions/api_test/automation/tests/desktop/selection.js b/chrome/test/data/extensions/api_test/automation/tests/desktop/selection.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..83c9997598a934bfefe04c992f9ffd83d6ea9b79 |
--- /dev/null |
+++ b/chrome/test/data/extensions/api_test/automation/tests/desktop/selection.js |
@@ -0,0 +1,63 @@ |
+// 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 selectOutsideTextField() { |
+ runWithDocument(html, function(document) { |
+ var textNode = document.find({role: RoleType.paragraph}).firstChild; |
+ assertTrue(!!textNode); |
+ chrome.automation.setSelection(textNode, 0, textNode, 3); |
+ listenOnce(document, EventType.textSelectionChanged, function(evt) { |
+ assertEq(textNode, document.anchorObject); |
+ assertEq(0, document.anchorOffset); |
+ assertEq(textNode, document.focusObject); |
+ assertEq(3, document.focusOffset); |
+ chrome.test.succeed(); |
+ }); |
+ }); |
+ }, |
+ |
+ function selectInTextField() { |
+ runWithDocument(html, function(document) { |
+ var textField = document.find({role: RoleType.textField}); |
+ assertTrue(!!textField); |
David Tseng
2015/09/23 17:57:41
nit: assertNotNullNorUndefined
|
+ textField.focus(); |
+ listenOnce(document, EventType.textSelectionChanged, function() { |
David Tseng
2015/09/23 17:57:42
Can you verify the event param's target as you exp
|
+ assertEq(textField, document.anchorObject); |
+ assertEq(0, document.anchorOffset); |
+ assertEq(textField, document.focusObject); |
+ assertEq(0, document.focusOffset); |
+ // Wait for another text selection change event. There's one for |
David Tseng
2015/09/23 17:57:41
Is this potentially flakey?
|
+ // the document root and one for the text field. |
+ listenOnce(document, EventType.textSelectionChanged, function() { |
David Tseng
2015/09/23 17:57:42
Ditto; vierfy event target.
|
+ chrome.automation.setSelection(textField, 1, textField, 3); |
+ listenOnce(document, EventType.textSelectionChanged, function(evt) { |
David Tseng
2015/09/23 17:57:42
Ditto.
|
+ assertEq(textField, document.anchorObject); |
+ assertEq(1, document.anchorOffset); |
+ assertEq(textField, document.focusObject); |
+ assertEq(3, document.focusOffset); |
+ chrome.test.succeed(); |
+ }); |
+ }); |
+ }); |
+ }); |
+ }, |
+ |
+ function testInitialSelectionNotSet() { |
+ runWithDocument(html, function(document) { |
David Tseng
2015/09/23 17:57:42
document here as a param looks pretty weird since
|
+ assertEq(undefined, document.anchorrObject); |
David Tseng
2015/09/23 17:57:41
Typo? s/anchorr/anchor
|
+ assertEq(undefined, document.anchorOffset); |
+ assertEq(undefined, document.focusObject); |
+ assertEq(undefined, document.focusOffset); |
+ chrome.test.succeed(); |
+ }); |
+ } |
+]; |
+ |
+setupAndRunTests(allTests); |