| Index: chrome/browser/ui/views/accessibility/accessibility_event_router_views_unittest.cc
|
| diff --git a/chrome/browser/ui/views/accessibility/accessibility_event_router_views_unittest.cc b/chrome/browser/ui/views/accessibility/accessibility_event_router_views_unittest.cc
|
| index 1559a29f9e8b8f851114b2710839239a02ce29d1..3f9d80da4a709199754d5bf4343ed8b8f70365bb 100644
|
| --- a/chrome/browser/ui/views/accessibility/accessibility_event_router_views_unittest.cc
|
| +++ b/chrome/browser/ui/views/accessibility/accessibility_event_router_views_unittest.cc
|
| @@ -8,9 +8,11 @@
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "chrome/browser/accessibility/accessibility_extension_api.h"
|
| +#include "chrome/browser/accessibility/accessibility_extension_api_constants.h"
|
| #include "chrome/browser/ui/views/accessibility/accessibility_event_router_views.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/base/accessibility/accessibility_types.h"
|
| #include "ui/base/accessibility/accessible_view_state.h"
|
| #include "ui/views/controls/button/label_button.h"
|
| #include "ui/views/controls/label.h"
|
| @@ -103,7 +105,7 @@ class ViewWithNameAndRole : public views::View {
|
| class AccessibilityEventRouterViewsTest
|
| : public testing::Test {
|
| public:
|
| - AccessibilityEventRouterViewsTest() : focus_event_count_(0) {
|
| + AccessibilityEventRouterViewsTest() : control_event_count_(0) {
|
| }
|
|
|
| virtual void SetUp() {
|
| @@ -158,7 +160,7 @@ class AccessibilityEventRouterViewsTest
|
| ExtensionAccessibilityEventRouter::GetInstance();
|
| accessibility_event_router->SetAccessibilityEnabled(true);
|
| accessibility_event_router->SetControlEventCallbackForTesting(base::Bind(
|
| - &AccessibilityEventRouterViewsTest::OnFocusEvent,
|
| + &AccessibilityEventRouterViewsTest::OnControlEvent,
|
| base::Unretained(this)));
|
| }
|
|
|
| @@ -170,15 +172,17 @@ class AccessibilityEventRouterViewsTest
|
|
|
| protected:
|
| // Handle Focus event.
|
| - virtual void OnFocusEvent(ui::AccessibilityTypes::Event event,
|
| + virtual void OnControlEvent(ui::AccessibilityTypes::Event event,
|
| const AccessibilityControlInfo* info) {
|
| - focus_event_count_++;
|
| + control_event_count_++;
|
| + last_control_type_ = info->type();
|
| last_control_name_ = info->name();
|
| last_control_context_ = info->context();
|
| }
|
|
|
| base::MessageLoopForUI message_loop_;
|
| - int focus_event_count_;
|
| + int control_event_count_;
|
| + std::string last_control_type_;
|
| std::string last_control_name_;
|
| std::string last_control_context_;
|
| TestingProfile profile_;
|
| @@ -214,7 +218,6 @@ TEST_F(AccessibilityEventRouterViewsTest, TestFocusNotification) {
|
| // Put the view in a window.
|
| views::Widget* window = CreateWindowWithContents(contents);
|
| window->Show();
|
| - window->Activate();
|
|
|
| // Set focus to the first button initially and run message loop to execute
|
| // callback.
|
| @@ -227,22 +230,22 @@ TEST_F(AccessibilityEventRouterViewsTest, TestFocusNotification) {
|
| // Advance focus to the next button and test that we got the
|
| // expected notification with the name of button 2.
|
| views::FocusManager* focus_manager = contents->GetWidget()->GetFocusManager();
|
| - focus_event_count_ = 0;
|
| + control_event_count_ = 0;
|
| focus_manager->AdvanceFocus(false);
|
| base::MessageLoop::current()->RunUntilIdle();
|
| - EXPECT_EQ(1, focus_event_count_);
|
| + EXPECT_EQ(1, control_event_count_);
|
| EXPECT_EQ(kButton2ASCII, last_control_name_);
|
|
|
| // Advance to button 3. Expect the new accessible name we assigned.
|
| focus_manager->AdvanceFocus(false);
|
| base::MessageLoop::current()->RunUntilIdle();
|
| - EXPECT_EQ(2, focus_event_count_);
|
| + EXPECT_EQ(2, control_event_count_);
|
| EXPECT_EQ(kButton3NewASCII, last_control_name_);
|
|
|
| // Advance to button 1 and check the notification.
|
| focus_manager->AdvanceFocus(false);
|
| base::MessageLoop::current()->RunUntilIdle();
|
| - EXPECT_EQ(3, focus_event_count_);
|
| + EXPECT_EQ(3, control_event_count_);
|
| EXPECT_EQ(kButton1ASCII, last_control_name_);
|
|
|
| window->CloseNow();
|
| @@ -265,13 +268,13 @@ TEST_F(AccessibilityEventRouterViewsTest, TestToolbarContext) {
|
| views::Widget* window = CreateWindowWithContents(contents);
|
|
|
| // Set focus to the button.
|
| - focus_event_count_ = 0;
|
| + control_event_count_ = 0;
|
| button->RequestFocus();
|
|
|
| base::MessageLoop::current()->RunUntilIdle();
|
|
|
| // Test that we got the event with the expected name and context.
|
| - EXPECT_EQ(kInitialFocusCount, focus_event_count_);
|
| + EXPECT_EQ(kInitialFocusCount, control_event_count_);
|
| EXPECT_EQ(kButtonNameASCII, last_control_name_);
|
| EXPECT_EQ(kToolbarNameASCII, last_control_context_);
|
|
|
| @@ -297,13 +300,13 @@ TEST_F(AccessibilityEventRouterViewsTest, TestAlertContext) {
|
| views::Widget* window = CreateWindowWithContents(contents);
|
|
|
| // Set focus to the button.
|
| - focus_event_count_ = 0;
|
| + control_event_count_ = 0;
|
| button->RequestFocus();
|
|
|
| base::MessageLoop::current()->RunUntilIdle();
|
|
|
| // Test that we got the event with the expected name and context.
|
| - EXPECT_EQ(kInitialFocusCount, focus_event_count_);
|
| + EXPECT_EQ(kInitialFocusCount, control_event_count_);
|
| EXPECT_EQ(kButtonNameASCII, last_control_name_);
|
| EXPECT_EQ(kAlertTextASCII, last_control_context_);
|
|
|
| @@ -329,19 +332,19 @@ TEST_F(AccessibilityEventRouterViewsTest, StateChangeAfterNotification) {
|
| views::Widget* window = CreateWindowWithContents(contents);
|
|
|
| // Set focus to the child view.
|
| - focus_event_count_ = 0;
|
| + control_event_count_ = 0;
|
| child->RequestFocus();
|
|
|
| // Change the child's name after the focus notification.
|
| child->set_name(ASCIIToUTF16(kNewNameASCII));
|
|
|
| // We shouldn't get the notification right away.
|
| - EXPECT_EQ(0, focus_event_count_);
|
| + EXPECT_EQ(0, control_event_count_);
|
|
|
| // Process anything in the event loop. Now we should get the notification,
|
| // and it should give us the new control name, not the old one.
|
| base::MessageLoop::current()->RunUntilIdle();
|
| - EXPECT_EQ(kInitialFocusCount, focus_event_count_);
|
| + EXPECT_EQ(kInitialFocusCount, control_event_count_);
|
| EXPECT_EQ(kNewNameASCII, last_control_name_);
|
|
|
| window->CloseNow();
|
| @@ -365,19 +368,56 @@ TEST_F(AccessibilityEventRouterViewsTest, NotificationOnDeletedObject) {
|
| views::Widget* window = CreateWindowWithContents(contents);
|
|
|
| // Set focus to the child view.
|
| - focus_event_count_ = 0;
|
| + control_event_count_ = 0;
|
| child->RequestFocus();
|
|
|
| // Delete the child!
|
| delete child;
|
|
|
| // We shouldn't get the notification right away.
|
| - EXPECT_EQ(0, focus_event_count_);
|
| + EXPECT_EQ(0, control_event_count_);
|
|
|
| // Process anything in the event loop. We shouldn't get a notification
|
| // because the view is no longer valid, and this shouldn't crash.
|
| base::MessageLoop::current()->RunUntilIdle();
|
| - EXPECT_EQ(0, focus_event_count_);
|
| + EXPECT_EQ(0, control_event_count_);
|
| +
|
| + window->CloseNow();
|
| +}
|
| +
|
| +TEST_F(AccessibilityEventRouterViewsTest, AlertsFromWindowAndControl) {
|
| + const char kButtonASCII[] = "Button";
|
| + const char* kTypeAlert = extension_accessibility_api_constants::kTypeAlert;
|
| + const char* kTypeWindow = extension_accessibility_api_constants::kTypeWindow;
|
| +
|
| + // Create a contents view with a button.
|
| + views::View* contents = new views::View();
|
| + views::LabelButton* button = new views::LabelButton(
|
| + NULL, ASCIIToUTF16(kButtonASCII));
|
| + button->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
|
| + contents->AddChildView(button);
|
| +
|
| + // Put the view in a window.
|
| + views::Widget* window = CreateWindowWithContents(contents);
|
| + window->Show();
|
| +
|
| + // Send an alert event from the button and let the event loop run.
|
| + control_event_count_ = 0;
|
| + button->NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true);
|
| + base::MessageLoop::current()->RunUntilIdle();
|
| +
|
| + EXPECT_EQ(kTypeAlert, last_control_type_);
|
| + EXPECT_EQ(1, control_event_count_);
|
| + EXPECT_EQ(kButtonASCII, last_control_name_);
|
| +
|
| + // Send an alert event from the window and let the event loop run.
|
| + control_event_count_ = 0;
|
| + window->GetRootView()->NotifyAccessibilityEvent(
|
| + ui::AccessibilityTypes::EVENT_ALERT, true);
|
| + base::MessageLoop::current()->RunUntilIdle();
|
| +
|
| + EXPECT_EQ(1, control_event_count_);
|
| + EXPECT_EQ(kTypeWindow, last_control_type_);
|
|
|
| window->CloseNow();
|
| }
|
|
|