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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "content/common/view_messages.h" | 6 #include "content/common/frame_messages.h" |
7 #include "content/public/test/render_view_test.h" | 7 #include "content/public/test/render_view_test.h" |
8 #include "content/renderer/accessibility/renderer_accessibility_complete.h" | 8 #include "content/renderer/accessibility/renderer_accessibility_complete.h" |
9 #include "content/renderer/render_view_impl.h" | 9 #include "content/renderer/render_view_impl.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "third_party/WebKit/public/platform/WebSize.h" | 11 #include "third_party/WebKit/public/platform/WebSize.h" |
12 #include "third_party/WebKit/public/web/WebAXObject.h" | 12 #include "third_party/WebKit/public/web/WebAXObject.h" |
13 #include "third_party/WebKit/public/web/WebDocument.h" | 13 #include "third_party/WebKit/public/web/WebDocument.h" |
14 #include "third_party/WebKit/public/web/WebView.h" | 14 #include "third_party/WebKit/public/web/WebView.h" |
15 #include "ui/accessibility/ax_node_data.h" | 15 #include "ui/accessibility/ax_node_data.h" |
16 | 16 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 }; | 55 }; |
56 | 56 |
57 class RendererAccessibilityTest : public RenderViewTest { | 57 class RendererAccessibilityTest : public RenderViewTest { |
58 public: | 58 public: |
59 RendererAccessibilityTest() {} | 59 RendererAccessibilityTest() {} |
60 | 60 |
61 RenderViewImpl* view() { | 61 RenderViewImpl* view() { |
62 return static_cast<RenderViewImpl*>(view_); | 62 return static_cast<RenderViewImpl*>(view_); |
63 } | 63 } |
64 | 64 |
| 65 RenderFrameImpl* frame() { |
| 66 return static_cast<RenderFrameImpl*>(view()->GetMainRenderFrame()); |
| 67 } |
| 68 |
65 virtual void SetUp() { | 69 virtual void SetUp() { |
66 RenderViewTest::SetUp(); | 70 RenderViewTest::SetUp(); |
67 sink_ = &render_thread_->sink(); | 71 sink_ = &render_thread_->sink(); |
68 } | 72 } |
69 | 73 |
70 void SetMode(unsigned int mode) { | 74 void SetMode(unsigned int mode) { |
71 view()->OnSetAccessibilityMode(mode); | 75 view()->OnSetAccessibilityMode(mode); |
72 } | 76 } |
73 | 77 |
74 void GetLastAccEvent( | 78 void GetLastAccEvent( |
(...skipping 10 matching lines...) Expand all Loading... |
85 int CountAccessibilityNodesSentToBrowser() { | 89 int CountAccessibilityNodesSentToBrowser() { |
86 AccessibilityHostMsg_EventParams event; | 90 AccessibilityHostMsg_EventParams event; |
87 GetLastAccEvent(&event); | 91 GetLastAccEvent(&event); |
88 return event.nodes.size(); | 92 return event.nodes.size(); |
89 } | 93 } |
90 | 94 |
91 protected: | 95 protected: |
92 IPC::TestSink* sink_; | 96 IPC::TestSink* sink_; |
93 | 97 |
94 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityTest); | 98 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityTest); |
| 99 |
95 }; | 100 }; |
96 | 101 |
97 TEST_F(RendererAccessibilityTest, EditableTextModeFocusEvents) { | 102 TEST_F(RendererAccessibilityTest, EditableTextModeFocusEvents) { |
98 // This is not a test of true web accessibility, it's a test of | 103 // This is not a test of true web accessibility, it's a test of |
99 // a mode used on Windows 8 in Metro mode where an extremely simplified | 104 // a mode used on Windows 8 in Metro mode where an extremely simplified |
100 // accessibility tree containing only the current focused node is | 105 // accessibility tree containing only the current focused node is |
101 // generated. | 106 // generated. |
102 SetMode(AccessibilityModeEditableTextOnly); | 107 SetMode(AccessibilityModeEditableTextOnly); |
103 | 108 |
104 // Set a minimum size and give focus so simulated events work. | 109 // Set a minimum size and give focus so simulated events work. |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 view()->OnSwapOut(); | 352 view()->OnSwapOut(); |
348 accessibility->SendPendingAccessibilityEvents(); | 353 accessibility->SendPendingAccessibilityEvents(); |
349 EXPECT_FALSE(sink_->GetUniqueMessageMatching( | 354 EXPECT_FALSE(sink_->GetUniqueMessageMatching( |
350 AccessibilityHostMsg_Events::ID)); | 355 AccessibilityHostMsg_Events::ID)); |
351 | 356 |
352 // Navigate, so we're not swapped out anymore. Now we should | 357 // Navigate, so we're not swapped out anymore. Now we should |
353 // send accessibility events again. Note that the | 358 // send accessibility events again. Note that the |
354 // message that was queued up before will be quickly discarded | 359 // message that was queued up before will be quickly discarded |
355 // because the element it was referring to no longer exists, | 360 // because the element it was referring to no longer exists, |
356 // so the event here is from loading this new page. | 361 // so the event here is from loading this new page. |
357 ViewMsg_Navigate_Params nav_params; | 362 FrameMsg_Navigate_Params nav_params; |
358 nav_params.url = GURL("data:text/html,<p>Hello, again.</p>"); | 363 nav_params.url = GURL("data:text/html,<p>Hello, again.</p>"); |
359 nav_params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 364 nav_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
360 nav_params.transition = PAGE_TRANSITION_TYPED; | 365 nav_params.transition = PAGE_TRANSITION_TYPED; |
361 nav_params.current_history_list_length = 1; | 366 nav_params.current_history_list_length = 1; |
362 nav_params.current_history_list_offset = 0; | 367 nav_params.current_history_list_offset = 0; |
363 nav_params.pending_history_list_offset = 1; | 368 nav_params.pending_history_list_offset = 1; |
364 nav_params.page_id = -1; | 369 nav_params.page_id = -1; |
365 view()->OnNavigate(nav_params); | 370 frame()->OnNavigate(nav_params); |
366 accessibility->SendPendingAccessibilityEvents(); | 371 accessibility->SendPendingAccessibilityEvents(); |
367 EXPECT_TRUE(sink_->GetUniqueMessageMatching( | 372 EXPECT_TRUE(sink_->GetUniqueMessageMatching( |
368 AccessibilityHostMsg_Events::ID)); | 373 AccessibilityHostMsg_Events::ID)); |
369 } | 374 } |
370 | 375 |
371 TEST_F(RendererAccessibilityTest, HideAccessibilityObject) { | 376 TEST_F(RendererAccessibilityTest, HideAccessibilityObject) { |
372 // Test RendererAccessibilityComplete and make sure it sends the | 377 // Test RendererAccessibilityComplete and make sure it sends the |
373 // proper event to the browser when an object in the tree | 378 // proper event to the browser when an object in the tree |
374 // is hidden, but its children are not. | 379 // is hidden, but its children are not. |
375 std::string html = | 380 std::string html = |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 GetLastAccEvent(&event); | 537 GetLastAccEvent(&event); |
533 ASSERT_EQ(5U, event.nodes.size()); | 538 ASSERT_EQ(5U, event.nodes.size()); |
534 | 539 |
535 EXPECT_EQ(body.axID(), event.nodes[0].id); | 540 EXPECT_EQ(body.axID(), event.nodes[0].id); |
536 EXPECT_EQ(text_1.axID(), event.nodes[1].id); | 541 EXPECT_EQ(text_1.axID(), event.nodes[1].id); |
537 // The third event is to update text_2, but its id changes | 542 // The third event is to update text_2, but its id changes |
538 // so we don't have a test expectation for it. | 543 // so we don't have a test expectation for it. |
539 } | 544 } |
540 | 545 |
541 } // namespace content | 546 } // namespace content |
OLD | NEW |