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

Side by Side Diff: content/browser/accessibility/browser_accessibility_win_unittest.cc

Issue 2864953002: Split out the MSCOM pieces of BrowserAccessibilityWin into a seperate class. (Closed)
Patch Set: follow up comment Created 3 years, 7 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/accessibility/browser_accessibility_win.h" 5 #include "content/browser/accessibility/browser_accessibility_win.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/win/scoped_bstr.h" 14 #include "base/win/scoped_bstr.h"
15 #include "base/win/scoped_comptr.h" 15 #include "base/win/scoped_comptr.h"
16 #include "base/win/scoped_variant.h" 16 #include "base/win/scoped_variant.h"
17 #include "content/browser/accessibility/browser_accessibility_manager.h" 17 #include "content/browser/accessibility/browser_accessibility_manager.h"
18 #include "content/browser/accessibility/browser_accessibility_manager_win.h" 18 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
19 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 19 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
20 #include "content/browser/renderer_host/legacy_render_widget_host_win.h" 20 #include "content/browser/renderer_host/legacy_render_widget_host_win.h"
21 #include "content/common/accessibility_messages.h" 21 #include "content/common/accessibility_messages.h"
22 #include "content/public/test/test_browser_thread_bundle.h" 22 #include "content/public/test/test_browser_thread_bundle.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 #include "ui/base/win/atl_module.h" 24 #include "ui/base/win/atl_module.h"
25 25
26 namespace content { 26 namespace content {
27 namespace {
28
29
30 // CountedBrowserAccessibility ------------------------------------------------
31
32 // Subclass of BrowserAccessibilityWin that counts the number of instances.
33 class CountedBrowserAccessibility : public BrowserAccessibilityWin {
34 public:
35 CountedBrowserAccessibility();
36 ~CountedBrowserAccessibility() override;
37
38 static void reset() { num_instances_ = 0; }
39 static int num_instances() { return num_instances_; }
40
41 private:
42 static int num_instances_;
43
44 DISALLOW_COPY_AND_ASSIGN(CountedBrowserAccessibility);
45 };
46
47 // static
48 int CountedBrowserAccessibility::num_instances_ = 0;
49
50 CountedBrowserAccessibility::CountedBrowserAccessibility() {
51 ++num_instances_;
52 }
53
54 CountedBrowserAccessibility::~CountedBrowserAccessibility() {
55 --num_instances_;
56 }
57
58
59 // CountedBrowserAccessibilityFactory -----------------------------------------
60
61 // Factory that creates a CountedBrowserAccessibility.
62 class CountedBrowserAccessibilityFactory : public BrowserAccessibilityFactory {
63 public:
64 CountedBrowserAccessibilityFactory();
65
66 private:
67 ~CountedBrowserAccessibilityFactory() override;
68
69 BrowserAccessibility* Create() override;
70
71 DISALLOW_COPY_AND_ASSIGN(CountedBrowserAccessibilityFactory);
72 };
73
74 CountedBrowserAccessibilityFactory::CountedBrowserAccessibilityFactory() {
75 }
76
77 CountedBrowserAccessibilityFactory::~CountedBrowserAccessibilityFactory() {
78 }
79
80 BrowserAccessibility* CountedBrowserAccessibilityFactory::Create() {
81 CComObject<CountedBrowserAccessibility>* instance;
82 HRESULT hr = CComObject<CountedBrowserAccessibility>::CreateInstance(
83 &instance);
84 DCHECK(SUCCEEDED(hr));
85 instance->AddRef();
86 return instance;
87 }
88
89 } // namespace
90
91 27
92 // BrowserAccessibilityTest --------------------------------------------------- 28 // BrowserAccessibilityTest ---------------------------------------------------
93 29
94 class BrowserAccessibilityTest : public testing::Test { 30 class BrowserAccessibilityTest : public testing::Test {
95 public: 31 public:
96 BrowserAccessibilityTest(); 32 BrowserAccessibilityTest();
97 ~BrowserAccessibilityTest() override; 33 ~BrowserAccessibilityTest() override;
98 34
99 private: 35 private:
100 void SetUp() override; 36 void SetUp() override;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 root.SetName("Document"); 76 root.SetName("Document");
141 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 77 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
142 root.state = 0; 78 root.state = 0;
143 root.child_ids.push_back(2); 79 root.child_ids.push_back(2);
144 root.child_ids.push_back(3); 80 root.child_ids.push_back(3);
145 81
146 // Construct a BrowserAccessibilityManager with this 82 // Construct a BrowserAccessibilityManager with this
147 // ui::AXNodeData tree and a factory for an instance-counting 83 // ui::AXNodeData tree and a factory for an instance-counting
148 // BrowserAccessibility, and ensure that exactly 3 instances were 84 // BrowserAccessibility, and ensure that exactly 3 instances were
149 // created. Note that the manager takes ownership of the factory. 85 // created. Note that the manager takes ownership of the factory.
150 CountedBrowserAccessibility::reset();
151 std::unique_ptr<BrowserAccessibilityManager> manager( 86 std::unique_ptr<BrowserAccessibilityManager> manager(
152 BrowserAccessibilityManager::Create( 87 BrowserAccessibilityManager::Create(
153 MakeAXTreeUpdate(root, button, checkbox), nullptr, 88 MakeAXTreeUpdate(root, button, checkbox), nullptr,
154 new CountedBrowserAccessibilityFactory())); 89 new BrowserAccessibilityFactory()));
155 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances());
156 90
157 // Delete the manager and test that all 3 instances are deleted. 91 // Delete the manager and test that all 3 instances are deleted.
158 manager.reset(); 92 manager.reset();
159 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
160 93
161 // Construct a manager again, and this time use the IAccessible interface 94 // Construct a manager again, and this time use the IAccessible interface
162 // to get new references to two of the three nodes in the tree. 95 // to get new references to two of the three nodes in the tree.
163 manager.reset(BrowserAccessibilityManager::Create( 96 manager.reset(BrowserAccessibilityManager::Create(
164 MakeAXTreeUpdate(root, button, checkbox), nullptr, 97 MakeAXTreeUpdate(root, button, checkbox), nullptr,
165 new CountedBrowserAccessibilityFactory())); 98 new BrowserAccessibilityFactory()));
166 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); 99 IAccessible* root_accessible =
167 IAccessible* root_accessible = ToBrowserAccessibilityWin(manager->GetRoot()); 100 ToBrowserAccessibilityWin(manager->GetRoot())->GetCOM();
168 IDispatch* root_iaccessible = NULL; 101 IDispatch* root_iaccessible = NULL;
169 IDispatch* child1_iaccessible = NULL; 102 IDispatch* child1_iaccessible = NULL;
170 base::win::ScopedVariant childid_self(CHILDID_SELF); 103 base::win::ScopedVariant childid_self(CHILDID_SELF);
171 HRESULT hr = root_accessible->get_accChild(childid_self, &root_iaccessible); 104 HRESULT hr = root_accessible->get_accChild(childid_self, &root_iaccessible);
172 ASSERT_EQ(S_OK, hr); 105 ASSERT_EQ(S_OK, hr);
173 base::win::ScopedVariant one(1); 106 base::win::ScopedVariant one(1);
174 hr = root_accessible->get_accChild(one, &child1_iaccessible); 107 hr = root_accessible->get_accChild(one, &child1_iaccessible);
175 ASSERT_EQ(S_OK, hr); 108 ASSERT_EQ(S_OK, hr);
176 109
177 // Now delete the manager, and only one of the three nodes in the tree 110 // Now delete the manager, and only one of the three nodes in the tree
178 // should be released. 111 // should be released.
179 manager.reset(); 112 manager.reset();
180 ASSERT_EQ(2, CountedBrowserAccessibility::num_instances());
181 113
182 // Release each of our references and make sure that each one results in 114 // Release each of our references and make sure that each one results in
183 // the instance being deleted as its reference count hits zero. 115 // the instance being deleted as its reference count hits zero.
184 root_iaccessible->Release(); 116 root_iaccessible->Release();
185 ASSERT_EQ(1, CountedBrowserAccessibility::num_instances());
186 child1_iaccessible->Release(); 117 child1_iaccessible->Release();
187 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
188 } 118 }
189 119
190 TEST_F(BrowserAccessibilityTest, TestChildrenChange) { 120 TEST_F(BrowserAccessibilityTest, TestChildrenChange) {
191 // Create ui::AXNodeData objects for a simple document tree, 121 // Create ui::AXNodeData objects for a simple document tree,
192 // representing the accessibility information used to initialize 122 // representing the accessibility information used to initialize
193 // BrowserAccessibilityManager. 123 // BrowserAccessibilityManager.
194 ui::AXNodeData text; 124 ui::AXNodeData text;
195 text.id = 2; 125 text.id = 2;
196 text.role = ui::AX_ROLE_STATIC_TEXT; 126 text.role = ui::AX_ROLE_STATIC_TEXT;
197 text.SetName("old text"); 127 text.SetName("old text");
198 text.state = 0; 128 text.state = 0;
199 129
200 ui::AXNodeData root; 130 ui::AXNodeData root;
201 root.id = 1; 131 root.id = 1;
202 root.SetName("Document"); 132 root.SetName("Document");
203 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 133 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
204 root.state = 0; 134 root.state = 0;
205 root.child_ids.push_back(2); 135 root.child_ids.push_back(2);
206 136
207 // Construct a BrowserAccessibilityManager with this 137 // Construct a BrowserAccessibilityManager with this
208 // ui::AXNodeData tree and a factory for an instance-counting 138 // ui::AXNodeData tree and a factory for an instance-counting
209 // BrowserAccessibility. 139 // BrowserAccessibility.
210 CountedBrowserAccessibility::reset();
211 std::unique_ptr<BrowserAccessibilityManager> manager( 140 std::unique_ptr<BrowserAccessibilityManager> manager(
212 BrowserAccessibilityManager::Create( 141 BrowserAccessibilityManager::Create(MakeAXTreeUpdate(root, text), nullptr,
213 MakeAXTreeUpdate(root, text), nullptr, 142 new BrowserAccessibilityFactory()));
214 new CountedBrowserAccessibilityFactory()));
215 143
216 // Query for the text IAccessible and verify that it returns "old text" as its 144 // Query for the text IAccessible and verify that it returns "old text" as its
217 // value. 145 // value.
218 base::win::ScopedVariant one(1); 146 base::win::ScopedVariant one(1);
219 base::win::ScopedComPtr<IDispatch> text_dispatch; 147 base::win::ScopedComPtr<IDispatch> text_dispatch;
220 HRESULT hr = ToBrowserAccessibilityWin(manager->GetRoot())->get_accChild( 148 HRESULT hr = ToBrowserAccessibilityWin(manager->GetRoot())
221 one, text_dispatch.Receive()); 149 ->GetCOM()
150 ->get_accChild(one, text_dispatch.Receive());
222 ASSERT_EQ(S_OK, hr); 151 ASSERT_EQ(S_OK, hr);
223 152
224 base::win::ScopedComPtr<IAccessible> text_accessible; 153 base::win::ScopedComPtr<IAccessible> text_accessible;
225 hr = text_dispatch.CopyTo(text_accessible.Receive()); 154 hr = text_dispatch.CopyTo(text_accessible.Receive());
226 ASSERT_EQ(S_OK, hr); 155 ASSERT_EQ(S_OK, hr);
227 156
228 base::win::ScopedVariant childid_self(CHILDID_SELF); 157 base::win::ScopedVariant childid_self(CHILDID_SELF);
229 base::win::ScopedBstr name; 158 base::win::ScopedBstr name;
230 hr = text_accessible->get_accName(childid_self, name.Receive()); 159 hr = text_accessible->get_accName(childid_self, name.Receive());
231 ASSERT_EQ(S_OK, hr); 160 ASSERT_EQ(S_OK, hr);
(...skipping 11 matching lines...) Expand all
243 AXEventNotificationDetails param; 172 AXEventNotificationDetails param;
244 param.event_type = ui::AX_EVENT_CHILDREN_CHANGED; 173 param.event_type = ui::AX_EVENT_CHILDREN_CHANGED;
245 param.update.nodes.push_back(text2); 174 param.update.nodes.push_back(text2);
246 param.id = text2.id; 175 param.id = text2.id;
247 std::vector<AXEventNotificationDetails> events; 176 std::vector<AXEventNotificationDetails> events;
248 events.push_back(param); 177 events.push_back(param);
249 manager->OnAccessibilityEvents(events); 178 manager->OnAccessibilityEvents(events);
250 179
251 // Query for the text IAccessible and verify that it now returns "new text" 180 // Query for the text IAccessible and verify that it now returns "new text"
252 // as its value. 181 // as its value.
253 hr = ToBrowserAccessibilityWin(manager->GetRoot())->get_accChild( 182 hr = ToBrowserAccessibilityWin(manager->GetRoot())
254 one, text_dispatch.Receive()); 183 ->GetCOM()
184 ->get_accChild(one, text_dispatch.Receive());
255 ASSERT_EQ(S_OK, hr); 185 ASSERT_EQ(S_OK, hr);
256 186
257 hr = text_dispatch.CopyTo(text_accessible.Receive()); 187 hr = text_dispatch.CopyTo(text_accessible.Receive());
258 ASSERT_EQ(S_OK, hr); 188 ASSERT_EQ(S_OK, hr);
259 189
260 hr = text_accessible->get_accName(childid_self, name.Receive()); 190 hr = text_accessible->get_accName(childid_self, name.Receive());
261 ASSERT_EQ(S_OK, hr); 191 ASSERT_EQ(S_OK, hr);
262 EXPECT_EQ(L"new text", base::string16(name)); 192 EXPECT_EQ(L"new text", base::string16(name));
263 193
264 text_dispatch.Reset(); 194 text_dispatch.Reset();
265 text_accessible.Reset(); 195 text_accessible.Reset();
266 196
267 // Delete the manager and test that all BrowserAccessibility instances are 197 // Delete the manager and test that all BrowserAccessibility instances are
268 // deleted. 198 // deleted.
269 manager.reset(); 199 manager.reset();
270 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
271 } 200 }
272 201
273 TEST_F(BrowserAccessibilityTest, TestChildrenChangeNoLeaks) { 202 TEST_F(BrowserAccessibilityTest, TestChildrenChangeNoLeaks) {
274 // Create ui::AXNodeData objects for a simple document tree, 203 // Create ui::AXNodeData objects for a simple document tree,
275 // representing the accessibility information used to initialize 204 // representing the accessibility information used to initialize
276 // BrowserAccessibilityManager. 205 // BrowserAccessibilityManager.
277 ui::AXNodeData div; 206 ui::AXNodeData div;
278 div.id = 2; 207 div.id = 2;
279 div.role = ui::AX_ROLE_GROUP; 208 div.role = ui::AX_ROLE_GROUP;
280 div.state = 0; 209 div.state = 0;
(...skipping 14 matching lines...) Expand all
295 ui::AXNodeData root; 224 ui::AXNodeData root;
296 root.id = 1; 225 root.id = 1;
297 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 226 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
298 root.state = 0; 227 root.state = 0;
299 root.child_ids.push_back(2); 228 root.child_ids.push_back(2);
300 229
301 // Construct a BrowserAccessibilityManager with this 230 // Construct a BrowserAccessibilityManager with this
302 // ui::AXNodeData tree and a factory for an instance-counting 231 // ui::AXNodeData tree and a factory for an instance-counting
303 // BrowserAccessibility and ensure that exactly 4 instances were 232 // BrowserAccessibility and ensure that exactly 4 instances were
304 // created. Note that the manager takes ownership of the factory. 233 // created. Note that the manager takes ownership of the factory.
305 CountedBrowserAccessibility::reset();
306 std::unique_ptr<BrowserAccessibilityManager> manager( 234 std::unique_ptr<BrowserAccessibilityManager> manager(
307 BrowserAccessibilityManager::Create( 235 BrowserAccessibilityManager::Create(
308 MakeAXTreeUpdate(root, div, text3, text4), nullptr, 236 MakeAXTreeUpdate(root, div, text3, text4), nullptr,
309 new CountedBrowserAccessibilityFactory())); 237 new BrowserAccessibilityFactory()));
310 ASSERT_EQ(4, CountedBrowserAccessibility::num_instances());
311 238
312 // Notify the BrowserAccessibilityManager that the div node and its children 239 // Notify the BrowserAccessibilityManager that the div node and its children
313 // were removed and ensure that only one BrowserAccessibility instance exists. 240 // were removed and ensure that only one BrowserAccessibility instance exists.
314 root.child_ids.clear(); 241 root.child_ids.clear();
315 AXEventNotificationDetails param; 242 AXEventNotificationDetails param;
316 param.event_type = ui::AX_EVENT_CHILDREN_CHANGED; 243 param.event_type = ui::AX_EVENT_CHILDREN_CHANGED;
317 param.update.nodes.push_back(root); 244 param.update.nodes.push_back(root);
318 param.id = root.id; 245 param.id = root.id;
319 std::vector<AXEventNotificationDetails> events; 246 std::vector<AXEventNotificationDetails> events;
320 events.push_back(param); 247 events.push_back(param);
321 manager->OnAccessibilityEvents(events); 248 manager->OnAccessibilityEvents(events);
322 ASSERT_EQ(1, CountedBrowserAccessibility::num_instances());
323 249
324 // Delete the manager and test that all BrowserAccessibility instances are 250 // Delete the manager and test that all BrowserAccessibility instances are
325 // deleted. 251 // deleted.
326 manager.reset(); 252 manager.reset();
327 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
328 } 253 }
329 254
330 TEST_F(BrowserAccessibilityTest, TestTextBoundaries) { 255 TEST_F(BrowserAccessibilityTest, TestTextBoundaries) {
331 std::string line1 = "One two three."; 256 std::string line1 = "One two three.";
332 std::string line2 = "Four five six."; 257 std::string line2 = "Four five six.";
333 std::string text_value = line1 + '\n' + line2; 258 std::string text_value = line1 + '\n' + line2;
334 259
335 ui::AXNodeData root; 260 ui::AXNodeData root;
336 root.id = 1; 261 root.id = 1;
337 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 262 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 inline_box2.role = ui::AX_ROLE_INLINE_TEXT_BOX; 312 inline_box2.role = ui::AX_ROLE_INLINE_TEXT_BOX;
388 inline_box2.state = 1 << ui::AX_STATE_EDITABLE; 313 inline_box2.state = 1 << ui::AX_STATE_EDITABLE;
389 inline_box2.SetName(line2); 314 inline_box2.SetName(line2);
390 std::vector<int32_t> word_start_offsets2; 315 std::vector<int32_t> word_start_offsets2;
391 word_start_offsets2.push_back(0); 316 word_start_offsets2.push_back(0);
392 word_start_offsets2.push_back(5); 317 word_start_offsets2.push_back(5);
393 word_start_offsets2.push_back(10); 318 word_start_offsets2.push_back(10);
394 inline_box2.AddIntListAttribute( 319 inline_box2.AddIntListAttribute(
395 ui::AX_ATTR_WORD_STARTS, word_start_offsets2); 320 ui::AX_ATTR_WORD_STARTS, word_start_offsets2);
396 321
397 CountedBrowserAccessibility::reset();
398 std::unique_ptr<BrowserAccessibilityManager> manager( 322 std::unique_ptr<BrowserAccessibilityManager> manager(
399 BrowserAccessibilityManager::Create( 323 BrowserAccessibilityManager::Create(
400 MakeAXTreeUpdate(root, text_field, static_text1, inline_box1, 324 MakeAXTreeUpdate(root, text_field, static_text1, inline_box1,
401 line_break, static_text2, inline_box2), 325 line_break, static_text2, inline_box2),
402 nullptr, new CountedBrowserAccessibilityFactory())); 326 nullptr, new BrowserAccessibilityFactory()));
403 ASSERT_EQ(7, CountedBrowserAccessibility::num_instances());
404 327
405 BrowserAccessibilityWin* root_obj = 328 BrowserAccessibilityWin* root_obj =
406 ToBrowserAccessibilityWin(manager->GetRoot()); 329 ToBrowserAccessibilityWin(manager->GetRoot());
407 ASSERT_NE(nullptr, root_obj); 330 ASSERT_NE(nullptr, root_obj);
408 ASSERT_EQ(1U, root_obj->PlatformChildCount()); 331 ASSERT_EQ(1U, root_obj->PlatformChildCount());
409 332
410 BrowserAccessibilityWin* text_field_obj = 333 BrowserAccessibilityComWin* text_field_obj =
411 ToBrowserAccessibilityWin(root_obj->PlatformGetChild(0)); 334 ToBrowserAccessibilityWin(root_obj->PlatformGetChild(0))->GetCOM();
412 ASSERT_NE(nullptr, text_field_obj); 335 ASSERT_NE(nullptr, text_field_obj);
413 336
414 long text_len; 337 long text_len;
415 EXPECT_EQ(S_OK, text_field_obj->get_nCharacters(&text_len)); 338 EXPECT_EQ(S_OK, text_field_obj->get_nCharacters(&text_len));
416 339
417 base::win::ScopedBstr text; 340 base::win::ScopedBstr text;
418 EXPECT_EQ(S_OK, text_field_obj->get_text(0, text_len, text.Receive())); 341 EXPECT_EQ(S_OK, text_field_obj->get_text(0, text_len, text.Receive()));
419 EXPECT_EQ(text_value, base::UTF16ToUTF8(base::string16(text))); 342 EXPECT_EQ(text_value, base::UTF16ToUTF8(base::string16(text)));
420 text.Reset(); 343 text.Reset();
421 344
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 EXPECT_STREQ(L"Four five six.", text); 404 EXPECT_STREQ(L"Four five six.", text);
482 text.Reset(); 405 text.Reset();
483 406
484 EXPECT_EQ(S_OK, text_field_obj->get_text( 407 EXPECT_EQ(S_OK, text_field_obj->get_text(
485 0, IA2_TEXT_OFFSET_LENGTH, text.Receive())); 408 0, IA2_TEXT_OFFSET_LENGTH, text.Receive()));
486 EXPECT_EQ(text_value, base::UTF16ToUTF8(base::string16(text))); 409 EXPECT_EQ(text_value, base::UTF16ToUTF8(base::string16(text)));
487 410
488 // Delete the manager and test that all BrowserAccessibility instances are 411 // Delete the manager and test that all BrowserAccessibility instances are
489 // deleted. 412 // deleted.
490 manager.reset(); 413 manager.reset();
491 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
492 } 414 }
493 415
494 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { 416 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) {
495 const std::string text1_name = "One two three."; 417 const std::string text1_name = "One two three.";
496 const std::string text2_name = " Four five six."; 418 const std::string text2_name = " Four five six.";
497 const long text_name_len = text1_name.length() + text2_name.length(); 419 const long text_name_len = text1_name.length() + text2_name.length();
498 420
499 ui::AXNodeData text1; 421 ui::AXNodeData text1;
500 text1.id = 11; 422 text1.id = 11;
501 text1.role = ui::AX_ROLE_STATIC_TEXT; 423 text1.role = ui::AX_ROLE_STATIC_TEXT;
502 text1.state = 1 << ui::AX_STATE_READ_ONLY; 424 text1.state = 1 << ui::AX_STATE_READ_ONLY;
503 text1.SetName(text1_name); 425 text1.SetName(text1_name);
504 426
505 ui::AXNodeData text2; 427 ui::AXNodeData text2;
506 text2.id = 12; 428 text2.id = 12;
507 text2.role = ui::AX_ROLE_STATIC_TEXT; 429 text2.role = ui::AX_ROLE_STATIC_TEXT;
508 text2.state = 1 << ui::AX_STATE_READ_ONLY; 430 text2.state = 1 << ui::AX_STATE_READ_ONLY;
509 text2.SetName(text2_name); 431 text2.SetName(text2_name);
510 432
511 ui::AXNodeData root; 433 ui::AXNodeData root;
512 root.id = 1; 434 root.id = 1;
513 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 435 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
514 root.state = 1 << ui::AX_STATE_READ_ONLY; 436 root.state = 1 << ui::AX_STATE_READ_ONLY;
515 root.child_ids.push_back(text1.id); 437 root.child_ids.push_back(text1.id);
516 root.child_ids.push_back(text2.id); 438 root.child_ids.push_back(text2.id);
517 439
518 CountedBrowserAccessibility::reset();
519 std::unique_ptr<BrowserAccessibilityManager> manager( 440 std::unique_ptr<BrowserAccessibilityManager> manager(
520 BrowserAccessibilityManager::Create( 441 BrowserAccessibilityManager::Create(MakeAXTreeUpdate(root, text1, text2),
521 MakeAXTreeUpdate(root, text1, text2), nullptr, 442 nullptr,
522 new CountedBrowserAccessibilityFactory())); 443 new BrowserAccessibilityFactory()));
523 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances());
524 444
525 BrowserAccessibilityWin* root_obj = 445 BrowserAccessibilityComWin* root_obj =
526 ToBrowserAccessibilityWin(manager->GetRoot()); 446 ToBrowserAccessibilityWin(manager->GetRoot())->GetCOM();
527 447
528 long text_len; 448 long text_len;
529 EXPECT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); 449 EXPECT_EQ(S_OK, root_obj->get_nCharacters(&text_len));
530 EXPECT_EQ(text_name_len, text_len); 450 EXPECT_EQ(text_name_len, text_len);
531 451
532 base::win::ScopedBstr text; 452 base::win::ScopedBstr text;
533 EXPECT_EQ(S_OK, root_obj->get_text(0, text_name_len, text.Receive())); 453 EXPECT_EQ(S_OK, root_obj->get_text(0, text_name_len, text.Receive()));
534 EXPECT_EQ(text1_name + text2_name, base::UTF16ToUTF8(base::string16(text))); 454 EXPECT_EQ(text1_name + text2_name, base::UTF16ToUTF8(base::string16(text)));
535 455
536 long hyperlink_count; 456 long hyperlink_count;
(...skipping 16 matching lines...) Expand all
553 EXPECT_EQ(E_INVALIDARG, 473 EXPECT_EQ(E_INVALIDARG,
554 root_obj->get_hyperlinkIndex(text_name_len, &hyperlink_index)); 474 root_obj->get_hyperlinkIndex(text_name_len, &hyperlink_index));
555 EXPECT_EQ(-2, hyperlink_index); 475 EXPECT_EQ(-2, hyperlink_index);
556 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index)); 476 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index));
557 EXPECT_EQ(-2, hyperlink_index); 477 EXPECT_EQ(-2, hyperlink_index);
558 EXPECT_EQ(E_INVALIDARG, 478 EXPECT_EQ(E_INVALIDARG,
559 root_obj->get_hyperlinkIndex(text_name_len + 1, &hyperlink_index)); 479 root_obj->get_hyperlinkIndex(text_name_len + 1, &hyperlink_index));
560 EXPECT_EQ(-2, hyperlink_index); 480 EXPECT_EQ(-2, hyperlink_index);
561 481
562 manager.reset(); 482 manager.reset();
563 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
564 } 483 }
565 484
566 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) { 485 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) {
567 const base::string16 text1_name = L"One two three."; 486 const base::string16 text1_name = L"One two three.";
568 const base::string16 combo_box_name = L"City:"; 487 const base::string16 combo_box_name = L"City:";
569 const base::string16 combo_box_value = L"Happyland"; 488 const base::string16 combo_box_value = L"Happyland";
570 const base::string16 text2_name = L" Four five six."; 489 const base::string16 text2_name = L" Four five six.";
571 const base::string16 check_box_name = L"I agree"; 490 const base::string16 check_box_name = L"I agree";
572 const base::string16 check_box_value = L"Checked"; 491 const base::string16 check_box_value = L"Checked";
573 const base::string16 button_text_name = L"Red"; 492 const base::string16 button_text_name = L"Red";
574 const base::string16 link_text_name = L"Blue"; 493 const base::string16 link_text_name = L"Blue";
575 // Each control (combo / check box, button and link) will be represented by an 494 // Each control (combo / check box, button and link) will be represented by an
576 // embedded object character. 495 // embedded object character.
577 const base::string16 embed(1, BrowserAccessibilityWin::kEmbeddedCharacter); 496 const base::string16 embed(1, BrowserAccessibilityComWin::kEmbeddedCharacter);
578 const base::string16 root_hypertext = 497 const base::string16 root_hypertext =
579 text1_name + embed + text2_name + embed + embed + embed; 498 text1_name + embed + text2_name + embed + embed + embed;
580 const long root_hypertext_len = root_hypertext.length(); 499 const long root_hypertext_len = root_hypertext.length();
581 500
582 ui::AXNodeData text1; 501 ui::AXNodeData text1;
583 text1.id = 11; 502 text1.id = 11;
584 text1.role = ui::AX_ROLE_STATIC_TEXT; 503 text1.role = ui::AX_ROLE_STATIC_TEXT;
585 text1.state = 1 << ui::AX_STATE_READ_ONLY; 504 text1.state = 1 << ui::AX_STATE_READ_ONLY;
586 text1.SetName(base::UTF16ToUTF8(text1_name)); 505 text1.SetName(base::UTF16ToUTF8(text1_name));
587 506
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 root.id = 1; 549 root.id = 1;
631 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 550 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
632 root.state = 1 << ui::AX_STATE_READ_ONLY; 551 root.state = 1 << ui::AX_STATE_READ_ONLY;
633 root.child_ids.push_back(text1.id); 552 root.child_ids.push_back(text1.id);
634 root.child_ids.push_back(combo_box.id); 553 root.child_ids.push_back(combo_box.id);
635 root.child_ids.push_back(text2.id); 554 root.child_ids.push_back(text2.id);
636 root.child_ids.push_back(check_box.id); 555 root.child_ids.push_back(check_box.id);
637 root.child_ids.push_back(button.id); 556 root.child_ids.push_back(button.id);
638 root.child_ids.push_back(link.id); 557 root.child_ids.push_back(link.id);
639 558
640 CountedBrowserAccessibility::reset();
641 std::unique_ptr<BrowserAccessibilityManager> manager( 559 std::unique_ptr<BrowserAccessibilityManager> manager(
642 BrowserAccessibilityManager::Create( 560 BrowserAccessibilityManager::Create(
643 MakeAXTreeUpdate(root, text1, combo_box, text2, check_box, button, 561 MakeAXTreeUpdate(root, text1, combo_box, text2, check_box, button,
644 button_text, link, link_text), 562 button_text, link, link_text),
645 nullptr, new CountedBrowserAccessibilityFactory())); 563 nullptr, new BrowserAccessibilityFactory()));
646 ASSERT_EQ(9, CountedBrowserAccessibility::num_instances());
647 564
648 BrowserAccessibilityWin* root_obj = 565 BrowserAccessibilityComWin* root_obj =
649 ToBrowserAccessibilityWin(manager->GetRoot()); 566 ToBrowserAccessibilityWin(manager->GetRoot())->GetCOM();
650 567
651 long text_len; 568 long text_len;
652 EXPECT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); 569 EXPECT_EQ(S_OK, root_obj->get_nCharacters(&text_len));
653 EXPECT_EQ(root_hypertext_len, text_len); 570 EXPECT_EQ(root_hypertext_len, text_len);
654 571
655 base::win::ScopedBstr text; 572 base::win::ScopedBstr text;
656 EXPECT_EQ(S_OK, root_obj->get_text(0, root_hypertext_len, text.Receive())); 573 EXPECT_EQ(S_OK, root_obj->get_text(0, root_hypertext_len, text.Receive()));
657 EXPECT_STREQ(root_hypertext.c_str(), text); 574 EXPECT_STREQ(root_hypertext.c_str(), text);
658 text.Reset(); 575 text.Reset();
659 576
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index)); 635 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index));
719 EXPECT_EQ(0, hyperlink_index); 636 EXPECT_EQ(0, hyperlink_index);
720 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index)); 637 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index));
721 EXPECT_EQ(1, hyperlink_index); 638 EXPECT_EQ(1, hyperlink_index);
722 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(31, &hyperlink_index)); 639 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(31, &hyperlink_index));
723 EXPECT_EQ(2, hyperlink_index); 640 EXPECT_EQ(2, hyperlink_index);
724 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(32, &hyperlink_index)); 641 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(32, &hyperlink_index));
725 EXPECT_EQ(3, hyperlink_index); 642 EXPECT_EQ(3, hyperlink_index);
726 643
727 manager.reset(); 644 manager.reset();
728 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
729 } 645 }
730 646
731 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) { 647 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) {
732 // Try creating an empty document with busy state. Readonly is 648 // Try creating an empty document with busy state. Readonly is
733 // set automatically. 649 // set automatically.
734 CountedBrowserAccessibility::reset();
735 const int32_t busy_state = 1 << ui::AX_STATE_BUSY; 650 const int32_t busy_state = 1 << ui::AX_STATE_BUSY;
736 const int32_t readonly_state = 1 << ui::AX_STATE_READ_ONLY; 651 const int32_t readonly_state = 1 << ui::AX_STATE_READ_ONLY;
737 std::unique_ptr<BrowserAccessibilityManager> manager( 652 std::unique_ptr<BrowserAccessibilityManager> manager(
738 new BrowserAccessibilityManagerWin( 653 new BrowserAccessibilityManagerWin(
739 BrowserAccessibilityManagerWin::GetEmptyDocument(), nullptr, 654 BrowserAccessibilityManagerWin::GetEmptyDocument(), nullptr,
740 new CountedBrowserAccessibilityFactory())); 655 new BrowserAccessibilityFactory()));
741 656
742 // Verify the root is as we expect by default. 657 // Verify the root is as we expect by default.
743 BrowserAccessibility* root = manager->GetRoot(); 658 BrowserAccessibility* root = manager->GetRoot();
744 EXPECT_EQ(0, root->GetId()); 659 EXPECT_EQ(0, root->GetId());
745 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->GetRole()); 660 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->GetRole());
746 EXPECT_EQ(busy_state | readonly_state, root->GetState()); 661 EXPECT_EQ(busy_state | readonly_state, root->GetState());
747 662
748 // Tree with a child textfield. 663 // Tree with a child textfield.
749 ui::AXNodeData tree1_1; 664 ui::AXNodeData tree1_1;
750 tree1_1.id = 1; 665 tree1_1.id = 1;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 713
799 // Verify the root has changed. 714 // Verify the root has changed.
800 EXPECT_NE(root, manager->GetRoot()); 715 EXPECT_NE(root, manager->GetRoot());
801 716
802 // And the new child exists. 717 // And the new child exists.
803 EXPECT_EQ(ui::AX_ROLE_BUTTON, acc2_2->GetRole()); 718 EXPECT_EQ(ui::AX_ROLE_BUTTON, acc2_2->GetRole());
804 EXPECT_EQ(3, acc2_2->GetId()); 719 EXPECT_EQ(3, acc2_2->GetId());
805 720
806 // Ensure we properly cleaned up. 721 // Ensure we properly cleaned up.
807 manager.reset(); 722 manager.reset();
808 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
809 } 723 }
810 724
811 // This is a regression test for a bug where the initial empty document 725 // This is a regression test for a bug where the initial empty document
812 // loaded by a BrowserAccessibilityManagerWin couldn't be looked up by 726 // loaded by a BrowserAccessibilityManagerWin couldn't be looked up by
813 // its UniqueIDWin, because the AX Tree was loaded in 727 // its UniqueIDWin, because the AX Tree was loaded in
814 // BrowserAccessibilityManager code before BrowserAccessibilityManagerWin 728 // BrowserAccessibilityManager code before BrowserAccessibilityManagerWin
815 // was initialized. 729 // was initialized.
816 TEST_F(BrowserAccessibilityTest, EmptyDocHasUniqueIdWin) { 730 TEST_F(BrowserAccessibilityTest, EmptyDocHasUniqueIdWin) {
817 std::unique_ptr<BrowserAccessibilityManagerWin> manager( 731 std::unique_ptr<BrowserAccessibilityManagerWin> manager(
818 new BrowserAccessibilityManagerWin( 732 new BrowserAccessibilityManagerWin(
819 BrowserAccessibilityManagerWin::GetEmptyDocument(), nullptr, 733 BrowserAccessibilityManagerWin::GetEmptyDocument(), nullptr,
820 new CountedBrowserAccessibilityFactory())); 734 new BrowserAccessibilityFactory()));
821 735
822 // Verify the root is as we expect by default. 736 // Verify the root is as we expect by default.
823 BrowserAccessibility* root = manager->GetRoot(); 737 BrowserAccessibility* root = manager->GetRoot();
824 EXPECT_EQ(0, root->GetId()); 738 EXPECT_EQ(0, root->GetId());
825 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->GetRole()); 739 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->GetRole());
826 EXPECT_EQ(1 << ui::AX_STATE_BUSY | 1 << ui::AX_STATE_READ_ONLY, 740 EXPECT_EQ(1 << ui::AX_STATE_BUSY | 1 << ui::AX_STATE_READ_ONLY,
827 root->GetState()); 741 root->GetState());
828 742
829 int32_t unique_id = ToBrowserAccessibilityWin(root)->unique_id(); 743 int32_t unique_id = ToBrowserAccessibilityWin(root)->unique_id();
830 ASSERT_EQ(root, BrowserAccessibility::GetFromUniqueID(unique_id)); 744 ASSERT_EQ(root, BrowserAccessibility::GetFromUniqueID(unique_id));
(...skipping 15 matching lines...) Expand all
846 ui::AX_CHECKED_STATE_TRUE); 760 ui::AX_CHECKED_STATE_TRUE);
847 761
848 ui::AXNodeData root; 762 ui::AXNodeData root;
849 root.id = 1; 763 root.id = 1;
850 root.SetName("Document"); 764 root.SetName("Document");
851 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 765 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
852 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); 766 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE);
853 root.child_ids.push_back(2); 767 root.child_ids.push_back(2);
854 root.child_ids.push_back(3); 768 root.child_ids.push_back(3);
855 769
856 CountedBrowserAccessibility::reset();
857 std::unique_ptr<BrowserAccessibilityManager> manager( 770 std::unique_ptr<BrowserAccessibilityManager> manager(
858 BrowserAccessibilityManager::Create( 771 BrowserAccessibilityManager::Create(
859 MakeAXTreeUpdate(root, pseudo_before, checkbox), nullptr, 772 MakeAXTreeUpdate(root, pseudo_before, checkbox), nullptr,
860 new CountedBrowserAccessibilityFactory())); 773 new BrowserAccessibilityFactory()));
861 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances());
862 774
863 ASSERT_NE(nullptr, manager->GetRoot()); 775 ASSERT_NE(nullptr, manager->GetRoot());
864 BrowserAccessibilityWin* root_accessible = 776 BrowserAccessibilityWin* root_accessible =
865 ToBrowserAccessibilityWin(manager->GetRoot()); 777 ToBrowserAccessibilityWin(manager->GetRoot());
866 ASSERT_NE(nullptr, root_accessible); 778 ASSERT_NE(nullptr, root_accessible);
867 ASSERT_EQ(2U, root_accessible->PlatformChildCount()); 779 ASSERT_EQ(2U, root_accessible->PlatformChildCount());
868 780
869 BrowserAccessibilityWin* pseudo_accessible = 781 BrowserAccessibilityWin* pseudo_accessible =
870 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0)); 782 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0));
871 ASSERT_NE(nullptr, pseudo_accessible); 783 ASSERT_NE(nullptr, pseudo_accessible);
872 784
873 base::win::ScopedBstr attributes; 785 base::win::ScopedBstr attributes;
874 HRESULT hr = pseudo_accessible->get_attributes(attributes.Receive()); 786 HRESULT hr =
787 pseudo_accessible->GetCOM()->get_attributes(attributes.Receive());
875 EXPECT_EQ(S_OK, hr); 788 EXPECT_EQ(S_OK, hr);
876 EXPECT_NE(nullptr, static_cast<BSTR>(attributes)); 789 EXPECT_NE(nullptr, static_cast<BSTR>(attributes));
877 std::wstring attributes_str(attributes, attributes.Length()); 790 std::wstring attributes_str(attributes, attributes.Length());
878 EXPECT_EQ(L"display:none;tag:<pseudo\\:before>;", attributes_str); 791 EXPECT_EQ(L"display:none;tag:<pseudo\\:before>;", attributes_str);
879 792
880 BrowserAccessibilityWin* checkbox_accessible = 793 BrowserAccessibilityWin* checkbox_accessible =
881 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(1)); 794 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(1));
882 ASSERT_NE(nullptr, checkbox_accessible); 795 ASSERT_NE(nullptr, checkbox_accessible);
883 796
884 attributes.Reset(); 797 attributes.Reset();
885 hr = checkbox_accessible->get_attributes(attributes.Receive()); 798 hr = checkbox_accessible->GetCOM()->get_attributes(attributes.Receive());
886 EXPECT_EQ(S_OK, hr); 799 EXPECT_EQ(S_OK, hr);
887 EXPECT_NE(nullptr, static_cast<BSTR>(attributes)); 800 EXPECT_NE(nullptr, static_cast<BSTR>(attributes));
888 attributes_str = std::wstring(attributes, attributes.Length()); 801 attributes_str = std::wstring(attributes, attributes.Length());
889 EXPECT_EQ(L"checkable:true;", attributes_str); 802 EXPECT_EQ(L"checkable:true;", attributes_str);
890 803
891 manager.reset(); 804 manager.reset();
892 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
893 } 805 }
894 806
895 TEST_F(BrowserAccessibilityTest, TestValueAttributeInTextControls) { 807 TEST_F(BrowserAccessibilityTest, TestValueAttributeInTextControls) {
896 ui::AXNodeData root; 808 ui::AXNodeData root;
897 root.id = 1; 809 root.id = 1;
898 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 810 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
899 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); 811 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE);
900 812
901 ui::AXNodeData combo_box, combo_box_text; 813 ui::AXNodeData combo_box, combo_box_text;
902 combo_box.id = 2; 814 combo_box.id = 2;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 slider_text.role = ui::AX_ROLE_STATIC_TEXT; 863 slider_text.role = ui::AX_ROLE_STATIC_TEXT;
952 slider.state = slider_text.state = 1 << ui::AX_STATE_READ_ONLY; 864 slider.state = slider_text.state = 1 << ui::AX_STATE_READ_ONLY;
953 slider.child_ids.push_back(slider_text.id); 865 slider.child_ids.push_back(slider_text.id);
954 866
955 root.child_ids.push_back(2); // Combo box. 867 root.child_ids.push_back(2); // Combo box.
956 root.child_ids.push_back(4); // Search box. 868 root.child_ids.push_back(4); // Search box.
957 root.child_ids.push_back(7); // Text field. 869 root.child_ids.push_back(7); // Text field.
958 root.child_ids.push_back(8); // Link. 870 root.child_ids.push_back(8); // Link.
959 root.child_ids.push_back(10); // Slider. 871 root.child_ids.push_back(10); // Slider.
960 872
961 CountedBrowserAccessibility::reset();
962 std::unique_ptr<BrowserAccessibilityManager> manager( 873 std::unique_ptr<BrowserAccessibilityManager> manager(
963 BrowserAccessibilityManager::Create( 874 BrowserAccessibilityManager::Create(
964 MakeAXTreeUpdate(root, combo_box, combo_box_text, search_box, 875 MakeAXTreeUpdate(root, combo_box, combo_box_text, search_box,
965 search_box_text, new_line, text_field, link, 876 search_box_text, new_line, text_field, link,
966 link_text, slider, slider_text), 877 link_text, slider, slider_text),
967 nullptr, new CountedBrowserAccessibilityFactory())); 878 nullptr, new BrowserAccessibilityFactory()));
968 ASSERT_EQ(11, CountedBrowserAccessibility::num_instances());
969 879
970 ASSERT_NE(nullptr, manager->GetRoot()); 880 ASSERT_NE(nullptr, manager->GetRoot());
971 BrowserAccessibilityWin* root_accessible = 881 BrowserAccessibilityWin* root_accessible =
972 ToBrowserAccessibilityWin(manager->GetRoot()); 882 ToBrowserAccessibilityWin(manager->GetRoot());
973 ASSERT_NE(nullptr, root_accessible); 883 ASSERT_NE(nullptr, root_accessible);
974 ASSERT_EQ(5U, root_accessible->PlatformChildCount()); 884 ASSERT_EQ(5U, root_accessible->PlatformChildCount());
975 885
976 BrowserAccessibilityWin* combo_box_accessible = 886 BrowserAccessibilityWin* combo_box_accessible =
977 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0)); 887 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0));
978 ASSERT_NE(nullptr, combo_box_accessible); 888 ASSERT_NE(nullptr, combo_box_accessible);
(...skipping 10 matching lines...) Expand all
989 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(3)); 899 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(3));
990 ASSERT_NE(nullptr, link_accessible); 900 ASSERT_NE(nullptr, link_accessible);
991 BrowserAccessibilityWin* slider_accessible = 901 BrowserAccessibilityWin* slider_accessible =
992 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(4)); 902 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(4));
993 ASSERT_NE(nullptr, slider_accessible); 903 ASSERT_NE(nullptr, slider_accessible);
994 904
995 base::win::ScopedVariant childid_self(CHILDID_SELF); 905 base::win::ScopedVariant childid_self(CHILDID_SELF);
996 base::win::ScopedVariant childid_slider(5); 906 base::win::ScopedVariant childid_slider(5);
997 base::win::ScopedBstr value; 907 base::win::ScopedBstr value;
998 908
999 HRESULT hr = 909 HRESULT hr = combo_box_accessible->GetCOM()->get_accValue(childid_self,
1000 combo_box_accessible->get_accValue(childid_self, value.Receive()); 910 value.Receive());
1001 EXPECT_EQ(S_OK, hr); 911 EXPECT_EQ(S_OK, hr);
1002 EXPECT_STREQ(L"Combo box text", value); 912 EXPECT_STREQ(L"Combo box text", value);
1003 value.Reset(); 913 value.Reset();
1004 hr = search_box_accessible->get_accValue(childid_self, value.Receive()); 914 hr = search_box_accessible->GetCOM()->get_accValue(childid_self,
915 value.Receive());
1005 EXPECT_EQ(S_OK, hr); 916 EXPECT_EQ(S_OK, hr);
1006 EXPECT_STREQ(L"Search box text\n", value); 917 EXPECT_STREQ(L"Search box text\n", value);
1007 value.Reset(); 918 value.Reset();
1008 hr = text_field_accessible->get_accValue(childid_self, value.Receive()); 919 hr = text_field_accessible->GetCOM()->get_accValue(childid_self,
920 value.Receive());
1009 EXPECT_EQ(S_OK, hr); 921 EXPECT_EQ(S_OK, hr);
1010 EXPECT_STREQ(L"Text field text", value); 922 EXPECT_STREQ(L"Text field text", value);
1011 value.Reset(); 923 value.Reset();
1012 924
1013 // Other controls, such as links, should not use their inner text as their 925 // Other controls, such as links, should not use their inner text as their
1014 // value. Only text entry controls. 926 // value. Only text entry controls.
1015 hr = link_accessible->get_accValue(childid_self, value.Receive()); 927 hr = link_accessible->GetCOM()->get_accValue(childid_self, value.Receive());
1016 EXPECT_EQ(S_OK, hr); 928 EXPECT_EQ(S_OK, hr);
1017 EXPECT_EQ(0u, value.Length()); 929 EXPECT_EQ(0u, value.Length());
1018 value.Reset(); 930 value.Reset();
1019 931
1020 // Sliders and other range controls should expose their current value and not 932 // Sliders and other range controls should expose their current value and not
1021 // their inner text. 933 // their inner text.
1022 // Also, try accessing the slider via its child number instead of directly. 934 // Also, try accessing the slider via its child number instead of directly.
1023 hr = root_accessible->get_accValue(childid_slider, value.Receive()); 935 hr = root_accessible->GetCOM()->get_accValue(childid_slider, value.Receive());
1024 EXPECT_EQ(S_OK, hr); 936 EXPECT_EQ(S_OK, hr);
1025 EXPECT_STREQ(L"5", value); 937 EXPECT_STREQ(L"5", value);
1026 value.Reset(); 938 value.Reset();
1027 939
1028 manager.reset(); 940 manager.reset();
1029 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
1030 } 941 }
1031 942
1032 TEST_F(BrowserAccessibilityTest, TestWordBoundariesInTextControls) { 943 TEST_F(BrowserAccessibilityTest, TestWordBoundariesInTextControls) {
1033 const base::string16 line1(L"This is a very long line of text that "); 944 const base::string16 line1(L"This is a very long line of text that ");
1034 const base::string16 line2(L"should wrap on more than one lines "); 945 const base::string16 line2(L"should wrap on more than one lines ");
1035 const base::string16 text(line1 + line2); 946 const base::string16 text(line1 + line2);
1036 947
1037 std::vector<int32_t> line1_word_starts; 948 std::vector<int32_t> line1_word_starts;
1038 line1_word_starts.push_back(0); 949 line1_word_starts.push_back(0);
1039 line1_word_starts.push_back(5); 950 line1_word_starts.push_back(5);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 text_field_line.role = ui::AX_ROLE_INLINE_TEXT_BOX; 1027 text_field_line.role = ui::AX_ROLE_INLINE_TEXT_BOX;
1117 text_field_line.state = 1 << ui::AX_STATE_EDITABLE; 1028 text_field_line.state = 1 << ui::AX_STATE_EDITABLE;
1118 text_field_line.SetName(base::UTF16ToUTF8(line1)); 1029 text_field_line.SetName(base::UTF16ToUTF8(line1));
1119 text_field_line.AddIntListAttribute(ui::AX_ATTR_WORD_STARTS, 1030 text_field_line.AddIntListAttribute(ui::AX_ATTR_WORD_STARTS,
1120 line1_word_starts); 1031 line1_word_starts);
1121 text_field_text.child_ids.push_back(text_field_line.id); 1032 text_field_text.child_ids.push_back(text_field_line.id);
1122 1033
1123 root.child_ids.push_back(2); // Textarea. 1034 root.child_ids.push_back(2); // Textarea.
1124 root.child_ids.push_back(7); // Text field. 1035 root.child_ids.push_back(7); // Text field.
1125 1036
1126 CountedBrowserAccessibility::reset();
1127 std::unique_ptr<BrowserAccessibilityManager> manager( 1037 std::unique_ptr<BrowserAccessibilityManager> manager(
1128 BrowserAccessibilityManager::Create( 1038 BrowserAccessibilityManager::Create(
1129 MakeAXTreeUpdate(root, textarea, textarea_div, textarea_text, 1039 MakeAXTreeUpdate(root, textarea, textarea_div, textarea_text,
1130 textarea_line1, textarea_line2, text_field, 1040 textarea_line1, textarea_line2, text_field,
1131 text_field_div, text_field_text, text_field_line), 1041 text_field_div, text_field_text, text_field_line),
1132 nullptr, new CountedBrowserAccessibilityFactory())); 1042 nullptr, new BrowserAccessibilityFactory()));
1133 ASSERT_EQ(10, CountedBrowserAccessibility::num_instances());
1134 1043
1135 ASSERT_NE(nullptr, manager->GetRoot()); 1044 ASSERT_NE(nullptr, manager->GetRoot());
1136 BrowserAccessibilityWin* root_accessible = 1045 BrowserAccessibilityWin* root_accessible =
1137 ToBrowserAccessibilityWin(manager->GetRoot()); 1046 ToBrowserAccessibilityWin(manager->GetRoot());
1138 ASSERT_NE(nullptr, root_accessible); 1047 ASSERT_NE(nullptr, root_accessible);
1139 ASSERT_EQ(2U, root_accessible->PlatformChildCount()); 1048 ASSERT_EQ(2U, root_accessible->PlatformChildCount());
1140 1049
1141 BrowserAccessibilityWin* textarea_accessible = 1050 BrowserAccessibilityWin* textarea_accessible =
1142 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0)); 1051 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0));
1143 ASSERT_NE(nullptr, textarea_accessible); 1052 ASSERT_NE(nullptr, textarea_accessible);
1144 BrowserAccessibilityWin* text_field_accessible = 1053 BrowserAccessibilityWin* text_field_accessible =
1145 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(1)); 1054 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(1));
1146 ASSERT_NE(nullptr, text_field_accessible); 1055 ASSERT_NE(nullptr, text_field_accessible);
1147 1056
1148 base::win::ScopedComPtr<IAccessibleText> textarea_object; 1057 base::win::ScopedComPtr<IAccessibleText> textarea_object;
1149 EXPECT_HRESULT_SUCCEEDED(textarea_accessible->QueryInterface( 1058 EXPECT_HRESULT_SUCCEEDED(textarea_accessible->GetCOM()->QueryInterface(
1150 IID_IAccessibleText, 1059 IID_IAccessibleText,
1151 reinterpret_cast<void**>(textarea_object.Receive()))); 1060 reinterpret_cast<void**>(textarea_object.Receive())));
1152 base::win::ScopedComPtr<IAccessibleText> text_field_object; 1061 base::win::ScopedComPtr<IAccessibleText> text_field_object;
1153 EXPECT_HRESULT_SUCCEEDED(text_field_accessible->QueryInterface( 1062 EXPECT_HRESULT_SUCCEEDED(text_field_accessible->GetCOM()->QueryInterface(
1154 IID_IAccessibleText, 1063 IID_IAccessibleText,
1155 reinterpret_cast<void**>(text_field_object.Receive()))); 1064 reinterpret_cast<void**>(text_field_object.Receive())));
1156 1065
1157 LONG offset = 0; 1066 LONG offset = 0;
1158 while (offset < static_cast<LONG>(text.length())) { 1067 while (offset < static_cast<LONG>(text.length())) {
1159 LONG start, end; 1068 LONG start, end;
1160 base::win::ScopedBstr word; 1069 base::win::ScopedBstr word;
1161 EXPECT_EQ(S_OK, 1070 EXPECT_EQ(S_OK,
1162 textarea_object->get_textAtOffset(offset, IA2_TEXT_BOUNDARY_WORD, 1071 textarea_object->get_textAtOffset(offset, IA2_TEXT_BOUNDARY_WORD,
1163 &start, &end, word.Receive())); 1072 &start, &end, word.Receive()));
(...skipping 21 matching lines...) Expand all
1185 LONG length = end - start; 1094 LONG length = end - start;
1186 EXPECT_STREQ(text.substr(start, length).c_str(), word); 1095 EXPECT_STREQ(text.substr(start, length).c_str(), word);
1187 word.Reset(); 1096 word.Reset();
1188 offset = end; 1097 offset = end;
1189 } 1098 }
1190 1099
1191 textarea_object.Reset(); 1100 textarea_object.Reset();
1192 text_field_object.Reset(); 1101 text_field_object.Reset();
1193 1102
1194 manager.reset(); 1103 manager.reset();
1195 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
1196 } 1104 }
1197 1105
1198 TEST_F(BrowserAccessibilityTest, TestCaretAndSelectionInSimpleFields) { 1106 TEST_F(BrowserAccessibilityTest, TestCaretAndSelectionInSimpleFields) {
1199 ui::AXNodeData root; 1107 ui::AXNodeData root;
1200 root.id = 1; 1108 root.id = 1;
1201 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 1109 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
1202 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); 1110 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE);
1203 1111
1204 ui::AXNodeData combo_box; 1112 ui::AXNodeData combo_box;
1205 combo_box.id = 2; 1113 combo_box.id = 2;
(...skipping 11 matching lines...) Expand all
1217 text_field.state = (1 << ui::AX_STATE_EDITABLE) | 1125 text_field.state = (1 << ui::AX_STATE_EDITABLE) |
1218 (1 << ui::AX_STATE_FOCUSABLE); 1126 (1 << ui::AX_STATE_FOCUSABLE);
1219 text_field.SetValue("Test2"); 1127 text_field.SetValue("Test2");
1220 // Select the letter 'e'. 1128 // Select the letter 'e'.
1221 text_field.AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, 1); 1129 text_field.AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, 1);
1222 text_field.AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, 2); 1130 text_field.AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, 2);
1223 1131
1224 root.child_ids.push_back(2); 1132 root.child_ids.push_back(2);
1225 root.child_ids.push_back(3); 1133 root.child_ids.push_back(3);
1226 1134
1227 CountedBrowserAccessibility::reset();
1228 std::unique_ptr<BrowserAccessibilityManager> manager( 1135 std::unique_ptr<BrowserAccessibilityManager> manager(
1229 BrowserAccessibilityManager::Create( 1136 BrowserAccessibilityManager::Create(
1230 MakeAXTreeUpdate(root, combo_box, text_field), nullptr, 1137 MakeAXTreeUpdate(root, combo_box, text_field), nullptr,
1231 new CountedBrowserAccessibilityFactory())); 1138 new BrowserAccessibilityFactory()));
1232 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances());
1233 1139
1234 ASSERT_NE(nullptr, manager->GetRoot()); 1140 ASSERT_NE(nullptr, manager->GetRoot());
1235 BrowserAccessibilityWin* root_accessible = 1141 BrowserAccessibilityWin* root_accessible =
1236 ToBrowserAccessibilityWin(manager->GetRoot()); 1142 ToBrowserAccessibilityWin(manager->GetRoot());
1237 ASSERT_NE(nullptr, root_accessible); 1143 ASSERT_NE(nullptr, root_accessible);
1238 ASSERT_EQ(2U, root_accessible->PlatformChildCount()); 1144 ASSERT_EQ(2U, root_accessible->PlatformChildCount());
1239 1145
1240 BrowserAccessibilityWin* combo_box_accessible = 1146 BrowserAccessibilityWin* combo_box_accessible =
1241 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0)); 1147 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0));
1242 ASSERT_NE(nullptr, combo_box_accessible); 1148 ASSERT_NE(nullptr, combo_box_accessible);
1243 manager->SetFocusLocallyForTesting(combo_box_accessible); 1149 manager->SetFocusLocallyForTesting(combo_box_accessible);
1244 ASSERT_EQ(combo_box_accessible, 1150 ASSERT_EQ(combo_box_accessible,
1245 ToBrowserAccessibilityWin(manager->GetFocus())); 1151 ToBrowserAccessibilityWin(manager->GetFocus()));
1246 BrowserAccessibilityWin* text_field_accessible = 1152 BrowserAccessibilityWin* text_field_accessible =
1247 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(1)); 1153 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(1));
1248 ASSERT_NE(nullptr, text_field_accessible); 1154 ASSERT_NE(nullptr, text_field_accessible);
1249 1155
1250 // -2 is never a valid offset. 1156 // -2 is never a valid offset.
1251 LONG caret_offset = -2; 1157 LONG caret_offset = -2;
1252 LONG n_selections = -2; 1158 LONG n_selections = -2;
1253 LONG selection_start = -2; 1159 LONG selection_start = -2;
1254 LONG selection_end = -2; 1160 LONG selection_end = -2;
1255 1161
1256 // Test get_caretOffset. 1162 // Test get_caretOffset.
1257 HRESULT hr = combo_box_accessible->get_caretOffset(&caret_offset); 1163 HRESULT hr = combo_box_accessible->GetCOM()->get_caretOffset(&caret_offset);
1258 EXPECT_EQ(S_OK, hr); 1164 EXPECT_EQ(S_OK, hr);
1259 EXPECT_EQ(1, caret_offset); 1165 EXPECT_EQ(1, caret_offset);
1260 // The caret should be at the end of the selection. 1166 // The caret should be at the end of the selection.
1261 hr = text_field_accessible->get_caretOffset(&caret_offset); 1167 hr = text_field_accessible->GetCOM()->get_caretOffset(&caret_offset);
1262 EXPECT_EQ(S_OK, hr); 1168 EXPECT_EQ(S_OK, hr);
1263 EXPECT_EQ(2, caret_offset); 1169 EXPECT_EQ(2, caret_offset);
1264 1170
1265 // Move the focus to the text field. 1171 // Move the focus to the text field.
1266 manager->SetFocusLocallyForTesting(text_field_accessible); 1172 manager->SetFocusLocallyForTesting(text_field_accessible);
1267 ASSERT_EQ(text_field_accessible, 1173 ASSERT_EQ(text_field_accessible,
1268 ToBrowserAccessibilityWin(manager->GetFocus())); 1174 ToBrowserAccessibilityWin(manager->GetFocus()));
1269 1175
1270 // The caret should not have moved. 1176 // The caret should not have moved.
1271 hr = text_field_accessible->get_caretOffset(&caret_offset); 1177 hr = text_field_accessible->GetCOM()->get_caretOffset(&caret_offset);
1272 EXPECT_EQ(S_OK, hr); 1178 EXPECT_EQ(S_OK, hr);
1273 EXPECT_EQ(2, caret_offset); 1179 EXPECT_EQ(2, caret_offset);
1274 1180
1275 // Test get_nSelections. 1181 // Test get_nSelections.
1276 hr = combo_box_accessible->get_nSelections(&n_selections); 1182 hr = combo_box_accessible->GetCOM()->get_nSelections(&n_selections);
1277 EXPECT_EQ(S_OK, hr); 1183 EXPECT_EQ(S_OK, hr);
1278 EXPECT_EQ(0, n_selections); 1184 EXPECT_EQ(0, n_selections);
1279 hr = text_field_accessible->get_nSelections(&n_selections); 1185 hr = text_field_accessible->GetCOM()->get_nSelections(&n_selections);
1280 EXPECT_EQ(S_OK, hr); 1186 EXPECT_EQ(S_OK, hr);
1281 EXPECT_EQ(1, n_selections); 1187 EXPECT_EQ(1, n_selections);
1282 1188
1283 // Test get_selection. 1189 // Test get_selection.
1284 hr = combo_box_accessible->get_selection( 1190 hr = combo_box_accessible->GetCOM()->get_selection(
1285 0L /* selection_index */, &selection_start, &selection_end); 1191 0L /* selection_index */, &selection_start, &selection_end);
1286 EXPECT_EQ(E_INVALIDARG, hr); // No selections available. 1192 EXPECT_EQ(E_INVALIDARG, hr); // No selections available.
1287 hr = text_field_accessible->get_selection( 1193 hr = text_field_accessible->GetCOM()->get_selection(
1288 0L /* selection_index */, &selection_start, &selection_end); 1194 0L /* selection_index */, &selection_start, &selection_end);
1289 EXPECT_EQ(S_OK, hr); 1195 EXPECT_EQ(S_OK, hr);
1290 EXPECT_EQ(1, selection_start); 1196 EXPECT_EQ(1, selection_start);
1291 EXPECT_EQ(2, selection_end); 1197 EXPECT_EQ(2, selection_end);
1292 1198
1293 manager.reset(); 1199 manager.reset();
1294 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
1295 } 1200 }
1296 1201
1297 TEST_F(BrowserAccessibilityTest, TestCaretInContentEditables) { 1202 TEST_F(BrowserAccessibilityTest, TestCaretInContentEditables) {
1298 ui::AXNodeData root; 1203 ui::AXNodeData root;
1299 root.id = 1; 1204 root.id = 1;
1300 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 1205 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
1301 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); 1206 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE);
1302 1207
1303 ui::AXNodeData div_editable; 1208 ui::AXNodeData div_editable;
1304 div_editable.id = 2; 1209 div_editable.id = 2;
(...skipping 29 matching lines...) Expand all
1334 ui::AXTreeUpdate update = MakeAXTreeUpdate( 1239 ui::AXTreeUpdate update = MakeAXTreeUpdate(
1335 root, div_editable, link, link_text, text); 1240 root, div_editable, link, link_text, text);
1336 1241
1337 // Place the caret between 'h' and 'e'. 1242 // Place the caret between 'h' and 'e'.
1338 update.has_tree_data = true; 1243 update.has_tree_data = true;
1339 update.tree_data.sel_anchor_object_id = 5; 1244 update.tree_data.sel_anchor_object_id = 5;
1340 update.tree_data.sel_anchor_offset = 1; 1245 update.tree_data.sel_anchor_offset = 1;
1341 update.tree_data.sel_focus_object_id = 5; 1246 update.tree_data.sel_focus_object_id = 5;
1342 update.tree_data.sel_focus_offset = 1; 1247 update.tree_data.sel_focus_offset = 1;
1343 1248
1344 CountedBrowserAccessibility::reset();
1345 std::unique_ptr<BrowserAccessibilityManager> manager( 1249 std::unique_ptr<BrowserAccessibilityManager> manager(
1346 BrowserAccessibilityManager::Create( 1250 BrowserAccessibilityManager::Create(update, nullptr,
1347 update, nullptr, new CountedBrowserAccessibilityFactory())); 1251 new BrowserAccessibilityFactory()));
1348 ASSERT_EQ(5, CountedBrowserAccessibility::num_instances());
1349 1252
1350 ASSERT_NE(nullptr, manager->GetRoot()); 1253 ASSERT_NE(nullptr, manager->GetRoot());
1351 BrowserAccessibilityWin* root_accessible = 1254 BrowserAccessibilityWin* root_accessible =
1352 ToBrowserAccessibilityWin(manager->GetRoot()); 1255 ToBrowserAccessibilityWin(manager->GetRoot());
1353 ASSERT_NE(nullptr, root_accessible); 1256 ASSERT_NE(nullptr, root_accessible);
1354 ASSERT_EQ(1U, root_accessible->PlatformChildCount()); 1257 ASSERT_EQ(1U, root_accessible->PlatformChildCount());
1355 1258
1356 BrowserAccessibilityWin* div_editable_accessible = 1259 BrowserAccessibilityWin* div_editable_accessible =
1357 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0)); 1260 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0));
1358 ASSERT_NE(nullptr, div_editable_accessible); 1261 ASSERT_NE(nullptr, div_editable_accessible);
1359 ASSERT_EQ(2U, div_editable_accessible->PlatformChildCount()); 1262 ASSERT_EQ(2U, div_editable_accessible->PlatformChildCount());
1360 1263
1361 // -2 is never a valid offset. 1264 // -2 is never a valid offset.
1362 LONG caret_offset = -2; 1265 LONG caret_offset = -2;
1363 LONG n_selections = -2; 1266 LONG n_selections = -2;
1364 1267
1365 // No selection should be present. 1268 // No selection should be present.
1366 HRESULT hr = div_editable_accessible->get_nSelections(&n_selections); 1269 HRESULT hr =
1270 div_editable_accessible->GetCOM()->get_nSelections(&n_selections);
1367 EXPECT_EQ(S_OK, hr); 1271 EXPECT_EQ(S_OK, hr);
1368 EXPECT_EQ(0, n_selections); 1272 EXPECT_EQ(0, n_selections);
1369 1273
1370 // The caret should be on the embedded object character. 1274 // The caret should be on the embedded object character.
1371 hr = div_editable_accessible->get_caretOffset(&caret_offset); 1275 hr = div_editable_accessible->GetCOM()->get_caretOffset(&caret_offset);
1372 EXPECT_EQ(S_OK, hr); 1276 EXPECT_EQ(S_OK, hr);
1373 EXPECT_EQ(6, caret_offset); 1277 EXPECT_EQ(6, caret_offset);
1374 1278
1375 // Move the focus to the content editable. 1279 // Move the focus to the content editable.
1376 manager->SetFocusLocallyForTesting(div_editable_accessible); 1280 manager->SetFocusLocallyForTesting(div_editable_accessible);
1377 ASSERT_EQ(div_editable_accessible, 1281 ASSERT_EQ(div_editable_accessible,
1378 ToBrowserAccessibilityWin(manager->GetFocus())); 1282 ToBrowserAccessibilityWin(manager->GetFocus()));
1379 1283
1380 BrowserAccessibilityWin* text_accessible = 1284 BrowserAccessibilityWin* text_accessible =
1381 ToBrowserAccessibilityWin(div_editable_accessible->PlatformGetChild(0)); 1285 ToBrowserAccessibilityWin(div_editable_accessible->PlatformGetChild(0));
1382 ASSERT_NE(nullptr, text_accessible); 1286 ASSERT_NE(nullptr, text_accessible);
1383 BrowserAccessibilityWin* link_accessible = 1287 BrowserAccessibilityWin* link_accessible =
1384 ToBrowserAccessibilityWin(div_editable_accessible->PlatformGetChild(1)); 1288 ToBrowserAccessibilityWin(div_editable_accessible->PlatformGetChild(1));
1385 ASSERT_NE(nullptr, link_accessible); 1289 ASSERT_NE(nullptr, link_accessible);
1386 ASSERT_EQ(1U, link_accessible->PlatformChildCount()); 1290 ASSERT_EQ(1U, link_accessible->PlatformChildCount());
1387 1291
1388 BrowserAccessibilityWin* link_text_accessible = 1292 BrowserAccessibilityWin* link_text_accessible =
1389 ToBrowserAccessibilityWin(link_accessible->PlatformGetChild(0)); 1293 ToBrowserAccessibilityWin(link_accessible->PlatformGetChild(0));
1390 ASSERT_NE(nullptr, link_text_accessible); 1294 ASSERT_NE(nullptr, link_text_accessible);
1391 1295
1392 // The caret should not have moved. 1296 // The caret should not have moved.
1393 hr = div_editable_accessible->get_nSelections(&n_selections); 1297 hr = div_editable_accessible->GetCOM()->get_nSelections(&n_selections);
1394 EXPECT_EQ(S_OK, hr); 1298 EXPECT_EQ(S_OK, hr);
1395 EXPECT_EQ(0, n_selections); 1299 EXPECT_EQ(0, n_selections);
1396 hr = div_editable_accessible->get_caretOffset(&caret_offset); 1300 hr = div_editable_accessible->GetCOM()->get_caretOffset(&caret_offset);
1397 EXPECT_EQ(S_OK, hr); 1301 EXPECT_EQ(S_OK, hr);
1398 EXPECT_EQ(6, caret_offset); 1302 EXPECT_EQ(6, caret_offset);
1399 1303
1400 hr = link_accessible->get_nSelections(&n_selections); 1304 hr = link_accessible->GetCOM()->get_nSelections(&n_selections);
1401 EXPECT_EQ(S_OK, hr); 1305 EXPECT_EQ(S_OK, hr);
1402 EXPECT_EQ(0, n_selections); 1306 EXPECT_EQ(0, n_selections);
1403 hr = link_text_accessible->get_nSelections(&n_selections); 1307 hr = link_text_accessible->GetCOM()->get_nSelections(&n_selections);
1404 EXPECT_EQ(S_OK, hr); 1308 EXPECT_EQ(S_OK, hr);
1405 EXPECT_EQ(0, n_selections); 1309 EXPECT_EQ(0, n_selections);
1406 1310
1407 hr = link_accessible->get_caretOffset(&caret_offset); 1311 hr = link_accessible->GetCOM()->get_caretOffset(&caret_offset);
1408 EXPECT_EQ(S_OK, hr); 1312 EXPECT_EQ(S_OK, hr);
1409 EXPECT_EQ(1, caret_offset); 1313 EXPECT_EQ(1, caret_offset);
1410 hr = link_text_accessible->get_caretOffset(&caret_offset); 1314 hr = link_text_accessible->GetCOM()->get_caretOffset(&caret_offset);
1411 EXPECT_EQ(S_OK, hr); 1315 EXPECT_EQ(S_OK, hr);
1412 EXPECT_EQ(1, caret_offset); 1316 EXPECT_EQ(1, caret_offset);
1413 1317
1414 manager.reset(); 1318 manager.reset();
1415 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
1416 } 1319 }
1417 1320
1418 TEST_F(BrowserAccessibilityTest, TestSelectionInContentEditables) { 1321 TEST_F(BrowserAccessibilityTest, TestSelectionInContentEditables) {
1419 ui::AXNodeData root; 1322 ui::AXNodeData root;
1420 root.id = 1; 1323 root.id = 1;
1421 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 1324 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
1422 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); 1325 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE);
1423 1326
1424 ui::AXNodeData div_editable; 1327 ui::AXNodeData div_editable;
1425 div_editable.id = 2; 1328 div_editable.id = 2;
(...skipping 29 matching lines...) Expand all
1455 ui::AXTreeUpdate update = 1358 ui::AXTreeUpdate update =
1456 MakeAXTreeUpdate(root, div_editable, link, link_text, text); 1359 MakeAXTreeUpdate(root, div_editable, link, link_text, text);
1457 1360
1458 // Select the following part of the text: "lick here". 1361 // Select the following part of the text: "lick here".
1459 update.has_tree_data = true; 1362 update.has_tree_data = true;
1460 update.tree_data.sel_anchor_object_id = 3; 1363 update.tree_data.sel_anchor_object_id = 3;
1461 update.tree_data.sel_anchor_offset = 1; 1364 update.tree_data.sel_anchor_offset = 1;
1462 update.tree_data.sel_focus_object_id = 5; 1365 update.tree_data.sel_focus_object_id = 5;
1463 update.tree_data.sel_focus_offset = 4; 1366 update.tree_data.sel_focus_offset = 4;
1464 1367
1465 CountedBrowserAccessibility::reset();
1466 std::unique_ptr<BrowserAccessibilityManager> manager( 1368 std::unique_ptr<BrowserAccessibilityManager> manager(
1467 BrowserAccessibilityManager::Create( 1369 BrowserAccessibilityManager::Create(update, nullptr,
1468 update, nullptr, new CountedBrowserAccessibilityFactory())); 1370 new BrowserAccessibilityFactory()));
1469 ASSERT_EQ(5, CountedBrowserAccessibility::num_instances());
1470 1371
1471 ASSERT_NE(nullptr, manager->GetRoot()); 1372 ASSERT_NE(nullptr, manager->GetRoot());
1472 BrowserAccessibilityWin* root_accessible = 1373 BrowserAccessibilityWin* root_accessible =
1473 ToBrowserAccessibilityWin(manager->GetRoot()); 1374 ToBrowserAccessibilityWin(manager->GetRoot());
1474 ASSERT_NE(nullptr, root_accessible); 1375 ASSERT_NE(nullptr, root_accessible);
1475 ASSERT_EQ(1U, root_accessible->PlatformChildCount()); 1376 ASSERT_EQ(1U, root_accessible->PlatformChildCount());
1476 1377
1477 BrowserAccessibilityWin* div_editable_accessible = 1378 BrowserAccessibilityWin* div_editable_accessible =
1478 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0)); 1379 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0));
1479 ASSERT_NE(nullptr, div_editable_accessible); 1380 ASSERT_NE(nullptr, div_editable_accessible);
(...skipping 11 matching lines...) Expand all
1491 BrowserAccessibilityWin* link_accessible = 1392 BrowserAccessibilityWin* link_accessible =
1492 ToBrowserAccessibilityWin(div_editable_accessible->PlatformGetChild(1)); 1393 ToBrowserAccessibilityWin(div_editable_accessible->PlatformGetChild(1));
1493 ASSERT_NE(nullptr, link_accessible); 1394 ASSERT_NE(nullptr, link_accessible);
1494 ASSERT_EQ(1U, link_accessible->PlatformChildCount()); 1395 ASSERT_EQ(1U, link_accessible->PlatformChildCount());
1495 1396
1496 BrowserAccessibilityWin* link_text_accessible = 1397 BrowserAccessibilityWin* link_text_accessible =
1497 ToBrowserAccessibilityWin(link_accessible->PlatformGetChild(0)); 1398 ToBrowserAccessibilityWin(link_accessible->PlatformGetChild(0));
1498 ASSERT_NE(nullptr, link_text_accessible); 1399 ASSERT_NE(nullptr, link_text_accessible);
1499 1400
1500 // get_nSelections should work on all objects. 1401 // get_nSelections should work on all objects.
1501 HRESULT hr = div_editable_accessible->get_nSelections(&n_selections); 1402 HRESULT hr =
1403 div_editable_accessible->GetCOM()->get_nSelections(&n_selections);
1502 EXPECT_EQ(S_OK, hr); 1404 EXPECT_EQ(S_OK, hr);
1503 EXPECT_EQ(1, n_selections); 1405 EXPECT_EQ(1, n_selections);
1504 hr = text_accessible->get_nSelections(&n_selections); 1406 hr = text_accessible->GetCOM()->get_nSelections(&n_selections);
1505 EXPECT_EQ(S_OK, hr); 1407 EXPECT_EQ(S_OK, hr);
1506 EXPECT_EQ(1, n_selections); 1408 EXPECT_EQ(1, n_selections);
1507 hr = link_accessible->get_nSelections(&n_selections); 1409 hr = link_accessible->GetCOM()->get_nSelections(&n_selections);
1508 EXPECT_EQ(S_OK, hr); 1410 EXPECT_EQ(S_OK, hr);
1509 EXPECT_EQ(1, n_selections); 1411 EXPECT_EQ(1, n_selections);
1510 hr = link_text_accessible->get_nSelections(&n_selections); 1412 hr = link_text_accessible->GetCOM()->get_nSelections(&n_selections);
1511 EXPECT_EQ(S_OK, hr); 1413 EXPECT_EQ(S_OK, hr);
1512 EXPECT_EQ(1, n_selections); 1414 EXPECT_EQ(1, n_selections);
1513 1415
1514 // get_selection should be unaffected by focus placement. 1416 // get_selection should be unaffected by focus placement.
1515 hr = div_editable_accessible->get_selection( 1417 hr = div_editable_accessible->GetCOM()->get_selection(
1516 0L /* selection_index */, &selection_start, &selection_end); 1418 0L /* selection_index */, &selection_start, &selection_end);
1517 EXPECT_EQ(S_OK, hr); 1419 EXPECT_EQ(S_OK, hr);
1518 EXPECT_EQ(1, selection_start); 1420 EXPECT_EQ(1, selection_start);
1519 // selection_end should be after embedded object character. 1421 // selection_end should be after embedded object character.
1520 EXPECT_EQ(7, selection_end); 1422 EXPECT_EQ(7, selection_end);
1521 1423
1522 hr = text_accessible->get_selection( 1424 hr = text_accessible->GetCOM()->get_selection(
1523 0L /* selection_index */, &selection_start, &selection_end); 1425 0L /* selection_index */, &selection_start, &selection_end);
1524 EXPECT_EQ(S_OK, hr); 1426 EXPECT_EQ(S_OK, hr);
1525 EXPECT_EQ(1, selection_start); 1427 EXPECT_EQ(1, selection_start);
1526 // No embedded character on this object, only the first part of the text. 1428 // No embedded character on this object, only the first part of the text.
1527 EXPECT_EQ(6, selection_end); 1429 EXPECT_EQ(6, selection_end);
1528 hr = link_accessible->get_selection( 1430 hr = link_accessible->GetCOM()->get_selection(
1529 0L /* selection_index */, &selection_start, &selection_end); 1431 0L /* selection_index */, &selection_start, &selection_end);
1530 EXPECT_EQ(S_OK, hr); 1432 EXPECT_EQ(S_OK, hr);
1531 EXPECT_EQ(0, selection_start); 1433 EXPECT_EQ(0, selection_start);
1532 EXPECT_EQ(4, selection_end); 1434 EXPECT_EQ(4, selection_end);
1533 hr = link_text_accessible->get_selection( 1435 hr = link_text_accessible->GetCOM()->get_selection(
1534 0L /* selection_index */, &selection_start, &selection_end); 1436 0L /* selection_index */, &selection_start, &selection_end);
1535 EXPECT_EQ(S_OK, hr); 1437 EXPECT_EQ(S_OK, hr);
1536 EXPECT_EQ(0, selection_start); 1438 EXPECT_EQ(0, selection_start);
1537 EXPECT_EQ(4, selection_end); 1439 EXPECT_EQ(4, selection_end);
1538 1440
1539 // The caret should be at the focus (the end) of the selection. 1441 // The caret should be at the focus (the end) of the selection.
1540 hr = div_editable_accessible->get_caretOffset(&caret_offset); 1442 hr = div_editable_accessible->GetCOM()->get_caretOffset(&caret_offset);
1541 EXPECT_EQ(S_OK, hr); 1443 EXPECT_EQ(S_OK, hr);
1542 EXPECT_EQ(7, caret_offset); 1444 EXPECT_EQ(7, caret_offset);
1543 1445
1544 // Move the focus to the content editable. 1446 // Move the focus to the content editable.
1545 manager->SetFocusLocallyForTesting(div_editable_accessible); 1447 manager->SetFocusLocallyForTesting(div_editable_accessible);
1546 ASSERT_EQ(div_editable_accessible, 1448 ASSERT_EQ(div_editable_accessible,
1547 ToBrowserAccessibilityWin(manager->GetFocus())); 1449 ToBrowserAccessibilityWin(manager->GetFocus()));
1548 1450
1549 // The caret should not have moved. 1451 // The caret should not have moved.
1550 hr = div_editable_accessible->get_caretOffset(&caret_offset); 1452 hr = div_editable_accessible->GetCOM()->get_caretOffset(&caret_offset);
1551 EXPECT_EQ(S_OK, hr); 1453 EXPECT_EQ(S_OK, hr);
1552 EXPECT_EQ(7, caret_offset); 1454 EXPECT_EQ(7, caret_offset);
1553 1455
1554 // The caret offset should reflect the position of the selection's focus in 1456 // The caret offset should reflect the position of the selection's focus in
1555 // any given object. 1457 // any given object.
1556 hr = link_accessible->get_caretOffset(&caret_offset); 1458 hr = link_accessible->GetCOM()->get_caretOffset(&caret_offset);
1557 EXPECT_EQ(S_OK, hr); 1459 EXPECT_EQ(S_OK, hr);
1558 EXPECT_EQ(4, caret_offset); 1460 EXPECT_EQ(4, caret_offset);
1559 hr = link_text_accessible->get_caretOffset(&caret_offset); 1461 hr = link_text_accessible->GetCOM()->get_caretOffset(&caret_offset);
1560 EXPECT_EQ(S_OK, hr); 1462 EXPECT_EQ(S_OK, hr);
1561 EXPECT_EQ(4, caret_offset); 1463 EXPECT_EQ(4, caret_offset);
1562 1464
1563 hr = div_editable_accessible->get_selection( 1465 hr = div_editable_accessible->GetCOM()->get_selection(
1564 0L /* selection_index */, &selection_start, &selection_end); 1466 0L /* selection_index */, &selection_start, &selection_end);
1565 EXPECT_EQ(S_OK, hr); 1467 EXPECT_EQ(S_OK, hr);
1566 EXPECT_EQ(1, selection_start); 1468 EXPECT_EQ(1, selection_start);
1567 EXPECT_EQ(7, selection_end); 1469 EXPECT_EQ(7, selection_end);
1568 1470
1569 manager.reset(); 1471 manager.reset();
1570 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
1571 } 1472 }
1572 1473
1573 TEST_F(BrowserAccessibilityTest, TestIAccessibleHyperlink) { 1474 TEST_F(BrowserAccessibilityTest, TestIAccessibleHyperlink) {
1574 ui::AXNodeData root; 1475 ui::AXNodeData root;
1575 root.id = 1; 1476 root.id = 1;
1576 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 1477 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
1577 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); 1478 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE);
1578 1479
1579 ui::AXNodeData div; 1480 ui::AXNodeData div;
1580 div.id = 2; 1481 div.id = 2;
1581 div.role = ui::AX_ROLE_DIV; 1482 div.role = ui::AX_ROLE_DIV;
1582 div.state = (1 << ui::AX_STATE_FOCUSABLE); 1483 div.state = (1 << ui::AX_STATE_FOCUSABLE);
1583 1484
1584 ui::AXNodeData text; 1485 ui::AXNodeData text;
1585 text.id = 3; 1486 text.id = 3;
1586 text.role = ui::AX_ROLE_STATIC_TEXT; 1487 text.role = ui::AX_ROLE_STATIC_TEXT;
1587 text.SetName("Click "); 1488 text.SetName("Click ");
1588 1489
1589 ui::AXNodeData link; 1490 ui::AXNodeData link;
1590 link.id = 4; 1491 link.id = 4;
1591 link.role = ui::AX_ROLE_LINK; 1492 link.role = ui::AX_ROLE_LINK;
1592 link.state = (1 << ui::AX_STATE_FOCUSABLE) | (1 << ui::AX_STATE_LINKED); 1493 link.state = (1 << ui::AX_STATE_FOCUSABLE) | (1 << ui::AX_STATE_LINKED);
1593 link.SetName("here"); 1494 link.SetName("here");
1594 link.AddStringAttribute(ui::AX_ATTR_URL, "example.com"); 1495 link.AddStringAttribute(ui::AX_ATTR_URL, "example.com");
1595 1496
1596 root.child_ids.push_back(2); 1497 root.child_ids.push_back(2);
1597 div.child_ids.push_back(3); 1498 div.child_ids.push_back(3);
1598 div.child_ids.push_back(4); 1499 div.child_ids.push_back(4);
1599 1500
1600 CountedBrowserAccessibility::reset();
1601 std::unique_ptr<BrowserAccessibilityManager> manager( 1501 std::unique_ptr<BrowserAccessibilityManager> manager(
1602 BrowserAccessibilityManager::Create( 1502 BrowserAccessibilityManager::Create(
1603 MakeAXTreeUpdate(root, div, link, text), nullptr, 1503 MakeAXTreeUpdate(root, div, link, text), nullptr,
1604 new CountedBrowserAccessibilityFactory())); 1504 new BrowserAccessibilityFactory()));
1605 ASSERT_EQ(4, CountedBrowserAccessibility::num_instances());
1606 1505
1607 ASSERT_NE(nullptr, manager->GetRoot()); 1506 ASSERT_NE(nullptr, manager->GetRoot());
1608 BrowserAccessibilityWin* root_accessible = 1507 BrowserAccessibilityWin* root_accessible =
1609 ToBrowserAccessibilityWin(manager->GetRoot()); 1508 ToBrowserAccessibilityWin(manager->GetRoot());
1610 ASSERT_NE(nullptr, root_accessible); 1509 ASSERT_NE(nullptr, root_accessible);
1611 ASSERT_EQ(1U, root_accessible->PlatformChildCount()); 1510 ASSERT_EQ(1U, root_accessible->PlatformChildCount());
1612 1511
1613 BrowserAccessibilityWin* div_accessible = 1512 BrowserAccessibilityWin* div_accessible =
1614 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0)); 1513 ToBrowserAccessibilityWin(root_accessible->PlatformGetChild(0));
1615 ASSERT_NE(nullptr, div_accessible); 1514 ASSERT_NE(nullptr, div_accessible);
(...skipping 10 matching lines...) Expand all
1626 LONG n_actions = -1; 1525 LONG n_actions = -1;
1627 LONG start_index = -1; 1526 LONG start_index = -1;
1628 LONG end_index = -1; 1527 LONG end_index = -1;
1629 1528
1630 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; 1529 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink;
1631 base::win::ScopedVariant anchor; 1530 base::win::ScopedVariant anchor;
1632 base::win::ScopedVariant anchor_target; 1531 base::win::ScopedVariant anchor_target;
1633 base::win::ScopedBstr bstr; 1532 base::win::ScopedBstr bstr;
1634 1533
1635 base::string16 div_hypertext(L"Click "); 1534 base::string16 div_hypertext(L"Click ");
1636 div_hypertext.push_back(BrowserAccessibilityWin::kEmbeddedCharacter); 1535 div_hypertext.push_back(BrowserAccessibilityComWin::kEmbeddedCharacter);
1637 1536
1638 // div_accessible and link_accessible are the only IA2 hyperlinks. 1537 // div_accessible and link_accessible are the only IA2 hyperlinks.
1639 EXPECT_HRESULT_FAILED(root_accessible->QueryInterface( 1538 EXPECT_HRESULT_FAILED(root_accessible->GetCOM()->QueryInterface(
1640 IID_IAccessibleHyperlink, reinterpret_cast<void**>(hyperlink.Receive()))); 1539 IID_IAccessibleHyperlink, reinterpret_cast<void**>(hyperlink.Receive())));
1641 hyperlink.Reset(); 1540 hyperlink.Reset();
1642 EXPECT_HRESULT_SUCCEEDED(div_accessible->QueryInterface( 1541 EXPECT_HRESULT_SUCCEEDED(div_accessible->GetCOM()->QueryInterface(
1643 IID_IAccessibleHyperlink, reinterpret_cast<void**>(hyperlink.Receive()))); 1542 IID_IAccessibleHyperlink, reinterpret_cast<void**>(hyperlink.Receive())));
1644 hyperlink.Reset(); 1543 hyperlink.Reset();
1645 EXPECT_HRESULT_FAILED(text_accessible->QueryInterface( 1544 EXPECT_HRESULT_FAILED(text_accessible->GetCOM()->QueryInterface(
1646 IID_IAccessibleHyperlink, reinterpret_cast<void**>(hyperlink.Receive()))); 1545 IID_IAccessibleHyperlink, reinterpret_cast<void**>(hyperlink.Receive())));
1647 hyperlink.Reset(); 1546 hyperlink.Reset();
1648 EXPECT_HRESULT_SUCCEEDED(link_accessible->QueryInterface( 1547 EXPECT_HRESULT_SUCCEEDED(link_accessible->GetCOM()->QueryInterface(
1649 IID_IAccessibleHyperlink, reinterpret_cast<void**>(hyperlink.Receive()))); 1548 IID_IAccessibleHyperlink, reinterpret_cast<void**>(hyperlink.Receive())));
1650 hyperlink.Reset(); 1549 hyperlink.Reset();
1651 1550
1652 EXPECT_HRESULT_SUCCEEDED(root_accessible->nActions(&n_actions)); 1551 EXPECT_HRESULT_SUCCEEDED(root_accessible->GetCOM()->nActions(&n_actions));
1653 EXPECT_EQ(0, n_actions); 1552 EXPECT_EQ(0, n_actions);
1654 EXPECT_HRESULT_SUCCEEDED(div_accessible->nActions(&n_actions)); 1553 EXPECT_HRESULT_SUCCEEDED(div_accessible->GetCOM()->nActions(&n_actions));
1655 EXPECT_EQ(1, n_actions); 1554 EXPECT_EQ(1, n_actions);
1656 EXPECT_HRESULT_SUCCEEDED(text_accessible->nActions(&n_actions)); 1555 EXPECT_HRESULT_SUCCEEDED(text_accessible->GetCOM()->nActions(&n_actions));
1657 EXPECT_EQ(0, n_actions); 1556 EXPECT_EQ(0, n_actions);
1658 EXPECT_HRESULT_SUCCEEDED(link_accessible->nActions(&n_actions)); 1557 EXPECT_HRESULT_SUCCEEDED(link_accessible->GetCOM()->nActions(&n_actions));
1659 EXPECT_EQ(1, n_actions); 1558 EXPECT_EQ(1, n_actions);
1660 1559
1661 EXPECT_HRESULT_FAILED(root_accessible->get_anchor(0, anchor.Receive())); 1560 EXPECT_HRESULT_FAILED(
1561 root_accessible->GetCOM()->get_anchor(0, anchor.Receive()));
1662 anchor.Reset(); 1562 anchor.Reset();
1663 HRESULT hr = div_accessible->get_anchor(0, anchor.Receive()); 1563 HRESULT hr = div_accessible->GetCOM()->get_anchor(0, anchor.Receive());
1664 EXPECT_EQ(S_OK, hr); 1564 EXPECT_EQ(S_OK, hr);
1665 EXPECT_EQ(VT_BSTR, anchor.type()); 1565 EXPECT_EQ(VT_BSTR, anchor.type());
1666 bstr.Reset(V_BSTR(anchor.ptr())); 1566 bstr.Reset(V_BSTR(anchor.ptr()));
1667 EXPECT_STREQ(div_hypertext.c_str(), bstr); 1567 EXPECT_STREQ(div_hypertext.c_str(), bstr);
1668 bstr.Reset(); 1568 bstr.Reset();
1669 anchor.Reset(); 1569 anchor.Reset();
1670 EXPECT_HRESULT_FAILED(text_accessible->get_anchor(0, anchor.Receive())); 1570 EXPECT_HRESULT_FAILED(
1571 text_accessible->GetCOM()->get_anchor(0, anchor.Receive()));
1671 anchor.Reset(); 1572 anchor.Reset();
1672 hr = link_accessible->get_anchor(0, anchor.Receive()); 1573 hr = link_accessible->GetCOM()->get_anchor(0, anchor.Receive());
1673 EXPECT_EQ(S_OK, hr); 1574 EXPECT_EQ(S_OK, hr);
1674 EXPECT_EQ(VT_BSTR, anchor.type()); 1575 EXPECT_EQ(VT_BSTR, anchor.type());
1675 bstr.Reset(V_BSTR(anchor.ptr())); 1576 bstr.Reset(V_BSTR(anchor.ptr()));
1676 EXPECT_STREQ(L"here", bstr); 1577 EXPECT_STREQ(L"here", bstr);
1677 bstr.Reset(); 1578 bstr.Reset();
1678 anchor.Reset(); 1579 anchor.Reset();
1679 EXPECT_HRESULT_FAILED(div_accessible->get_anchor(1, anchor.Receive())); 1580 EXPECT_HRESULT_FAILED(
1581 div_accessible->GetCOM()->get_anchor(1, anchor.Receive()));
1680 anchor.Reset(); 1582 anchor.Reset();
1681 EXPECT_HRESULT_FAILED(link_accessible->get_anchor(1, anchor.Receive())); 1583 EXPECT_HRESULT_FAILED(
1584 link_accessible->GetCOM()->get_anchor(1, anchor.Receive()));
1682 anchor.Reset(); 1585 anchor.Reset();
1683 1586
1684 EXPECT_HRESULT_FAILED( 1587 EXPECT_HRESULT_FAILED(
1685 root_accessible->get_anchorTarget(0, anchor_target.Receive())); 1588 root_accessible->GetCOM()->get_anchorTarget(0, anchor_target.Receive()));
1686 anchor_target.Reset(); 1589 anchor_target.Reset();
1687 hr = div_accessible->get_anchorTarget(0, anchor_target.Receive()); 1590 hr = div_accessible->GetCOM()->get_anchorTarget(0, anchor_target.Receive());
1688 EXPECT_EQ(S_FALSE, hr); 1591 EXPECT_EQ(S_FALSE, hr);
1689 EXPECT_EQ(VT_BSTR, anchor_target.type()); 1592 EXPECT_EQ(VT_BSTR, anchor_target.type());
1690 bstr.Reset(V_BSTR(anchor_target.ptr())); 1593 bstr.Reset(V_BSTR(anchor_target.ptr()));
1691 // Target should be empty. 1594 // Target should be empty.
1692 EXPECT_STREQ(L"", bstr); 1595 EXPECT_STREQ(L"", bstr);
1693 bstr.Reset(); 1596 bstr.Reset();
1694 anchor_target.Reset(); 1597 anchor_target.Reset();
1695 EXPECT_HRESULT_FAILED( 1598 EXPECT_HRESULT_FAILED(
1696 text_accessible->get_anchorTarget(0, anchor_target.Receive())); 1599 text_accessible->GetCOM()->get_anchorTarget(0, anchor_target.Receive()));
1697 anchor_target.Reset(); 1600 anchor_target.Reset();
1698 hr = link_accessible->get_anchorTarget(0, anchor_target.Receive()); 1601 hr = link_accessible->GetCOM()->get_anchorTarget(0, anchor_target.Receive());
1699 EXPECT_EQ(S_OK, hr); 1602 EXPECT_EQ(S_OK, hr);
1700 EXPECT_EQ(VT_BSTR, anchor_target.type()); 1603 EXPECT_EQ(VT_BSTR, anchor_target.type());
1701 bstr.Reset(V_BSTR(anchor_target.ptr())); 1604 bstr.Reset(V_BSTR(anchor_target.ptr()));
1702 EXPECT_STREQ(L"example.com", bstr); 1605 EXPECT_STREQ(L"example.com", bstr);
1703 bstr.Reset(); 1606 bstr.Reset();
1704 anchor_target.Reset(); 1607 anchor_target.Reset();
1705 EXPECT_HRESULT_FAILED( 1608 EXPECT_HRESULT_FAILED(
1706 div_accessible->get_anchorTarget(1, anchor_target.Receive())); 1609 div_accessible->GetCOM()->get_anchorTarget(1, anchor_target.Receive()));
1707 anchor_target.Reset(); 1610 anchor_target.Reset();
1708 EXPECT_HRESULT_FAILED( 1611 EXPECT_HRESULT_FAILED(
1709 link_accessible->get_anchorTarget(1, anchor_target.Receive())); 1612 link_accessible->GetCOM()->get_anchorTarget(1, anchor_target.Receive()));
1710 anchor_target.Reset(); 1613 anchor_target.Reset();
1711 1614
1712 EXPECT_HRESULT_FAILED(root_accessible->get_startIndex(&start_index)); 1615 EXPECT_HRESULT_FAILED(
1713 EXPECT_HRESULT_SUCCEEDED(div_accessible->get_startIndex(&start_index)); 1616 root_accessible->GetCOM()->get_startIndex(&start_index));
1617 EXPECT_HRESULT_SUCCEEDED(
1618 div_accessible->GetCOM()->get_startIndex(&start_index));
1714 EXPECT_EQ(0, start_index); 1619 EXPECT_EQ(0, start_index);
1715 EXPECT_HRESULT_FAILED(text_accessible->get_startIndex(&start_index)); 1620 EXPECT_HRESULT_FAILED(
1716 EXPECT_HRESULT_SUCCEEDED(link_accessible->get_startIndex(&start_index)); 1621 text_accessible->GetCOM()->get_startIndex(&start_index));
1622 EXPECT_HRESULT_SUCCEEDED(
1623 link_accessible->GetCOM()->get_startIndex(&start_index));
1717 EXPECT_EQ(6, start_index); 1624 EXPECT_EQ(6, start_index);
1718 1625
1719 EXPECT_HRESULT_FAILED(root_accessible->get_endIndex(&end_index)); 1626 EXPECT_HRESULT_FAILED(root_accessible->GetCOM()->get_endIndex(&end_index));
1720 EXPECT_HRESULT_SUCCEEDED(div_accessible->get_endIndex(&end_index)); 1627 EXPECT_HRESULT_SUCCEEDED(div_accessible->GetCOM()->get_endIndex(&end_index));
1721 EXPECT_EQ(1, end_index); 1628 EXPECT_EQ(1, end_index);
1722 EXPECT_HRESULT_FAILED(text_accessible->get_endIndex(&end_index)); 1629 EXPECT_HRESULT_FAILED(text_accessible->GetCOM()->get_endIndex(&end_index));
1723 EXPECT_HRESULT_SUCCEEDED(link_accessible->get_endIndex(&end_index)); 1630 EXPECT_HRESULT_SUCCEEDED(link_accessible->GetCOM()->get_endIndex(&end_index));
1724 EXPECT_EQ(7, end_index); 1631 EXPECT_EQ(7, end_index);
1725 } 1632 }
1726 1633
1727 TEST_F(BrowserAccessibilityTest, TestTextAttributesInContentEditables) { 1634 TEST_F(BrowserAccessibilityTest, TestTextAttributesInContentEditables) {
1728 ui::AXNodeData root; 1635 ui::AXNodeData root;
1729 root.id = 1; 1636 root.id = 1;
1730 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 1637 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
1731 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); 1638 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE);
1732 1639
1733 ui::AXNodeData div_editable; 1640 ui::AXNodeData div_editable;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 1690
1784 root.child_ids.push_back(div_editable.id); 1691 root.child_ids.push_back(div_editable.id);
1785 div_editable.child_ids.push_back(text_before.id); 1692 div_editable.child_ids.push_back(text_before.id);
1786 div_editable.child_ids.push_back(link.id); 1693 div_editable.child_ids.push_back(link.id);
1787 div_editable.child_ids.push_back(text_after.id); 1694 div_editable.child_ids.push_back(text_after.id);
1788 link.child_ids.push_back(link_text.id); 1695 link.child_ids.push_back(link_text.id);
1789 1696
1790 ui::AXTreeUpdate update = MakeAXTreeUpdate(root, div_editable, text_before, 1697 ui::AXTreeUpdate update = MakeAXTreeUpdate(root, div_editable, text_before,
1791 link, link_text, text_after); 1698 link, link_text, text_after);
1792 1699
1793 CountedBrowserAccessibility::reset();
1794 std::unique_ptr<BrowserAccessibilityManager> manager( 1700 std::unique_ptr<BrowserAccessibilityManager> manager(
1795 BrowserAccessibilityManager::Create( 1701 BrowserAccessibilityManager::Create(update, nullptr,
1796 update, nullptr, new CountedBrowserAccessibilityFactory())); 1702 new BrowserAccessibilityFactory()));
1797 ASSERT_EQ(6, CountedBrowserAccessibility::num_instances());
1798 1703
1799 ASSERT_NE(nullptr, manager->GetRoot()); 1704 ASSERT_NE(nullptr, manager->GetRoot());
1800 BrowserAccessibilityWin* ax_root = 1705 BrowserAccessibilityWin* ax_root =
1801 ToBrowserAccessibilityWin(manager->GetRoot()); 1706 ToBrowserAccessibilityWin(manager->GetRoot());
1802 ASSERT_NE(nullptr, ax_root); 1707 ASSERT_NE(nullptr, ax_root);
1803 ASSERT_EQ(1U, ax_root->PlatformChildCount()); 1708 ASSERT_EQ(1U, ax_root->PlatformChildCount());
1804 1709
1805 BrowserAccessibilityWin* ax_div = 1710 BrowserAccessibilityWin* ax_div =
1806 ToBrowserAccessibilityWin(ax_root->PlatformGetChild(0)); 1711 ToBrowserAccessibilityWin(ax_root->PlatformGetChild(0));
1807 ASSERT_NE(nullptr, ax_div); 1712 ASSERT_NE(nullptr, ax_div);
(...skipping 11 matching lines...) Expand all
1819 ASSERT_NE(nullptr, ax_after); 1724 ASSERT_NE(nullptr, ax_after);
1820 1725
1821 BrowserAccessibilityWin* ax_link_text = 1726 BrowserAccessibilityWin* ax_link_text =
1822 ToBrowserAccessibilityWin(ax_link->PlatformGetChild(0)); 1727 ToBrowserAccessibilityWin(ax_link->PlatformGetChild(0));
1823 ASSERT_NE(nullptr, ax_link_text); 1728 ASSERT_NE(nullptr, ax_link_text);
1824 1729
1825 HRESULT hr; 1730 HRESULT hr;
1826 LONG n_characters, start_offset, end_offset; 1731 LONG n_characters, start_offset, end_offset;
1827 base::win::ScopedBstr text_attributes; 1732 base::win::ScopedBstr text_attributes;
1828 1733
1829 ASSERT_HRESULT_SUCCEEDED(ax_root->get_nCharacters(&n_characters)); 1734 ASSERT_HRESULT_SUCCEEDED(ax_root->GetCOM()->get_nCharacters(&n_characters));
1830 ASSERT_EQ(1, n_characters); 1735 ASSERT_EQ(1, n_characters);
1831 ASSERT_HRESULT_SUCCEEDED(ax_div->get_nCharacters(&n_characters)); 1736 ASSERT_HRESULT_SUCCEEDED(ax_div->GetCOM()->get_nCharacters(&n_characters));
1832 ASSERT_EQ(15, n_characters); 1737 ASSERT_EQ(15, n_characters);
1833 1738
1834 // Test the style of the root. 1739 // Test the style of the root.
1835 hr = ax_root->get_attributes(0, &start_offset, &end_offset, 1740 hr = ax_root->GetCOM()->get_attributes(0, &start_offset, &end_offset,
1836 text_attributes.Receive()); 1741 text_attributes.Receive());
1837 EXPECT_EQ(S_OK, hr); 1742 EXPECT_EQ(S_OK, hr);
1838 EXPECT_EQ(0, start_offset); 1743 EXPECT_EQ(0, start_offset);
1839 EXPECT_EQ(1, end_offset); 1744 EXPECT_EQ(1, end_offset);
1840 EXPECT_NE(base::string16::npos, 1745 EXPECT_NE(base::string16::npos,
1841 base::string16(text_attributes).find(L"font-family:Helvetica")); 1746 base::string16(text_attributes).find(L"font-family:Helvetica"));
1842 text_attributes.Reset(); 1747 text_attributes.Reset();
1843 1748
1844 // Test the style of text_before. 1749 // Test the style of text_before.
1845 for (LONG offset = 0; offset < 7; ++offset) { 1750 for (LONG offset = 0; offset < 7; ++offset) {
1846 hr = ax_div->get_attributes(0, &start_offset, &end_offset, 1751 hr = ax_div->GetCOM()->get_attributes(0, &start_offset, &end_offset,
1847 text_attributes.Receive()); 1752 text_attributes.Receive());
1848 EXPECT_EQ(S_OK, hr); 1753 EXPECT_EQ(S_OK, hr);
1849 EXPECT_EQ(0, start_offset); 1754 EXPECT_EQ(0, start_offset);
1850 EXPECT_EQ(7, end_offset); 1755 EXPECT_EQ(7, end_offset);
1851 base::string16 attributes(text_attributes); 1756 base::string16 attributes(text_attributes);
1852 EXPECT_NE(base::string16::npos, attributes.find(L"font-family:Helvetica")); 1757 EXPECT_NE(base::string16::npos, attributes.find(L"font-family:Helvetica"));
1853 EXPECT_NE(base::string16::npos, attributes.find(L"font-weight:bold")); 1758 EXPECT_NE(base::string16::npos, attributes.find(L"font-weight:bold"));
1854 EXPECT_NE(base::string16::npos, attributes.find(L"font-style:italic")); 1759 EXPECT_NE(base::string16::npos, attributes.find(L"font-style:italic"));
1855 text_attributes.Reset(); 1760 text_attributes.Reset();
1856 } 1761 }
1857 1762
1858 // Test the style of the link. 1763 // Test the style of the link.
1859 hr = ax_link->get_attributes(0, &start_offset, &end_offset, 1764 hr = ax_link->GetCOM()->get_attributes(0, &start_offset, &end_offset,
1860 text_attributes.Receive()); 1765 text_attributes.Receive());
1861 EXPECT_EQ(S_OK, hr); 1766 EXPECT_EQ(S_OK, hr);
1862 EXPECT_EQ(0, start_offset); 1767 EXPECT_EQ(0, start_offset);
1863 EXPECT_EQ(3, end_offset); 1768 EXPECT_EQ(3, end_offset);
1864 EXPECT_NE(base::string16::npos, 1769 EXPECT_NE(base::string16::npos,
1865 base::string16(text_attributes).find(L"font-family:Helvetica")); 1770 base::string16(text_attributes).find(L"font-family:Helvetica"));
1866 EXPECT_NE(base::string16::npos, 1771 EXPECT_NE(base::string16::npos,
1867 base::string16(text_attributes).find(L"font-weight:normal")); 1772 base::string16(text_attributes).find(L"font-weight:normal"));
1868 EXPECT_NE(base::string16::npos, 1773 EXPECT_NE(base::string16::npos,
1869 base::string16(text_attributes).find(L"font-style:normal")); 1774 base::string16(text_attributes).find(L"font-style:normal"));
1870 EXPECT_NE( 1775 EXPECT_NE(
1871 base::string16::npos, 1776 base::string16::npos,
1872 base::string16(text_attributes).find(L"text-underline-style:solid")); 1777 base::string16(text_attributes).find(L"text-underline-style:solid"));
1873 EXPECT_NE( 1778 EXPECT_NE(
1874 base::string16::npos, 1779 base::string16::npos,
1875 base::string16(text_attributes).find(L"text-underline-type:single")); 1780 base::string16(text_attributes).find(L"text-underline-type:single"));
1876 text_attributes.Reset(); 1781 text_attributes.Reset();
1877 1782
1878 hr = ax_link_text->get_attributes(2, &start_offset, &end_offset, 1783 hr = ax_link_text->GetCOM()->get_attributes(2, &start_offset, &end_offset,
1879 text_attributes.Receive()); 1784 text_attributes.Receive());
1880 EXPECT_EQ(S_OK, hr); 1785 EXPECT_EQ(S_OK, hr);
1881 EXPECT_EQ(0, start_offset); 1786 EXPECT_EQ(0, start_offset);
1882 EXPECT_EQ(3, end_offset); 1787 EXPECT_EQ(3, end_offset);
1883 EXPECT_NE(base::string16::npos, 1788 EXPECT_NE(base::string16::npos,
1884 base::string16(text_attributes).find(L"font-family:Helvetica")); 1789 base::string16(text_attributes).find(L"font-family:Helvetica"));
1885 EXPECT_NE(base::string16::npos, 1790 EXPECT_NE(base::string16::npos,
1886 base::string16(text_attributes).find(L"font-weight:normal")); 1791 base::string16(text_attributes).find(L"font-weight:normal"));
1887 EXPECT_NE(base::string16::npos, 1792 EXPECT_NE(base::string16::npos,
1888 base::string16(text_attributes).find(L"font-style:normal")); 1793 base::string16(text_attributes).find(L"font-style:normal"));
1889 EXPECT_NE( 1794 EXPECT_NE(
1890 base::string16::npos, 1795 base::string16::npos,
1891 base::string16(text_attributes).find(L"text-underline-style:solid")); 1796 base::string16(text_attributes).find(L"text-underline-style:solid"));
1892 EXPECT_NE( 1797 EXPECT_NE(
1893 base::string16::npos, 1798 base::string16::npos,
1894 base::string16(text_attributes).find(L"text-underline-type:single")); 1799 base::string16(text_attributes).find(L"text-underline-type:single"));
1895 EXPECT_NE(base::string16::npos, 1800 EXPECT_NE(base::string16::npos,
1896 base::string16(text_attributes).find(L"invalid:spelling")); 1801 base::string16(text_attributes).find(L"invalid:spelling"));
1897 text_attributes.Reset(); 1802 text_attributes.Reset();
1898 1803
1899 // Test the style of text_after. 1804 // Test the style of text_after.
1900 for (LONG offset = 8; offset < 15; ++offset) { 1805 for (LONG offset = 8; offset < 15; ++offset) {
1901 hr = ax_div->get_attributes(offset, &start_offset, &end_offset, 1806 hr = ax_div->GetCOM()->get_attributes(offset, &start_offset, &end_offset,
1902 text_attributes.Receive()); 1807 text_attributes.Receive());
1903 EXPECT_EQ(S_OK, hr); 1808 EXPECT_EQ(S_OK, hr);
1904 EXPECT_EQ(8, start_offset); 1809 EXPECT_EQ(8, start_offset);
1905 EXPECT_EQ(15, end_offset); 1810 EXPECT_EQ(15, end_offset);
1906 base::string16 attributes(text_attributes); 1811 base::string16 attributes(text_attributes);
1907 EXPECT_NE(base::string16::npos, attributes.find(L"font-family:Helvetica")); 1812 EXPECT_NE(base::string16::npos, attributes.find(L"font-family:Helvetica"));
1908 EXPECT_NE(base::string16::npos, attributes.find(L"font-weight:normal")); 1813 EXPECT_NE(base::string16::npos, attributes.find(L"font-weight:normal"));
1909 EXPECT_NE(base::string16::npos, attributes.find(L"font-style:normal")); 1814 EXPECT_NE(base::string16::npos, attributes.find(L"font-style:normal"));
1910 EXPECT_NE( 1815 EXPECT_NE(
1911 base::string16::npos, 1816 base::string16::npos,
1912 base::string16(text_attributes).find(L"text-underline-style:none")); 1817 base::string16(text_attributes).find(L"text-underline-style:none"));
1913 EXPECT_NE( 1818 EXPECT_NE(
1914 base::string16::npos, 1819 base::string16::npos,
1915 base::string16(text_attributes).find(L"text-underline-type:none")); 1820 base::string16(text_attributes).find(L"text-underline-type:none"));
1916 EXPECT_EQ(base::string16::npos, attributes.find(L"invalid:spelling")); 1821 EXPECT_EQ(base::string16::npos, attributes.find(L"invalid:spelling"));
1917 text_attributes.Reset(); 1822 text_attributes.Reset();
1918 } 1823 }
1919 1824
1920 // Test the style of the static text nodes. 1825 // Test the style of the static text nodes.
1921 hr = ax_before->get_attributes(6, &start_offset, &end_offset, 1826 hr = ax_before->GetCOM()->get_attributes(6, &start_offset, &end_offset,
1922 text_attributes.Receive()); 1827 text_attributes.Receive());
1923 EXPECT_EQ(S_OK, hr); 1828 EXPECT_EQ(S_OK, hr);
1924 EXPECT_EQ(0, start_offset); 1829 EXPECT_EQ(0, start_offset);
1925 EXPECT_EQ(7, end_offset); 1830 EXPECT_EQ(7, end_offset);
1926 EXPECT_NE(base::string16::npos, 1831 EXPECT_NE(base::string16::npos,
1927 base::string16(text_attributes).find(L"font-family:Helvetica")); 1832 base::string16(text_attributes).find(L"font-family:Helvetica"));
1928 EXPECT_NE(base::string16::npos, 1833 EXPECT_NE(base::string16::npos,
1929 base::string16(text_attributes).find(L"font-weight:bold")); 1834 base::string16(text_attributes).find(L"font-weight:bold"));
1930 EXPECT_NE(base::string16::npos, 1835 EXPECT_NE(base::string16::npos,
1931 base::string16(text_attributes).find(L"font-style:italic")); 1836 base::string16(text_attributes).find(L"font-style:italic"));
1932 EXPECT_EQ(base::string16::npos, 1837 EXPECT_EQ(base::string16::npos,
1933 base::string16(text_attributes).find(L"invalid:spelling")); 1838 base::string16(text_attributes).find(L"invalid:spelling"));
1934 text_attributes.Reset(); 1839 text_attributes.Reset();
1935 1840
1936 hr = ax_after->get_attributes(6, &start_offset, &end_offset, 1841 hr = ax_after->GetCOM()->get_attributes(6, &start_offset, &end_offset,
1937 text_attributes.Receive()); 1842 text_attributes.Receive());
1938 EXPECT_EQ(S_OK, hr); 1843 EXPECT_EQ(S_OK, hr);
1939 EXPECT_EQ(0, start_offset); 1844 EXPECT_EQ(0, start_offset);
1940 EXPECT_EQ(7, end_offset); 1845 EXPECT_EQ(7, end_offset);
1941 EXPECT_NE(base::string16::npos, 1846 EXPECT_NE(base::string16::npos,
1942 base::string16(text_attributes).find(L"font-family:Helvetica")); 1847 base::string16(text_attributes).find(L"font-family:Helvetica"));
1943 EXPECT_NE(base::string16::npos, 1848 EXPECT_NE(base::string16::npos,
1944 base::string16(text_attributes).find(L"font-weight:normal")); 1849 base::string16(text_attributes).find(L"font-weight:normal"));
1945 EXPECT_NE(base::string16::npos, 1850 EXPECT_NE(base::string16::npos,
1946 base::string16(text_attributes).find(L"font-style:normal")); 1851 base::string16(text_attributes).find(L"font-style:normal"));
1947 EXPECT_NE(base::string16::npos, 1852 EXPECT_NE(base::string16::npos,
1948 base::string16(text_attributes).find(L"text-underline-style:none")); 1853 base::string16(text_attributes).find(L"text-underline-style:none"));
1949 EXPECT_NE(base::string16::npos, 1854 EXPECT_NE(base::string16::npos,
1950 base::string16(text_attributes).find(L"text-underline-type:none")); 1855 base::string16(text_attributes).find(L"text-underline-type:none"));
1951 EXPECT_EQ(base::string16::npos, 1856 EXPECT_EQ(base::string16::npos,
1952 base::string16(text_attributes).find(L"invalid:spelling")); 1857 base::string16(text_attributes).find(L"invalid:spelling"));
1953 text_attributes.Reset(); 1858 text_attributes.Reset();
1954 1859
1955 manager.reset(); 1860 manager.reset();
1956 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
1957 } 1861 }
1958 1862
1959 TEST_F(BrowserAccessibilityTest, TestMisspellingsInSimpleTextFields) { 1863 TEST_F(BrowserAccessibilityTest, TestMisspellingsInSimpleTextFields) {
1960 std::string value1("Testing ."); 1864 std::string value1("Testing .");
1961 // The word "helo" is misspelled. 1865 // The word "helo" is misspelled.
1962 std::string value2("Helo there."); 1866 std::string value2("Helo there.");
1963 1867
1964 LONG value1_length = static_cast<LONG>(value1.length()); 1868 LONG value1_length = static_cast<LONG>(value1.length());
1965 LONG value2_length = static_cast<LONG>(value2.length()); 1869 LONG value2_length = static_cast<LONG>(value2.length());
1966 LONG combo_box_value_length = value1_length + value2_length; 1870 LONG combo_box_value_length = value1_length + value2_length;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 marker_ends.push_back(4); 1906 marker_ends.push_back(4);
2003 static_text2.AddIntListAttribute(ui::AX_ATTR_MARKER_TYPES, marker_types); 1907 static_text2.AddIntListAttribute(ui::AX_ATTR_MARKER_TYPES, marker_types);
2004 static_text2.AddIntListAttribute(ui::AX_ATTR_MARKER_STARTS, marker_starts); 1908 static_text2.AddIntListAttribute(ui::AX_ATTR_MARKER_STARTS, marker_starts);
2005 static_text2.AddIntListAttribute(ui::AX_ATTR_MARKER_ENDS, marker_ends); 1909 static_text2.AddIntListAttribute(ui::AX_ATTR_MARKER_ENDS, marker_ends);
2006 1910
2007 root.child_ids.push_back(combo_box.id); 1911 root.child_ids.push_back(combo_box.id);
2008 combo_box.child_ids.push_back(combo_box_div.id); 1912 combo_box.child_ids.push_back(combo_box_div.id);
2009 combo_box_div.child_ids.push_back(static_text1.id); 1913 combo_box_div.child_ids.push_back(static_text1.id);
2010 combo_box_div.child_ids.push_back(static_text2.id); 1914 combo_box_div.child_ids.push_back(static_text2.id);
2011 1915
2012 CountedBrowserAccessibility::reset();
2013 std::unique_ptr<BrowserAccessibilityManager> manager( 1916 std::unique_ptr<BrowserAccessibilityManager> manager(
2014 BrowserAccessibilityManager::Create( 1917 BrowserAccessibilityManager::Create(
2015 MakeAXTreeUpdate(root, combo_box, combo_box_div, static_text1, 1918 MakeAXTreeUpdate(root, combo_box, combo_box_div, static_text1,
2016 static_text2), 1919 static_text2),
2017 nullptr, new CountedBrowserAccessibilityFactory())); 1920 nullptr, new BrowserAccessibilityFactory()));
2018 ASSERT_EQ(5, CountedBrowserAccessibility::num_instances());
2019 1921
2020 ASSERT_NE(nullptr, manager->GetRoot()); 1922 ASSERT_NE(nullptr, manager->GetRoot());
2021 BrowserAccessibilityWin* ax_root = 1923 BrowserAccessibilityWin* ax_root =
2022 ToBrowserAccessibilityWin(manager->GetRoot()); 1924 ToBrowserAccessibilityWin(manager->GetRoot());
2023 ASSERT_NE(nullptr, ax_root); 1925 ASSERT_NE(nullptr, ax_root);
2024 ASSERT_EQ(1U, ax_root->PlatformChildCount()); 1926 ASSERT_EQ(1U, ax_root->PlatformChildCount());
2025 1927
2026 BrowserAccessibilityWin* ax_combo_box = 1928 BrowserAccessibilityWin* ax_combo_box =
2027 ToBrowserAccessibilityWin(ax_root->PlatformGetChild(0)); 1929 ToBrowserAccessibilityWin(ax_root->PlatformGetChild(0));
2028 ASSERT_NE(nullptr, ax_combo_box); 1930 ASSERT_NE(nullptr, ax_combo_box);
2029 ASSERT_EQ(1U, ax_combo_box->PlatformChildCount()); 1931 ASSERT_EQ(1U, ax_combo_box->PlatformChildCount());
2030 1932
2031 HRESULT hr; 1933 HRESULT hr;
2032 LONG start_offset, end_offset; 1934 LONG start_offset, end_offset;
2033 base::win::ScopedBstr text_attributes; 1935 base::win::ScopedBstr text_attributes;
2034 1936
2035 // Ensure that the first part of the value is not marked misspelled. 1937 // Ensure that the first part of the value is not marked misspelled.
2036 for (LONG offset = 0; offset < value1_length; ++offset) { 1938 for (LONG offset = 0; offset < value1_length; ++offset) {
2037 hr = ax_combo_box->get_attributes(offset, &start_offset, &end_offset, 1939 hr = ax_combo_box->GetCOM()->get_attributes(
2038 text_attributes.Receive()); 1940 offset, &start_offset, &end_offset, text_attributes.Receive());
2039 EXPECT_EQ(S_OK, hr); 1941 EXPECT_EQ(S_OK, hr);
2040 EXPECT_EQ(0, start_offset); 1942 EXPECT_EQ(0, start_offset);
2041 EXPECT_EQ(value1_length, end_offset); 1943 EXPECT_EQ(value1_length, end_offset);
2042 EXPECT_EQ(base::string16::npos, 1944 EXPECT_EQ(base::string16::npos,
2043 base::string16(text_attributes).find(L"invalid:spelling")); 1945 base::string16(text_attributes).find(L"invalid:spelling"));
2044 text_attributes.Reset(); 1946 text_attributes.Reset();
2045 } 1947 }
2046 1948
2047 // Ensure that "helo" is marked misspelled. 1949 // Ensure that "helo" is marked misspelled.
2048 for (LONG offset = value1_length; offset < value1_length + 4; ++offset) { 1950 for (LONG offset = value1_length; offset < value1_length + 4; ++offset) {
2049 hr = ax_combo_box->get_attributes(offset, &start_offset, &end_offset, 1951 hr = ax_combo_box->GetCOM()->get_attributes(
2050 text_attributes.Receive()); 1952 offset, &start_offset, &end_offset, text_attributes.Receive());
2051 EXPECT_EQ(S_OK, hr); 1953 EXPECT_EQ(S_OK, hr);
2052 EXPECT_EQ(value1_length, start_offset); 1954 EXPECT_EQ(value1_length, start_offset);
2053 EXPECT_EQ(value1_length + 4, end_offset); 1955 EXPECT_EQ(value1_length + 4, end_offset);
2054 EXPECT_NE(base::string16::npos, 1956 EXPECT_NE(base::string16::npos,
2055 base::string16(text_attributes).find(L"invalid:spelling")); 1957 base::string16(text_attributes).find(L"invalid:spelling"));
2056 text_attributes.Reset(); 1958 text_attributes.Reset();
2057 } 1959 }
2058 1960
2059 // Ensure that the last part of the value is not marked misspelled. 1961 // Ensure that the last part of the value is not marked misspelled.
2060 for (LONG offset = value1_length + 4; offset < combo_box_value_length; 1962 for (LONG offset = value1_length + 4; offset < combo_box_value_length;
2061 ++offset) { 1963 ++offset) {
2062 hr = ax_combo_box->get_attributes(offset, &start_offset, &end_offset, 1964 hr = ax_combo_box->GetCOM()->get_attributes(
2063 text_attributes.Receive()); 1965 offset, &start_offset, &end_offset, text_attributes.Receive());
2064 EXPECT_EQ(S_OK, hr); 1966 EXPECT_EQ(S_OK, hr);
2065 EXPECT_EQ(value1_length + 4, start_offset); 1967 EXPECT_EQ(value1_length + 4, start_offset);
2066 EXPECT_EQ(combo_box_value_length, end_offset); 1968 EXPECT_EQ(combo_box_value_length, end_offset);
2067 EXPECT_EQ(base::string16::npos, 1969 EXPECT_EQ(base::string16::npos,
2068 base::string16(text_attributes).find(L"invalid:spelling")); 1970 base::string16(text_attributes).find(L"invalid:spelling"));
2069 text_attributes.Reset(); 1971 text_attributes.Reset();
2070 } 1972 }
2071 1973
2072 manager.reset(); 1974 manager.reset();
2073 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
2074 } 1975 }
2075 1976
2076 TEST_F(BrowserAccessibilityTest, TestDeepestFirstLastChild) { 1977 TEST_F(BrowserAccessibilityTest, TestDeepestFirstLastChild) {
2077 ui::AXNodeData root; 1978 ui::AXNodeData root;
2078 root.id = 1; 1979 root.id = 1;
2079 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 1980 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
2080 1981
2081 ui::AXNodeData child1; 1982 ui::AXNodeData child1;
2082 child1.id = 2; 1983 child1.id = 2;
2083 child1.role = ui::AX_ROLE_STATIC_TEXT; 1984 child1.role = ui::AX_ROLE_STATIC_TEXT;
(...skipping 10 matching lines...) Expand all
2094 child2.child_ids.push_back(4); 1995 child2.child_ids.push_back(4);
2095 1996
2096 ui::AXNodeData child2_child2; 1997 ui::AXNodeData child2_child2;
2097 child2_child2.id = 5; 1998 child2_child2.id = 5;
2098 child2_child2.role = ui::AX_ROLE_INLINE_TEXT_BOX; 1999 child2_child2.role = ui::AX_ROLE_INLINE_TEXT_BOX;
2099 child2.child_ids.push_back(5); 2000 child2.child_ids.push_back(5);
2100 2001
2101 std::unique_ptr<BrowserAccessibilityManager> manager( 2002 std::unique_ptr<BrowserAccessibilityManager> manager(
2102 BrowserAccessibilityManager::Create( 2003 BrowserAccessibilityManager::Create(
2103 MakeAXTreeUpdate(root, child1, child2, child2_child1, child2_child2), 2004 MakeAXTreeUpdate(root, child1, child2, child2_child1, child2_child2),
2104 nullptr, new CountedBrowserAccessibilityFactory())); 2005 nullptr, new BrowserAccessibilityFactory()));
2105 2006
2106 BrowserAccessibility* root_accessible = manager->GetRoot(); 2007 BrowserAccessibility* root_accessible = manager->GetRoot();
2107 ASSERT_NE(nullptr, root_accessible); 2008 ASSERT_NE(nullptr, root_accessible);
2108 ASSERT_EQ(2U, root_accessible->PlatformChildCount()); 2009 ASSERT_EQ(2U, root_accessible->PlatformChildCount());
2109 BrowserAccessibility* child1_accessible = 2010 BrowserAccessibility* child1_accessible =
2110 root_accessible->PlatformGetChild(0); 2011 root_accessible->PlatformGetChild(0);
2111 ASSERT_NE(nullptr, child1_accessible); 2012 ASSERT_NE(nullptr, child1_accessible);
2112 BrowserAccessibility* child2_accessible = 2013 BrowserAccessibility* child2_accessible =
2113 root_accessible->PlatformGetChild(1); 2014 root_accessible->PlatformGetChild(1);
2114 ASSERT_NE(nullptr, child2_accessible); 2015 ASSERT_NE(nullptr, child2_accessible);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2177 child2.child_ids.push_back(4); 2078 child2.child_ids.push_back(4);
2178 2079
2179 ui::AXNodeData child2_child2; 2080 ui::AXNodeData child2_child2;
2180 child2_child2.id = 5; 2081 child2_child2.id = 5;
2181 child2_child2.role = ui::AX_ROLE_INLINE_TEXT_BOX; 2082 child2_child2.role = ui::AX_ROLE_INLINE_TEXT_BOX;
2182 child2.child_ids.push_back(5); 2083 child2.child_ids.push_back(5);
2183 2084
2184 std::unique_ptr<BrowserAccessibilityManager> manager( 2085 std::unique_ptr<BrowserAccessibilityManager> manager(
2185 BrowserAccessibilityManager::Create( 2086 BrowserAccessibilityManager::Create(
2186 MakeAXTreeUpdate(root, child1, child2, child2_child1, child2_child2), 2087 MakeAXTreeUpdate(root, child1, child2, child2_child1, child2_child2),
2187 nullptr, new CountedBrowserAccessibilityFactory())); 2088 nullptr, new BrowserAccessibilityFactory()));
2188 2089
2189 BrowserAccessibility* root_accessible = manager->GetRoot(); 2090 BrowserAccessibility* root_accessible = manager->GetRoot();
2190 ASSERT_NE(nullptr, root_accessible); 2091 ASSERT_NE(nullptr, root_accessible);
2191 BrowserAccessibility* child1_accessible = 2092 BrowserAccessibility* child1_accessible =
2192 root_accessible->PlatformGetChild(0); 2093 root_accessible->PlatformGetChild(0);
2193 ASSERT_NE(nullptr, child1_accessible); 2094 ASSERT_NE(nullptr, child1_accessible);
2194 BrowserAccessibility* child2_accessible = 2095 BrowserAccessibility* child2_accessible =
2195 root_accessible->PlatformGetChild(1); 2096 root_accessible->PlatformGetChild(1);
2196 ASSERT_NE(nullptr, child2_accessible); 2097 ASSERT_NE(nullptr, child2_accessible);
2197 BrowserAccessibility* child2_child1_accessible = 2098 BrowserAccessibility* child2_child1_accessible =
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 ui::AX_ATTR_FONT_FAMILY, &value)); 2164 ui::AX_ATTR_FONT_FAMILY, &value));
2264 EXPECT_EQ("Arial", value); 2165 EXPECT_EQ("Arial", value);
2265 EXPECT_TRUE(child2_child2_accessible->GetInheritedStringAttribute( 2166 EXPECT_TRUE(child2_child2_accessible->GetInheritedStringAttribute(
2266 ui::AX_ATTR_FONT_FAMILY, &value)); 2167 ui::AX_ATTR_FONT_FAMILY, &value));
2267 EXPECT_EQ("Arial", value); 2168 EXPECT_EQ("Arial", value);
2268 } 2169 }
2269 2170
2270 TEST_F(BrowserAccessibilityTest, TestSanitizeStringAttributeForIA2) { 2171 TEST_F(BrowserAccessibilityTest, TestSanitizeStringAttributeForIA2) {
2271 base::string16 input(L"\\:=,;"); 2172 base::string16 input(L"\\:=,;");
2272 base::string16 output; 2173 base::string16 output;
2273 BrowserAccessibilityWin::SanitizeStringAttributeForIA2(input, &output); 2174 BrowserAccessibilityComWin::SanitizeStringAttributeForIA2(input, &output);
2274 EXPECT_EQ(L"\\\\\\:\\=\\,\\;", output); 2175 EXPECT_EQ(L"\\\\\\:\\=\\,\\;", output);
2275 } 2176 }
2276 2177
2277 TEST_F(BrowserAccessibilityTest, UniqueIdWinInvalidAfterDeletingTree) { 2178 TEST_F(BrowserAccessibilityTest, UniqueIdWinInvalidAfterDeletingTree) {
2278 ui::AXNodeData root_node; 2179 ui::AXNodeData root_node;
2279 root_node.id = 1; 2180 root_node.id = 1;
2280 root_node.role = ui::AX_ROLE_ROOT_WEB_AREA; 2181 root_node.role = ui::AX_ROLE_ROOT_WEB_AREA;
2281 2182
2282 ui::AXNodeData child_node; 2183 ui::AXNodeData child_node;
2283 child_node.id = 2; 2184 child_node.id = 2;
2284 root_node.child_ids.push_back(2); 2185 root_node.child_ids.push_back(2);
2285 2186
2286 std::unique_ptr<BrowserAccessibilityManagerWin> manager( 2187 std::unique_ptr<BrowserAccessibilityManagerWin> manager(
2287 new BrowserAccessibilityManagerWin( 2188 new BrowserAccessibilityManagerWin(
2288 MakeAXTreeUpdate(root_node, child_node), nullptr, 2189 MakeAXTreeUpdate(root_node, child_node), nullptr,
2289 new CountedBrowserAccessibilityFactory())); 2190 new BrowserAccessibilityFactory()));
2290 2191
2291 BrowserAccessibility* root = manager->GetRoot(); 2192 BrowserAccessibility* root = manager->GetRoot();
2292 int32_t root_unique_id = root->unique_id(); 2193 int32_t root_unique_id = root->unique_id();
2293 BrowserAccessibility* child = root->PlatformGetChild(0); 2194 BrowserAccessibility* child = root->PlatformGetChild(0);
2294 int32_t child_unique_id = child->unique_id(); 2195 int32_t child_unique_id = child->unique_id();
2295 2196
2296 // Now destroy that original tree and create a new tree. 2197 // Now destroy that original tree and create a new tree.
2297 manager.reset( 2198 manager.reset(new BrowserAccessibilityManagerWin(
2298 new BrowserAccessibilityManagerWin( 2199 MakeAXTreeUpdate(root_node, child_node), nullptr,
2299 MakeAXTreeUpdate(root_node, child_node), 2200 new BrowserAccessibilityFactory()));
2300 nullptr,
2301 new CountedBrowserAccessibilityFactory()));
2302 root = manager->GetRoot(); 2201 root = manager->GetRoot();
2303 int32_t root_unique_id_2 = root->unique_id(); 2202 int32_t root_unique_id_2 = root->unique_id();
2304 child = root->PlatformGetChild(0); 2203 child = root->PlatformGetChild(0);
2305 int32_t child_unique_id_2 = child->unique_id(); 2204 int32_t child_unique_id_2 = child->unique_id();
2306 2205
2307 // The nodes in the new tree should not have the same ids. 2206 // The nodes in the new tree should not have the same ids.
2308 EXPECT_NE(root_unique_id, root_unique_id_2); 2207 EXPECT_NE(root_unique_id, root_unique_id_2);
2309 EXPECT_NE(child_unique_id, child_unique_id_2); 2208 EXPECT_NE(child_unique_id, child_unique_id_2);
2310 2209
2311 // Trying to access the unique IDs of the old, deleted objects should fail. 2210 // Trying to access the unique IDs of the old, deleted objects should fail.
2312 base::win::ScopedVariant old_root_variant(-root_unique_id); 2211 base::win::ScopedVariant old_root_variant(-root_unique_id);
2313 base::win::ScopedComPtr<IDispatch> old_root_dispatch; 2212 base::win::ScopedComPtr<IDispatch> old_root_dispatch;
2314 HRESULT hr = ToBrowserAccessibilityWin(root)->get_accChild( 2213 HRESULT hr = ToBrowserAccessibilityWin(root)->GetCOM()->get_accChild(
2315 old_root_variant, old_root_dispatch.Receive()); 2214 old_root_variant, old_root_dispatch.Receive());
2316 EXPECT_EQ(E_INVALIDARG, hr); 2215 EXPECT_EQ(E_INVALIDARG, hr);
2317 2216
2318 base::win::ScopedVariant old_child_variant(-child_unique_id); 2217 base::win::ScopedVariant old_child_variant(-child_unique_id);
2319 base::win::ScopedComPtr<IDispatch> old_child_dispatch; 2218 base::win::ScopedComPtr<IDispatch> old_child_dispatch;
2320 hr = ToBrowserAccessibilityWin(root)->get_accChild( 2219 hr = ToBrowserAccessibilityWin(root)->GetCOM()->get_accChild(
2321 old_child_variant, old_child_dispatch.Receive()); 2220 old_child_variant, old_child_dispatch.Receive());
2322 EXPECT_EQ(E_INVALIDARG, hr); 2221 EXPECT_EQ(E_INVALIDARG, hr);
2323 2222
2324 // Trying to access the unique IDs of the new objects should succeed. 2223 // Trying to access the unique IDs of the new objects should succeed.
2325 base::win::ScopedVariant new_root_variant(-root_unique_id_2); 2224 base::win::ScopedVariant new_root_variant(-root_unique_id_2);
2326 base::win::ScopedComPtr<IDispatch> new_root_dispatch; 2225 base::win::ScopedComPtr<IDispatch> new_root_dispatch;
2327 hr = ToBrowserAccessibilityWin(root)->get_accChild( 2226 hr = ToBrowserAccessibilityWin(root)->GetCOM()->get_accChild(
2328 new_root_variant, new_root_dispatch.Receive()); 2227 new_root_variant, new_root_dispatch.Receive());
2329 EXPECT_EQ(S_OK, hr); 2228 EXPECT_EQ(S_OK, hr);
2330 2229
2331 base::win::ScopedVariant new_child_variant(-child_unique_id_2); 2230 base::win::ScopedVariant new_child_variant(-child_unique_id_2);
2332 base::win::ScopedComPtr<IDispatch> new_child_dispatch; 2231 base::win::ScopedComPtr<IDispatch> new_child_dispatch;
2333 hr = ToBrowserAccessibilityWin(root)->get_accChild( 2232 hr = ToBrowserAccessibilityWin(root)->GetCOM()->get_accChild(
2334 new_child_variant, new_child_dispatch.Receive()); 2233 new_child_variant, new_child_dispatch.Receive());
2335 EXPECT_EQ(S_OK, hr); 2234 EXPECT_EQ(S_OK, hr);
2336 } 2235 }
2337 2236
2338 TEST_F(BrowserAccessibilityTest, AccChildOnlyReturnsDescendants) { 2237 TEST_F(BrowserAccessibilityTest, AccChildOnlyReturnsDescendants) {
2339 ui::AXNodeData root_node; 2238 ui::AXNodeData root_node;
2340 root_node.id = 1; 2239 root_node.id = 1;
2341 root_node.role = ui::AX_ROLE_ROOT_WEB_AREA; 2240 root_node.role = ui::AX_ROLE_ROOT_WEB_AREA;
2342 2241
2343 ui::AXNodeData child_node; 2242 ui::AXNodeData child_node;
2344 child_node.id = 2; 2243 child_node.id = 2;
2345 root_node.child_ids.push_back(2); 2244 root_node.child_ids.push_back(2);
2346 2245
2347 std::unique_ptr<BrowserAccessibilityManagerWin> manager( 2246 std::unique_ptr<BrowserAccessibilityManagerWin> manager(
2348 new BrowserAccessibilityManagerWin( 2247 new BrowserAccessibilityManagerWin(
2349 MakeAXTreeUpdate(root_node, child_node), nullptr, 2248 MakeAXTreeUpdate(root_node, child_node), nullptr,
2350 new CountedBrowserAccessibilityFactory())); 2249 new BrowserAccessibilityFactory()));
2351 2250
2352 BrowserAccessibility* root = manager->GetRoot(); 2251 BrowserAccessibility* root = manager->GetRoot();
2353 BrowserAccessibility* child = root->PlatformGetChild(0); 2252 BrowserAccessibility* child = root->PlatformGetChild(0);
2354 2253
2355 base::win::ScopedVariant root_unique_id_variant(-root->unique_id()); 2254 base::win::ScopedVariant root_unique_id_variant(-root->unique_id());
2356 base::win::ScopedComPtr<IDispatch> result; 2255 base::win::ScopedComPtr<IDispatch> result;
2357 EXPECT_EQ(E_INVALIDARG, ToBrowserAccessibilityWin(child)->get_accChild( 2256 EXPECT_EQ(E_INVALIDARG,
2358 root_unique_id_variant, result.Receive())); 2257 ToBrowserAccessibilityWin(child)->GetCOM()->get_accChild(
2258 root_unique_id_variant, result.Receive()));
2359 2259
2360 base::win::ScopedVariant child_unique_id_variant(-child->unique_id()); 2260 base::win::ScopedVariant child_unique_id_variant(-child->unique_id());
2361 EXPECT_EQ(S_OK, ToBrowserAccessibilityWin(root)->get_accChild( 2261 EXPECT_EQ(S_OK, ToBrowserAccessibilityWin(root)->GetCOM()->get_accChild(
2362 child_unique_id_variant, result.Receive())); 2262 child_unique_id_variant, result.Receive()));
2363 } 2263 }
2364 2264
2365 TEST_F(BrowserAccessibilityTest, TestIAccessible2Relations) { 2265 TEST_F(BrowserAccessibilityTest, TestIAccessible2Relations) {
2366 ui::AXNodeData root; 2266 ui::AXNodeData root;
2367 root.id = 1; 2267 root.id = 1;
2368 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 2268 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
2369 // Reflexive relations should be ignored. 2269 // Reflexive relations should be ignored.
2370 std::vector<int32_t> describedby_ids = {1, 2, 3}; 2270 std::vector<int32_t> describedby_ids = {1, 2, 3};
2371 root.AddIntListAttribute(ui::AX_ATTR_DESCRIBEDBY_IDS, describedby_ids); 2271 root.AddIntListAttribute(ui::AX_ATTR_DESCRIBEDBY_IDS, describedby_ids);
2372 2272
2373 ui::AXNodeData child1; 2273 ui::AXNodeData child1;
2374 child1.id = 2; 2274 child1.id = 2;
2375 child1.role = ui::AX_ROLE_STATIC_TEXT; 2275 child1.role = ui::AX_ROLE_STATIC_TEXT;
2376 root.child_ids.push_back(2); 2276 root.child_ids.push_back(2);
2377 2277
2378 ui::AXNodeData child2; 2278 ui::AXNodeData child2;
2379 child2.id = 3; 2279 child2.id = 3;
2380 child2.role = ui::AX_ROLE_STATIC_TEXT; 2280 child2.role = ui::AX_ROLE_STATIC_TEXT;
2381 root.child_ids.push_back(3); 2281 root.child_ids.push_back(3);
2382 2282
2383 std::unique_ptr<BrowserAccessibilityManager> manager( 2283 std::unique_ptr<BrowserAccessibilityManager> manager(
2384 BrowserAccessibilityManager::Create( 2284 BrowserAccessibilityManager::Create(
2385 MakeAXTreeUpdate(root, child1, child2), nullptr, 2285 MakeAXTreeUpdate(root, child1, child2), nullptr,
2386 new CountedBrowserAccessibilityFactory())); 2286 new BrowserAccessibilityFactory()));
2387 2287
2388 BrowserAccessibilityWin* ax_root = 2288 BrowserAccessibilityWin* ax_root =
2389 ToBrowserAccessibilityWin(manager->GetRoot()); 2289 ToBrowserAccessibilityWin(manager->GetRoot());
2390 ASSERT_NE(nullptr, ax_root); 2290 ASSERT_NE(nullptr, ax_root);
2391 BrowserAccessibilityWin* ax_child1 = 2291 BrowserAccessibilityWin* ax_child1 =
2392 ToBrowserAccessibilityWin(ax_root->PlatformGetChild(0)); 2292 ToBrowserAccessibilityWin(ax_root->PlatformGetChild(0));
2393 ASSERT_NE(nullptr, ax_child1); 2293 ASSERT_NE(nullptr, ax_child1);
2394 BrowserAccessibilityWin* ax_child2 = 2294 BrowserAccessibilityWin* ax_child2 =
2395 ToBrowserAccessibilityWin(ax_root->PlatformGetChild(1)); 2295 ToBrowserAccessibilityWin(ax_root->PlatformGetChild(1));
2396 ASSERT_NE(nullptr, ax_child2); 2296 ASSERT_NE(nullptr, ax_child2);
2397 2297
2398 LONG n_relations = 0; 2298 LONG n_relations = 0;
2399 LONG n_targets = 0; 2299 LONG n_targets = 0;
2400 LONG unique_id = 0; 2300 LONG unique_id = 0;
2401 base::win::ScopedBstr relation_type; 2301 base::win::ScopedBstr relation_type;
2402 base::win::ScopedComPtr<IAccessibleRelation> describedby_relation; 2302 base::win::ScopedComPtr<IAccessibleRelation> describedby_relation;
2403 base::win::ScopedComPtr<IAccessibleRelation> description_for_relation; 2303 base::win::ScopedComPtr<IAccessibleRelation> description_for_relation;
2404 base::win::ScopedComPtr<IUnknown> target; 2304 base::win::ScopedComPtr<IUnknown> target;
2405 base::win::ScopedComPtr<IAccessible2> ax_target; 2305 base::win::ScopedComPtr<IAccessible2> ax_target;
2406 2306
2407 EXPECT_HRESULT_SUCCEEDED(ax_root->get_nRelations(&n_relations)); 2307 EXPECT_HRESULT_SUCCEEDED(ax_root->GetCOM()->get_nRelations(&n_relations));
2408 EXPECT_EQ(1, n_relations); 2308 EXPECT_EQ(1, n_relations);
2409 2309
2410 EXPECT_HRESULT_SUCCEEDED( 2310 EXPECT_HRESULT_SUCCEEDED(
2411 ax_root->get_relation(0, describedby_relation.Receive())); 2311 ax_root->GetCOM()->get_relation(0, describedby_relation.Receive()));
2412 EXPECT_HRESULT_SUCCEEDED( 2312 EXPECT_HRESULT_SUCCEEDED(
2413 describedby_relation->get_relationType(relation_type.Receive())); 2313 describedby_relation->get_relationType(relation_type.Receive()));
2414 EXPECT_EQ(L"describedBy", base::string16(relation_type)); 2314 EXPECT_EQ(L"describedBy", base::string16(relation_type));
2415 relation_type.Reset(); 2315 relation_type.Reset();
2416 2316
2417 EXPECT_HRESULT_SUCCEEDED(describedby_relation->get_nTargets(&n_targets)); 2317 EXPECT_HRESULT_SUCCEEDED(describedby_relation->get_nTargets(&n_targets));
2418 EXPECT_EQ(2, n_targets); 2318 EXPECT_EQ(2, n_targets);
2419 2319
2420 EXPECT_HRESULT_SUCCEEDED( 2320 EXPECT_HRESULT_SUCCEEDED(
2421 describedby_relation->get_target(0, target.Receive())); 2321 describedby_relation->get_target(0, target.Receive()));
2422 target.CopyTo(ax_target.Receive()); 2322 target.CopyTo(ax_target.Receive());
2423 EXPECT_HRESULT_SUCCEEDED(ax_target->get_uniqueID(&unique_id)); 2323 EXPECT_HRESULT_SUCCEEDED(ax_target->get_uniqueID(&unique_id));
2424 EXPECT_EQ(-ax_child1->unique_id(), unique_id); 2324 EXPECT_EQ(-ax_child1->unique_id(), unique_id);
2425 ax_target.Reset(); 2325 ax_target.Reset();
2426 target.Reset(); 2326 target.Reset();
2427 2327
2428 EXPECT_HRESULT_SUCCEEDED( 2328 EXPECT_HRESULT_SUCCEEDED(
2429 describedby_relation->get_target(1, target.Receive())); 2329 describedby_relation->get_target(1, target.Receive()));
2430 target.CopyTo(ax_target.Receive()); 2330 target.CopyTo(ax_target.Receive());
2431 EXPECT_HRESULT_SUCCEEDED(ax_target->get_uniqueID(&unique_id)); 2331 EXPECT_HRESULT_SUCCEEDED(ax_target->get_uniqueID(&unique_id));
2432 EXPECT_EQ(-ax_child2->unique_id(), unique_id); 2332 EXPECT_EQ(-ax_child2->unique_id(), unique_id);
2433 ax_target.Reset(); 2333 ax_target.Reset();
2434 target.Reset(); 2334 target.Reset();
2435 describedby_relation.Reset(); 2335 describedby_relation.Reset();
2436 2336
2437 // Test the reverse relations. 2337 // Test the reverse relations.
2438 EXPECT_HRESULT_SUCCEEDED(ax_child1->get_nRelations(&n_relations)); 2338 EXPECT_HRESULT_SUCCEEDED(ax_child1->GetCOM()->get_nRelations(&n_relations));
2439 EXPECT_EQ(1, n_relations); 2339 EXPECT_EQ(1, n_relations);
2440 2340
2441 EXPECT_HRESULT_SUCCEEDED( 2341 EXPECT_HRESULT_SUCCEEDED(
2442 ax_child1->get_relation(0, description_for_relation.Receive())); 2342 ax_child1->GetCOM()->get_relation(0, description_for_relation.Receive()));
2443 EXPECT_HRESULT_SUCCEEDED( 2343 EXPECT_HRESULT_SUCCEEDED(
2444 description_for_relation->get_relationType(relation_type.Receive())); 2344 description_for_relation->get_relationType(relation_type.Receive()));
2445 EXPECT_EQ(L"descriptionFor", base::string16(relation_type)); 2345 EXPECT_EQ(L"descriptionFor", base::string16(relation_type));
2446 relation_type.Reset(); 2346 relation_type.Reset();
2447 2347
2448 EXPECT_HRESULT_SUCCEEDED(description_for_relation->get_nTargets(&n_targets)); 2348 EXPECT_HRESULT_SUCCEEDED(description_for_relation->get_nTargets(&n_targets));
2449 EXPECT_EQ(1, n_targets); 2349 EXPECT_EQ(1, n_targets);
2450 2350
2451 EXPECT_HRESULT_SUCCEEDED( 2351 EXPECT_HRESULT_SUCCEEDED(
2452 description_for_relation->get_target(0, target.Receive())); 2352 description_for_relation->get_target(0, target.Receive()));
2453 target.CopyTo(ax_target.Receive()); 2353 target.CopyTo(ax_target.Receive());
2454 EXPECT_HRESULT_SUCCEEDED(ax_target->get_uniqueID(&unique_id)); 2354 EXPECT_HRESULT_SUCCEEDED(ax_target->get_uniqueID(&unique_id));
2455 EXPECT_EQ(-ax_root->unique_id(), unique_id); 2355 EXPECT_EQ(-ax_root->unique_id(), unique_id);
2456 ax_target.Reset(); 2356 ax_target.Reset();
2457 target.Reset(); 2357 target.Reset();
2458 description_for_relation.Reset(); 2358 description_for_relation.Reset();
2459 2359
2460 EXPECT_HRESULT_SUCCEEDED(ax_child2->get_nRelations(&n_relations)); 2360 EXPECT_HRESULT_SUCCEEDED(ax_child2->GetCOM()->get_nRelations(&n_relations));
2461 EXPECT_EQ(1, n_relations); 2361 EXPECT_EQ(1, n_relations);
2462 2362
2463 EXPECT_HRESULT_SUCCEEDED( 2363 EXPECT_HRESULT_SUCCEEDED(
2464 ax_child2->get_relation(0, description_for_relation.Receive())); 2364 ax_child2->GetCOM()->get_relation(0, description_for_relation.Receive()));
2465 EXPECT_HRESULT_SUCCEEDED( 2365 EXPECT_HRESULT_SUCCEEDED(
2466 description_for_relation->get_relationType(relation_type.Receive())); 2366 description_for_relation->get_relationType(relation_type.Receive()));
2467 EXPECT_EQ(L"descriptionFor", base::string16(relation_type)); 2367 EXPECT_EQ(L"descriptionFor", base::string16(relation_type));
2468 relation_type.Reset(); 2368 relation_type.Reset();
2469 2369
2470 EXPECT_HRESULT_SUCCEEDED(description_for_relation->get_nTargets(&n_targets)); 2370 EXPECT_HRESULT_SUCCEEDED(description_for_relation->get_nTargets(&n_targets));
2471 EXPECT_EQ(1, n_targets); 2371 EXPECT_EQ(1, n_targets);
2472 2372
2473 EXPECT_HRESULT_SUCCEEDED( 2373 EXPECT_HRESULT_SUCCEEDED(
2474 description_for_relation->get_target(0, target.Receive())); 2374 description_for_relation->get_target(0, target.Receive()));
2475 target.CopyTo(ax_target.Receive()); 2375 target.CopyTo(ax_target.Receive());
2476 EXPECT_HRESULT_SUCCEEDED(ax_target->get_uniqueID(&unique_id)); 2376 EXPECT_HRESULT_SUCCEEDED(ax_target->get_uniqueID(&unique_id));
2477 EXPECT_EQ(-ax_root->unique_id(), unique_id); 2377 EXPECT_EQ(-ax_root->unique_id(), unique_id);
2478 ax_target.Reset(); 2378 ax_target.Reset();
2479 target.Reset(); 2379 target.Reset();
2480 2380
2481 // Try adding one more relation. 2381 // Try adding one more relation.
2482 std::vector<int32_t> labelledby_ids = {3}; 2382 std::vector<int32_t> labelledby_ids = {3};
2483 child1.AddIntListAttribute(ui::AX_ATTR_LABELLEDBY_IDS, labelledby_ids); 2383 child1.AddIntListAttribute(ui::AX_ATTR_LABELLEDBY_IDS, labelledby_ids);
2484 AXEventNotificationDetails event; 2384 AXEventNotificationDetails event;
2485 event.event_type = ui::AX_EVENT_ARIA_ATTRIBUTE_CHANGED; 2385 event.event_type = ui::AX_EVENT_ARIA_ATTRIBUTE_CHANGED;
2486 event.update.nodes.push_back(child1); 2386 event.update.nodes.push_back(child1);
2487 event.id = child1.id; 2387 event.id = child1.id;
2488 std::vector<AXEventNotificationDetails> events = {event}; 2388 std::vector<AXEventNotificationDetails> events = {event};
2489 manager->OnAccessibilityEvents(events); 2389 manager->OnAccessibilityEvents(events);
2490 2390
2491 EXPECT_HRESULT_SUCCEEDED(ax_child1->get_nRelations(&n_relations)); 2391 EXPECT_HRESULT_SUCCEEDED(ax_child1->GetCOM()->get_nRelations(&n_relations));
2492 EXPECT_EQ(2, n_relations); 2392 EXPECT_EQ(2, n_relations);
2493 EXPECT_HRESULT_SUCCEEDED(ax_child2->get_nRelations(&n_relations)); 2393 EXPECT_HRESULT_SUCCEEDED(ax_child2->GetCOM()->get_nRelations(&n_relations));
2494 EXPECT_EQ(2, n_relations); 2394 EXPECT_EQ(2, n_relations);
2495 } 2395 }
2496 2396
2497 } // namespace content 2397 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698