| Index: chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/ui/views/accessibility_event_router_views_unittest.cc (revision 74020)
|
| +++ chrome/browser/ui/views/accessibility_event_router_views_unittest.cc (working copy)
|
| @@ -9,7 +9,6 @@
|
| #include "base/utf_string_conversions.h"
|
| #include "chrome/browser/extensions/extension_accessibility_api.h"
|
| #include "chrome/browser/ui/views/accessibility_event_router_views.h"
|
| -#include "chrome/browser/ui/views/accessible_view_helper.h"
|
| #include "chrome/common/notification_registrar.h"
|
| #include "chrome/common/notification_service.h"
|
| #include "chrome/test/testing_profile.h"
|
| @@ -18,14 +17,10 @@
|
| #include "views/layout/grid_layout.h"
|
| #include "views/views_delegate.h"
|
| #include "views/widget/root_view.h"
|
| +#include "views/widget/widget.h"
|
| #include "views/window/window.h"
|
| +#include "views/window/window_delegate.h"
|
|
|
| -#if defined(OS_WIN)
|
| -#include "views/widget/widget_win.h"
|
| -#elif defined(OS_LINUX)
|
| -#include "views/widget/widget_gtk.h"
|
| -#endif
|
| -
|
| #if defined(TOOLKIT_VIEWS)
|
|
|
| class AccessibilityViewsDelegate : public views::ViewsDelegate {
|
| @@ -66,25 +61,39 @@
|
| DISALLOW_COPY_AND_ASSIGN(AccessibilityViewsDelegate);
|
| };
|
|
|
| +class AccessibilityWindowDelegate : public views::WindowDelegate {
|
| + public:
|
| + explicit AccessibilityWindowDelegate(views::View* contents)
|
| + : contents_(contents) { }
|
| +
|
| + virtual void DeleteDelegate() { delete this; }
|
| +
|
| + virtual views::View* GetContentsView() { return contents_; }
|
| +
|
| + private:
|
| + views::View* contents_;
|
| +};
|
| +
|
| class AccessibilityEventRouterViewsTest
|
| : public testing::Test,
|
| public NotificationObserver {
|
| public:
|
| virtual void SetUp() {
|
| views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate();
|
| + window_delegate_ = NULL;
|
| }
|
|
|
| virtual void TearDown() {
|
| delete views::ViewsDelegate::views_delegate;
|
| views::ViewsDelegate::views_delegate = NULL;
|
| + if (window_delegate_)
|
| + delete window_delegate_;
|
| }
|
|
|
| - views::Widget* CreateWidget() {
|
| -#if defined(OS_WIN)
|
| - return new views::WidgetWin();
|
| -#elif defined(OS_LINUX)
|
| - return new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW);
|
| -#endif
|
| + views::Window* CreateWindowWithContents(views::View* contents) {
|
| + window_delegate_ = new AccessibilityWindowDelegate(contents);
|
| + return views::Window::CreateChromeWindow(
|
| + NULL, gfx::Rect(0, 0, 500, 500), window_delegate_);
|
| }
|
|
|
| protected:
|
| @@ -103,38 +112,30 @@
|
| MessageLoopForUI message_loop_;
|
| int focus_event_count_;
|
| std::string last_control_name_;
|
| + AccessibilityWindowDelegate* window_delegate_;
|
| };
|
|
|
| TEST_F(AccessibilityEventRouterViewsTest, TestFocusNotification) {
|
| const char kButton1ASCII[] = "Button1";
|
| const char kButton2ASCII[] = "Button2";
|
| const char kButton3ASCII[] = "Button3";
|
| - const char kButton3NewASCII[] = "Button3";
|
| + const char kButton3NewASCII[] = "Button3New";
|
|
|
| - // Create a window and layout.
|
| - views::Widget* window = CreateWidget();
|
| - window->Init(NULL, gfx::Rect(0, 0, 100, 100));
|
| - views::RootView* root_view = window->GetRootView();
|
| - views::GridLayout* layout = new views::GridLayout(root_view);
|
| - root_view->SetLayoutManager(layout);
|
| - views::ColumnSet* column_set = layout->AddColumnSet(0);
|
| - column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
|
| - views::GridLayout::USE_PREF, 0, 0);
|
| -
|
| - // Add 3 buttons.
|
| + // Create a contents view with 3 buttons.
|
| + views::View* contents = new views::View();
|
| views::NativeButton* button1 = new views::NativeButton(
|
| NULL, ASCIIToWide(kButton1ASCII));
|
| - layout->StartRow(0, 0);
|
| - layout->AddView(button1);
|
| + contents->AddChildView(button1);
|
| views::NativeButton* button2 = new views::NativeButton(
|
| NULL, ASCIIToWide(kButton2ASCII));
|
| - layout->StartRow(0, 0);
|
| - layout->AddView(button2);
|
| + contents->AddChildView(button2);
|
| views::NativeButton* button3 = new views::NativeButton(
|
| NULL, ASCIIToWide(kButton3ASCII));
|
| - layout->StartRow(0, 0);
|
| - layout->AddView(button3);
|
| + contents->AddChildView(button3);
|
|
|
| + // Put the view in a window.
|
| + views::Window* window = CreateWindowWithContents(contents);
|
| +
|
| // Set focus to the first button initially.
|
| button1->RequestFocus();
|
|
|
| @@ -145,19 +146,21 @@
|
| NotificationService::AllSources());
|
|
|
| // Switch on accessibility event notifications.
|
| - TestingProfile profile;
|
| ExtensionAccessibilityEventRouter* accessibility_event_router =
|
| ExtensionAccessibilityEventRouter::GetInstance();
|
| accessibility_event_router->SetAccessibilityEnabled(true);
|
|
|
| - // Create an AccessibleViewHelper for this window, which will send
|
| - // accessibility notifications for all events that happen in child views.
|
| - AccessibleViewHelper accessible_view_helper(root_view, &profile);
|
| - accessible_view_helper.SetViewName(button3, std::string(kButton3NewASCII));
|
| + // Create a profile and associate it with this window.
|
| + TestingProfile profile;
|
| + window->SetNativeWindowProperty(
|
| + Profile::kProfileKey, &profile);
|
|
|
| + // Change the accessible name of button3.
|
| + button3->SetAccessibleName(ASCIIToUTF16(kButton3NewASCII));
|
| +
|
| // Advance focus to the next button and test that we got the
|
| // expected notification with the name of button 2.
|
| - views::FocusManager* focus_manager = window->GetFocusManager();
|
| + views::FocusManager* focus_manager = contents->GetWidget()->GetFocusManager();
|
| focus_event_count_ = 0;
|
| focus_manager->AdvanceFocus(false);
|
| EXPECT_EQ(1, focus_event_count_);
|
|
|