Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: chrome/test/data/extensions/api_test/automation/tests/tabs/document_selection.js

Issue 1365433002: Add setSelection function to automation API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nobrailleautostartintests
Patch Set: Change setDocumentSelection to take named arguments. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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({anchorObject: textNode,
23 anchorOffset: 0,
24 focusObject: textNode,
25 focusOffset: 3});
26 listenOnce(rootNode, EventType.textSelectionChanged, function(evt) {
27 assertEq(textNode, rootNode.anchorObject);
28 assertEq(0, rootNode.anchorOffset);
29 assertEq(textNode, rootNode.focusObject);
30 assertEq(3, rootNode.focusOffset);
31 chrome.test.succeed();
32 });
33 },
34
35 function selectInTextField() {
36 var textField = rootNode.find({role: RoleType.textField});
37 assertTrue(!!textField);
38 textField.focus();
39 listenOnce(rootNode, EventType.textSelectionChanged, function(evt) {
40 assertTrue(evt.target === rootNode || evt.target === textField);
41 assertEq(textField, rootNode.anchorObject);
42 assertEq(0, rootNode.anchorOffset);
43 assertEq(textField, rootNode.focusObject);
44 assertEq(0, rootNode.focusOffset);
45 // Wait for another text selection change event. There's one for
46 // the document root and one for the text field.
47 listenOnce(rootNode, EventType.textSelectionChanged, function() {
48 assertTrue(evt.target === rootNode || evt.target === textField);
49 assertTrue(evt.target === rootNode || evt.target === textField);
50 chrome.automation.setDocumentSelection({anchorObject: textField,
51 anchorOffset: 1,
52 focusObject: textField,
53 focusOffset: 3});
54 listenOnce(rootNode, EventType.textSelectionChanged, function(evt) {
55 assertEq(textField, rootNode.anchorObject);
56 assertEq(1, rootNode.anchorOffset);
57 assertEq(textField, rootNode.focusObject);
58 assertEq(3, rootNode.focusOffset);
59 chrome.test.succeed();
60 });
61 });
62 });
63 },
64 ];
65
66 setUpAndRunTests(allTests, 'document_selection.html');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698