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

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

Issue 642313003: [C++11 Allowed Features] Declares a type-safe null pointer converting from NULL to nullptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Including id in the AUTHORS file. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "base/win/scoped_bstr.h" 7 #include "base/win/scoped_bstr.h"
8 #include "base/win/scoped_comptr.h" 8 #include "base/win/scoped_comptr.h"
9 #include "base/win/scoped_variant.h" 9 #include "base/win/scoped_variant.h"
10 #include "content/browser/accessibility/browser_accessibility_manager.h" 10 #include "content/browser/accessibility/browser_accessibility_manager.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 root.child_ids.push_back(3); 135 root.child_ids.push_back(3);
136 136
137 // Construct a BrowserAccessibilityManager with this 137 // Construct a BrowserAccessibilityManager with this
138 // ui::AXNodeData tree and a factory for an instance-counting 138 // ui::AXNodeData tree and a factory for an instance-counting
139 // BrowserAccessibility, and ensure that exactly 3 instances were 139 // BrowserAccessibility, and ensure that exactly 3 instances were
140 // created. Note that the manager takes ownership of the factory. 140 // created. Note that the manager takes ownership of the factory.
141 CountedBrowserAccessibility::reset(); 141 CountedBrowserAccessibility::reset();
142 scoped_ptr<BrowserAccessibilityManager> manager( 142 scoped_ptr<BrowserAccessibilityManager> manager(
143 BrowserAccessibilityManager::Create( 143 BrowserAccessibilityManager::Create(
144 MakeAXTreeUpdate(root, button, checkbox), 144 MakeAXTreeUpdate(root, button, checkbox),
145 NULL, new CountedBrowserAccessibilityFactory())); 145 nullptr, new CountedBrowserAccessibilityFactory()));
146 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); 146 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances());
147 147
148 // Delete the manager and test that all 3 instances are deleted. 148 // Delete the manager and test that all 3 instances are deleted.
149 manager.reset(); 149 manager.reset();
150 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); 150 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
151 151
152 // Construct a manager again, and this time use the IAccessible interface 152 // Construct a manager again, and this time use the IAccessible interface
153 // to get new references to two of the three nodes in the tree. 153 // to get new references to two of the three nodes in the tree.
154 manager.reset(BrowserAccessibilityManager::Create( 154 manager.reset(BrowserAccessibilityManager::Create(
155 MakeAXTreeUpdate(root, button, checkbox), 155 MakeAXTreeUpdate(root, button, checkbox),
156 NULL, new CountedBrowserAccessibilityFactory())); 156 nullptr, new CountedBrowserAccessibilityFactory()));
157 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); 157 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances());
158 IAccessible* root_accessible = 158 IAccessible* root_accessible =
159 manager->GetRoot()->ToBrowserAccessibilityWin(); 159 manager->GetRoot()->ToBrowserAccessibilityWin();
160 IDispatch* root_iaccessible = NULL; 160 IDispatch* root_iaccessible = nullptr;
161 IDispatch* child1_iaccessible = NULL; 161 IDispatch* child1_iaccessible = nullptr;
162 base::win::ScopedVariant childid_self(CHILDID_SELF); 162 base::win::ScopedVariant childid_self(CHILDID_SELF);
163 HRESULT hr = root_accessible->get_accChild(childid_self, &root_iaccessible); 163 HRESULT hr = root_accessible->get_accChild(childid_self, &root_iaccessible);
164 ASSERT_EQ(S_OK, hr); 164 ASSERT_EQ(S_OK, hr);
165 base::win::ScopedVariant one(1); 165 base::win::ScopedVariant one(1);
166 hr = root_accessible->get_accChild(one, &child1_iaccessible); 166 hr = root_accessible->get_accChild(one, &child1_iaccessible);
167 ASSERT_EQ(S_OK, hr); 167 ASSERT_EQ(S_OK, hr);
168 168
169 // Now delete the manager, and only one of the three nodes in the tree 169 // Now delete the manager, and only one of the three nodes in the tree
170 // should be released. 170 // should be released.
171 manager.reset(); 171 manager.reset();
(...skipping 24 matching lines...) Expand all
196 root.state = 0; 196 root.state = 0;
197 root.child_ids.push_back(2); 197 root.child_ids.push_back(2);
198 198
199 // Construct a BrowserAccessibilityManager with this 199 // Construct a BrowserAccessibilityManager with this
200 // ui::AXNodeData tree and a factory for an instance-counting 200 // ui::AXNodeData tree and a factory for an instance-counting
201 // BrowserAccessibility. 201 // BrowserAccessibility.
202 CountedBrowserAccessibility::reset(); 202 CountedBrowserAccessibility::reset();
203 scoped_ptr<BrowserAccessibilityManager> manager( 203 scoped_ptr<BrowserAccessibilityManager> manager(
204 BrowserAccessibilityManager::Create( 204 BrowserAccessibilityManager::Create(
205 MakeAXTreeUpdate(root, text), 205 MakeAXTreeUpdate(root, text),
206 NULL, new CountedBrowserAccessibilityFactory())); 206 nullptr, new CountedBrowserAccessibilityFactory()));
207 207
208 // Query for the text IAccessible and verify that it returns "old text" as its 208 // Query for the text IAccessible and verify that it returns "old text" as its
209 // value. 209 // value.
210 base::win::ScopedVariant one(1); 210 base::win::ScopedVariant one(1);
211 base::win::ScopedComPtr<IDispatch> text_dispatch; 211 base::win::ScopedComPtr<IDispatch> text_dispatch;
212 HRESULT hr = manager->GetRoot()->ToBrowserAccessibilityWin()->get_accChild( 212 HRESULT hr = manager->GetRoot()->ToBrowserAccessibilityWin()->get_accChild(
213 one, text_dispatch.Receive()); 213 one, text_dispatch.Receive());
214 ASSERT_EQ(S_OK, hr); 214 ASSERT_EQ(S_OK, hr);
215 215
216 base::win::ScopedComPtr<IAccessible> text_accessible; 216 base::win::ScopedComPtr<IAccessible> text_accessible;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 root.child_ids.push_back(2); 292 root.child_ids.push_back(2);
293 293
294 // Construct a BrowserAccessibilityManager with this 294 // Construct a BrowserAccessibilityManager with this
295 // ui::AXNodeData tree and a factory for an instance-counting 295 // ui::AXNodeData tree and a factory for an instance-counting
296 // BrowserAccessibility and ensure that exactly 4 instances were 296 // BrowserAccessibility and ensure that exactly 4 instances were
297 // created. Note that the manager takes ownership of the factory. 297 // created. Note that the manager takes ownership of the factory.
298 CountedBrowserAccessibility::reset(); 298 CountedBrowserAccessibility::reset();
299 scoped_ptr<BrowserAccessibilityManager> manager( 299 scoped_ptr<BrowserAccessibilityManager> manager(
300 BrowserAccessibilityManager::Create( 300 BrowserAccessibilityManager::Create(
301 MakeAXTreeUpdate(root, div, text3, text4), 301 MakeAXTreeUpdate(root, div, text3, text4),
302 NULL, new CountedBrowserAccessibilityFactory())); 302 nullptr, new CountedBrowserAccessibilityFactory()));
303 ASSERT_EQ(4, CountedBrowserAccessibility::num_instances()); 303 ASSERT_EQ(4, CountedBrowserAccessibility::num_instances());
304 304
305 // Notify the BrowserAccessibilityManager that the div node and its children 305 // Notify the BrowserAccessibilityManager that the div node and its children
306 // were removed and ensure that only one BrowserAccessibility instance exists. 306 // were removed and ensure that only one BrowserAccessibility instance exists.
307 root.child_ids.clear(); 307 root.child_ids.clear();
308 AccessibilityHostMsg_EventParams param; 308 AccessibilityHostMsg_EventParams param;
309 param.event_type = ui::AX_EVENT_CHILDREN_CHANGED; 309 param.event_type = ui::AX_EVENT_CHILDREN_CHANGED;
310 param.update.nodes.push_back(root); 310 param.update.nodes.push_back(root);
311 param.id = root.id; 311 param.id = root.id;
312 std::vector<AccessibilityHostMsg_EventParams> events; 312 std::vector<AccessibilityHostMsg_EventParams> events;
(...skipping 23 matching lines...) Expand all
336 ui::AXNodeData root; 336 ui::AXNodeData root;
337 root.id = 1; 337 root.id = 1;
338 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 338 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
339 root.state = 0; 339 root.state = 0;
340 root.child_ids.push_back(11); 340 root.child_ids.push_back(11);
341 341
342 CountedBrowserAccessibility::reset(); 342 CountedBrowserAccessibility::reset();
343 scoped_ptr<BrowserAccessibilityManager> manager( 343 scoped_ptr<BrowserAccessibilityManager> manager(
344 BrowserAccessibilityManager::Create( 344 BrowserAccessibilityManager::Create(
345 MakeAXTreeUpdate(root, text1), 345 MakeAXTreeUpdate(root, text1),
346 NULL, new CountedBrowserAccessibilityFactory())); 346 nullptr, new CountedBrowserAccessibilityFactory()));
347 ASSERT_EQ(2, CountedBrowserAccessibility::num_instances()); 347 ASSERT_EQ(2, CountedBrowserAccessibility::num_instances());
348 348
349 BrowserAccessibilityWin* root_obj = 349 BrowserAccessibilityWin* root_obj =
350 manager->GetRoot()->ToBrowserAccessibilityWin(); 350 manager->GetRoot()->ToBrowserAccessibilityWin();
351 BrowserAccessibilityWin* text1_obj = 351 BrowserAccessibilityWin* text1_obj =
352 root_obj->PlatformGetChild(0)->ToBrowserAccessibilityWin(); 352 root_obj->PlatformGetChild(0)->ToBrowserAccessibilityWin();
353 353
354 long text1_len; 354 long text1_len;
355 ASSERT_EQ(S_OK, text1_obj->get_nCharacters(&text1_len)); 355 ASSERT_EQ(S_OK, text1_obj->get_nCharacters(&text1_len));
356 356
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 root.id = 1; 436 root.id = 1;
437 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 437 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
438 root.state = 1 << ui::AX_STATE_READ_ONLY; 438 root.state = 1 << ui::AX_STATE_READ_ONLY;
439 root.child_ids.push_back(11); 439 root.child_ids.push_back(11);
440 root.child_ids.push_back(12); 440 root.child_ids.push_back(12);
441 441
442 CountedBrowserAccessibility::reset(); 442 CountedBrowserAccessibility::reset();
443 scoped_ptr<BrowserAccessibilityManager> manager( 443 scoped_ptr<BrowserAccessibilityManager> manager(
444 BrowserAccessibilityManager::Create( 444 BrowserAccessibilityManager::Create(
445 MakeAXTreeUpdate(root, root, text1, text2), 445 MakeAXTreeUpdate(root, root, text1, text2),
446 NULL, new CountedBrowserAccessibilityFactory())); 446 nullptr, new CountedBrowserAccessibilityFactory()));
447 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances()); 447 ASSERT_EQ(3, CountedBrowserAccessibility::num_instances());
448 448
449 BrowserAccessibilityWin* root_obj = 449 BrowserAccessibilityWin* root_obj =
450 manager->GetRoot()->ToBrowserAccessibilityWin(); 450 manager->GetRoot()->ToBrowserAccessibilityWin();
451 451
452 long text_len; 452 long text_len;
453 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); 453 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len));
454 454
455 base::win::ScopedBstr text; 455 base::win::ScopedBstr text;
456 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); 456 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive()));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 root.child_ids.push_back(13); 528 root.child_ids.push_back(13);
529 root.child_ids.push_back(12); 529 root.child_ids.push_back(12);
530 root.child_ids.push_back(14); 530 root.child_ids.push_back(14);
531 531
532 CountedBrowserAccessibility::reset(); 532 CountedBrowserAccessibility::reset();
533 scoped_ptr<BrowserAccessibilityManager> manager( 533 scoped_ptr<BrowserAccessibilityManager> manager(
534 BrowserAccessibilityManager::Create( 534 BrowserAccessibilityManager::Create(
535 MakeAXTreeUpdate(root, 535 MakeAXTreeUpdate(root,
536 text1, button1, button1_text, 536 text1, button1, button1_text,
537 text2, link1, link1_text), 537 text2, link1, link1_text),
538 NULL, new CountedBrowserAccessibilityFactory())); 538 nullptr, new CountedBrowserAccessibilityFactory()));
539 ASSERT_EQ(7, CountedBrowserAccessibility::num_instances()); 539 ASSERT_EQ(7, CountedBrowserAccessibility::num_instances());
540 540
541 BrowserAccessibilityWin* root_obj = 541 BrowserAccessibilityWin* root_obj =
542 manager->GetRoot()->ToBrowserAccessibilityWin(); 542 manager->GetRoot()->ToBrowserAccessibilityWin();
543 543
544 long text_len; 544 long text_len;
545 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); 545 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len));
546 546
547 base::win::ScopedBstr text; 547 base::win::ScopedBstr text;
548 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive())); 548 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, text.Receive()));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) { 601 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) {
602 // Try creating an empty document with busy state. Readonly is 602 // Try creating an empty document with busy state. Readonly is
603 // set automatically. 603 // set automatically.
604 CountedBrowserAccessibility::reset(); 604 CountedBrowserAccessibility::reset();
605 const int32 busy_state = 1 << ui::AX_STATE_BUSY; 605 const int32 busy_state = 1 << ui::AX_STATE_BUSY;
606 const int32 readonly_state = 1 << ui::AX_STATE_READ_ONLY; 606 const int32 readonly_state = 1 << ui::AX_STATE_READ_ONLY;
607 const int32 enabled_state = 1 << ui::AX_STATE_ENABLED; 607 const int32 enabled_state = 1 << ui::AX_STATE_ENABLED;
608 scoped_ptr<BrowserAccessibilityManager> manager( 608 scoped_ptr<BrowserAccessibilityManager> manager(
609 new BrowserAccessibilityManagerWin( 609 new BrowserAccessibilityManagerWin(
610 BrowserAccessibilityManagerWin::GetEmptyDocument(), 610 BrowserAccessibilityManagerWin::GetEmptyDocument(),
611 NULL, 611 nullptr,
612 new CountedBrowserAccessibilityFactory())); 612 new CountedBrowserAccessibilityFactory()));
613 613
614 // Verify the root is as we expect by default. 614 // Verify the root is as we expect by default.
615 BrowserAccessibility* root = manager->GetRoot(); 615 BrowserAccessibility* root = manager->GetRoot();
616 EXPECT_EQ(0, root->GetId()); 616 EXPECT_EQ(0, root->GetId());
617 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->GetRole()); 617 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->GetRole());
618 EXPECT_EQ(busy_state | readonly_state | enabled_state, root->GetState()); 618 EXPECT_EQ(busy_state | readonly_state | enabled_state, root->GetState());
619 619
620 // Tree with a child textfield. 620 // Tree with a child textfield.
621 ui::AXNodeData tree1_1; 621 ui::AXNodeData tree1_1;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 681
682 // This is a regression test for a bug where the initial empty document 682 // This is a regression test for a bug where the initial empty document
683 // loaded by a BrowserAccessibilityManagerWin couldn't be looked up by 683 // loaded by a BrowserAccessibilityManagerWin couldn't be looked up by
684 // its UniqueIDWin, because the AX Tree was loaded in 684 // its UniqueIDWin, because the AX Tree was loaded in
685 // BrowserAccessibilityManager code before BrowserAccessibilityManagerWin 685 // BrowserAccessibilityManager code before BrowserAccessibilityManagerWin
686 // was initialized. 686 // was initialized.
687 TEST_F(BrowserAccessibilityTest, EmptyDocHasUniqueIdWin) { 687 TEST_F(BrowserAccessibilityTest, EmptyDocHasUniqueIdWin) {
688 scoped_ptr<BrowserAccessibilityManagerWin> manager( 688 scoped_ptr<BrowserAccessibilityManagerWin> manager(
689 new BrowserAccessibilityManagerWin( 689 new BrowserAccessibilityManagerWin(
690 BrowserAccessibilityManagerWin::GetEmptyDocument(), 690 BrowserAccessibilityManagerWin::GetEmptyDocument(),
691 NULL, 691 nullptr,
692 new CountedBrowserAccessibilityFactory())); 692 new CountedBrowserAccessibilityFactory()));
693 693
694 // Verify the root is as we expect by default. 694 // Verify the root is as we expect by default.
695 BrowserAccessibility* root = manager->GetRoot(); 695 BrowserAccessibility* root = manager->GetRoot();
696 EXPECT_EQ(0, root->GetId()); 696 EXPECT_EQ(0, root->GetId());
697 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->GetRole()); 697 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->GetRole());
698 EXPECT_EQ(1 << ui::AX_STATE_BUSY | 698 EXPECT_EQ(1 << ui::AX_STATE_BUSY |
699 1 << ui::AX_STATE_READ_ONLY | 699 1 << ui::AX_STATE_READ_ONLY |
700 1 << ui::AX_STATE_ENABLED, 700 1 << ui::AX_STATE_ENABLED,
701 root->GetState()); 701 root->GetState());
702 702
703 LONG unique_id_win = root->ToBrowserAccessibilityWin()->unique_id_win(); 703 LONG unique_id_win = root->ToBrowserAccessibilityWin()->unique_id_win();
704 ASSERT_EQ(root, manager->GetFromUniqueIdWin(unique_id_win)); 704 ASSERT_EQ(root, manager->GetFromUniqueIdWin(unique_id_win));
705 } 705 }
706 706
707 } // namespace content 707 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698