Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3303)

Unified Diff: chrome/browser/ui/views/accessibility_event_router_views_unittest.cc

Issue 8850004: Add a context field to the accessibility extension API. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
===================================================================
--- chrome/browser/ui/views/accessibility_event_router_views_unittest.cc (revision 114416)
+++ chrome/browser/ui/views/accessibility_event_router_views_unittest.cc (working copy)
@@ -14,7 +14,9 @@
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/views/controls/button/text_button.h"
+#include "ui/views/controls/label.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/native_widget.h"
@@ -84,6 +86,25 @@
views::View* contents_;
};
+class ViewWithNameAndRole : public views::View {
+ public:
+ explicit ViewWithNameAndRole(const string16& name,
+ ui::AccessibilityTypes::Role role)
+ : name_(name),
+ role_(role) {
+ }
+
+ void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE {
+ views::View::GetAccessibleState(state);
+ state->name = name_;
+ state->role = role_;
+ }
+
+ private:
+ string16 name_;
+ ui::AccessibilityTypes::Role role_;
+};
+
class AccessibilityEventRouterViewsTest
: public testing::Test,
public content::NotificationObserver {
@@ -114,11 +135,13 @@
content::Details<const AccessibilityControlInfo>(details).ptr();
focus_event_count_++;
last_control_name_ = info->name();
+ last_control_context_ = info->context();
}
MessageLoopForUI message_loop_;
int focus_event_count_;
std::string last_control_name_;
+ std::string last_control_context_;
};
TEST_F(AccessibilityEventRouterViewsTest, TestFocusNotification) {
@@ -184,4 +207,90 @@
window->CloseNow();
}
+TEST_F(AccessibilityEventRouterViewsTest, TestToolbarContext) {
+ const char kToolbarNameASCII[] = "MyToolbar";
+ const char kButtonNameASCII[] = "MyButton";
+
+ // Create a toolbar with a button.
+ views::View* contents = new ViewWithNameAndRole(
+ ASCIIToUTF16(kToolbarNameASCII),
+ ui::AccessibilityTypes::ROLE_TOOLBAR);
+ views::NativeTextButton* button = new views::NativeTextButton(
+ NULL, ASCIIToUTF16(kButtonNameASCII));
+ contents->AddChildView(button);
+
+ // Put the view in a window.
+ views::Widget* window = CreateWindowWithContents(contents);
+
+ // Start listening to ACCESSIBILITY_CONTROL_FOCUSED notifications.
+ content::NotificationRegistrar registrar;
+ registrar.Add(this,
+ chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED,
+ content::NotificationService::AllSources());
+
+ // Switch on accessibility event notifications.
+ ExtensionAccessibilityEventRouter* accessibility_event_router =
+ ExtensionAccessibilityEventRouter::GetInstance();
+ accessibility_event_router->SetAccessibilityEnabled(true);
+
+ // Create a profile and associate it with this window.
+ TestingProfile profile;
+ window->SetNativeWindowProperty(Profile::kProfileKey, &profile);
+
+ // Set focus to the button.
+ focus_event_count_ = 0;
+ button->RequestFocus();
+
+ // Test that we got the event with the expected name and context.
+ EXPECT_EQ(1, focus_event_count_);
+ EXPECT_EQ(kButtonNameASCII, last_control_name_);
+ EXPECT_EQ(kToolbarNameASCII, last_control_context_);
+
+ window->CloseNow();
+}
+
+TEST_F(AccessibilityEventRouterViewsTest, TestAlertContext) {
+ const char kAlertTextASCII[] = "MyAlertText";
+ const char kButtonNameASCII[] = "MyButton";
+
+ // Create an alert with static text and a button, similar to an infobar.
+ views::View* contents = new ViewWithNameAndRole(
+ string16(),
+ ui::AccessibilityTypes::ROLE_ALERT);
+ views::Label* label = new views::Label(ASCIIToUTF16(kAlertTextASCII));
+ contents->AddChildView(label);
+ views::NativeTextButton* button = new views::NativeTextButton(
+ NULL, ASCIIToUTF16(kButtonNameASCII));
+ contents->AddChildView(button);
+
+ // Put the view in a window.
+ views::Widget* window = CreateWindowWithContents(contents);
+
+ // Start listening to ACCESSIBILITY_CONTROL_FOCUSED notifications.
+ content::NotificationRegistrar registrar;
+ registrar.Add(this,
+ chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED,
+ content::NotificationService::AllSources());
+
+ // Switch on accessibility event notifications.
+ ExtensionAccessibilityEventRouter* accessibility_event_router =
+ ExtensionAccessibilityEventRouter::GetInstance();
+ accessibility_event_router->SetAccessibilityEnabled(true);
+
+ // Create a profile and associate it with this window.
+ TestingProfile profile;
+ window->SetNativeWindowProperty(Profile::kProfileKey, &profile);
+
+ // Set focus to the button.
+ focus_event_count_ = 0;
+ button->RequestFocus();
+
+ // Test that we got the event with the expected name and context.
+ EXPECT_EQ(1, focus_event_count_);
+ EXPECT_EQ(kButtonNameASCII, last_control_name_);
+ EXPECT_EQ(kAlertTextASCII, last_control_context_);
+
+ window->CloseNow();
+}
+
#endif // defined(TOOLKIT_VIEWS)
« no previous file with comments | « chrome/browser/ui/views/accessibility_event_router_views.cc ('k') | chrome/common/extensions/api/extension_api.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698