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

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

Issue 686493002: Standardize usage of virtual/override/final specifiers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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/widget/native_widget_aura.h ('k') | ui/views/widget/native_widget_private.h » ('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 "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 19 matching lines...) Expand all
30 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 30 Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
31 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 31 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
32 params.parent = parent; 32 params.parent = parent;
33 widget->Init(params); 33 widget->Init(params);
34 return static_cast<NativeWidgetAura*>(widget->native_widget()); 34 return static_cast<NativeWidgetAura*>(widget->native_widget());
35 } 35 }
36 36
37 class NativeWidgetAuraTest : public aura::test::AuraTestBase { 37 class NativeWidgetAuraTest : public aura::test::AuraTestBase {
38 public: 38 public:
39 NativeWidgetAuraTest() {} 39 NativeWidgetAuraTest() {}
40 virtual ~NativeWidgetAuraTest() {} 40 ~NativeWidgetAuraTest() override {}
41 41
42 // testing::Test overrides: 42 // testing::Test overrides:
43 virtual void SetUp() override { 43 void SetUp() override {
44 AuraTestBase::SetUp(); 44 AuraTestBase::SetUp();
45 new wm::DefaultActivationClient(root_window()); 45 new wm::DefaultActivationClient(root_window());
46 host()->SetBounds(gfx::Rect(640, 480)); 46 host()->SetBounds(gfx::Rect(640, 480));
47 } 47 }
48 48
49 private: 49 private:
50 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAuraTest); 50 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAuraTest);
51 }; 51 };
52 52
53 TEST_F(NativeWidgetAuraTest, CenterWindowLargeParent) { 53 TEST_F(NativeWidgetAuraTest, CenterWindowLargeParent) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 window->CenterWindow(gfx::Size(500, 600)); 96 window->CenterWindow(gfx::Size(500, 600));
97 97
98 // |window| should be no bigger than |parent|. 98 // |window| should be no bigger than |parent|.
99 EXPECT_EQ("20,40 480x320", window->GetNativeWindow()->bounds().ToString()); 99 EXPECT_EQ("20,40 480x320", window->GetNativeWindow()->bounds().ToString());
100 widget->CloseNow(); 100 widget->CloseNow();
101 } 101 }
102 102
103 class TestLayoutManagerBase : public aura::LayoutManager { 103 class TestLayoutManagerBase : public aura::LayoutManager {
104 public: 104 public:
105 TestLayoutManagerBase() {} 105 TestLayoutManagerBase() {}
106 virtual ~TestLayoutManagerBase() {} 106 ~TestLayoutManagerBase() override {}
107 107
108 // aura::LayoutManager: 108 // aura::LayoutManager:
109 virtual void OnWindowResized() override {} 109 void OnWindowResized() override {}
110 virtual void OnWindowAddedToLayout(aura::Window* child) override {} 110 void OnWindowAddedToLayout(aura::Window* child) override {}
111 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) override {} 111 void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
112 virtual void OnWindowRemovedFromLayout(aura::Window* child) override {} 112 void OnWindowRemovedFromLayout(aura::Window* child) override {}
113 virtual void OnChildWindowVisibilityChanged(aura::Window* child, 113 void OnChildWindowVisibilityChanged(aura::Window* child,
114 bool visible) override {} 114 bool visible) override {}
115 virtual void SetChildBounds(aura::Window* child, 115 void SetChildBounds(aura::Window* child,
116 const gfx::Rect& requested_bounds) override {} 116 const gfx::Rect& requested_bounds) override {}
117 117
118 private: 118 private:
119 DISALLOW_COPY_AND_ASSIGN(TestLayoutManagerBase); 119 DISALLOW_COPY_AND_ASSIGN(TestLayoutManagerBase);
120 }; 120 };
121 121
122 // Used by ShowMaximizedDoesntBounceAround. See it for details. 122 // Used by ShowMaximizedDoesntBounceAround. See it for details.
123 class MaximizeLayoutManager : public TestLayoutManagerBase { 123 class MaximizeLayoutManager : public TestLayoutManagerBase {
124 public: 124 public:
125 MaximizeLayoutManager() {} 125 MaximizeLayoutManager() {}
126 virtual ~MaximizeLayoutManager() {} 126 ~MaximizeLayoutManager() override {}
127 127
128 private: 128 private:
129 // aura::LayoutManager: 129 // aura::LayoutManager:
130 virtual void OnWindowAddedToLayout(aura::Window* child) override { 130 void OnWindowAddedToLayout(aura::Window* child) override {
131 // This simulates what happens when adding a maximized window. 131 // This simulates what happens when adding a maximized window.
132 SetChildBoundsDirect(child, gfx::Rect(0, 0, 300, 300)); 132 SetChildBoundsDirect(child, gfx::Rect(0, 0, 300, 300));
133 } 133 }
134 134
135 DISALLOW_COPY_AND_ASSIGN(MaximizeLayoutManager); 135 DISALLOW_COPY_AND_ASSIGN(MaximizeLayoutManager);
136 }; 136 };
137 137
138 // This simulates BrowserView, which creates a custom RootView so that 138 // This simulates BrowserView, which creates a custom RootView so that
139 // OnNativeWidgetSizeChanged that is invoked during Init matters. 139 // OnNativeWidgetSizeChanged that is invoked during Init matters.
140 class TestWidget : public views::Widget { 140 class TestWidget : public views::Widget {
141 public: 141 public:
142 TestWidget() : did_size_change_more_than_once_(false) { 142 TestWidget() : did_size_change_more_than_once_(false) {
143 } 143 }
144 144
145 // Returns true if the size changes to a non-empty size, and then to another 145 // Returns true if the size changes to a non-empty size, and then to another
146 // size. 146 // size.
147 bool did_size_change_more_than_once() const { 147 bool did_size_change_more_than_once() const {
148 return did_size_change_more_than_once_; 148 return did_size_change_more_than_once_;
149 } 149 }
150 150
151 virtual void OnNativeWidgetSizeChanged(const gfx::Size& new_size) override { 151 void OnNativeWidgetSizeChanged(const gfx::Size& new_size) override {
152 if (last_size_.IsEmpty()) 152 if (last_size_.IsEmpty())
153 last_size_ = new_size; 153 last_size_ = new_size;
154 else if (!did_size_change_more_than_once_ && new_size != last_size_) 154 else if (!did_size_change_more_than_once_ && new_size != last_size_)
155 did_size_change_more_than_once_ = true; 155 did_size_change_more_than_once_ = true;
156 Widget::OnNativeWidgetSizeChanged(new_size); 156 Widget::OnNativeWidgetSizeChanged(new_size);
157 } 157 }
158 158
159 private: 159 private:
160 bool did_size_change_more_than_once_; 160 bool did_size_change_more_than_once_;
161 gfx::Size last_size_; 161 gfx::Size last_size_;
(...skipping 16 matching lines...) Expand all
178 params.show_state = ui::SHOW_STATE_MAXIMIZED; 178 params.show_state = ui::SHOW_STATE_MAXIMIZED;
179 params.bounds = gfx::Rect(10, 10, 100, 200); 179 params.bounds = gfx::Rect(10, 10, 100, 200);
180 widget->Init(params); 180 widget->Init(params);
181 EXPECT_FALSE(widget->did_size_change_more_than_once()); 181 EXPECT_FALSE(widget->did_size_change_more_than_once());
182 widget->CloseNow(); 182 widget->CloseNow();
183 } 183 }
184 184
185 class PropertyTestLayoutManager : public TestLayoutManagerBase { 185 class PropertyTestLayoutManager : public TestLayoutManagerBase {
186 public: 186 public:
187 PropertyTestLayoutManager() : added_(false) {} 187 PropertyTestLayoutManager() : added_(false) {}
188 virtual ~PropertyTestLayoutManager() {} 188 ~PropertyTestLayoutManager() override {}
189 189
190 bool added() const { return added_; } 190 bool added() const { return added_; }
191 191
192 private: 192 private:
193 // aura::LayoutManager: 193 // aura::LayoutManager:
194 virtual void OnWindowAddedToLayout(aura::Window* child) override { 194 void OnWindowAddedToLayout(aura::Window* child) override {
195 EXPECT_TRUE(child->GetProperty(aura::client::kCanMaximizeKey)); 195 EXPECT_TRUE(child->GetProperty(aura::client::kCanMaximizeKey));
196 EXPECT_TRUE(child->GetProperty(aura::client::kCanMinimizeKey)); 196 EXPECT_TRUE(child->GetProperty(aura::client::kCanMinimizeKey));
197 EXPECT_TRUE(child->GetProperty(aura::client::kCanResizeKey)); 197 EXPECT_TRUE(child->GetProperty(aura::client::kCanResizeKey));
198 added_ = true; 198 added_ = true;
199 } 199 }
200 200
201 bool added_; 201 bool added_;
202 202
203 DISALLOW_COPY_AND_ASSIGN(PropertyTestLayoutManager); 203 DISALLOW_COPY_AND_ASSIGN(PropertyTestLayoutManager);
204 }; 204 };
205 205
206 class PropertyTestWidgetDelegate : public views::WidgetDelegate { 206 class PropertyTestWidgetDelegate : public views::WidgetDelegate {
207 public: 207 public:
208 explicit PropertyTestWidgetDelegate(Widget* widget) : widget_(widget) {} 208 explicit PropertyTestWidgetDelegate(Widget* widget) : widget_(widget) {}
209 virtual ~PropertyTestWidgetDelegate() {} 209 ~PropertyTestWidgetDelegate() override {}
210 210
211 private: 211 private:
212 // views::WidgetDelegate: 212 // views::WidgetDelegate:
213 virtual bool CanMaximize() const override { 213 bool CanMaximize() const override { return true; }
214 return true; 214 bool CanMinimize() const override { return true; }
215 } 215 bool CanResize() const override { return true; }
216 virtual bool CanMinimize() const override { 216 void DeleteDelegate() override { delete this; }
217 return true; 217 Widget* GetWidget() override { return widget_; }
218 } 218 const Widget* GetWidget() const override { return widget_; }
219 virtual bool CanResize() const override {
220 return true;
221 }
222 virtual void DeleteDelegate() override {
223 delete this;
224 }
225 virtual Widget* GetWidget() override {
226 return widget_;
227 }
228 virtual const Widget* GetWidget() const override {
229 return widget_;
230 }
231 219
232 Widget* widget_; 220 Widget* widget_;
233 DISALLOW_COPY_AND_ASSIGN(PropertyTestWidgetDelegate); 221 DISALLOW_COPY_AND_ASSIGN(PropertyTestWidgetDelegate);
234 }; 222 };
235 223
236 // Verifies that the kCanMaximizeKey/kCanMinimizeKey/kCanResizeKey have the 224 // Verifies that the kCanMaximizeKey/kCanMinimizeKey/kCanResizeKey have the
237 // correct value when added to the layout manager. 225 // correct value when added to the layout manager.
238 TEST_F(NativeWidgetAuraTest, TestPropertiesWhenAddedToLayout) { 226 TEST_F(NativeWidgetAuraTest, TestPropertiesWhenAddedToLayout) {
239 root_window()->SetBounds(gfx::Rect(0, 0, 640, 480)); 227 root_window()->SetBounds(gfx::Rect(0, 0, 640, 480));
240 PropertyTestLayoutManager* layout_manager = new PropertyTestLayoutManager(); 228 PropertyTestLayoutManager* layout_manager = new PropertyTestLayoutManager();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 267 }
280 268
281 void clear_got_gesture_event() { 269 void clear_got_gesture_event() {
282 got_gesture_event_ = false; 270 got_gesture_event_ = false;
283 } 271 }
284 bool got_gesture_event() const { 272 bool got_gesture_event() const {
285 return got_gesture_event_; 273 return got_gesture_event_;
286 } 274 }
287 275
288 // View overrides: 276 // View overrides:
289 virtual void OnGestureEvent(ui::GestureEvent* event) override { 277 void OnGestureEvent(ui::GestureEvent* event) override {
290 got_gesture_event_ = true; 278 got_gesture_event_ = true;
291 if (consume_gesture_event_) 279 if (consume_gesture_event_)
292 event->StopPropagation(); 280 event->StopPropagation();
293 } 281 }
294 282
295 private: 283 private:
296 // Was OnGestureEvent() invoked? 284 // Was OnGestureEvent() invoked?
297 bool got_gesture_event_; 285 bool got_gesture_event_;
298 286
299 // Dictates what OnGestureEvent() returns. 287 // Dictates what OnGestureEvent() returns.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 widget->Show(); 429 widget->Show();
442 widget->Close(); 430 widget->Close();
443 base::MessageLoop::current()->RunUntilIdle(); 431 base::MessageLoop::current()->RunUntilIdle();
444 widget->GetNativeTheme(); // Shouldn't crash. 432 widget->GetNativeTheme(); // Shouldn't crash.
445 } 433 }
446 434
447 // Used to track calls to WidgetDelegate::OnWidgetMove(). 435 // Used to track calls to WidgetDelegate::OnWidgetMove().
448 class MoveTestWidgetDelegate : public WidgetDelegateView { 436 class MoveTestWidgetDelegate : public WidgetDelegateView {
449 public: 437 public:
450 MoveTestWidgetDelegate() : got_move_(false) {} 438 MoveTestWidgetDelegate() : got_move_(false) {}
451 virtual ~MoveTestWidgetDelegate() {} 439 ~MoveTestWidgetDelegate() override {}
452 440
453 void ClearGotMove() { got_move_ = false; } 441 void ClearGotMove() { got_move_ = false; }
454 bool got_move() const { return got_move_; } 442 bool got_move() const { return got_move_; }
455 443
456 // WidgetDelegate overrides: 444 // WidgetDelegate overrides:
457 virtual void OnWidgetMove() override { got_move_ = true; } 445 void OnWidgetMove() override { got_move_ = true; }
458 446
459 private: 447 private:
460 bool got_move_; 448 bool got_move_;
461 449
462 DISALLOW_COPY_AND_ASSIGN(MoveTestWidgetDelegate); 450 DISALLOW_COPY_AND_ASSIGN(MoveTestWidgetDelegate);
463 }; 451 };
464 452
465 // This test simulates what happens when a window is normally maximized. That 453 // This test simulates what happens when a window is normally maximized. That
466 // is, it's layer is acquired for animation then the window is maximized. 454 // is, it's layer is acquired for animation then the window is maximized.
467 // Acquiring the layer resets the bounds of the window. This test verifies the 455 // Acquiring the layer resets the bounds of the window. This test verifies the
468 // Widget is still notified correctly of a move in this case. 456 // Widget is still notified correctly of a move in this case.
469 TEST_F(NativeWidgetAuraTest, OnWidgetMovedInvokedAfterAcquireLayer) { 457 TEST_F(NativeWidgetAuraTest, OnWidgetMovedInvokedAfterAcquireLayer) {
470 // |delegate| deletes itself when the widget is destroyed. 458 // |delegate| deletes itself when the widget is destroyed.
471 MoveTestWidgetDelegate* delegate = new MoveTestWidgetDelegate; 459 MoveTestWidgetDelegate* delegate = new MoveTestWidgetDelegate;
472 Widget* widget = 460 Widget* widget =
473 Widget::CreateWindowWithContextAndBounds(delegate, 461 Widget::CreateWindowWithContextAndBounds(delegate,
474 root_window(), 462 root_window(),
475 gfx::Rect(10, 10, 100, 200)); 463 gfx::Rect(10, 10, 100, 200));
476 widget->Show(); 464 widget->Show();
477 delegate->ClearGotMove(); 465 delegate->ClearGotMove();
478 // Simulate a maximize with animation. 466 // Simulate a maximize with animation.
479 delete widget->GetNativeView()->RecreateLayer().release(); 467 delete widget->GetNativeView()->RecreateLayer().release();
480 widget->SetBounds(gfx::Rect(0, 0, 500, 500)); 468 widget->SetBounds(gfx::Rect(0, 0, 500, 500));
481 EXPECT_TRUE(delegate->got_move()); 469 EXPECT_TRUE(delegate->got_move());
482 widget->CloseNow(); 470 widget->CloseNow();
483 } 471 }
484 472
485 } // namespace 473 } // namespace
486 } // namespace views 474 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_aura.h ('k') | ui/views/widget/native_widget_private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698