OLD | NEW |
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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
11 #include "content/public/browser/notification_types.h" | 11 #include "content/public/browser/notification_types.h" |
| 12 #include "content/public/browser/render_view_host_observer.h" |
12 #include "content/public/browser/render_widget_host_view.h" | 13 #include "content/public/browser/render_widget_host_view.h" |
13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
14 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
15 #include "content/test/content_browser_test.h" | 16 #include "content/test/content_browser_test.h" |
16 #include "content/test/content_browser_test_utils.h" | 17 #include "content/test/content_browser_test_utils.h" |
17 #include "content/shell/shell.h" | 18 #include "content/shell/shell.h" |
18 | 19 |
19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
20 #include <atlbase.h> | 21 #include <atlbase.h> |
21 #include <atlcom.h> | 22 #include <atlcom.h> |
22 #include "base/win/scoped_com_initializer.h" | 23 #include "base/win/scoped_com_initializer.h" |
23 #include "ui/base/win/atl_module.h" | 24 #include "ui/base/win/atl_module.h" |
24 #endif | 25 #endif |
25 | 26 |
26 namespace content { | 27 namespace content { |
27 | 28 |
| 29 namespace { |
| 30 |
| 31 class TestRenderViewHostObserver : public RenderViewHostObserver { |
| 32 public: |
| 33 explicit TestRenderViewHostObserver(RenderViewHost* rvh, |
| 34 const base::Closure& callback) |
| 35 : RenderViewHostObserver(rvh), |
| 36 callback_(callback) { |
| 37 } |
| 38 |
| 39 virtual void AccessibilityLayoutComplete() OVERRIDE { |
| 40 callback_.Run(); |
| 41 } |
| 42 |
| 43 private: |
| 44 base::Closure callback_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(TestRenderViewHostObserver); |
| 47 }; |
| 48 |
| 49 } // namespace |
| 50 |
28 class CrossPlatformAccessibilityBrowserTest : public ContentBrowserTest { | 51 class CrossPlatformAccessibilityBrowserTest : public ContentBrowserTest { |
29 public: | 52 public: |
30 CrossPlatformAccessibilityBrowserTest() {} | 53 CrossPlatformAccessibilityBrowserTest() {} |
31 | 54 |
32 // Tell the renderer to send an accessibility tree, then wait for the | 55 // Tell the renderer to send an accessibility tree, then wait for the |
33 // notification that it's been received. | 56 // notification that it's been received. |
34 const AccessibilityNodeData& GetAccessibilityNodeDataTree( | 57 const AccessibilityNodeData& GetAccessibilityNodeDataTree( |
35 AccessibilityMode accessibility_mode = AccessibilityModeComplete) { | 58 AccessibilityMode accessibility_mode = AccessibilityModeComplete) { |
36 WindowedNotificationObserver tree_updated_observer( | 59 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
37 NOTIFICATION_ACCESSIBILITY_LAYOUT_COMPLETE, | |
38 NotificationService::AllSources()); | |
39 RenderWidgetHostView* host_view = | 60 RenderWidgetHostView* host_view = |
40 shell()->web_contents()->GetRenderWidgetHostView(); | 61 shell()->web_contents()->GetRenderWidgetHostView(); |
41 RenderWidgetHostImpl* host = | 62 RenderWidgetHostImpl* host = |
42 RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost()); | 63 RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost()); |
43 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>(host); | 64 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>(host); |
| 65 TestRenderViewHostObserver observer(view_host, loop_runner->QuitClosure()); |
44 view_host->set_save_accessibility_tree_for_testing(true); | 66 view_host->set_save_accessibility_tree_for_testing(true); |
45 view_host->SetAccessibilityMode(accessibility_mode); | 67 view_host->SetAccessibilityMode(accessibility_mode); |
46 tree_updated_observer.Wait(); | 68 loop_runner->Run(); |
47 return view_host->accessibility_tree_for_testing(); | 69 return view_host->accessibility_tree_for_testing(); |
48 } | 70 } |
49 | 71 |
50 // Make sure each node in the tree has an unique id. | 72 // Make sure each node in the tree has an unique id. |
51 void RecursiveAssertUniqueIds( | 73 void RecursiveAssertUniqueIds( |
52 const AccessibilityNodeData& node, base::hash_set<int>* ids) { | 74 const AccessibilityNodeData& node, base::hash_set<int>* ids) { |
53 ASSERT_TRUE(ids->find(node.id) == ids->end()); | 75 ASSERT_TRUE(ids->find(node.id) == ids->end()); |
54 ids->insert(node.id); | 76 ids->insert(node.id); |
55 for (size_t i = 0; i < node.children.size(); i++) | 77 for (size_t i = 0; i < node.children.size(); i++) |
56 RecursiveAssertUniqueIds(node.children[i], ids); | 78 RecursiveAssertUniqueIds(node.children[i], ids); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 const AccessibilityNodeData& tree = GetAccessibilityNodeDataTree(); | 480 const AccessibilityNodeData& tree = GetAccessibilityNodeDataTree(); |
459 | 481 |
460 ASSERT_EQ(1U, tree.children.size()); | 482 ASSERT_EQ(1U, tree.children.size()); |
461 const AccessibilityNodeData& textbox = tree.children[0]; | 483 const AccessibilityNodeData& textbox = tree.children[0]; |
462 | 484 |
463 EXPECT_EQ( | 485 EXPECT_EQ( |
464 true, GetBoolAttr(textbox, AccessibilityNodeData::ATTR_CAN_SET_VALUE)); | 486 true, GetBoolAttr(textbox, AccessibilityNodeData::ATTR_CAN_SET_VALUE)); |
465 } | 487 } |
466 | 488 |
467 } // namespace content | 489 } // namespace content |
OLD | NEW |