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

Side by Side Diff: ui/accessibility/platform/ax_platform_node_win_unittest.cc

Issue 2981073002: Move BrowserAccessibilityRelation code to the ui/accessibility/ (Closed)
Patch Set: Force tests to calculate relationships. Created 3 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
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/accessibility/platform/ax_platform_node.h" 5 #include "ui/accessibility/platform/ax_platform_node.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <atlcom.h> 8 #include <atlcom.h>
9 #include <oleacc.h> 9 #include <oleacc.h>
10 10
11 #include <memory> 11 #include <memory>
12 12
13 #include "base/win/scoped_bstr.h" 13 #include "base/win/scoped_bstr.h"
14 #include "base/win/scoped_comptr.h" 14 #include "base/win/scoped_comptr.h"
15 #include "base/win/scoped_variant.h" 15 #include "base/win/scoped_variant.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/iaccessible2/ia2_api_all.h" 17 #include "third_party/iaccessible2/ia2_api_all.h"
18 #include "ui/accessibility/ax_node_data.h" 18 #include "ui/accessibility/ax_node_data.h"
19 #include "ui/accessibility/platform/ax_platform_node_win.h"
19 #include "ui/accessibility/platform/test_ax_node_wrapper.h" 20 #include "ui/accessibility/platform/test_ax_node_wrapper.h"
20 #include "ui/base/win/atl_module.h" 21 #include "ui/base/win/atl_module.h"
21 22
22 using base::win::ScopedBstr; 23 using base::win::ScopedBstr;
23 using base::win::ScopedComPtr; 24 using base::win::ScopedComPtr;
24 using base::win::ScopedVariant; 25 using base::win::ScopedVariant;
25 26
26 namespace ui { 27 namespace ui {
27 28
28 namespace { 29 namespace {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 update.nodes.push_back(node3); 86 update.nodes.push_back(node3);
86 update.nodes.push_back(node4); 87 update.nodes.push_back(node4);
87 Init(update); 88 Init(update);
88 } 89 }
89 90
90 protected: 91 protected:
91 AXNode* GetRootNode() { 92 AXNode* GetRootNode() {
92 return tree_->root(); 93 return tree_->root();
93 } 94 }
94 95
96 void BuildRelationships(ScopedComPtr<IAccessible2> accessible) {
97 CHECK(accessible);
98 AXPlatformNodeWin* node = static_cast<AXPlatformNodeWin*>(accessible.Get());
99 node->CalculateRelationships();
100 }
101
95 ScopedComPtr<IAccessible> IAccessibleFromNode(AXNode* node) { 102 ScopedComPtr<IAccessible> IAccessibleFromNode(AXNode* node) {
96 TestAXNodeWrapper* wrapper = 103 TestAXNodeWrapper* wrapper =
97 TestAXNodeWrapper::GetOrCreate(tree_.get(), node); 104 TestAXNodeWrapper::GetOrCreate(tree_.get(), node);
98 if (!wrapper) 105 if (!wrapper)
99 return ScopedComPtr<IAccessible>(); 106 return ScopedComPtr<IAccessible>();
100 AXPlatformNode* ax_platform_node = wrapper->ax_platform_node(); 107 AXPlatformNode* ax_platform_node = wrapper->ax_platform_node();
101 IAccessible* iaccessible = ax_platform_node->GetNativeViewAccessible(); 108 IAccessible* iaccessible = ax_platform_node->GetNativeViewAccessible();
102 return ScopedComPtr<IAccessible>(iaccessible); 109 return ScopedComPtr<IAccessible>(iaccessible);
103 } 110 }
104 111
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 ScopedComPtr<IAccessibleTable> result; 1293 ScopedComPtr<IAccessibleTable> result;
1287 table.CopyTo(result.GetAddressOf()); 1294 table.CopyTo(result.GetAddressOf());
1288 ASSERT_NE(nullptr, result); 1295 ASSERT_NE(nullptr, result);
1289 1296
1290 // Check to make sure that this is the right table by checking one cell. 1297 // Check to make sure that this is the right table by checking one cell.
1291 ScopedComPtr<IUnknown> cell_1; 1298 ScopedComPtr<IUnknown> cell_1;
1292 EXPECT_EQ(S_OK, result->get_accessibleAt(1, 1, cell_1.GetAddressOf())); 1299 EXPECT_EQ(S_OK, result->get_accessibleAt(1, 1, cell_1.GetAddressOf()));
1293 CheckIUnknownHasName(cell_1, L"1"); 1300 CheckIUnknownHasName(cell_1, L"1");
1294 } 1301 }
1295 1302
1303 TEST_F(AXPlatformNodeWinTest, TestIAccessible2GetNRelations) {
1304 // This is is a duplicated of
1305 // BrowserAccessibilityTest::TestIAccessible2Relations but without the
1306 // specific COM/BrowserAccessibility knowledge.
1307 ui::AXNodeData root;
1308 root.id = 1;
1309 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
1310
1311 std::vector<int32_t> describedby_ids = {1, 2, 3};
1312 root.AddIntListAttribute(ui::AX_ATTR_DESCRIBEDBY_IDS, describedby_ids);
1313
1314 ui::AXNodeData child1;
1315 child1.id = 2;
1316 child1.role = ui::AX_ROLE_STATIC_TEXT;
1317
1318 root.child_ids.push_back(2);
1319
1320 ui::AXNodeData child2;
1321 child2.id = 3;
1322 child2.role = ui::AX_ROLE_STATIC_TEXT;
1323
1324 root.child_ids.push_back(3);
1325
1326 Init(root, child1, child2);
1327 ScopedComPtr<IAccessible> root_iaccessible(GetRootIAccessible());
1328 ScopedComPtr<IAccessible2> root_iaccessible2 =
1329 ToIAccessible2(root_iaccessible);
1330
1331 ScopedComPtr<IDispatch> result;
1332 EXPECT_EQ(S_OK, root_iaccessible2->get_accChild(ScopedVariant(1),
1333 result.GetAddressOf()));
1334 ScopedComPtr<IAccessible2> ax_child1;
1335 EXPECT_EQ(S_OK, result.CopyTo(ax_child1.GetAddressOf()));
1336 result.Reset();
1337
1338 EXPECT_EQ(S_OK, root_iaccessible2->get_accChild(ScopedVariant(2),
1339 result.GetAddressOf()));
1340 ScopedComPtr<IAccessible2> ax_child2;
1341 EXPECT_EQ(S_OK, result.CopyTo(ax_child2.GetAddressOf()));
1342 result.Reset();
1343
1344 BuildRelationships(root_iaccessible2);
1345 BuildRelationships(ax_child1);
1346 BuildRelationships(ax_child2);
1347
1348 LONG n_relations = 0;
1349 LONG n_targets = 0;
1350 ScopedBstr relation_type;
1351 ScopedComPtr<IAccessibleRelation> describedby_relation;
1352 ScopedComPtr<IAccessibleRelation> description_for_relation;
1353 ScopedComPtr<IUnknown> target;
1354
1355 EXPECT_HRESULT_SUCCEEDED(root_iaccessible2->get_nRelations(&n_relations));
1356 EXPECT_EQ(1, n_relations);
1357
1358 EXPECT_HRESULT_SUCCEEDED(
1359 root_iaccessible2->get_relation(0, describedby_relation.GetAddressOf()));
1360 EXPECT_HRESULT_SUCCEEDED(
1361 describedby_relation->get_relationType(relation_type.Receive()));
1362 EXPECT_EQ(L"describedBy", base::string16(relation_type));
1363 relation_type.Reset();
1364
1365 EXPECT_HRESULT_SUCCEEDED(describedby_relation->get_nTargets(&n_targets));
1366 EXPECT_EQ(2, n_targets);
1367
1368 EXPECT_HRESULT_SUCCEEDED(
1369 describedby_relation->get_target(0, target.GetAddressOf()));
1370 target.Reset();
1371
1372 EXPECT_HRESULT_SUCCEEDED(
1373 describedby_relation->get_target(1, target.GetAddressOf()));
1374 target.Reset();
1375 describedby_relation.Reset();
1376
1377 // Test the reverse relations.
1378 EXPECT_HRESULT_SUCCEEDED(ax_child1->get_nRelations(&n_relations));
1379 EXPECT_EQ(1, n_relations);
1380
1381 EXPECT_HRESULT_SUCCEEDED(
1382 ax_child1->get_relation(0, description_for_relation.GetAddressOf()));
1383 EXPECT_HRESULT_SUCCEEDED(
1384 description_for_relation->get_relationType(relation_type.Receive()));
1385 EXPECT_EQ(L"descriptionFor", base::string16(relation_type));
1386 relation_type.Reset();
1387
1388 EXPECT_HRESULT_SUCCEEDED(description_for_relation->get_nTargets(&n_targets));
1389 EXPECT_EQ(1, n_targets);
1390
1391 EXPECT_HRESULT_SUCCEEDED(
1392 description_for_relation->get_target(0, target.GetAddressOf()));
1393 target.Reset();
1394 description_for_relation.Reset();
1395
1396 EXPECT_HRESULT_SUCCEEDED(ax_child2->get_nRelations(&n_relations));
1397 EXPECT_EQ(1, n_relations);
1398
1399 EXPECT_HRESULT_SUCCEEDED(
1400 ax_child2->get_relation(0, description_for_relation.GetAddressOf()));
1401 EXPECT_HRESULT_SUCCEEDED(
1402 description_for_relation->get_relationType(relation_type.Receive()));
1403 EXPECT_EQ(L"descriptionFor", base::string16(relation_type));
1404 relation_type.Reset();
1405
1406 EXPECT_HRESULT_SUCCEEDED(description_for_relation->get_nTargets(&n_targets));
1407 EXPECT_EQ(1, n_targets);
1408
1409 EXPECT_HRESULT_SUCCEEDED(
1410 description_for_relation->get_target(0, target.GetAddressOf()));
1411 target.Reset();
1412
1413 // TODO(dougt): Try adding one more relation.
1414 }
1415
1296 } // namespace ui 1416 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698