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

Unified Diff: ui/views/view_unittest.cc

Issue 1544803004: Fix accelerator handling for in-menu buttons in the app menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add back the unit test, disable logic on ChromeOS Created 4 years, 11 months 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
« ui/views/view.cc ('K') | « ui/views/view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/view_unittest.cc
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 68675c0aa8d0748f74102ea9f7b7e3295d9d9334..8e4a7a7f8a933d5d9a4c9a16768fff706809ee75 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -212,7 +212,9 @@ class TestView : public View {
delete_on_pressed_(false),
did_paint_(false),
native_theme_(NULL),
- can_process_events_within_subtree_(true) {}
+ can_process_events_within_subtree_(true),
+ is_child_widget_(false),
+ focus_in_child_widget_(false) {}
~TestView() override {}
// Reset all test state
@@ -265,6 +267,12 @@ class TestView : public View {
void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override;
+ bool IsChildWidget() const override { return is_child_widget_; }
+ bool FocusInChildWidget() const override { return focus_in_child_widget_; }
+
+ void set_child_widget(bool b) { is_child_widget_ = b; }
+ void set_focus_in_child_widget(bool b) { focus_in_child_widget_ = b; }
+
// OnBoundsChanged.
bool did_change_bounds_;
gfx::Rect new_bounds_;
@@ -291,6 +299,9 @@ class TestView : public View {
// Value to return from CanProcessEventsWithinSubtree().
bool can_process_events_within_subtree_;
+
+ bool is_child_widget_;
+ bool focus_in_child_widget_;
};
////////////////////////////////////////////////////////////////////////////////
@@ -2101,6 +2112,72 @@ bool TestView::AcceleratorPressed(const ui::Accelerator& accelerator) {
return true;
}
+class TestWidget : public Widget {
+ public:
+ TestWidget() : Widget() {}
+
+ // Widget method:
+ bool IsActive() const override { return active_; }
+
+ void set_active(bool active) { active_ = active; }
+
+ private:
+ bool active_ = false;
+
+ DISALLOW_COPY_AND_ASSIGN(TestWidget);
+};
+
+// ChromeOS handles accelerators correctly with regards to the activeness or top
+// level status of the widget, so there's no extra logic there to test.
+#if !defined(OS_CHROMEOS)
+TEST_F(ViewTest, HandleAccelerator) {
+ ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE);
+ TestView* view = new TestView();
+ view->Reset();
+ view->AddAccelerator(return_accelerator);
+ EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
+
+ // Create a window and add the view as its child.
+ scoped_ptr<TestWidget> widget(new TestWidget);
+ Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
+ params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ params.bounds = gfx::Rect(0, 0, 100, 100);
+ widget->Init(params);
+ View* root = widget->GetRootView();
+ root->AddChildView(view);
+ widget->Show();
+
+ FocusManager* focus_manager = widget->GetFocusManager();
+ ASSERT_TRUE(focus_manager);
+
+ // Child widgets shouldn't handle accelerators when they are not focused.
+ EXPECT_FALSE(view->IsChildWidget());
+ EXPECT_FALSE(view->FocusInChildWidget());
+ EXPECT_FALSE(widget->IsActive());
+ EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
+ EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]);
+
+ // Child without focus.
+ view->set_child_widget(true);
+ view->set_focus_in_child_widget(false);
+ EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
+ EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]);
+
+ // Child with focus.
+ view->set_child_widget(true);
+ view->set_focus_in_child_widget(true);
+ EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator));
+ EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]);
+
+ // Not a child, but active.
+ view->set_child_widget(false);
+ view->set_focus_in_child_widget(true);
+ widget->set_active(true);
+ EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator));
+ EXPECT_EQ(2, view->accelerator_count_map_[return_accelerator]);
+}
+#endif
+
// TODO: these tests were initially commented out when getting aura to
// run. Figure out if still valuable and either nuke or fix.
#if 0
« ui/views/view.cc ('K') | « ui/views/view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698