| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/accessibility/accessibility_extension_api.h" | 10 #include "chrome/browser/accessibility/accessibility_extension_api.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 private: | 83 private: |
| 84 views::View* contents_; | 84 views::View* contents_; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 class AccessibilityEventRouterViewsTest | 87 class AccessibilityEventRouterViewsTest |
| 88 : public testing::Test, | 88 : public testing::Test, |
| 89 public content::NotificationObserver { | 89 public content::NotificationObserver { |
| 90 public: | 90 public: |
| 91 virtual void SetUp() { | 91 virtual void SetUp() { |
| 92 views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate(); | 92 views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate(); |
| 93 window_delegate_ = NULL; | |
| 94 } | 93 } |
| 95 | 94 |
| 96 virtual void TearDown() { | 95 virtual void TearDown() { |
| 97 delete views::ViewsDelegate::views_delegate; | 96 delete views::ViewsDelegate::views_delegate; |
| 98 views::ViewsDelegate::views_delegate = NULL; | 97 views::ViewsDelegate::views_delegate = NULL; |
| 99 if (window_delegate_) | |
| 100 delete window_delegate_; | |
| 101 } | 98 } |
| 102 | 99 |
| 103 views::Widget* CreateWindowWithContents(views::View* contents) { | 100 views::Widget* CreateWindowWithContents(views::View* contents) { |
| 104 window_delegate_ = new AccessibilityWindowDelegate(contents); | 101 return views::Widget::CreateWindowWithBounds( |
| 105 return views::Widget::CreateWindowWithBounds(window_delegate_, | 102 new AccessibilityWindowDelegate(contents), |
| 106 gfx::Rect(0, 0, 500, 500)); | 103 gfx::Rect(0, 0, 500, 500)); |
| 107 } | 104 } |
| 108 | 105 |
| 109 protected: | 106 protected: |
| 110 // Implement NotificationObserver::Observe and store information about a | 107 // Implement NotificationObserver::Observe and store information about a |
| 111 // ACCESSIBILITY_CONTROL_FOCUSED event. | 108 // ACCESSIBILITY_CONTROL_FOCUSED event. |
| 112 virtual void Observe(int type, | 109 virtual void Observe(int type, |
| 113 const content::NotificationSource& source, | 110 const content::NotificationSource& source, |
| 114 const content::NotificationDetails& details) { | 111 const content::NotificationDetails& details) { |
| 115 ASSERT_EQ(type, chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED); | 112 ASSERT_EQ(type, chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED); |
| 116 const AccessibilityControlInfo* info = | 113 const AccessibilityControlInfo* info = |
| 117 content::Details<const AccessibilityControlInfo>(details).ptr(); | 114 content::Details<const AccessibilityControlInfo>(details).ptr(); |
| 118 focus_event_count_++; | 115 focus_event_count_++; |
| 119 last_control_name_ = info->name(); | 116 last_control_name_ = info->name(); |
| 120 } | 117 } |
| 121 | 118 |
| 122 MessageLoopForUI message_loop_; | 119 MessageLoopForUI message_loop_; |
| 123 int focus_event_count_; | 120 int focus_event_count_; |
| 124 std::string last_control_name_; | 121 std::string last_control_name_; |
| 125 AccessibilityWindowDelegate* window_delegate_; | |
| 126 }; | 122 }; |
| 127 | 123 |
| 128 TEST_F(AccessibilityEventRouterViewsTest, TestFocusNotification) { | 124 TEST_F(AccessibilityEventRouterViewsTest, TestFocusNotification) { |
| 129 const char kButton1ASCII[] = "Button1"; | 125 const char kButton1ASCII[] = "Button1"; |
| 130 const char kButton2ASCII[] = "Button2"; | 126 const char kButton2ASCII[] = "Button2"; |
| 131 const char kButton3ASCII[] = "Button3"; | 127 const char kButton3ASCII[] = "Button3"; |
| 132 const char kButton3NewASCII[] = "Button3New"; | 128 const char kButton3NewASCII[] = "Button3New"; |
| 133 | 129 |
| 134 // Create a contents view with 3 buttons. | 130 // Create a contents view with 3 buttons. |
| 135 views::View* contents = new views::View(); | 131 views::View* contents = new views::View(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 173 |
| 178 // Advance to button 3. Expect the new accessible name we assigned. | 174 // Advance to button 3. Expect the new accessible name we assigned. |
| 179 focus_manager->AdvanceFocus(false); | 175 focus_manager->AdvanceFocus(false); |
| 180 EXPECT_EQ(2, focus_event_count_); | 176 EXPECT_EQ(2, focus_event_count_); |
| 181 EXPECT_EQ(kButton3NewASCII, last_control_name_); | 177 EXPECT_EQ(kButton3NewASCII, last_control_name_); |
| 182 | 178 |
| 183 // Advance to button 1 and check the notification. | 179 // Advance to button 1 and check the notification. |
| 184 focus_manager->AdvanceFocus(false); | 180 focus_manager->AdvanceFocus(false); |
| 185 EXPECT_EQ(3, focus_event_count_); | 181 EXPECT_EQ(3, focus_event_count_); |
| 186 EXPECT_EQ(kButton1ASCII, last_control_name_); | 182 EXPECT_EQ(kButton1ASCII, last_control_name_); |
| 183 |
| 184 window->CloseNow(); |
| 187 } | 185 } |
| 188 | 186 |
| 189 #endif // defined(TOOLKIT_VIEWS) | 187 #endif // defined(TOOLKIT_VIEWS) |
| OLD | NEW |