OLD | NEW |
---|---|
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 Loading... | |
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 Aura there is extra logic to determine whether a view should handle | |
2105 // accelerators or not (see View::CanHandleAccelerators for details). This test | |
2106 // 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 // When a non-child view is not active, it shouldn't handle accelerators. | |
2128 EXPECT_FALSE(widget->IsActive()); | |
msw
2016/02/04 22:45:36
q: Odd, doesn't Show also activate the widget?
meacer
2016/02/09 20:33:32
It doesn't, need to explicitly call Activate.
| |
2129 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); | |
2130 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]); | |
2131 | |
2132 // When a non-child view is active, it should handle accelerators. | |
2133 widget->Activate(); | |
2134 EXPECT_TRUE(widget->IsActive()); | |
2135 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); | |
2136 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]); | |
2137 | |
2138 // Add a child view associated with a child widget. | |
2139 TestView* child_view = new TestView(); | |
2140 child_view->Reset(); | |
2141 child_view->AddAccelerator(return_accelerator); | |
2142 EXPECT_EQ(child_view->accelerator_count_map_[return_accelerator], 0); | |
2143 view->AddChildView(child_view); | |
2144 Widget* child_widget = new Widget; | |
2145 Widget::InitParams child_params = | |
2146 CreateParams(Widget::InitParams::TYPE_CONTROL); | |
2147 child_params.parent = widget->GetNativeView(); | |
2148 child_widget->Init(child_params); | |
2149 child_widget->SetContentsView(child_view); | |
2150 | |
2151 FocusManager* child_focus_manager = child_widget->GetFocusManager(); | |
2152 ASSERT_TRUE(child_focus_manager); | |
2153 | |
2154 // When a child view is in focus, it should handle accelerators. | |
2155 child_focus_manager->SetFocusedView(child_view); | |
2156 EXPECT_FALSE(child_view->GetWidget()->IsActive()); | |
2157 EXPECT_TRUE(child_focus_manager->ProcessAccelerator(return_accelerator)); | |
2158 EXPECT_EQ(1, child_view->accelerator_count_map_[return_accelerator]); | |
2159 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]); | |
2160 | |
2161 // When a child view is not in focus, its parent should handle accelerators. | |
2162 child_focus_manager->ClearFocus(); | |
2163 EXPECT_FALSE(child_view->GetWidget()->IsActive()); | |
2164 EXPECT_TRUE(child_focus_manager->ProcessAccelerator(return_accelerator)); | |
2165 EXPECT_EQ(1, child_view->accelerator_count_map_[return_accelerator]); | |
2166 EXPECT_EQ(2, view->accelerator_count_map_[return_accelerator]); | |
2167 } | |
2168 | |
2104 // TODO: these tests were initially commented out when getting aura to | 2169 // TODO: these tests were initially commented out when getting aura to |
2105 // run. Figure out if still valuable and either nuke or fix. | 2170 // run. Figure out if still valuable and either nuke or fix. |
2106 #if 0 | 2171 #if 0 |
2107 TEST_F(ViewTest, ActivateAccelerator) { | 2172 TEST_F(ViewTest, ActivateAccelerator) { |
2108 // Register a keyboard accelerator before the view is added to a window. | 2173 // Register a keyboard accelerator before the view is added to a window. |
2109 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); | 2174 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); |
2110 TestView* view = new TestView(); | 2175 TestView* view = new TestView(); |
2111 view->Reset(); | 2176 view->Reset(); |
2112 view->AddAccelerator(return_accelerator); | 2177 view->AddAccelerator(return_accelerator); |
2113 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); | 2178 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); |
(...skipping 2283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4397 | 4462 |
4398 // The View should continue receiving events after the |handler| is deleted. | 4463 // The View should continue receiving events after the |handler| is deleted. |
4399 v->Reset(); | 4464 v->Reset(); |
4400 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 4465 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
4401 ui::EventTimeForNow(), 0, 0); | 4466 ui::EventTimeForNow(), 0, 0); |
4402 root->OnMouseReleased(released); | 4467 root->OnMouseReleased(released); |
4403 EXPECT_EQ(ui::ET_MOUSE_RELEASED, v->last_mouse_event_type_); | 4468 EXPECT_EQ(ui::ET_MOUSE_RELEASED, v->last_mouse_event_type_); |
4404 } | 4469 } |
4405 | 4470 |
4406 } // namespace views | 4471 } // namespace views |
OLD | NEW |