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

Side by Side Diff: ui/views/view_unittest.cc

Issue 1759453002: Convert location bar bubble delegates to bubble dialog delegates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: msw review Created 4 years, 9 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
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 2091 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 } 2102 }
2103 2103
2104 // On non-ChromeOS aura there is extra logic to determine whether a view should 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). 2105 // handle accelerators or not (see View::CanHandleAccelerators for details).
2106 // This test targets that extra logic, but should also work on other platforms. 2106 // This test targets that extra logic, but should also work on other platforms.
2107 TEST_F(ViewTest, HandleAccelerator) { 2107 TEST_F(ViewTest, HandleAccelerator) {
2108 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); 2108 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE);
2109 TestView* view = new TestView(); 2109 TestView* view = new TestView();
2110 view->Reset(); 2110 view->Reset();
2111 view->AddAccelerator(return_accelerator); 2111 view->AddAccelerator(return_accelerator);
2112 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); 2112 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]);
2113 EXPECT_FALSE(view->HandlesAccelerator(return_accelerator));
2113 2114
2114 // Create a window and add the view as its child. 2115 // Create a window and add the view as its child.
2115 scoped_ptr<Widget> widget(new Widget); 2116 scoped_ptr<Widget> widget(new Widget);
2116 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); 2117 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
2117 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 2118 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
2118 params.bounds = gfx::Rect(0, 0, 100, 100); 2119 params.bounds = gfx::Rect(0, 0, 100, 100);
2119 widget->Init(params); 2120 widget->Init(params);
2120 View* root = widget->GetRootView(); 2121 View* root = widget->GetRootView();
2121 root->AddChildView(view); 2122 root->AddChildView(view);
2122 widget->Show(); 2123 widget->Show();
2123 2124
2124 FocusManager* focus_manager = widget->GetFocusManager(); 2125 FocusManager* focus_manager = widget->GetFocusManager();
2125 ASSERT_TRUE(focus_manager); 2126 ASSERT_TRUE(focus_manager);
2126 2127
2127 #if defined(USE_AURA) && !defined(OS_CHROMEOS) 2128 #if defined(USE_AURA) && !defined(OS_CHROMEOS)
2128 // When a non-child view is not active, it shouldn't handle accelerators. 2129 // When a non-child view is not active, it shouldn't handle accelerators.
2129 EXPECT_FALSE(widget->IsActive()); 2130 EXPECT_FALSE(widget->IsActive());
2130 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); 2131 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
2131 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]); 2132 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]);
2132 #endif 2133 #endif
2133 2134
2134 // When a non-child view is active, it should handle accelerators. 2135 // When a non-child view is active, it should handle accelerators.
2135 view->accelerator_count_map_[return_accelerator] = 0; 2136 view->accelerator_count_map_[return_accelerator] = 0;
2136 widget->Activate(); 2137 widget->Activate();
2137 EXPECT_TRUE(widget->IsActive()); 2138 EXPECT_TRUE(widget->IsActive());
2138 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); 2139 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator));
2139 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]); 2140 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]);
2141 EXPECT_TRUE(view->HandlesAccelerator(return_accelerator));
2140 2142
2141 // Add a child view associated with a child widget. 2143 // Add a child view associated with a child widget.
2142 TestView* child_view = new TestView(); 2144 TestView* child_view = new TestView();
2143 child_view->Reset(); 2145 child_view->Reset();
2144 child_view->AddAccelerator(return_accelerator); 2146 child_view->AddAccelerator(return_accelerator);
2145 EXPECT_EQ(child_view->accelerator_count_map_[return_accelerator], 0); 2147 EXPECT_EQ(child_view->accelerator_count_map_[return_accelerator], 0);
2146 view->AddChildView(child_view); 2148 view->AddChildView(child_view);
2147 Widget* child_widget = new Widget; 2149 Widget* child_widget = new Widget;
2148 Widget::InitParams child_params = 2150 Widget::InitParams child_params =
2149 CreateParams(Widget::InitParams::TYPE_CONTROL); 2151 CreateParams(Widget::InitParams::TYPE_CONTROL);
2150 child_params.parent = widget->GetNativeView(); 2152 child_params.parent = widget->GetNativeView();
2151 child_widget->Init(child_params); 2153 child_widget->Init(child_params);
2152 child_widget->SetContentsView(child_view); 2154 child_widget->SetContentsView(child_view);
2153 2155
2154 FocusManager* child_focus_manager = child_widget->GetFocusManager(); 2156 FocusManager* child_focus_manager = child_widget->GetFocusManager();
2155 ASSERT_TRUE(child_focus_manager); 2157 ASSERT_TRUE(child_focus_manager);
2156 2158
2157 // When a child view is in focus, it should handle accelerators. 2159 // When a child view is in focus, it should handle accelerators.
2158 child_view->accelerator_count_map_[return_accelerator] = 0; 2160 child_view->accelerator_count_map_[return_accelerator] = 0;
2159 view->accelerator_count_map_[return_accelerator] = 0; 2161 view->accelerator_count_map_[return_accelerator] = 0;
2160 child_focus_manager->SetFocusedView(child_view); 2162 child_focus_manager->SetFocusedView(child_view);
2161 EXPECT_FALSE(child_view->GetWidget()->IsActive()); 2163 EXPECT_FALSE(child_view->GetWidget()->IsActive());
2162 EXPECT_TRUE(child_focus_manager->ProcessAccelerator(return_accelerator)); 2164 EXPECT_TRUE(child_focus_manager->ProcessAccelerator(return_accelerator));
2163 EXPECT_EQ(1, child_view->accelerator_count_map_[return_accelerator]); 2165 EXPECT_EQ(1, child_view->accelerator_count_map_[return_accelerator]);
2164 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]); 2166 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]);
2167 EXPECT_TRUE(child_view->HandlesAccelerator(return_accelerator));
2168 EXPECT_TRUE(view->HandlesAccelerator(return_accelerator));
2165 2169
2166 #if defined(USE_AURA) && !defined(OS_CHROMEOS) 2170 #if defined(USE_AURA) && !defined(OS_CHROMEOS)
2167 // When a child view is not in focus, its parent should handle accelerators. 2171 // When a child view is not in focus, its parent should handle accelerators.
2168 child_view->accelerator_count_map_[return_accelerator] = 0; 2172 child_view->accelerator_count_map_[return_accelerator] = 0;
2169 view->accelerator_count_map_[return_accelerator] = 0; 2173 view->accelerator_count_map_[return_accelerator] = 0;
2170 child_focus_manager->ClearFocus(); 2174 child_focus_manager->ClearFocus();
2171 EXPECT_FALSE(child_view->GetWidget()->IsActive()); 2175 EXPECT_FALSE(child_view->GetWidget()->IsActive());
2172 EXPECT_TRUE(child_focus_manager->ProcessAccelerator(return_accelerator)); 2176 EXPECT_TRUE(child_focus_manager->ProcessAccelerator(return_accelerator));
2173 EXPECT_EQ(0, child_view->accelerator_count_map_[return_accelerator]); 2177 EXPECT_EQ(0, child_view->accelerator_count_map_[return_accelerator]);
2174 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]); 2178 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]);
2179 EXPECT_FALSE(child_view->HandlesAccelerator(return_accelerator));
2180 EXPECT_TRUE(view->HandlesAccelerator(return_accelerator));
2175 #endif 2181 #endif
2176 } 2182 }
2177 2183
2178 // TODO: these tests were initially commented out when getting aura to 2184 // TODO: these tests were initially commented out when getting aura to
2179 // run. Figure out if still valuable and either nuke or fix. 2185 // run. Figure out if still valuable and either nuke or fix.
2180 #if 0 2186 #if 0
2181 TEST_F(ViewTest, ActivateAccelerator) { 2187 TEST_F(ViewTest, ActivateAccelerator) {
2182 // Register a keyboard accelerator before the view is added to a window. 2188 // Register a keyboard accelerator before the view is added to a window.
2183 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); 2189 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE);
2184 TestView* view = new TestView(); 2190 TestView* view = new TestView();
(...skipping 2282 matching lines...) Expand 10 before | Expand all | Expand 10 after
4467 4473
4468 // The View should continue receiving events after the |handler| is deleted. 4474 // The View should continue receiving events after the |handler| is deleted.
4469 v->Reset(); 4475 v->Reset();
4470 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 4476 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(),
4471 ui::EventTimeForNow(), 0, 0); 4477 ui::EventTimeForNow(), 0, 0);
4472 root->OnMouseReleased(released); 4478 root->OnMouseReleased(released);
4473 EXPECT_EQ(ui::ET_MOUSE_RELEASED, v->last_mouse_event_type_); 4479 EXPECT_EQ(ui::ET_MOUSE_RELEASED, v->last_mouse_event_type_);
4474 } 4480 }
4475 4481
4476 } // namespace views 4482 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698