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/accessibility_node_data.h" | 6 #include "content/common/accessibility_node_data.h" |
7 #include "content/common/view_messages.h" | 7 #include "content/common/view_messages.h" |
8 #include "content/public/test/render_view_test.h" | 8 #include "content/public/test/render_view_test.h" |
9 #include "content/renderer/accessibility/renderer_accessibility_complete.h" | 9 #include "content/renderer/accessibility/renderer_accessibility_complete.h" |
10 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 sink_->ClearMessages(); | 303 sink_->ClearMessages(); |
304 const WebAccessibilityObject& first_child = root_obj.childAt(0); | 304 const WebAccessibilityObject& first_child = root_obj.childAt(0); |
305 accessibility->HandleWebAccessibilityNotification( | 305 accessibility->HandleWebAccessibilityNotification( |
306 first_child, | 306 first_child, |
307 WebKit::WebAccessibilityNotificationLiveRegionChanged); | 307 WebKit::WebAccessibilityNotificationLiveRegionChanged); |
308 accessibility->SendPendingAccessibilityNotifications(); | 308 accessibility->SendPendingAccessibilityNotifications(); |
309 EXPECT_EQ(4, accessibility->browser_tree_node_count()); | 309 EXPECT_EQ(4, accessibility->browser_tree_node_count()); |
310 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); | 310 EXPECT_EQ(4, CountAccessibilityNodesSentToBrowser()); |
311 } | 311 } |
312 | 312 |
313 TEST_F(RendererAccessibilityTest, AccessibilityMessagesQueueWhileSwappedOut) { | |
314 std::string html = | |
315 "<body>" | |
316 " <p>Hello, world.</p>" | |
317 "</body>"; | |
318 LoadHTML(html.c_str()); | |
319 | |
320 // Creating a RendererAccessibilityComplete should send the tree | |
321 // to the browser. | |
322 scoped_ptr<TestRendererAccessibilityComplete> accessibility( | |
323 new TestRendererAccessibilityComplete(view())); | |
324 accessibility->SendPendingAccessibilityNotifications(); | |
325 EXPECT_EQ(3, accessibility->browser_tree_node_count()); | |
326 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); | |
327 | |
328 // Post a "value changed" notification, but then swap out | |
329 // before sending it. It shouldn't sent the notification while | |
Charlie Reis
2013/06/19 15:09:47
nit: s/sent/send/
dmazzoni
2013/06/19 15:34:21
Done.
| |
330 // swapped out. | |
331 sink_->ClearMessages(); | |
332 WebDocument document = view()->GetWebView()->mainFrame()->document(); | |
333 WebAccessibilityObject root_obj = document.accessibilityObject(); | |
334 accessibility->HandleWebAccessibilityNotification( | |
335 root_obj, | |
336 WebKit::WebAccessibilityNotificationValueChanged); | |
337 view()->OnSwapOut(); | |
338 accessibility->SendPendingAccessibilityNotifications(); | |
339 EXPECT_EQ(NULL, sink_->GetUniqueMessageMatching( | |
Charlie Reis
2013/06/19 15:09:47
nit: EXPECT_FALSE rather than EXPECT_EQ(NULL
(Cons
dmazzoni
2013/06/19 15:34:21
Done.
| |
340 AccessibilityHostMsg_Notifications::ID)); | |
341 | |
342 // Navigate, so we're not swapped out anymore. Now we should | |
343 // send accessibility notifications again. Note that the | |
344 // message that was queued up before will be quickly discarded | |
345 // because the element it was referring to no longer exists, | |
346 // so the notification here is from loading this new page. | |
347 ViewMsg_Navigate_Params nav_params; | |
348 nav_params.url = GURL("data:text/html,<p>Hello, again.</p>"); | |
349 nav_params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | |
350 nav_params.transition = PAGE_TRANSITION_TYPED; | |
351 nav_params.current_history_list_length = 1; | |
352 nav_params.current_history_list_offset = 0; | |
353 nav_params.pending_history_list_offset = 1; | |
354 nav_params.page_id = -1; | |
355 view()->OnNavigate(nav_params); | |
356 accessibility->SendPendingAccessibilityNotifications(); | |
357 EXPECT_TRUE(NULL != sink_->GetUniqueMessageMatching( | |
Charlie Reis
2013/06/19 15:09:47
nit: Don't need "NULL !="
dmazzoni
2013/06/19 15:34:21
Done.
| |
358 AccessibilityHostMsg_Notifications::ID)); | |
359 } | |
360 | |
313 TEST_F(RendererAccessibilityTest, HideAccessibilityObject) { | 361 TEST_F(RendererAccessibilityTest, HideAccessibilityObject) { |
314 // Test RendererAccessibilityComplete and make sure it sends the | 362 // Test RendererAccessibilityComplete and make sure it sends the |
315 // proper notification to the browser when an object in the tree | 363 // proper notification to the browser when an object in the tree |
316 // is hidden, but its children are not. | 364 // is hidden, but its children are not. |
317 std::string html = | 365 std::string html = |
318 "<body>" | 366 "<body>" |
319 " <div role='group' id='A'>" | 367 " <div role='group' id='A'>" |
320 " <div role='group' id='B'>" | 368 " <div role='group' id='B'>" |
321 " <div role='group' id='C' style='visibility:visible'>" | 369 " <div role='group' id='C' style='visibility:visible'>" |
322 " </div>" | 370 " </div>" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 | 449 |
402 accessibility->SendPendingAccessibilityNotifications(); | 450 accessibility->SendPendingAccessibilityNotifications(); |
403 EXPECT_EQ(4, accessibility->browser_tree_node_count()); | 451 EXPECT_EQ(4, accessibility->browser_tree_node_count()); |
404 AccessibilityHostMsg_NotificationParams notification; | 452 AccessibilityHostMsg_NotificationParams notification; |
405 GetLastAccNotification(¬ification); | 453 GetLastAccNotification(¬ification); |
406 ASSERT_EQ(3U, notification.nodes.size()); | 454 ASSERT_EQ(3U, notification.nodes.size()); |
407 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); | 455 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); |
408 } | 456 } |
409 | 457 |
410 } // namespace content | 458 } // namespace content |
OLD | NEW |