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

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

Issue 1782773002: MacViews: Fix ViewTest.HandleAccelerator by faking window activation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Faked activations for everyone! 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
« no previous file with comments | « ui/views/test/widget_test_mac.mm ('k') | ui/views/views.gyp » ('j') | 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 2097 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 TEST_F(ViewTest, HandleAccelerator) { 2108 TEST_F(ViewTest, HandleAccelerator) {
2109 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); 2109 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE);
2110 TestView* view = new TestView(); 2110 TestView* view = new TestView();
2111 view->Reset(); 2111 view->Reset();
2112 view->AddAccelerator(return_accelerator); 2112 view->AddAccelerator(return_accelerator);
2113 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); 2113 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
2114 2114
2115 // Create a window and add the view as its child. 2115 // Create a window and add the view as its child.
2116 scoped_ptr<Widget> widget(new Widget); 2116 scoped_ptr<Widget> widget(new Widget);
2117 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); 2117 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
2118 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 2118 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
2119 params.bounds = gfx::Rect(0, 0, 100, 100); 2119 params.bounds = gfx::Rect(0, 0, 100, 100);
2120 widget->Init(params); 2120 widget->Init(params);
2121 View* root = widget->GetRootView(); 2121 View* root = widget->GetRootView();
2122 root->AddChildView(view); 2122 root->AddChildView(view);
2123 widget->Show(); 2123 widget->Show();
2124 2124
2125 FocusManager* focus_manager = widget->GetFocusManager(); 2125 FocusManager* focus_manager = widget->GetFocusManager();
2126 ASSERT_TRUE(focus_manager); 2126 ASSERT_TRUE(focus_manager);
2127 2127
2128 #if defined(USE_AURA) && !defined(OS_CHROMEOS) 2128 #if defined(USE_AURA) && !defined(OS_CHROMEOS)
2129 // 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.
2130 EXPECT_FALSE(widget->IsActive()); 2130 EXPECT_FALSE(widget->IsActive());
2131 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); 2131 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
2132 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]); 2132 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]);
2133 #endif 2133 #endif
2134 2134
2135 // TYPE_POPUP widgets default to non-activatable, so the Show() above wouldn't
2136 // have activated the Widget. First, allow activation.
2137 widget->widget_delegate()->set_can_activate(true);
2138
2135 // When a non-child view is active, it should handle accelerators. 2139 // When a non-child view is active, it should handle accelerators.
2136 view->accelerator_count_map_[return_accelerator] = 0; 2140 view->accelerator_count_map_[return_accelerator] = 0;
2137 widget->Activate(); 2141 widget->Activate();
2138 EXPECT_TRUE(widget->IsActive()); 2142 EXPECT_TRUE(widget->IsActive());
2139 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); 2143 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator));
2140 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]); 2144 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]);
2141 2145
2142 // Add a child view associated with a child widget. 2146 // Add a child view associated with a child widget.
2143 TestView* child_view = new TestView(); 2147 TestView* child_view = new TestView();
2144 child_view->Reset(); 2148 child_view->Reset();
(...skipping 2415 matching lines...) Expand 10 before | Expand all | Expand 10 after
4560 widget.Init(params); 4564 widget.Init(params);
4561 4565
4562 AddViewWithChildLayer(widget.GetRootView()); 4566 AddViewWithChildLayer(widget.GetRootView());
4563 ViewThatAddsViewInOnNativeThemeChanged* v = 4567 ViewThatAddsViewInOnNativeThemeChanged* v =
4564 new ViewThatAddsViewInOnNativeThemeChanged; 4568 new ViewThatAddsViewInOnNativeThemeChanged;
4565 widget.GetRootView()->AddChildView(v); 4569 widget.GetRootView()->AddChildView(v);
4566 EXPECT_TRUE(v->on_native_theme_changed_called()); 4570 EXPECT_TRUE(v->on_native_theme_changed_called());
4567 } 4571 }
4568 4572
4569 } // namespace views 4573 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/test/widget_test_mac.mm ('k') | ui/views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698