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

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

Issue 10382051: Add initial GTK web accessibility framework (third attempt). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
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/win/scoped_comptr.h" 6 #include "base/win/scoped_comptr.h"
7 #include "content/browser/accessibility/browser_accessibility_manager.h" 7 #include "content/browser/accessibility/browser_accessibility_manager.h"
8 #include "content/browser/accessibility/browser_accessibility_win.h" 8 #include "content/browser/accessibility/browser_accessibility_win.h"
9 #include "content/common/accessibility_messages.h" 9 #include "content/common/accessibility_messages.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // Construct a manager again, and this time use the IAccessible interface 108 // Construct a manager again, and this time use the IAccessible interface
109 // to get new references to two of the three nodes in the tree. 109 // to get new references to two of the three nodes in the tree.
110 manager = 110 manager =
111 BrowserAccessibilityManager::Create( 111 BrowserAccessibilityManager::Create(
112 GetDesktopWindow(), 112 GetDesktopWindow(),
113 root, 113 root,
114 NULL, 114 NULL,
115 new CountedBrowserAccessibilityFactory()); 115 new CountedBrowserAccessibilityFactory());
116 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); 116 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_);
117 IAccessible* root_accessible = 117 IAccessible* root_accessible =
118 manager->GetRoot()->toBrowserAccessibilityWin(); 118 manager->GetRoot()->ToBrowserAccessibilityWin();
119 IDispatch* root_iaccessible = NULL; 119 IDispatch* root_iaccessible = NULL;
120 IDispatch* child1_iaccessible = NULL; 120 IDispatch* child1_iaccessible = NULL;
121 VARIANT var_child; 121 VARIANT var_child;
122 var_child.vt = VT_I4; 122 var_child.vt = VT_I4;
123 var_child.lVal = CHILDID_SELF; 123 var_child.lVal = CHILDID_SELF;
124 HRESULT hr = root_accessible->get_accChild(var_child, &root_iaccessible); 124 HRESULT hr = root_accessible->get_accChild(var_child, &root_iaccessible);
125 ASSERT_EQ(S_OK, hr); 125 ASSERT_EQ(S_OK, hr);
126 var_child.lVal = 1; 126 var_child.lVal = 1;
127 hr = root_accessible->get_accChild(var_child, &child1_iaccessible); 127 hr = root_accessible->get_accChild(var_child, &child1_iaccessible);
128 ASSERT_EQ(S_OK, hr); 128 ASSERT_EQ(S_OK, hr);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 BrowserAccessibilityManager* manager = 163 BrowserAccessibilityManager* manager =
164 BrowserAccessibilityManager::Create( 164 BrowserAccessibilityManager::Create(
165 GetDesktopWindow(), 165 GetDesktopWindow(),
166 root, 166 root,
167 NULL, 167 NULL,
168 new CountedBrowserAccessibilityFactory()); 168 new CountedBrowserAccessibilityFactory());
169 169
170 // Query for the text IAccessible and verify that it returns "old text" as its 170 // Query for the text IAccessible and verify that it returns "old text" as its
171 // value. 171 // value.
172 base::win::ScopedComPtr<IDispatch> text_dispatch; 172 base::win::ScopedComPtr<IDispatch> text_dispatch;
173 HRESULT hr = manager->GetRoot()->toBrowserAccessibilityWin()->get_accChild( 173 HRESULT hr = manager->GetRoot()->ToBrowserAccessibilityWin()->get_accChild(
174 CreateI4Variant(1), text_dispatch.Receive()); 174 CreateI4Variant(1), text_dispatch.Receive());
175 ASSERT_EQ(S_OK, hr); 175 ASSERT_EQ(S_OK, hr);
176 176
177 base::win::ScopedComPtr<IAccessible> text_accessible; 177 base::win::ScopedComPtr<IAccessible> text_accessible;
178 hr = text_dispatch.QueryInterface(text_accessible.Receive()); 178 hr = text_dispatch.QueryInterface(text_accessible.Receive());
179 ASSERT_EQ(S_OK, hr); 179 ASSERT_EQ(S_OK, hr);
180 180
181 CComBSTR name; 181 CComBSTR name;
182 hr = text_accessible->get_accName(CreateI4Variant(CHILDID_SELF), &name); 182 hr = text_accessible->get_accName(CreateI4Variant(CHILDID_SELF), &name);
183 ASSERT_EQ(S_OK, hr); 183 ASSERT_EQ(S_OK, hr);
184 EXPECT_STREQ(L"old text", name.m_str); 184 EXPECT_STREQ(L"old text", name.m_str);
185 185
186 text_dispatch.Release(); 186 text_dispatch.Release();
187 text_accessible.Release(); 187 text_accessible.Release();
188 188
189 // Notify the BrowserAccessibilityManager that the text child has changed. 189 // Notify the BrowserAccessibilityManager that the text child has changed.
190 text.name = L"new text"; 190 text.name = L"new text";
191 AccessibilityHostMsg_NotificationParams param; 191 AccessibilityHostMsg_NotificationParams param;
192 param.notification_type = AccessibilityNotificationChildrenChanged; 192 param.notification_type = AccessibilityNotificationChildrenChanged;
193 param.acc_tree = text; 193 param.acc_tree = text;
194 param.includes_children = true; 194 param.includes_children = true;
195 param.id = text.id; 195 param.id = text.id;
196 std::vector<AccessibilityHostMsg_NotificationParams> notifications; 196 std::vector<AccessibilityHostMsg_NotificationParams> notifications;
197 notifications.push_back(param); 197 notifications.push_back(param);
198 manager->OnAccessibilityNotifications(notifications); 198 manager->OnAccessibilityNotifications(notifications);
199 199
200 // Query for the text IAccessible and verify that it now returns "new text" 200 // Query for the text IAccessible and verify that it now returns "new text"
201 // as its value. 201 // as its value.
202 hr = manager->GetRoot()->toBrowserAccessibilityWin()->get_accChild( 202 hr = manager->GetRoot()->ToBrowserAccessibilityWin()->get_accChild(
203 CreateI4Variant(1), 203 CreateI4Variant(1),
204 text_dispatch.Receive()); 204 text_dispatch.Receive());
205 ASSERT_EQ(S_OK, hr); 205 ASSERT_EQ(S_OK, hr);
206 206
207 hr = text_dispatch.QueryInterface(text_accessible.Receive()); 207 hr = text_dispatch.QueryInterface(text_accessible.Receive());
208 ASSERT_EQ(S_OK, hr); 208 ASSERT_EQ(S_OK, hr);
209 209
210 hr = text_accessible->get_accName(CreateI4Variant(CHILDID_SELF), &name); 210 hr = text_accessible->get_accName(CreateI4Variant(CHILDID_SELF), &name);
211 ASSERT_EQ(S_OK, hr); 211 ASSERT_EQ(S_OK, hr);
212 EXPECT_STREQ(L"new text", name.m_str); 212 EXPECT_STREQ(L"new text", name.m_str);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 root.state = 0; 290 root.state = 0;
291 root.children.push_back(text1); 291 root.children.push_back(text1);
292 292
293 CountedBrowserAccessibility::global_obj_count_ = 0; 293 CountedBrowserAccessibility::global_obj_count_ = 0;
294 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create( 294 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create(
295 GetDesktopWindow(), root, NULL, 295 GetDesktopWindow(), root, NULL,
296 new CountedBrowserAccessibilityFactory()); 296 new CountedBrowserAccessibilityFactory());
297 ASSERT_EQ(2, CountedBrowserAccessibility::global_obj_count_); 297 ASSERT_EQ(2, CountedBrowserAccessibility::global_obj_count_);
298 298
299 BrowserAccessibilityWin* root_obj = 299 BrowserAccessibilityWin* root_obj =
300 manager->GetRoot()->toBrowserAccessibilityWin(); 300 manager->GetRoot()->ToBrowserAccessibilityWin();
301 BrowserAccessibilityWin* text1_obj = 301 BrowserAccessibilityWin* text1_obj =
302 root_obj->GetChild(0)->toBrowserAccessibilityWin(); 302 root_obj->GetChild(0)->ToBrowserAccessibilityWin();
303 303
304 BSTR text; 304 BSTR text;
305 long start; 305 long start;
306 long end; 306 long end;
307 307
308 long text1_len; 308 long text1_len;
309 ASSERT_EQ(S_OK, text1_obj->get_nCharacters(&text1_len)); 309 ASSERT_EQ(S_OK, text1_obj->get_nCharacters(&text1_len));
310 310
311 ASSERT_EQ(S_OK, text1_obj->get_text(0, text1_len, &text)); 311 ASSERT_EQ(S_OK, text1_obj->get_text(0, text1_len, &text));
312 ASSERT_EQ(text, text1.value); 312 ASSERT_EQ(text, text1.value);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 root.children.push_back(text1); 386 root.children.push_back(text1);
387 root.children.push_back(text2); 387 root.children.push_back(text2);
388 388
389 CountedBrowserAccessibility::global_obj_count_ = 0; 389 CountedBrowserAccessibility::global_obj_count_ = 0;
390 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create( 390 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create(
391 GetDesktopWindow(), root, NULL, 391 GetDesktopWindow(), root, NULL,
392 new CountedBrowserAccessibilityFactory()); 392 new CountedBrowserAccessibilityFactory());
393 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); 393 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_);
394 394
395 BrowserAccessibilityWin* root_obj = 395 BrowserAccessibilityWin* root_obj =
396 manager->GetRoot()->toBrowserAccessibilityWin(); 396 manager->GetRoot()->ToBrowserAccessibilityWin();
397 397
398 BSTR text; 398 BSTR text;
399 399
400 long text_len; 400 long text_len;
401 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); 401 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len));
402 402
403 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text)); 403 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text));
404 EXPECT_EQ(text, text1.name + text2.name); 404 EXPECT_EQ(text, text1.name + text2.name);
405 SysFreeString(text); 405 SysFreeString(text);
406 406
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 root.children.push_back(text2); 470 root.children.push_back(text2);
471 root.children.push_back(link1); 471 root.children.push_back(link1);
472 472
473 CountedBrowserAccessibility::global_obj_count_ = 0; 473 CountedBrowserAccessibility::global_obj_count_ = 0;
474 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create( 474 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create(
475 GetDesktopWindow(), root, NULL, 475 GetDesktopWindow(), root, NULL,
476 new CountedBrowserAccessibilityFactory()); 476 new CountedBrowserAccessibilityFactory());
477 ASSERT_EQ(7, CountedBrowserAccessibility::global_obj_count_); 477 ASSERT_EQ(7, CountedBrowserAccessibility::global_obj_count_);
478 478
479 BrowserAccessibilityWin* root_obj = 479 BrowserAccessibilityWin* root_obj =
480 manager->GetRoot()->toBrowserAccessibilityWin(); 480 manager->GetRoot()->ToBrowserAccessibilityWin();
481 481
482 BSTR text; 482 BSTR text;
483 483
484 long text_len; 484 long text_len;
485 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); 485 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len));
486 486
487 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text)); 487 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text));
488 const string16 embed = BrowserAccessibilityWin::kEmbeddedCharacter; 488 const string16 embed = BrowserAccessibilityWin::kEmbeddedCharacter;
489 EXPECT_EQ(text, text1.name + embed + text2.name + embed); 489 EXPECT_EQ(text, text1.name + embed + text2.name + embed);
490 SysFreeString(text); 490 SysFreeString(text);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index)); 525 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index));
526 EXPECT_EQ(0, hyperlink_index); 526 EXPECT_EQ(0, hyperlink_index);
527 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index)); 527 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index));
528 EXPECT_EQ(1, hyperlink_index); 528 EXPECT_EQ(1, hyperlink_index);
529 529
530 // Delete the manager and test that all BrowserAccessibility instances are 530 // Delete the manager and test that all BrowserAccessibility instances are
531 // deleted. 531 // deleted.
532 delete manager; 532 delete manager;
533 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); 533 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
534 } 534 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698