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

Side by Side Diff: ui/views/widget/native_widget_aura_unittest.cc

Issue 1905333004: Corrects NativeWidgetAura state model to not minimize on every restore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Corrects NativeWidgetAura state model to not minimize on every restore (test) Created 4 years, 8 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 | « no previous file | ui/views/widget/widget.cc » ('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 "ui/views/widget/native_widget_aura.h" 5 #include "ui/views/widget/native_widget_aura.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/aura/client/aura_constants.h" 13 #include "ui/aura/client/aura_constants.h"
14 #include "ui/aura/env.h" 14 #include "ui/aura/env.h"
15 #include "ui/aura/layout_manager.h" 15 #include "ui/aura/layout_manager.h"
16 #include "ui/aura/test/aura_test_base.h" 16 #include "ui/aura/test/aura_test_base.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/aura/window_observer.h"
18 #include "ui/aura/window_tree_host.h" 19 #include "ui/aura/window_tree_host.h"
19 #include "ui/events/event.h" 20 #include "ui/events/event.h"
20 #include "ui/events/event_utils.h" 21 #include "ui/events/event_utils.h"
21 #include "ui/gfx/screen.h" 22 #include "ui/gfx/screen.h"
22 #include "ui/views/layout/fill_layout.h" 23 #include "ui/views/layout/fill_layout.h"
23 #include "ui/views/test/widget_test.h" 24 #include "ui/views/test/widget_test.h"
24 #include "ui/views/widget/root_view.h" 25 #include "ui/views/widget/root_view.h"
25 #include "ui/views/widget/widget_delegate.h" 26 #include "ui/views/widget/widget_delegate.h"
26 #include "ui/wm/core/base_focus_rules.h" 27 #include "ui/wm/core/base_focus_rules.h"
27 #include "ui/wm/core/default_activation_client.h" 28 #include "ui/wm/core/default_activation_client.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 params.show_state = ui::SHOW_STATE_MINIMIZED; 144 params.show_state = ui::SHOW_STATE_MINIMIZED;
144 params.bounds.SetRect(0, 0, 1024, 800); 145 params.bounds.SetRect(0, 0, 1024, 800);
145 std::unique_ptr<Widget> widget(new Widget()); 146 std::unique_ptr<Widget> widget(new Widget());
146 widget->Init(params); 147 widget->Init(params);
147 widget->Show(); 148 widget->Show();
148 149
149 EXPECT_TRUE(widget->IsMinimized()); 150 EXPECT_TRUE(widget->IsMinimized());
150 widget->CloseNow(); 151 widget->CloseNow();
151 } 152 }
152 153
154 // A WindowObserver that counts kShowStateKey property changes.
155 class TestWindowObserver : public aura::WindowObserver {
156 public:
157 TestWindowObserver(gfx::NativeWindow window) : window_(window) {
sky 2016/04/25 15:01:18 explicit
varkha 2016/04/25 15:56:57 Done.
158 window_->AddObserver(this);
159 }
160 ~TestWindowObserver() override {
161 window_->RemoveObserver(this);
162 }
163
164 // aura::WindowObserver:
165 void OnWindowPropertyChanged(aura::Window* window,
166 const void* key,
167 intptr_t old) override {
168 if (key != aura::client::kShowStateKey)
169 return;
170 count_++;
171 state_ = window_->GetProperty(aura::client::kShowStateKey);
172 }
173
174 int count() const { return count_; }
175 ui::WindowShowState state() const { return state_; }
176 void Reset() { count_ = 0; }
177
178 private:
179 gfx::NativeWindow window_;
180 int count_ = 0;
181 ui::WindowShowState state_ = ui::WindowShowState::SHOW_STATE_DEFAULT;
182
183 DISALLOW_COPY_AND_ASSIGN(TestWindowObserver);
184 };
185
186 // Tests that window transitions from normal to minimized and back do not
187 // involve extra show state transitions.
188 TEST_F(NativeWidgetAuraTest, ToggleState) {
189 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
190 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
191 params.parent = NULL;
sky 2016/04/25 15:01:18 nullptr
varkha 2016/04/25 15:56:57 Done. Here and elsewhere in this file.
192 params.context = root_window();
193 params.show_state = ui::SHOW_STATE_NORMAL;
194 params.bounds.SetRect(0, 0, 1024, 800);
195 std::unique_ptr<Widget> widget(new Widget());
sky 2016/04/25 15:01:18 nit: no need for a unique_ptr here, declare widget
varkha 2016/04/25 15:56:57 Done.
196 widget->Init(params);
197 std::unique_ptr<TestWindowObserver> observer(
198 new TestWindowObserver(widget->GetNativeWindow()));
199 widget->Show();
200 EXPECT_FALSE(widget->IsMinimized());
201 EXPECT_EQ(0, observer->count());
202 EXPECT_EQ(ui::WindowShowState::SHOW_STATE_DEFAULT, observer->state());
203
204 widget->Minimize();
205 EXPECT_TRUE(widget->IsMinimized());
206 EXPECT_EQ(1, observer->count());
207 EXPECT_EQ(ui::WindowShowState::SHOW_STATE_MINIMIZED, observer->state());
208 observer->Reset();
209
210 widget->Show();
211 widget->Restore();
212 EXPECT_EQ(1, observer->count());
213 EXPECT_EQ(ui::WindowShowState::SHOW_STATE_NORMAL, observer->state());
214
215 observer.reset();
216 EXPECT_FALSE(widget->IsMinimized());
217 widget->CloseNow();
218 }
219
153 class TestLayoutManagerBase : public aura::LayoutManager { 220 class TestLayoutManagerBase : public aura::LayoutManager {
154 public: 221 public:
155 TestLayoutManagerBase() {} 222 TestLayoutManagerBase() {}
156 ~TestLayoutManagerBase() override {} 223 ~TestLayoutManagerBase() override {}
157 224
158 // aura::LayoutManager: 225 // aura::LayoutManager:
159 void OnWindowResized() override {} 226 void OnWindowResized() override {}
160 void OnWindowAddedToLayout(aura::Window* child) override {} 227 void OnWindowAddedToLayout(aura::Window* child) override {}
161 void OnWillRemoveWindowFromLayout(aura::Window* child) override {} 228 void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
162 void OnWindowRemovedFromLayout(aura::Window* child) override {} 229 void OnWindowRemovedFromLayout(aura::Window* child) override {}
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 EXPECT_FALSE(delegate.view()->HasFocus()); 597 EXPECT_FALSE(delegate.view()->HasFocus());
531 598
532 test_focus_rules()->set_can_activate(true); 599 test_focus_rules()->set_can_activate(true);
533 views::test::TestInitialFocusWidgetDelegate delegate2(root_window()); 600 views::test::TestInitialFocusWidgetDelegate delegate2(root_window());
534 delegate2.GetWidget()->Show(); 601 delegate2.GetWidget()->Show();
535 EXPECT_TRUE(delegate2.view()->HasFocus()); 602 EXPECT_TRUE(delegate2.view()->HasFocus());
536 } 603 }
537 604
538 } // namespace 605 } // namespace
539 } // namespace views 606 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/widget/widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698