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

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

Issue 11416251: Desktop aura: Continue threading context through views. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One last line removed. Created 8 years 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 | Annotate | Revision Log
« ui/views/test/views_test_base.cc ('K') | « ui/views/widget/widget.h ('k') | no next file » | 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gfx/native_widget_types.h" 10 #include "ui/gfx/native_widget_types.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (event->type() == ui::ET_GESTURE_BEGIN) { 131 if (event->type() == ui::ET_GESTURE_BEGIN) {
132 GetWidget()->SetCapture(this); 132 GetWidget()->SetCapture(this);
133 return ui::ER_CONSUMED; 133 return ui::ER_CONSUMED;
134 } 134 }
135 return ui::ER_UNHANDLED; 135 return ui::ER_UNHANDLED;
136 } 136 }
137 137
138 DISALLOW_COPY_AND_ASSIGN(GestureCaptureView); 138 DISALLOW_COPY_AND_ASSIGN(GestureCaptureView);
139 }; 139 };
140 140
141 typedef ViewsTestBase WidgetTest; 141 class WidgetTest : public ViewsTestBase {
142 public:
143 WidgetTest() {}
144 virtual ~WidgetTest() {}
142 145
143 NativeWidget* CreatePlatformNativeWidget( 146 NativeWidget* CreatePlatformNativeWidget(
144 internal::NativeWidgetDelegate* delegate) { 147 internal::NativeWidgetDelegate* delegate) {
145 return new NativeWidgetPlatformForTest(delegate); 148 return new NativeWidgetPlatformForTest(delegate);
146 } 149 }
147 150
148 Widget* CreateTopLevelPlatformWidget() { 151 Widget* CreateTopLevelPlatformWidget() {
149 Widget* toplevel = new Widget; 152 Widget* toplevel = new Widget;
150 Widget::InitParams toplevel_params(Widget::InitParams::TYPE_WINDOW); 153 Widget::InitParams toplevel_params =
151 toplevel_params.native_widget = CreatePlatformNativeWidget(toplevel); 154 CreateParams(Widget::InitParams::TYPE_WINDOW);
152 toplevel->Init(toplevel_params); 155 toplevel_params.native_widget = CreatePlatformNativeWidget(toplevel);
153 return toplevel; 156 toplevel->Init(toplevel_params);
154 } 157 return toplevel;
158 }
155 159
156 Widget* CreateChildPlatformWidget(gfx::NativeView parent_native_view) { 160 Widget* CreateChildPlatformWidget(gfx::NativeView parent_native_view) {
157 Widget* child = new Widget; 161 Widget* child = new Widget;
158 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL); 162 Widget::InitParams child_params =
159 child_params.native_widget = CreatePlatformNativeWidget(child); 163 CreateParams(Widget::InitParams::TYPE_CONTROL);
160 child_params.parent = parent_native_view; 164 child_params.native_widget = CreatePlatformNativeWidget(child);
161 child->Init(child_params); 165 child_params.parent = parent_native_view;
162 child->SetContentsView(new View); 166 child->Init(child_params);
163 return child; 167 child->SetContentsView(new View);
164 } 168 return child;
169 }
165 170
166 #if defined(OS_WIN) && !defined(USE_AURA) 171 #if defined(OS_WIN) && !defined(USE_AURA)
167 // On Windows, it is possible for us to have a child window that is TYPE_POPUP. 172 // On Windows, it is possible for us to have a child window that is
168 Widget* CreateChildPopupPlatformWidget(gfx::NativeView parent_native_view) { 173 // TYPE_POPUP.
169 Widget* child = new Widget; 174 Widget* CreateChildPopupPlatformWidget(gfx::NativeView parent_native_view) {
170 Widget::InitParams child_params(Widget::InitParams::TYPE_POPUP); 175 Widget* child = new Widget;
171 child_params.child = true; 176 Widget::InitParams child_params =
172 child_params.native_widget = CreatePlatformNativeWidget(child); 177 CreateParams(Widget::InitParams::TYPE_POPUP);
173 child_params.parent = parent_native_view; 178 child_params.child = true;
174 child->Init(child_params); 179 child_params.native_widget = CreatePlatformNativeWidget(child);
175 child->SetContentsView(new View); 180 child_params.parent = parent_native_view;
176 return child; 181 child->Init(child_params);
177 } 182 child->SetContentsView(new View);
183 return child;
184 }
178 #endif 185 #endif
179 186
180 Widget* CreateTopLevelNativeWidget() { 187 Widget* CreateTopLevelNativeWidget() {
181 Widget* toplevel = new Widget; 188 Widget* toplevel = new Widget;
182 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); 189 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
183 toplevel->Init(params); 190 toplevel->Init(params);
184 toplevel->SetContentsView(new View); 191 toplevel->SetContentsView(new View);
185 return toplevel; 192 return toplevel;
186 } 193 }
187 194
188 Widget* CreateChildNativeWidgetWithParent(Widget* parent) { 195 Widget* CreateChildNativeWidgetWithParent(Widget* parent) {
189 Widget* child = new Widget; 196 Widget* child = new Widget;
190 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); 197 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_CONTROL);
191 params.parent_widget = parent; 198 params.parent_widget = parent;
192 child->Init(params); 199 child->Init(params);
193 child->SetContentsView(new View); 200 child->SetContentsView(new View);
194 return child; 201 return child;
195 } 202 }
196 203
197 Widget* CreateChildNativeWidget() { 204 Widget* CreateChildNativeWidget() {
198 return CreateChildNativeWidgetWithParent(NULL); 205 return CreateChildNativeWidgetWithParent(NULL);
199 } 206 }
207 };
200 208
201 bool WidgetHasMouseCapture(const Widget* widget) { 209 bool WidgetHasMouseCapture(const Widget* widget) {
202 return static_cast<const internal::NativeWidgetPrivate*>(widget-> 210 return static_cast<const internal::NativeWidgetPrivate*>(widget->
203 native_widget())->HasCapture(); 211 native_widget())->HasCapture();
204 } 212 }
205 213
206 ui::WindowShowState GetWidgetShowState(const Widget* widget) { 214 ui::WindowShowState GetWidgetShowState(const Widget* widget) {
207 // Use IsMaximized/IsMinimized/IsFullScreen instead of GetWindowPlacement 215 // Use IsMaximized/IsMinimized/IsFullScreen instead of GetWindowPlacement
208 // because the former is implemented on all platforms but the latter is not. 216 // because the former is implemented on all platforms but the latter is not.
209 return widget->IsFullscreen() ? ui::SHOW_STATE_FULLSCREEN : 217 return widget->IsFullscreen() ? ui::SHOW_STATE_FULLSCREEN :
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 526
519 DISALLOW_COPY_AND_ASSIGN(OwnershipTestWidget); 527 DISALLOW_COPY_AND_ASSIGN(OwnershipTestWidget);
520 }; 528 };
521 529
522 // Widget owns its NativeWidget, part 1: NativeWidget is a platform-native 530 // Widget owns its NativeWidget, part 1: NativeWidget is a platform-native
523 // widget. 531 // widget.
524 TEST_F(WidgetOwnershipTest, Ownership_WidgetOwnsPlatformNativeWidget) { 532 TEST_F(WidgetOwnershipTest, Ownership_WidgetOwnsPlatformNativeWidget) {
525 OwnershipTestState state; 533 OwnershipTestState state;
526 534
527 scoped_ptr<Widget> widget(new OwnershipTestWidget(&state)); 535 scoped_ptr<Widget> widget(new OwnershipTestWidget(&state));
528 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 536 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
529 params.native_widget = 537 params.native_widget =
530 new OwnershipTestNativeWidgetPlatform(widget.get(), &state); 538 new OwnershipTestNativeWidgetPlatform(widget.get(), &state);
531 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
532 widget->Init(params); 539 widget->Init(params);
533 540
534 // Now delete the Widget, which should delete the NativeWidget. 541 // Now delete the Widget, which should delete the NativeWidget.
535 widget.reset(); 542 widget.reset();
536 543
537 EXPECT_TRUE(state.widget_deleted); 544 EXPECT_TRUE(state.widget_deleted);
538 EXPECT_TRUE(state.native_widget_deleted); 545 EXPECT_TRUE(state.native_widget_deleted);
539 546
540 // TODO(beng): write test for this ownership scenario and the NativeWidget 547 // TODO(beng): write test for this ownership scenario and the NativeWidget
541 // being deleted out from under the Widget. 548 // being deleted out from under the Widget.
542 } 549 }
543 550
544 // Widget owns its NativeWidget, part 2: NativeWidget is a NativeWidget. 551 // Widget owns its NativeWidget, part 2: NativeWidget is a NativeWidget.
545 TEST_F(WidgetOwnershipTest, Ownership_WidgetOwnsViewsNativeWidget) { 552 TEST_F(WidgetOwnershipTest, Ownership_WidgetOwnsViewsNativeWidget) {
546 OwnershipTestState state; 553 OwnershipTestState state;
547 554
548 scoped_ptr<Widget> widget(new OwnershipTestWidget(&state)); 555 scoped_ptr<Widget> widget(new OwnershipTestWidget(&state));
549 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 556 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
550 params.native_widget = 557 params.native_widget =
551 new OwnershipTestNativeWidgetPlatform(widget.get(), &state); 558 new OwnershipTestNativeWidgetPlatform(widget.get(), &state);
552 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
553 widget->Init(params); 559 widget->Init(params);
554 560
555 // Now delete the Widget, which should delete the NativeWidget. 561 // Now delete the Widget, which should delete the NativeWidget.
556 widget.reset(); 562 widget.reset();
557 563
558 EXPECT_TRUE(state.widget_deleted); 564 EXPECT_TRUE(state.widget_deleted);
559 EXPECT_TRUE(state.native_widget_deleted); 565 EXPECT_TRUE(state.native_widget_deleted);
560 566
561 // TODO(beng): write test for this ownership scenario and the NativeWidget 567 // TODO(beng): write test for this ownership scenario and the NativeWidget
562 // being deleted out from under the Widget. 568 // being deleted out from under the Widget.
563 } 569 }
564 570
565 // Widget owns its NativeWidget, part 3: NativeWidget is a NativeWidget, 571 // Widget owns its NativeWidget, part 3: NativeWidget is a NativeWidget,
566 // destroy the parent view. 572 // destroy the parent view.
567 TEST_F(WidgetOwnershipTest, 573 TEST_F(WidgetOwnershipTest,
568 Ownership_WidgetOwnsViewsNativeWidget_DestroyParentView) { 574 Ownership_WidgetOwnsViewsNativeWidget_DestroyParentView) {
569 OwnershipTestState state; 575 OwnershipTestState state;
570 576
571 Widget* toplevel = CreateTopLevelPlatformWidget(); 577 Widget* toplevel = CreateTopLevelPlatformWidget();
572 578
573 scoped_ptr<Widget> widget(new OwnershipTestWidget(&state)); 579 scoped_ptr<Widget> widget(new OwnershipTestWidget(&state));
574 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 580 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
575 params.native_widget = 581 params.native_widget =
576 new OwnershipTestNativeWidgetPlatform(widget.get(), &state); 582 new OwnershipTestNativeWidgetPlatform(widget.get(), &state);
577 params.parent_widget = toplevel; 583 params.parent_widget = toplevel;
578 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
579 widget->Init(params); 584 widget->Init(params);
580 585
581 // Now close the toplevel, which deletes the view hierarchy. 586 // Now close the toplevel, which deletes the view hierarchy.
582 toplevel->CloseNow(); 587 toplevel->CloseNow();
583 588
584 RunPendingMessages(); 589 RunPendingMessages();
585 590
586 // This shouldn't delete the widget because it shouldn't be deleted 591 // This shouldn't delete the widget because it shouldn't be deleted
587 // from the native side. 592 // from the native side.
588 EXPECT_FALSE(state.widget_deleted); 593 EXPECT_FALSE(state.widget_deleted);
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 EXPECT_TRUE(toplevel->OnKeyEvent(backspace_p)); 1002 EXPECT_TRUE(toplevel->OnKeyEvent(backspace_p));
998 ui::KeyEvent backspace_r(ui::ET_KEY_RELEASED, ui::VKEY_DELETE, 0, false); 1003 ui::KeyEvent backspace_r(ui::ET_KEY_RELEASED, ui::VKEY_DELETE, 0, false);
999 EXPECT_FALSE(toplevel->OnKeyEvent(backspace_r)); 1004 EXPECT_FALSE(toplevel->OnKeyEvent(backspace_r));
1000 1005
1001 toplevel->Close(); 1006 toplevel->Close();
1002 } 1007 }
1003 #endif // defined(USE_AURA) 1008 #endif // defined(USE_AURA)
1004 1009
1005 } // namespace 1010 } // namespace
1006 } // namespace views 1011 } // namespace views
OLDNEW
« ui/views/test/views_test_base.cc ('K') | « ui/views/widget/widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698