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

Side by Side 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: Disable the check on ChromeOS (again). Accelerator handling in extension popups is different betwee… Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 2083 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 } 2094 }
2095 2095
2096 //////////////////////////////////////////////////////////////////////////////// 2096 ////////////////////////////////////////////////////////////////////////////////
2097 // Accelerators 2097 // Accelerators
2098 //////////////////////////////////////////////////////////////////////////////// 2098 ////////////////////////////////////////////////////////////////////////////////
2099 bool TestView::AcceleratorPressed(const ui::Accelerator& accelerator) { 2099 bool TestView::AcceleratorPressed(const ui::Accelerator& accelerator) {
2100 accelerator_count_map_[accelerator]++; 2100 accelerator_count_map_[accelerator]++;
2101 return true; 2101 return true;
2102 } 2102 }
2103 2103
2104 // On non-ChromeOS aura there is extra logic to determine whether a view should
2105 // handle accelerators or not (see View::CanHandleAccelerators for details).
2106 // This test targets that extra logic, but should also work on other platforms.
2107 TEST_F(ViewTest, HandleAccelerator) {
2108 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE);
2109 TestView* view = new TestView();
2110 view->Reset();
2111 view->AddAccelerator(return_accelerator);
2112 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
2113
2114 // Create a window and add the view as its child.
2115 scoped_ptr<Widget> widget(new Widget);
2116 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
2117 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
2118 params.bounds = gfx::Rect(0, 0, 100, 100);
2119 widget->Init(params);
2120 View* root = widget->GetRootView();
2121 root->AddChildView(view);
2122 widget->Show();
2123
2124 FocusManager* focus_manager = widget->GetFocusManager();
2125 ASSERT_TRUE(focus_manager);
2126
2127 #if defined(USE_AURA) && !defined(OS_CHROMEOS)
2128 // When a non-child view is not active, it shouldn't handle accelerators.
2129 EXPECT_FALSE(widget->IsActive());
2130 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
2131 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]);
2132 #endif
2133
2134 // When a non-child view is active, it should handle accelerators.
2135 view->accelerator_count_map_[return_accelerator] = 0;
2136 widget->Activate();
2137 EXPECT_TRUE(widget->IsActive());
2138 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator));
2139 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]);
2140
2141 // Add a child view associated with a child widget.
2142 TestView* child_view = new TestView();
2143 child_view->Reset();
2144 child_view->AddAccelerator(return_accelerator);
2145 EXPECT_EQ(child_view->accelerator_count_map_[return_accelerator], 0);
2146 view->AddChildView(child_view);
2147 Widget* child_widget = new Widget;
2148 Widget::InitParams child_params =
2149 CreateParams(Widget::InitParams::TYPE_CONTROL);
2150 child_params.parent = widget->GetNativeView();
2151 child_widget->Init(child_params);
2152 child_widget->SetContentsView(child_view);
2153
2154 FocusManager* child_focus_manager = child_widget->GetFocusManager();
2155 ASSERT_TRUE(child_focus_manager);
2156
2157 // When a child view is in focus, it should handle accelerators.
2158 child_view->accelerator_count_map_[return_accelerator] = 0;
2159 view->accelerator_count_map_[return_accelerator] = 0;
2160 child_focus_manager->SetFocusedView(child_view);
2161 EXPECT_FALSE(child_view->GetWidget()->IsActive());
2162 EXPECT_TRUE(child_focus_manager->ProcessAccelerator(return_accelerator));
2163 EXPECT_EQ(1, child_view->accelerator_count_map_[return_accelerator]);
2164 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]);
2165
2166 #if defined(USE_AURA) && !defined(OS_CHROMEOS)
2167 // When a child view is not in focus, its parent should handle accelerators.
2168 child_view->accelerator_count_map_[return_accelerator] = 0;
2169 view->accelerator_count_map_[return_accelerator] = 0;
2170 child_focus_manager->ClearFocus();
2171 EXPECT_FALSE(child_view->GetWidget()->IsActive());
2172 EXPECT_TRUE(child_focus_manager->ProcessAccelerator(return_accelerator));
2173 EXPECT_EQ(0, child_view->accelerator_count_map_[return_accelerator]);
2174 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]);
2175 #endif
2176 }
2177
2104 // TODO: these tests were initially commented out when getting aura to 2178 // TODO: these tests were initially commented out when getting aura to
2105 // run. Figure out if still valuable and either nuke or fix. 2179 // run. Figure out if still valuable and either nuke or fix.
2106 #if 0 2180 #if 0
2107 TEST_F(ViewTest, ActivateAccelerator) { 2181 TEST_F(ViewTest, ActivateAccelerator) {
2108 // Register a keyboard accelerator before the view is added to a window. 2182 // Register a keyboard accelerator before the view is added to a window.
2109 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); 2183 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE);
2110 TestView* view = new TestView(); 2184 TestView* view = new TestView();
2111 view->Reset(); 2185 view->Reset();
2112 view->AddAccelerator(return_accelerator); 2186 view->AddAccelerator(return_accelerator);
2113 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); 2187 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
(...skipping 2283 matching lines...) Expand 10 before | Expand all | Expand 10 after
4397 4471
4398 // The View should continue receiving events after the |handler| is deleted. 4472 // The View should continue receiving events after the |handler| is deleted.
4399 v->Reset(); 4473 v->Reset();
4400 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 4474 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(),
4401 ui::EventTimeForNow(), 0, 0); 4475 ui::EventTimeForNow(), 0, 0);
4402 root->OnMouseReleased(released); 4476 root->OnMouseReleased(released);
4403 EXPECT_EQ(ui::ET_MOUSE_RELEASED, v->last_mouse_event_type_); 4477 EXPECT_EQ(ui::ET_MOUSE_RELEASED, v->last_mouse_event_type_);
4404 } 4478 }
4405 4479
4406 } // namespace views 4480 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698