OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/widget/native_widget_views.h" | |
6 | |
7 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/views/test/test_views_delegate.h" | 9 #include "ui/views/test/test_views_delegate.h" |
12 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
| 11 #include "ui/gfx/point.h" |
| 12 #include "ui/gfx/native_widget_types.h" |
13 #include "views/views_delegate.h" | 13 #include "views/views_delegate.h" |
| 14 #include "views/widget/native_widget_delegate.h" |
14 | 15 |
15 #if defined(USE_AURA) | 16 #if defined(USE_AURA) |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "views/widget/native_widget_aura.h" | 18 #include "views/widget/native_widget_aura.h" |
18 #elif defined(OS_WIN) | 19 #elif defined(OS_WIN) |
19 #include "views/widget/native_widget_win.h" | 20 #include "views/widget/native_widget_win.h" |
20 #elif defined(TOOLKIT_USES_GTK) | 21 #elif defined(TOOLKIT_USES_GTK) |
21 #include "views/widget/native_widget_gtk.h" | 22 #include "views/widget/native_widget_gtk.h" |
22 #endif | 23 #endif |
23 | 24 |
24 namespace views { | 25 namespace views { |
25 namespace { | 26 namespace { |
26 | 27 |
27 #if defined(TOOLKIT_USES_GTK) | 28 // A generic typedef to pick up relevant NativeWidget implementations. |
28 // A widget that assumes mouse capture always works. | 29 #if defined(USE_AURA) |
29 class NativeWidgetGtkCapture : public NativeWidgetGtk { | 30 typedef NativeWidgetAura NativeWidgetPlatform; |
| 31 #elif defined(OS_WIN) |
| 32 typedef NativeWidgetWin NativeWidgetPlatform; |
| 33 #elif defined(TOOLKIT_USES_GTK) |
| 34 typedef NativeWidgetGtk NativeWidgetPlatform; |
| 35 #endif |
| 36 |
| 37 // A widget that assumes mouse capture always works. It won't on Gtk/Aura in |
| 38 // testing, so we mock it. |
| 39 #if defined(TOOLKIT_USES_GTK) || defined(USE_AURA) |
| 40 class NativeWidgetCapture : public NativeWidgetPlatform { |
30 public: | 41 public: |
31 NativeWidgetGtkCapture(internal::NativeWidgetDelegate* delegate) | 42 NativeWidgetCapture(internal::NativeWidgetDelegate* delegate) |
32 : NativeWidgetGtk(delegate), | 43 : NativeWidgetPlatform(delegate), |
33 mouse_capture_(false) {} | 44 mouse_capture_(false) {} |
34 virtual ~NativeWidgetGtkCapture() {} | 45 virtual ~NativeWidgetCapture() {} |
| 46 |
35 virtual void SetMouseCapture() OVERRIDE { | 47 virtual void SetMouseCapture() OVERRIDE { |
36 mouse_capture_ = true; | 48 mouse_capture_ = true; |
37 } | 49 } |
38 virtual void ReleaseMouseCapture() OVERRIDE { | 50 virtual void ReleaseMouseCapture() OVERRIDE { |
39 if (mouse_capture_) | 51 if (mouse_capture_) |
40 delegate()->OnMouseCaptureLost(); | 52 delegate()->OnMouseCaptureLost(); |
41 mouse_capture_ = false; | 53 mouse_capture_ = false; |
42 } | 54 } |
43 virtual bool HasMouseCapture() const OVERRIDE { | 55 virtual bool HasMouseCapture() const OVERRIDE { |
44 return mouse_capture_; | 56 return mouse_capture_; |
45 } | 57 } |
46 | 58 |
47 private: | 59 private: |
48 bool mouse_capture_; | 60 bool mouse_capture_; |
49 | 61 |
50 DISALLOW_COPY_AND_ASSIGN(NativeWidgetGtkCapture); | 62 DISALLOW_COPY_AND_ASSIGN(NativeWidgetCapture); |
51 }; | 63 }; |
52 #endif | 64 #endif |
53 | 65 |
| 66 // A typedef that inserts our mock-capture NativeWidget implementation for |
| 67 // relevant platforms. |
| 68 #if defined(USE_AURA) |
| 69 typedef NativeWidgetCapture NativeWidgetPlatformForTest; |
| 70 #elif defined(OS_WIN) |
| 71 typedef NativeWidgetWin NativeWidgetPlatformForTest; |
| 72 #elif defined(TOOLKIT_USES_GTK) |
| 73 typedef NativeWidgetCapture NativeWidgetPlatformForTest; |
| 74 #endif |
| 75 |
54 // A view that always processes all mouse events. | 76 // A view that always processes all mouse events. |
55 class MouseView : public View { | 77 class MouseView : public View { |
56 public: | 78 public: |
57 MouseView() : View() { | 79 MouseView() : View() { |
58 } | 80 } |
59 virtual ~MouseView() {} | 81 virtual ~MouseView() {} |
60 | 82 |
61 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE { | 83 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE { |
62 return true; | 84 return true; |
63 } | 85 } |
64 }; | 86 }; |
65 | 87 |
66 class WidgetTestViewsDelegate : public TestViewsDelegate { | 88 typedef ViewsTestBase WidgetTest; |
67 public: | |
68 WidgetTestViewsDelegate() : default_parent_view_(NULL) { | |
69 } | |
70 virtual ~WidgetTestViewsDelegate() {} | |
71 | |
72 void set_default_parent_view(View* default_parent_view) { | |
73 default_parent_view_ = default_parent_view; | |
74 } | |
75 | |
76 // Overridden from TestViewsDelegate: | |
77 virtual View* GetDefaultParentView() OVERRIDE { | |
78 return default_parent_view_; | |
79 } | |
80 | |
81 private: | |
82 View* default_parent_view_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(WidgetTestViewsDelegate); | |
85 }; | |
86 | |
87 class WidgetTest : public ViewsTestBase { | |
88 public: | |
89 WidgetTest() { | |
90 } | |
91 virtual ~WidgetTest() { | |
92 } | |
93 | |
94 virtual void SetUp() OVERRIDE { | |
95 set_views_delegate(new WidgetTestViewsDelegate()); | |
96 ViewsTestBase::SetUp(); | |
97 } | |
98 | |
99 WidgetTestViewsDelegate& widget_views_delegate() const { | |
100 return static_cast<WidgetTestViewsDelegate&>(views_delegate()); | |
101 } | |
102 | |
103 private: | |
104 DISALLOW_COPY_AND_ASSIGN(WidgetTest); | |
105 }; | |
106 | 89 |
107 NativeWidget* CreatePlatformNativeWidget( | 90 NativeWidget* CreatePlatformNativeWidget( |
108 internal::NativeWidgetDelegate* delegate) { | 91 internal::NativeWidgetDelegate* delegate) { |
109 #if defined(USE_AURA) | 92 return new NativeWidgetPlatformForTest(delegate); |
110 return new NativeWidgetAura(delegate); | |
111 #elif defined(OS_WIN) | |
112 return new NativeWidgetWin(delegate); | |
113 #elif defined(TOOLKIT_USES_GTK) | |
114 return new NativeWidgetGtkCapture(delegate); | |
115 #endif | |
116 } | 93 } |
117 | 94 |
118 Widget* CreateTopLevelPlatformWidget() { | 95 Widget* CreateTopLevelPlatformWidget() { |
119 Widget* toplevel = new Widget; | 96 Widget* toplevel = new Widget; |
120 Widget::InitParams toplevel_params(Widget::InitParams::TYPE_WINDOW); | 97 Widget::InitParams toplevel_params(Widget::InitParams::TYPE_WINDOW); |
121 toplevel_params.native_widget = CreatePlatformNativeWidget(toplevel); | 98 toplevel_params.native_widget = CreatePlatformNativeWidget(toplevel); |
122 toplevel->Init(toplevel_params); | 99 toplevel->Init(toplevel_params); |
123 return toplevel; | 100 return toplevel; |
124 } | 101 } |
125 | 102 |
(...skipping 14 matching lines...) Expand all Loading... |
140 Widget::InitParams child_params(Widget::InitParams::TYPE_POPUP); | 117 Widget::InitParams child_params(Widget::InitParams::TYPE_POPUP); |
141 child_params.child = true; | 118 child_params.child = true; |
142 child_params.native_widget = CreatePlatformNativeWidget(child); | 119 child_params.native_widget = CreatePlatformNativeWidget(child); |
143 child_params.parent = parent_native_view; | 120 child_params.parent = parent_native_view; |
144 child->Init(child_params); | 121 child->Init(child_params); |
145 child->SetContentsView(new View); | 122 child->SetContentsView(new View); |
146 return child; | 123 return child; |
147 } | 124 } |
148 #endif | 125 #endif |
149 | 126 |
150 Widget* CreateTopLevelNativeWidgetViews() { | 127 Widget* CreateTopLevelNativeWidget() { |
151 Widget* toplevel = new Widget; | 128 Widget* toplevel = new Widget; |
152 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 129 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
153 params.native_widget = new NativeWidgetViews(toplevel); | |
154 toplevel->Init(params); | 130 toplevel->Init(params); |
155 toplevel->SetContentsView(new View); | 131 toplevel->SetContentsView(new View); |
156 return toplevel; | 132 return toplevel; |
157 } | 133 } |
158 | 134 |
159 Widget* CreateChildNativeWidgetViewsWithParent(Widget* parent) { | 135 Widget* CreateChildNativeWidgetWithParent(Widget* parent) { |
160 Widget* child = new Widget; | 136 Widget* child = new Widget; |
161 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); | 137 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); |
162 params.native_widget = new NativeWidgetViews(child); | |
163 params.parent_widget = parent; | 138 params.parent_widget = parent; |
164 child->Init(params); | 139 child->Init(params); |
165 child->SetContentsView(new View); | 140 child->SetContentsView(new View); |
166 return child; | 141 return child; |
167 } | 142 } |
168 | 143 |
169 Widget* CreateChildNativeWidgetViews() { | 144 Widget* CreateChildNativeWidget() { |
170 return CreateChildNativeWidgetViewsWithParent(NULL); | 145 return CreateChildNativeWidgetWithParent(NULL); |
171 } | 146 } |
172 | 147 |
173 bool WidgetHasMouseCapture(const Widget* widget) { | 148 bool WidgetHasMouseCapture(const Widget* widget) { |
174 return static_cast<const internal::NativeWidgetPrivate*>(widget-> | 149 return static_cast<const internal::NativeWidgetPrivate*>(widget-> |
175 native_widget())-> HasMouseCapture(); | 150 native_widget())->HasMouseCapture(); |
176 } | 151 } |
177 | 152 |
178 //////////////////////////////////////////////////////////////////////////////// | 153 //////////////////////////////////////////////////////////////////////////////// |
179 // Widget::GetTopLevelWidget tests. | 154 // Widget::GetTopLevelWidget tests. |
180 | 155 |
181 TEST_F(WidgetTest, GetTopLevelWidget_Native) { | 156 TEST_F(WidgetTest, GetTopLevelWidget_Native) { |
182 // Create a hierarchy of native widgets. | 157 // Create a hierarchy of native widgets. |
183 Widget* toplevel = CreateTopLevelPlatformWidget(); | 158 Widget* toplevel = CreateTopLevelPlatformWidget(); |
184 #if defined(TOOLKIT_USES_GTK) | 159 #if defined(TOOLKIT_USES_GTK) |
185 NativeWidgetGtk* native_widget = | 160 NativeWidgetGtk* native_widget = |
186 static_cast<NativeWidgetGtk*>(toplevel->native_widget()); | 161 static_cast<NativeWidgetGtk*>(toplevel->native_widget()); |
187 gfx::NativeView parent = native_widget->window_contents(); | 162 gfx::NativeView parent = native_widget->window_contents(); |
188 #else | 163 #else |
189 gfx::NativeView parent = toplevel->GetNativeView(); | 164 gfx::NativeView parent = toplevel->GetNativeView(); |
190 #endif | 165 #endif |
191 Widget* child = CreateChildPlatformWidget(parent); | 166 Widget* child = CreateChildPlatformWidget(parent); |
192 | 167 |
193 EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget()); | 168 EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget()); |
194 EXPECT_EQ(toplevel, child->GetTopLevelWidget()); | 169 EXPECT_EQ(toplevel, child->GetTopLevelWidget()); |
195 | 170 |
196 toplevel->CloseNow(); | 171 toplevel->CloseNow(); |
197 // |child| should be automatically destroyed with |toplevel|. | 172 // |child| should be automatically destroyed with |toplevel|. |
198 } | 173 } |
199 | 174 |
200 TEST_F(WidgetTest, GetTopLevelWidget_Synthetic) { | 175 TEST_F(WidgetTest, GetTopLevelWidget_Synthetic) { |
201 // Create a hierarchy consisting of a top level platform native widget and a | 176 // Create a hierarchy consisting of a top level platform native widget and a |
202 // child NativeWidgetViews. | 177 // child NativeWidget. |
203 Widget* toplevel = CreateTopLevelPlatformWidget(); | 178 Widget* toplevel = CreateTopLevelPlatformWidget(); |
204 widget_views_delegate().set_default_parent_view(toplevel->GetRootView()); | 179 Widget* child = CreateTopLevelNativeWidget(); |
205 Widget* child = CreateTopLevelNativeWidgetViews(); | |
206 | 180 |
207 EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget()); | 181 EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget()); |
208 EXPECT_EQ(child, child->GetTopLevelWidget()); | 182 EXPECT_EQ(child, child->GetTopLevelWidget()); |
209 | 183 |
210 toplevel->CloseNow(); | 184 toplevel->CloseNow(); |
211 // |child| should be automatically destroyed with |toplevel|. | 185 // |child| should be automatically destroyed with |toplevel|. |
212 } | 186 } |
213 | 187 |
214 // Creates a hierarchy consisting of a desktop platform native widget, a | 188 // Creates a hierarchy consisting of a desktop platform native widget, a |
215 // toplevel NativeWidgetViews, and a child of that toplevel, another | 189 // toplevel NativeWidget, and a child of that toplevel, another NativeWidget. |
216 // NativeWidgetViews. | |
217 TEST_F(WidgetTest, GetTopLevelWidget_SyntheticDesktop) { | 190 TEST_F(WidgetTest, GetTopLevelWidget_SyntheticDesktop) { |
218 // Create a hierarchy consisting of a desktop platform native widget, | 191 // Create a hierarchy consisting of a desktop platform native widget, |
219 // a toplevel NativeWidgetViews and a chlid NativeWidgetViews. | 192 // a toplevel NativeWidget and a chlid NativeWidget. |
220 Widget* desktop = CreateTopLevelPlatformWidget(); | 193 Widget* desktop = CreateTopLevelPlatformWidget(); |
221 widget_views_delegate().set_default_parent_view(desktop->GetRootView()); | 194 Widget* toplevel = CreateTopLevelNativeWidget(); // Will be parented |
222 Widget* toplevel = CreateTopLevelNativeWidgetViews(); // Will be parented | 195 // automatically to |
223 // automatically to | 196 // |toplevel|. |
224 // |toplevel|. | |
225 | 197 |
226 Widget* child = CreateChildNativeWidgetViewsWithParent(toplevel); | 198 Widget* child = CreateChildNativeWidgetWithParent(toplevel); |
227 | 199 |
228 EXPECT_EQ(desktop, desktop->GetTopLevelWidget()); | 200 EXPECT_EQ(desktop, desktop->GetTopLevelWidget()); |
229 EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget()); | 201 EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget()); |
230 EXPECT_EQ(toplevel, child->GetTopLevelWidget()); | 202 EXPECT_EQ(toplevel, child->GetTopLevelWidget()); |
231 | 203 |
232 desktop->CloseNow(); | 204 desktop->CloseNow(); |
233 // |toplevel|, |child| should be automatically destroyed with |toplevel|. | 205 // |toplevel|, |child| should be automatically destroyed with |toplevel|. |
234 } | 206 } |
235 | 207 |
236 // This is flaky on touch build. See crbug.com/94137. | |
237 #if defined(TOUCH_UI) | |
238 #define MAYBE_GrabUngrab DISABLED_GrabUngrab | |
239 #else | |
240 #define MAYBE_GrabUngrab GrabUngrab | |
241 #endif | |
242 // Tests some grab/ungrab events. | 208 // Tests some grab/ungrab events. |
243 TEST_F(WidgetTest, MAYBE_GrabUngrab) { | 209 TEST_F(WidgetTest, DISABLED_GrabUngrab) { |
244 Widget* toplevel = CreateTopLevelPlatformWidget(); | 210 Widget* toplevel = CreateTopLevelPlatformWidget(); |
245 Widget* child1 = CreateChildNativeWidgetViewsWithParent(toplevel); | 211 Widget* child1 = CreateChildNativeWidgetWithParent(toplevel); |
246 Widget* child2 = CreateChildNativeWidgetViewsWithParent(toplevel); | 212 Widget* child2 = CreateChildNativeWidgetWithParent(toplevel); |
247 | 213 |
248 toplevel->SetBounds(gfx::Rect(0, 0, 500, 500)); | 214 toplevel->SetBounds(gfx::Rect(0, 0, 500, 500)); |
249 | 215 |
250 child1->SetBounds(gfx::Rect(10, 10, 300, 300)); | 216 child1->SetBounds(gfx::Rect(10, 10, 300, 300)); |
251 View* view = new MouseView(); | 217 View* view = new MouseView(); |
252 view->SetBounds(0, 0, 300, 300); | 218 view->SetBounds(0, 0, 300, 300); |
253 child1->GetRootView()->AddChildView(view); | 219 child1->GetRootView()->AddChildView(view); |
254 | 220 |
255 child2->SetBounds(gfx::Rect(200, 10, 200, 200)); | 221 child2->SetBounds(gfx::Rect(200, 10, 200, 200)); |
256 view = new MouseView(); | 222 view = new MouseView(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 EXPECT_TRUE(child_popup->IsVisible()); | 338 EXPECT_TRUE(child_popup->IsVisible()); |
373 | 339 |
374 toplevel->CloseNow(); | 340 toplevel->CloseNow(); |
375 // |child_popup| should be automatically destroyed with |toplevel|. | 341 // |child_popup| should be automatically destroyed with |toplevel|. |
376 } | 342 } |
377 #endif | 343 #endif |
378 | 344 |
379 // Tests visibility of synthetic child widgets. | 345 // Tests visibility of synthetic child widgets. |
380 TEST_F(WidgetTest, Visibility_Synthetic) { | 346 TEST_F(WidgetTest, Visibility_Synthetic) { |
381 // Create a hierarchy consisting of a desktop platform native widget, | 347 // Create a hierarchy consisting of a desktop platform native widget, |
382 // a toplevel NativeWidgetViews and a chlid NativeWidgetViews. | 348 // a toplevel NativeWidget and a chlid NativeWidget. |
383 Widget* desktop = CreateTopLevelPlatformWidget(); | 349 Widget* desktop = CreateTopLevelPlatformWidget(); |
384 desktop->Show(); | 350 desktop->Show(); |
385 | 351 |
386 widget_views_delegate().set_default_parent_view(desktop->GetRootView()); | 352 Widget* toplevel = CreateTopLevelNativeWidget(); // Will be parented |
387 Widget* toplevel = CreateTopLevelNativeWidgetViews(); // Will be parented | 353 // automatically to |
388 // automatically to | 354 // |toplevel|. |
389 // |toplevel|. | |
390 | 355 |
391 Widget* child = CreateChildNativeWidgetViewsWithParent(toplevel); | 356 Widget* child = CreateChildNativeWidgetWithParent(toplevel); |
392 | 357 |
393 EXPECT_FALSE(toplevel->IsVisible()); | 358 EXPECT_FALSE(toplevel->IsVisible()); |
394 EXPECT_FALSE(child->IsVisible()); | 359 EXPECT_FALSE(child->IsVisible()); |
395 | 360 |
396 child->Show(); | 361 child->Show(); |
397 | 362 |
398 EXPECT_FALSE(toplevel->IsVisible()); | 363 EXPECT_FALSE(toplevel->IsVisible()); |
399 EXPECT_FALSE(child->IsVisible()); | 364 EXPECT_FALSE(child->IsVisible()); |
400 | 365 |
401 toplevel->Show(); | 366 toplevel->Show(); |
402 | 367 |
403 EXPECT_TRUE(toplevel->IsVisible()); | 368 EXPECT_TRUE(toplevel->IsVisible()); |
404 EXPECT_TRUE(child->IsVisible()); | 369 EXPECT_TRUE(child->IsVisible()); |
405 | 370 |
406 desktop->CloseNow(); | 371 desktop->CloseNow(); |
407 } | 372 } |
408 | 373 |
409 //////////////////////////////////////////////////////////////////////////////// | 374 //////////////////////////////////////////////////////////////////////////////// |
410 // Widget ownership tests. | 375 // Widget ownership tests. |
411 // | 376 // |
412 // Tests various permutations of Widget ownership specified in the | 377 // Tests various permutations of Widget ownership specified in the |
413 // InitParams::Ownership param. | 378 // InitParams::Ownership param. |
414 | 379 |
415 // A WidgetTest that supplies a toplevel widget for NativeWidgetViews to parent | 380 // A WidgetTest that supplies a toplevel widget for NativeWidget to parent to. |
416 // to. | |
417 class WidgetOwnershipTest : public WidgetTest { | 381 class WidgetOwnershipTest : public WidgetTest { |
418 public: | 382 public: |
419 WidgetOwnershipTest() {} | 383 WidgetOwnershipTest() {} |
420 virtual ~WidgetOwnershipTest() {} | 384 virtual ~WidgetOwnershipTest() {} |
421 | 385 |
422 virtual void SetUp() { | 386 virtual void SetUp() { |
423 WidgetTest::SetUp(); | 387 WidgetTest::SetUp(); |
424 desktop_widget_ = CreateTopLevelPlatformWidget(); | 388 desktop_widget_ = CreateTopLevelPlatformWidget(); |
425 widget_views_delegate().set_default_parent_view( | |
426 desktop_widget_->GetRootView()); | |
427 } | 389 } |
428 | 390 |
429 virtual void TearDown() { | 391 virtual void TearDown() { |
430 desktop_widget_->CloseNow(); | 392 desktop_widget_->CloseNow(); |
431 WidgetTest::TearDown(); | 393 WidgetTest::TearDown(); |
432 } | 394 } |
433 | 395 |
434 private: | 396 private: |
435 Widget* desktop_widget_; | 397 Widget* desktop_widget_; |
436 | 398 |
437 DISALLOW_COPY_AND_ASSIGN(WidgetOwnershipTest); | 399 DISALLOW_COPY_AND_ASSIGN(WidgetOwnershipTest); |
438 }; | 400 }; |
439 | 401 |
440 // A bag of state to monitor destructions. | 402 // A bag of state to monitor destructions. |
441 struct OwnershipTestState { | 403 struct OwnershipTestState { |
442 OwnershipTestState() : widget_deleted(false), native_widget_deleted(false) {} | 404 OwnershipTestState() : widget_deleted(false), native_widget_deleted(false) {} |
443 | 405 |
444 bool widget_deleted; | 406 bool widget_deleted; |
445 bool native_widget_deleted; | 407 bool native_widget_deleted; |
446 }; | 408 }; |
447 | 409 |
448 // A platform NativeWidget subclass that updates a bag of state when it is | 410 // A platform NativeWidget subclass that updates a bag of state when it is |
449 // destroyed. | 411 // destroyed. |
450 class OwnershipTestNativeWidget : | 412 class OwnershipTestNativeWidget : public NativeWidgetPlatform { |
451 #if defined(USE_AURA) | 413 public: |
452 public NativeWidgetAura { | |
453 #elif defined(OS_WIN) | |
454 public NativeWidgetWin { | |
455 #elif defined(TOOLKIT_USES_GTK) | |
456 public NativeWidgetGtk { | |
457 #endif | |
458 public: | |
459 OwnershipTestNativeWidget(internal::NativeWidgetDelegate* delegate, | 414 OwnershipTestNativeWidget(internal::NativeWidgetDelegate* delegate, |
460 OwnershipTestState* state) | 415 OwnershipTestState* state) |
461 #if defined(USE_AURA) | 416 : NativeWidgetPlatform(delegate), |
462 : NativeWidgetAura(delegate), | 417 state_(state) { |
463 #elif defined(OS_WIN) | |
464 : NativeWidgetWin(delegate), | |
465 #elif defined(TOOLKIT_USES_GTK) | |
466 : NativeWidgetGtk(delegate), | |
467 #endif | |
468 state_(state) { | |
469 } | 418 } |
470 virtual ~OwnershipTestNativeWidget() { | 419 virtual ~OwnershipTestNativeWidget() { |
471 state_->native_widget_deleted = true; | 420 state_->native_widget_deleted = true; |
472 } | 421 } |
473 | 422 |
474 private: | 423 private: |
475 OwnershipTestState* state_; | 424 OwnershipTestState* state_; |
476 | 425 |
477 DISALLOW_COPY_AND_ASSIGN(OwnershipTestNativeWidget); | 426 DISALLOW_COPY_AND_ASSIGN(OwnershipTestNativeWidget); |
478 }; | 427 }; |
479 | 428 |
480 // A views NativeWidget subclass that updates a bag of state when it is | 429 // A views NativeWidget subclass that updates a bag of state when it is |
481 // destroyed. | 430 // destroyed. |
482 class OwnershipTestNativeWidgetViews : public NativeWidgetViews { | 431 class OwnershipTestNativeWidgetPlatform : public NativeWidgetPlatformForTest { |
483 public: | 432 public: |
484 OwnershipTestNativeWidgetViews(internal::NativeWidgetDelegate* delegate, | 433 OwnershipTestNativeWidgetPlatform(internal::NativeWidgetDelegate* delegate, |
485 OwnershipTestState* state) | 434 OwnershipTestState* state) |
486 : NativeWidgetViews(delegate), | 435 : NativeWidgetPlatformForTest(delegate), |
487 state_(state) { | 436 state_(state) { |
488 } | 437 } |
489 virtual ~OwnershipTestNativeWidgetViews() { | 438 virtual ~OwnershipTestNativeWidgetPlatform() { |
490 state_->native_widget_deleted = true; | 439 state_->native_widget_deleted = true; |
491 } | 440 } |
492 | 441 |
493 private: | 442 private: |
494 OwnershipTestState* state_; | 443 OwnershipTestState* state_; |
495 | 444 |
496 DISALLOW_COPY_AND_ASSIGN(OwnershipTestNativeWidgetViews); | 445 DISALLOW_COPY_AND_ASSIGN(OwnershipTestNativeWidgetPlatform); |
497 }; | 446 }; |
498 | 447 |
499 // A Widget subclass that updates a bag of state when it is destroyed. | 448 // A Widget subclass that updates a bag of state when it is destroyed. |
500 class OwnershipTestWidget : public Widget { | 449 class OwnershipTestWidget : public Widget { |
501 public: | 450 public: |
502 OwnershipTestWidget(OwnershipTestState* state) : state_(state) {} | 451 OwnershipTestWidget(OwnershipTestState* state) : state_(state) {} |
503 virtual ~OwnershipTestWidget() { | 452 virtual ~OwnershipTestWidget() { |
504 state_->widget_deleted = true; | 453 state_->widget_deleted = true; |
505 } | 454 } |
506 | 455 |
507 private: | 456 private: |
508 OwnershipTestState* state_; | 457 OwnershipTestState* state_; |
509 | 458 |
510 DISALLOW_COPY_AND_ASSIGN(OwnershipTestWidget); | 459 DISALLOW_COPY_AND_ASSIGN(OwnershipTestWidget); |
511 }; | 460 }; |
512 | 461 |
513 // Widget owns its NativeWidget, part 1: NativeWidget is a platform-native | 462 // Widget owns its NativeWidget, part 1: NativeWidget is a platform-native |
514 // widget. | 463 // widget. |
515 TEST_F(WidgetOwnershipTest, Ownership_WidgetOwnsPlatformNativeWidget) { | 464 TEST_F(WidgetOwnershipTest, Ownership_WidgetOwnsPlatformNativeWidget) { |
516 OwnershipTestState state; | 465 OwnershipTestState state; |
517 | 466 |
518 scoped_ptr<Widget> widget(new OwnershipTestWidget(&state)); | 467 scoped_ptr<Widget> widget(new OwnershipTestWidget(&state)); |
519 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 468 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
520 params.native_widget = new OwnershipTestNativeWidget(widget.get(), &state); | 469 params.native_widget = |
| 470 new OwnershipTestNativeWidgetPlatform(widget.get(), &state); |
521 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 471 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
522 widget->Init(params); | 472 widget->Init(params); |
523 | 473 |
524 // Now delete the Widget, which should delete the NativeWidget. | 474 // Now delete the Widget, which should delete the NativeWidget. |
525 widget.reset(); | 475 widget.reset(); |
526 | 476 |
527 EXPECT_TRUE(state.widget_deleted); | 477 EXPECT_TRUE(state.widget_deleted); |
528 EXPECT_TRUE(state.native_widget_deleted); | 478 EXPECT_TRUE(state.native_widget_deleted); |
529 | 479 |
530 // TODO(beng): write test for this ownership scenario and the NativeWidget | 480 // TODO(beng): write test for this ownership scenario and the NativeWidget |
531 // being deleted out from under the Widget. | 481 // being deleted out from under the Widget. |
532 } | 482 } |
533 | 483 |
534 // Widget owns its NativeWidget, part 2: NativeWidget is a NativeWidgetViews. | 484 // Widget owns its NativeWidget, part 2: NativeWidget is a NativeWidget. |
535 TEST_F(WidgetOwnershipTest, Ownership_WidgetOwnsViewsNativeWidget) { | 485 TEST_F(WidgetOwnershipTest, Ownership_WidgetOwnsViewsNativeWidget) { |
536 OwnershipTestState state; | 486 OwnershipTestState state; |
537 | 487 |
538 scoped_ptr<Widget> widget(new OwnershipTestWidget(&state)); | 488 scoped_ptr<Widget> widget(new OwnershipTestWidget(&state)); |
539 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 489 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
540 params.native_widget = | 490 params.native_widget = |
541 new OwnershipTestNativeWidgetViews(widget.get(), &state); | 491 new OwnershipTestNativeWidgetPlatform(widget.get(), &state); |
542 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 492 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
543 widget->Init(params); | 493 widget->Init(params); |
544 | 494 |
545 // Now delete the Widget, which should delete the NativeWidget. | 495 // Now delete the Widget, which should delete the NativeWidget. |
546 widget.reset(); | 496 widget.reset(); |
547 | 497 |
548 EXPECT_TRUE(state.widget_deleted); | 498 EXPECT_TRUE(state.widget_deleted); |
549 EXPECT_TRUE(state.native_widget_deleted); | 499 EXPECT_TRUE(state.native_widget_deleted); |
550 | 500 |
551 // TODO(beng): write test for this ownership scenario and the NativeWidget | 501 // TODO(beng): write test for this ownership scenario and the NativeWidget |
552 // being deleted out from under the Widget. | 502 // being deleted out from under the Widget. |
553 } | 503 } |
554 | 504 |
555 // Widget owns its NativeWidget, part 3: NativeWidget is a NativeWidgetViews, | 505 // Widget owns its NativeWidget, part 3: NativeWidget is a NativeWidget, |
556 // destroy the parent view. | 506 // destroy the parent view. |
557 TEST_F(WidgetOwnershipTest, | 507 TEST_F(WidgetOwnershipTest, |
558 Ownership_WidgetOwnsViewsNativeWidget_DestroyParentView) { | 508 Ownership_WidgetOwnsViewsNativeWidget_DestroyParentView) { |
559 OwnershipTestState state; | 509 OwnershipTestState state; |
560 | 510 |
561 Widget* toplevel = CreateTopLevelPlatformWidget(); | 511 Widget* toplevel = CreateTopLevelPlatformWidget(); |
562 | 512 |
563 scoped_ptr<Widget> widget(new OwnershipTestWidget(&state)); | 513 scoped_ptr<Widget> widget(new OwnershipTestWidget(&state)); |
564 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 514 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
565 params.native_widget = new OwnershipTestNativeWidgetViews(widget.get(), | 515 params.native_widget = |
566 &state); | 516 new OwnershipTestNativeWidgetPlatform(widget.get(), &state); |
567 params.parent_widget = toplevel; | 517 params.parent_widget = toplevel; |
568 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 518 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
569 widget->Init(params); | 519 widget->Init(params); |
570 | 520 |
571 // Now close the toplevel, which deletes the view hierarchy. | 521 // Now close the toplevel, which deletes the view hierarchy. |
572 toplevel->CloseNow(); | 522 toplevel->CloseNow(); |
573 | 523 |
574 RunPendingMessages(); | 524 RunPendingMessages(); |
575 | 525 |
576 // This shouldn't delete the widget because it shouldn't be deleted | 526 // This shouldn't delete the widget because it shouldn't be deleted |
577 // from the native side. | 527 // from the native side. |
578 EXPECT_FALSE(state.widget_deleted); | 528 EXPECT_FALSE(state.widget_deleted); |
579 EXPECT_FALSE(state.native_widget_deleted); | 529 EXPECT_FALSE(state.native_widget_deleted); |
580 | 530 |
581 // Now delete it explicitly. | 531 // Now delete it explicitly. |
582 widget.reset(); | 532 widget.reset(); |
583 | 533 |
584 EXPECT_TRUE(state.widget_deleted); | 534 EXPECT_TRUE(state.widget_deleted); |
585 EXPECT_TRUE(state.native_widget_deleted); | 535 EXPECT_TRUE(state.native_widget_deleted); |
586 } | 536 } |
587 | 537 |
588 // NativeWidget owns its Widget, part 1: NativeWidget is a platform-native | 538 // NativeWidget owns its Widget, part 1: NativeWidget is a platform-native |
589 // widget. | 539 // widget. |
590 TEST_F(WidgetOwnershipTest, Ownership_PlatformNativeWidgetOwnsWidget) { | 540 TEST_F(WidgetOwnershipTest, Ownership_PlatformNativeWidgetOwnsWidget) { |
591 OwnershipTestState state; | 541 OwnershipTestState state; |
592 | 542 |
593 Widget* widget = new OwnershipTestWidget(&state); | 543 Widget* widget = new OwnershipTestWidget(&state); |
594 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 544 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
595 params.native_widget = new OwnershipTestNativeWidget(widget, &state); | 545 params.native_widget = |
| 546 new OwnershipTestNativeWidgetPlatform(widget, &state); |
596 widget->Init(params); | 547 widget->Init(params); |
597 | 548 |
598 // Now destroy the native widget. | 549 // Now destroy the native widget. |
599 widget->CloseNow(); | 550 widget->CloseNow(); |
600 | 551 |
601 EXPECT_TRUE(state.widget_deleted); | 552 EXPECT_TRUE(state.widget_deleted); |
602 EXPECT_TRUE(state.native_widget_deleted); | 553 EXPECT_TRUE(state.native_widget_deleted); |
603 } | 554 } |
604 | 555 |
605 // NativeWidget owns its Widget, part 2: NativeWidget is a NativeWidgetViews. | 556 // NativeWidget owns its Widget, part 2: NativeWidget is a NativeWidget. |
606 TEST_F(WidgetOwnershipTest, Ownership_ViewsNativeWidgetOwnsWidget) { | 557 TEST_F(WidgetOwnershipTest, Ownership_ViewsNativeWidgetOwnsWidget) { |
607 OwnershipTestState state; | 558 OwnershipTestState state; |
608 | 559 |
609 Widget* toplevel = CreateTopLevelPlatformWidget(); | 560 Widget* toplevel = CreateTopLevelPlatformWidget(); |
610 | 561 |
611 Widget* widget = new OwnershipTestWidget(&state); | 562 Widget* widget = new OwnershipTestWidget(&state); |
612 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 563 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
613 params.native_widget = new OwnershipTestNativeWidgetViews(widget, &state); | 564 params.native_widget = |
| 565 new OwnershipTestNativeWidgetPlatform(widget, &state); |
614 params.parent_widget = toplevel; | 566 params.parent_widget = toplevel; |
615 widget->Init(params); | 567 widget->Init(params); |
616 | 568 |
617 // Now destroy the native widget. This is achieved by closing the toplevel. | 569 // Now destroy the native widget. This is achieved by closing the toplevel. |
618 toplevel->CloseNow(); | 570 toplevel->CloseNow(); |
619 | 571 |
620 // The NativeWidgetViews won't be deleted until after a return to the message | 572 // The NativeWidget won't be deleted until after a return to the message loop |
621 // loop so we have to run pending messages before testing the destruction | 573 // so we have to run pending messages before testing the destruction status. |
622 // status. | |
623 RunPendingMessages(); | 574 RunPendingMessages(); |
624 | 575 |
625 EXPECT_TRUE(state.widget_deleted); | 576 EXPECT_TRUE(state.widget_deleted); |
626 EXPECT_TRUE(state.native_widget_deleted); | 577 EXPECT_TRUE(state.native_widget_deleted); |
627 } | 578 } |
628 | 579 |
629 // NativeWidget owns its Widget, part 3: NativeWidget is a platform-native | 580 // NativeWidget owns its Widget, part 3: NativeWidget is a platform-native |
630 // widget, destroyed out from under it by the OS. | 581 // widget, destroyed out from under it by the OS. |
631 TEST_F(WidgetOwnershipTest, | 582 TEST_F(WidgetOwnershipTest, |
632 Ownership_PlatformNativeWidgetOwnsWidget_NativeDestroy) { | 583 Ownership_PlatformNativeWidgetOwnsWidget_NativeDestroy) { |
633 OwnershipTestState state; | 584 OwnershipTestState state; |
634 | 585 |
635 Widget* widget = new OwnershipTestWidget(&state); | 586 Widget* widget = new OwnershipTestWidget(&state); |
636 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 587 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
637 params.native_widget = new OwnershipTestNativeWidget(widget, &state); | 588 params.native_widget = |
| 589 new OwnershipTestNativeWidgetPlatform(widget, &state); |
638 widget->Init(params); | 590 widget->Init(params); |
639 | 591 |
640 // Now simulate a destroy of the platform native widget from the OS: | 592 // Now simulate a destroy of the platform native widget from the OS: |
641 #if defined(USE_AURA) | 593 #if defined(USE_AURA) |
642 delete widget->GetNativeView(); | 594 delete widget->GetNativeView(); |
643 #elif defined(OS_WIN) | 595 #elif defined(OS_WIN) |
644 DestroyWindow(widget->GetNativeView()); | 596 DestroyWindow(widget->GetNativeView()); |
645 #elif defined(TOOLKIT_USES_GTK) | 597 #elif defined(TOOLKIT_USES_GTK) |
646 gtk_widget_destroy(widget->GetNativeView()); | 598 gtk_widget_destroy(widget->GetNativeView()); |
647 #endif | 599 #endif |
648 | 600 |
649 EXPECT_TRUE(state.widget_deleted); | 601 EXPECT_TRUE(state.widget_deleted); |
650 EXPECT_TRUE(state.native_widget_deleted); | 602 EXPECT_TRUE(state.native_widget_deleted); |
651 } | 603 } |
652 | 604 |
653 // NativeWidget owns its Widget, part 4: NativeWidget is a NativeWidgetViews, | 605 // NativeWidget owns its Widget, part 4: NativeWidget is a NativeWidget, |
654 // destroyed by the view hierarchy that contains it. | 606 // destroyed by the view hierarchy that contains it. |
655 TEST_F(WidgetOwnershipTest, | 607 TEST_F(WidgetOwnershipTest, |
656 Ownership_ViewsNativeWidgetOwnsWidget_NativeDestroy) { | 608 Ownership_ViewsNativeWidgetOwnsWidget_NativeDestroy) { |
657 OwnershipTestState state; | 609 OwnershipTestState state; |
658 | 610 |
659 Widget* toplevel = CreateTopLevelPlatformWidget(); | 611 Widget* toplevel = CreateTopLevelPlatformWidget(); |
660 | 612 |
661 Widget* widget = new OwnershipTestWidget(&state); | 613 Widget* widget = new OwnershipTestWidget(&state); |
662 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 614 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
663 params.native_widget = new OwnershipTestNativeWidgetViews(widget, &state); | 615 params.native_widget = |
| 616 new OwnershipTestNativeWidgetPlatform(widget, &state); |
664 params.parent_widget = toplevel; | 617 params.parent_widget = toplevel; |
665 widget->Init(params); | 618 widget->Init(params); |
666 | 619 |
667 // Destroy the widget (achieved by closing the toplevel). | 620 // Destroy the widget (achieved by closing the toplevel). |
668 toplevel->CloseNow(); | 621 toplevel->CloseNow(); |
669 | 622 |
670 // The NativeWidgetViews won't be deleted until after a return to the message | 623 // The NativeWidget won't be deleted until after a return to the message loop |
671 // loop so we have to run pending messages before testing the destruction | 624 // so we have to run pending messages before testing the destruction status. |
672 // status. | |
673 RunPendingMessages(); | 625 RunPendingMessages(); |
674 | 626 |
675 EXPECT_TRUE(state.widget_deleted); | 627 EXPECT_TRUE(state.widget_deleted); |
676 EXPECT_TRUE(state.native_widget_deleted); | 628 EXPECT_TRUE(state.native_widget_deleted); |
677 } | 629 } |
678 | 630 |
679 // NativeWidget owns its Widget, part 5: NativeWidget is a NativeWidgetViews, | 631 // NativeWidget owns its Widget, part 5: NativeWidget is a NativeWidget, |
680 // we close it directly. | 632 // we close it directly. |
681 TEST_F(WidgetOwnershipTest, | 633 TEST_F(WidgetOwnershipTest, |
682 Ownership_ViewsNativeWidgetOwnsWidget_Close) { | 634 Ownership_ViewsNativeWidgetOwnsWidget_Close) { |
683 OwnershipTestState state; | 635 OwnershipTestState state; |
684 | 636 |
685 Widget* toplevel = CreateTopLevelPlatformWidget(); | 637 Widget* toplevel = CreateTopLevelPlatformWidget(); |
686 | 638 |
687 Widget* widget = new OwnershipTestWidget(&state); | 639 Widget* widget = new OwnershipTestWidget(&state); |
688 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 640 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
689 params.native_widget = new OwnershipTestNativeWidgetViews(widget, &state); | 641 params.native_widget = |
| 642 new OwnershipTestNativeWidgetPlatform(widget, &state); |
690 params.parent_widget = toplevel; | 643 params.parent_widget = toplevel; |
691 widget->Init(params); | 644 widget->Init(params); |
692 | 645 |
693 // Destroy the widget. | 646 // Destroy the widget. |
694 widget->Close(); | 647 widget->Close(); |
695 toplevel->CloseNow(); | 648 toplevel->CloseNow(); |
696 | 649 |
697 // The NativeWidgetViews won't be deleted until after a return to the message | 650 // The NativeWidget won't be deleted until after a return to the message loop |
698 // loop so we have to run pending messages before testing the destruction | 651 // so we have to run pending messages before testing the destruction status. |
699 // status. | |
700 RunPendingMessages(); | 652 RunPendingMessages(); |
701 | 653 |
702 EXPECT_TRUE(state.widget_deleted); | 654 EXPECT_TRUE(state.widget_deleted); |
703 EXPECT_TRUE(state.native_widget_deleted); | 655 EXPECT_TRUE(state.native_widget_deleted); |
704 } | 656 } |
705 | 657 |
706 //////////////////////////////////////////////////////////////////////////////// | 658 //////////////////////////////////////////////////////////////////////////////// |
707 // Widget observer tests. | 659 // Widget observer tests. |
708 // | 660 // |
709 | 661 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 void reset() { | 703 void reset() { |
752 active_ = NULL; | 704 active_ = NULL; |
753 widget_closed_ = NULL; | 705 widget_closed_ = NULL; |
754 widget_activated_ = NULL; | 706 widget_activated_ = NULL; |
755 widget_deactivated_ = NULL; | 707 widget_deactivated_ = NULL; |
756 widget_shown_ = NULL; | 708 widget_shown_ = NULL; |
757 widget_hidden_ = NULL; | 709 widget_hidden_ = NULL; |
758 } | 710 } |
759 | 711 |
760 Widget* NewWidget() { | 712 Widget* NewWidget() { |
761 Widget* widget = CreateTopLevelNativeWidgetViews(); | 713 Widget* widget = CreateTopLevelNativeWidget(); |
762 widget->AddObserver(this); | 714 widget->AddObserver(this); |
763 return widget; | 715 return widget; |
764 } | 716 } |
765 | 717 |
766 const Widget* active() const { return active_; } | 718 const Widget* active() const { return active_; } |
767 const Widget* widget_closed() const { return widget_closed_; } | 719 const Widget* widget_closed() const { return widget_closed_; } |
768 const Widget* widget_activated() const { return widget_activated_; } | 720 const Widget* widget_activated() const { return widget_activated_; } |
769 const Widget* widget_deactivated() const { return widget_deactivated_; } | 721 const Widget* widget_deactivated() const { return widget_deactivated_; } |
770 const Widget* widget_shown() const { return widget_shown_; } | 722 const Widget* widget_shown() const { return widget_shown_; } |
771 const Widget* widget_hidden() const { return widget_hidden_; } | 723 const Widget* widget_hidden() const { return widget_hidden_; } |
772 | 724 |
773 private: | 725 private: |
774 | 726 |
775 Widget* active_; | 727 Widget* active_; |
776 | 728 |
777 Widget* widget_closed_; | 729 Widget* widget_closed_; |
778 Widget* widget_activated_; | 730 Widget* widget_activated_; |
779 Widget* widget_deactivated_; | 731 Widget* widget_deactivated_; |
780 Widget* widget_shown_; | 732 Widget* widget_shown_; |
781 Widget* widget_hidden_; | 733 Widget* widget_hidden_; |
782 }; | 734 }; |
783 | 735 |
784 TEST_F(WidgetObserverTest, ActivationChange) { | 736 TEST_F(WidgetObserverTest, DISABLED_ActivationChange) { |
785 Widget* toplevel = CreateTopLevelPlatformWidget(); | 737 Widget* toplevel = CreateTopLevelPlatformWidget(); |
786 widget_views_delegate().set_default_parent_view(toplevel->GetRootView()); | |
787 | 738 |
788 Widget* toplevel1 = NewWidget(); | 739 Widget* toplevel1 = NewWidget(); |
789 Widget* toplevel2 = NewWidget(); | 740 Widget* toplevel2 = NewWidget(); |
790 | 741 |
791 toplevel1->Show(); | 742 toplevel1->Show(); |
792 toplevel2->Show(); | 743 toplevel2->Show(); |
793 | 744 |
794 reset(); | 745 reset(); |
795 | 746 |
796 toplevel1->Activate(); | 747 toplevel1->Activate(); |
797 | 748 |
798 RunPendingMessages(); | 749 RunPendingMessages(); |
799 EXPECT_EQ(toplevel1, widget_activated()); | 750 EXPECT_EQ(toplevel1, widget_activated()); |
800 | 751 |
801 toplevel2->Activate(); | 752 toplevel2->Activate(); |
802 RunPendingMessages(); | 753 RunPendingMessages(); |
803 EXPECT_EQ(toplevel1, widget_deactivated()); | 754 EXPECT_EQ(toplevel1, widget_deactivated()); |
804 EXPECT_EQ(toplevel2, widget_activated()); | 755 EXPECT_EQ(toplevel2, widget_activated()); |
805 EXPECT_EQ(toplevel2, active()); | 756 EXPECT_EQ(toplevel2, active()); |
806 | 757 |
807 toplevel->CloseNow(); | 758 toplevel->CloseNow(); |
808 } | 759 } |
809 | 760 |
810 TEST_F(WidgetObserverTest, VisibilityChange) { | 761 TEST_F(WidgetObserverTest, DISABLED_VisibilityChange) { |
811 Widget* toplevel = CreateTopLevelPlatformWidget(); | 762 Widget* toplevel = CreateTopLevelPlatformWidget(); |
812 widget_views_delegate().set_default_parent_view(toplevel->GetRootView()); | |
813 | 763 |
814 Widget* child1 = NewWidget(); | 764 Widget* child1 = NewWidget(); |
815 Widget* child2 = NewWidget(); | 765 Widget* child2 = NewWidget(); |
816 | 766 |
817 toplevel->Show(); | 767 toplevel->Show(); |
818 child1->Show(); | 768 child1->Show(); |
819 child2->Show(); | 769 child2->Show(); |
820 | 770 |
821 reset(); | 771 reset(); |
822 | 772 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 RunPendingMessages(); | 809 RunPendingMessages(); |
860 EXPECT_NE(toplevel->GetWindowScreenBounds().ToString(), | 810 EXPECT_NE(toplevel->GetWindowScreenBounds().ToString(), |
861 toplevel->GetRestoredBounds().ToString()); | 811 toplevel->GetRestoredBounds().ToString()); |
862 EXPECT_GT(toplevel->GetRestoredBounds().width(), 0); | 812 EXPECT_GT(toplevel->GetRestoredBounds().width(), 0); |
863 EXPECT_GT(toplevel->GetRestoredBounds().height(), 0); | 813 EXPECT_GT(toplevel->GetRestoredBounds().height(), 0); |
864 } | 814 } |
865 #endif | 815 #endif |
866 | 816 |
867 } // namespace | 817 } // namespace |
868 } // namespace views | 818 } // namespace views |
OLD | NEW |