OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 class AndroidGranularityMovementBrowserTest : public ContentBrowserTest { | 33 class AndroidGranularityMovementBrowserTest : public ContentBrowserTest { |
34 public: | 34 public: |
35 AndroidGranularityMovementBrowserTest() {} | 35 AndroidGranularityMovementBrowserTest() {} |
36 ~AndroidGranularityMovementBrowserTest() override {} | 36 ~AndroidGranularityMovementBrowserTest() override {} |
37 | 37 |
38 BrowserAccessibility* LoadUrlAndGetAccessibilityRoot(const GURL& url) { | 38 BrowserAccessibility* LoadUrlAndGetAccessibilityRoot(const GURL& url) { |
39 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 39 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
40 | 40 |
41 // Load the page. | 41 // Load the page. |
42 AccessibilityNotificationWaiter waiter( | 42 AccessibilityNotificationWaiter waiter(shell()->web_contents(), |
43 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, | 43 kAccessibilityModeComplete, |
44 ui::AX_EVENT_LOAD_COMPLETE); | 44 ui::AX_EVENT_LOAD_COMPLETE); |
45 NavigateToURL(shell(), url); | 45 NavigateToURL(shell(), url); |
46 waiter.WaitForNotification(); | 46 waiter.WaitForNotification(); |
47 | 47 |
48 // Get the BrowserAccessibilityManager. | 48 // Get the BrowserAccessibilityManager. |
49 WebContentsImpl* web_contents = | 49 WebContentsImpl* web_contents = |
50 static_cast<WebContentsImpl*>(shell()->web_contents()); | 50 static_cast<WebContentsImpl*>(shell()->web_contents()); |
51 return web_contents->GetRootBrowserAccessibilityManager()->GetRoot(); | 51 return web_contents->GetRootBrowserAccessibilityManager()->GetRoot(); |
52 } | 52 } |
53 | 53 |
54 // First, set accessibility focus to a node and wait for the update that | 54 // First, set accessibility focus to a node and wait for the update that |
55 // loads inline text boxes for that node. (We load inline text boxes | 55 // loads inline text boxes for that node. (We load inline text boxes |
56 // asynchronously on Android since we only ever need them for the node | 56 // asynchronously on Android since we only ever need them for the node |
57 // with accessibility focus.) | 57 // with accessibility focus.) |
58 // | 58 // |
59 // Then call NextAtGranularity repeatedly and return a string that | 59 // Then call NextAtGranularity repeatedly and return a string that |
60 // concatenates all of the text of the returned text ranges. | 60 // concatenates all of the text of the returned text ranges. |
61 // | 61 // |
62 // As an example, if the node's text is "cat dog" and you traverse by | 62 // As an example, if the node's text is "cat dog" and you traverse by |
63 // word, this returns "'cat', 'dog'". | 63 // word, this returns "'cat', 'dog'". |
64 // | 64 // |
65 // Also calls PreviousAtGranularity from the end back to the beginning | 65 // Also calls PreviousAtGranularity from the end back to the beginning |
66 // and fails (by logging an error and returning the empty string) if | 66 // and fails (by logging an error and returning the empty string) if |
67 // the result when traversing backwards is not the same | 67 // the result when traversing backwards is not the same |
68 // (but in reverse order). | 68 // (but in reverse order). |
69 base::string16 TraverseNodeAtGranularity( | 69 base::string16 TraverseNodeAtGranularity( |
70 BrowserAccessibility* node, | 70 BrowserAccessibility* node, |
71 int granularity) { | 71 int granularity) { |
72 AccessibilityNotificationWaiter waiter( | 72 AccessibilityNotificationWaiter waiter(shell()->web_contents(), |
73 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, | 73 kAccessibilityModeComplete, |
74 ui::AX_EVENT_TREE_CHANGED); | 74 ui::AX_EVENT_TREE_CHANGED); |
75 node->manager()->SetAccessibilityFocus(*node); | 75 node->manager()->SetAccessibilityFocus(*node); |
76 waiter.WaitForNotification(); | 76 waiter.WaitForNotification(); |
77 | 77 |
78 int start_index = -1; | 78 int start_index = -1; |
79 int end_index = -1; | 79 int end_index = -1; |
80 BrowserAccessibilityAndroid* android_node = | 80 BrowserAccessibilityAndroid* android_node = |
81 static_cast<BrowserAccessibilityAndroid*>(node); | 81 static_cast<BrowserAccessibilityAndroid*>(node); |
82 BrowserAccessibilityManagerAndroid* manager = | 82 BrowserAccessibilityManagerAndroid* manager = |
83 static_cast<BrowserAccessibilityManagerAndroid*>(node->manager()); | 83 static_cast<BrowserAccessibilityManagerAndroid*>(node->manager()); |
84 base::string16 text = android_node->GetText(); | 84 base::string16 text = android_node->GetText(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 BrowserAccessibility* root = LoadUrlAndGetAccessibilityRoot(url); | 205 BrowserAccessibility* root = LoadUrlAndGetAccessibilityRoot(url); |
206 ASSERT_EQ(1U, root->PlatformChildCount()); | 206 ASSERT_EQ(1U, root->PlatformChildCount()); |
207 BrowserAccessibility* pre = root->PlatformGetChild(0); | 207 BrowserAccessibility* pre = root->PlatformGetChild(0); |
208 ASSERT_EQ(0U, pre->PlatformChildCount()); | 208 ASSERT_EQ(0U, pre->PlatformChildCount()); |
209 | 209 |
210 ASSERT_EQ(base::ASCIIToUTF16("'One,', 'two,', 'three!'"), | 210 ASSERT_EQ(base::ASCIIToUTF16("'One,', 'two,', 'three!'"), |
211 TraverseNodeAtGranularity(pre, GRANULARITY_LINE)); | 211 TraverseNodeAtGranularity(pre, GRANULARITY_LINE)); |
212 } | 212 } |
213 | 213 |
214 } // namespace content | 214 } // namespace content |
OLD | NEW |