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

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

Issue 2054393002: Implemented IAccessible2 reverse relations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed content_browsertests. Created 4 years, 5 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 10
(...skipping 2322 matching lines...) Expand 10 before | Expand all | Expand 10 after
2333 base::win::ScopedVariant root_unique_id_variant(-root->unique_id()); 2333 base::win::ScopedVariant root_unique_id_variant(-root->unique_id());
2334 base::win::ScopedComPtr<IDispatch> result; 2334 base::win::ScopedComPtr<IDispatch> result;
2335 EXPECT_EQ(E_INVALIDARG, ToBrowserAccessibilityWin(child)->get_accChild( 2335 EXPECT_EQ(E_INVALIDARG, ToBrowserAccessibilityWin(child)->get_accChild(
2336 root_unique_id_variant, result.Receive())); 2336 root_unique_id_variant, result.Receive()));
2337 2337
2338 base::win::ScopedVariant child_unique_id_variant(-child->unique_id()); 2338 base::win::ScopedVariant child_unique_id_variant(-child->unique_id());
2339 EXPECT_EQ(S_OK, ToBrowserAccessibilityWin(root)->get_accChild( 2339 EXPECT_EQ(S_OK, ToBrowserAccessibilityWin(root)->get_accChild(
2340 child_unique_id_variant, result.Receive())); 2340 child_unique_id_variant, result.Receive()));
2341 } 2341 }
2342 2342
2343 TEST_F(BrowserAccessibilityTest, TestIAccessible2Relations) {
2344 std::vector<int32_t> describedby_ids = {2, 3};
2345 ui::AXNodeData root;
2346 root.id = 1;
2347 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
2348 root.AddIntListAttribute(ui::AX_ATTR_DESCRIBEDBY_IDS, describedby_ids);
2349
2350 ui::AXNodeData child1;
2351 child1.id = 2;
2352 child1.role = ui::AX_ROLE_STATIC_TEXT;
2353 root.child_ids.push_back(2);
2354
2355 ui::AXNodeData child2;
2356 child2.id = 3;
2357 child2.role = ui::AX_ROLE_STATIC_TEXT;
2358 root.child_ids.push_back(3);
2359
2360 std::unique_ptr<BrowserAccessibilityManager> manager(
2361 BrowserAccessibilityManager::Create(
2362 MakeAXTreeUpdate(root, child1, child2), nullptr,
2363 new CountedBrowserAccessibilityFactory()));
2364
2365 BrowserAccessibilityWin* ax_root =
2366 ToBrowserAccessibilityWin(manager->GetRoot());
2367 ASSERT_NE(nullptr, ax_root);
2368 BrowserAccessibilityWin* ax_child1 =
2369 ToBrowserAccessibilityWin(ax_root->PlatformGetChild(0));
2370 ASSERT_NE(nullptr, ax_child1);
2371 BrowserAccessibilityWin* ax_child2 =
2372 ToBrowserAccessibilityWin(ax_root->PlatformGetChild(1));
2373 ASSERT_NE(nullptr, ax_child2);
2374
2375 LONG n_relations = 0;
2376 LONG n_targets = 0;
2377 LONG unique_id = 0;
2378 base::win::ScopedBstr relation_type;
2379 base::win::ScopedComPtr<IAccessibleRelation> describedby_relation;
2380 base::win::ScopedComPtr<IAccessibleRelation> description_for_relation;
2381 base::win::ScopedComPtr<IUnknown> target;
2382 base::win::ScopedComPtr<IAccessible2> ax_target;
2383
2384 EXPECT_HRESULT_SUCCEEDED(ax_root->get_nRelations(&n_relations));
2385 EXPECT_EQ(1, n_relations);
2386
2387 EXPECT_HRESULT_SUCCEEDED(
2388 ax_root->get_relation(0, describedby_relation.Receive()));
2389 EXPECT_HRESULT_SUCCEEDED(
2390 describedby_relation->get_relationType(relation_type.Receive()));
2391 EXPECT_EQ(L"describedBy", base::string16(relation_type));
2392 relation_type.Reset();
2393
2394 EXPECT_HRESULT_SUCCEEDED(describedby_relation->get_nTargets(&n_targets));
2395 EXPECT_EQ(2, n_targets);
2396
2397 EXPECT_HRESULT_SUCCEEDED(
2398 describedby_relation->get_target(0, target.Receive()));
2399 target.QueryInterface(ax_target.Receive());
2400 EXPECT_HRESULT_SUCCEEDED(ax_target->get_uniqueID(&unique_id));
2401 EXPECT_EQ(-ax_child1->unique_id(), unique_id);
2402 ax_target.Release();
2403 target.Release();
2404
2405 EXPECT_HRESULT_SUCCEEDED(
2406 describedby_relation->get_target(1, target.Receive()));
2407 target.QueryInterface(ax_target.Receive());
2408 EXPECT_HRESULT_SUCCEEDED(ax_target->get_uniqueID(&unique_id));
2409 EXPECT_EQ(-ax_child2->unique_id(), unique_id);
2410 ax_target.Release();
2411 target.Release();
2412 describedby_relation.Release();
2413
2414 // Test the reverse relations.
2415 EXPECT_HRESULT_SUCCEEDED(ax_child1->get_nRelations(&n_relations));
2416 EXPECT_EQ(1, n_relations);
2417
2418 EXPECT_HRESULT_SUCCEEDED(
2419 ax_child1->get_relation(0, description_for_relation.Receive()));
2420 EXPECT_HRESULT_SUCCEEDED(
2421 description_for_relation->get_relationType(relation_type.Receive()));
2422 EXPECT_EQ(L"descriptionFor", base::string16(relation_type));
2423 relation_type.Reset();
2424
2425 EXPECT_HRESULT_SUCCEEDED(description_for_relation->get_nTargets(&n_targets));
2426 EXPECT_EQ(1, n_targets);
2427
2428 EXPECT_HRESULT_SUCCEEDED(
2429 description_for_relation->get_target(0, target.Receive()));
2430 target.QueryInterface(ax_target.Receive());
2431 EXPECT_HRESULT_SUCCEEDED(ax_target->get_uniqueID(&unique_id));
2432 EXPECT_EQ(-ax_root->unique_id(), unique_id);
2433 ax_target.Release();
2434 target.Release();
2435 description_for_relation.Release();
2436
2437 EXPECT_HRESULT_SUCCEEDED(ax_child2->get_nRelations(&n_relations));
2438 EXPECT_EQ(1, n_relations);
2439
2440 EXPECT_HRESULT_SUCCEEDED(
2441 ax_child2->get_relation(0, description_for_relation.Receive()));
2442 EXPECT_HRESULT_SUCCEEDED(
2443 description_for_relation->get_relationType(relation_type.Receive()));
2444 EXPECT_EQ(L"descriptionFor", base::string16(relation_type));
2445 relation_type.Reset();
2446
2447 EXPECT_HRESULT_SUCCEEDED(description_for_relation->get_nTargets(&n_targets));
2448 EXPECT_EQ(1, n_targets);
2449
2450 EXPECT_HRESULT_SUCCEEDED(
2451 description_for_relation->get_target(0, target.Receive()));
2452 target.QueryInterface(ax_target.Receive());
2453 EXPECT_HRESULT_SUCCEEDED(ax_target->get_uniqueID(&unique_id));
2454 EXPECT_EQ(-ax_root->unique_id(), unique_id);
2455 ax_target.Release();
2456 target.Release();
2457
2458 // Try adding one more relation.
2459 std::vector<int32_t> labelledby_ids = {3};
2460 child1.AddIntListAttribute(ui::AX_ATTR_LABELLEDBY_IDS, labelledby_ids);
2461 AXEventNotificationDetails event;
2462 event.event_type = ui::AX_EVENT_ARIA_ATTRIBUTE_CHANGED;
2463 event.update.nodes.push_back(child1);
2464 event.id = child1.id;
2465 std::vector<AXEventNotificationDetails> events = {event};
2466 manager->OnAccessibilityEvents(events);
2467
2468 EXPECT_HRESULT_SUCCEEDED(ax_child1->get_nRelations(&n_relations));
2469 EXPECT_EQ(2, n_relations);
2470 EXPECT_HRESULT_SUCCEEDED(ax_child2->get_nRelations(&n_relations));
2471 EXPECT_EQ(2, n_relations);
2472 }
2473
2343 } // namespace content 2474 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/accessibility/browser_accessibility_win.cc ('k') | content/renderer/accessibility/blink_ax_tree_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698