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

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

Issue 3550017: Implement additional IAccessibleText methods to return the nearest... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/accessibility/browser_accessibility_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/scoped_ptr.h" 5 #include "base/scoped_ptr.h"
6 #include "base/scoped_comptr_win.h" 6 #include "base/scoped_comptr_win.h"
7 #include "chrome/browser/accessibility/browser_accessibility_manager.h" 7 #include "chrome/browser/accessibility/browser_accessibility_manager.h"
8 #include "chrome/browser/accessibility/browser_accessibility_win.h" 8 #include "chrome/browser/accessibility/browser_accessibility_win.h"
9 #include "chrome/common/render_messages_params.h" 9 #include "chrome/common/render_messages_params.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications; 267 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
268 notifications.push_back(param); 268 notifications.push_back(param);
269 manager->OnAccessibilityNotifications(notifications); 269 manager->OnAccessibilityNotifications(notifications);
270 ASSERT_EQ(1, CountedBrowserAccessibility::global_obj_count_); 270 ASSERT_EQ(1, CountedBrowserAccessibility::global_obj_count_);
271 271
272 // Delete the manager and test that all BrowserAccessibility instances are 272 // Delete the manager and test that all BrowserAccessibility instances are
273 // deleted. 273 // deleted.
274 delete manager; 274 delete manager;
275 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); 275 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
276 } 276 }
277
278 TEST_F(BrowserAccessibilityTest, TestTextBoundaries) {
279 WebAccessibility text1;
280 text1.id = 11;
281 text1.role = WebAccessibility::ROLE_TEXT_FIELD;
282 text1.state = 0;
283 text1.value = L"One two three.\nFour five six.";
284
285 WebAccessibility root;
286 root.id = 1;
287 root.role = WebAccessibility::ROLE_DOCUMENT;
288 root.state = 0;
289 root.children.push_back(text1);
290
291 CountedBrowserAccessibility::global_obj_count_ = 0;
292 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create(
293 GetDesktopWindow(), root, NULL,
294 new CountedBrowserAccessibilityFactory());
295 ASSERT_EQ(2, CountedBrowserAccessibility::global_obj_count_);
296
297 BrowserAccessibilityWin* root_obj =
298 static_cast<BrowserAccessibilityWin*>(manager->GetRoot());
Chris Guillory 2010/10/08 17:15:06 You can avoid a cast here by using toBrowserAccess
299 BrowserAccessibilityWin* text1_obj =
Chris Guillory 2010/10/08 17:15:06 Optional: It might be interesting to see if you co
300 static_cast<BrowserAccessibilityWin*>(root_obj->GetChild(0));
301
302 BSTR text;
303 long start;
304 long end;
305
306 long text1_len;
307 ASSERT_EQ(S_OK, text1_obj->get_nCharacters(&text1_len));
308
309 ASSERT_EQ(S_OK, text1_obj->get_text(0, text1_len, &text));
310 ASSERT_EQ(text, text1.value);
311 SysFreeString(text);
312
313 ASSERT_EQ(S_OK, text1_obj->get_text(0, 4, &text));
314 ASSERT_EQ(text, std::wstring(L"One "));
315 SysFreeString(text);
316
317 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset(
318 1, IA2_TEXT_BOUNDARY_CHAR, &start, &end, &text));
319 ASSERT_EQ(start, 1);
320 ASSERT_EQ(end, 2);
321 ASSERT_EQ(text, std::wstring(L"n"));
322 SysFreeString(text);
323
324 ASSERT_EQ(S_FALSE, text1_obj->get_textAtOffset(
325 text1_len, IA2_TEXT_BOUNDARY_CHAR, &start, &end, &text));
326 ASSERT_EQ(start, text1_len);
327 ASSERT_EQ(end, text1_len);
328
329 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset(
330 1, IA2_TEXT_BOUNDARY_WORD, &start, &end, &text));
331 ASSERT_EQ(start, 0);
332 ASSERT_EQ(end, 3);
333 ASSERT_EQ(text, std::wstring(L"One"));
334 SysFreeString(text);
335
336 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset(
337 6, IA2_TEXT_BOUNDARY_WORD, &start, &end, &text));
338 ASSERT_EQ(start, 4);
339 ASSERT_EQ(end, 7);
340 ASSERT_EQ(text, std::wstring(L"two"));
341 SysFreeString(text);
342
343 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset(
344 text1_len, IA2_TEXT_BOUNDARY_WORD, &start, &end, &text));
345 ASSERT_EQ(start, 25);
346 ASSERT_EQ(end, 29);
347 ASSERT_EQ(text, std::wstring(L"six."));
348 SysFreeString(text);
349
350 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset(
351 1, IA2_TEXT_BOUNDARY_LINE, &start, &end, &text));
352 ASSERT_EQ(start, 0);
353 ASSERT_EQ(end, 13);
354 ASSERT_EQ(text, std::wstring(L"One two three"));
355 SysFreeString(text);
356
357 // Delete the manager and test that all BrowserAccessibility instances are
358 // deleted.
359 delete manager;
360 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_);
361 }
OLDNEW
« no previous file with comments | « chrome/browser/accessibility/browser_accessibility_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698