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

Side by Side Diff: ui/views/test/widget_test.cc

Issue 2875513003: cleanup: make WidgetClosingObserver as test support (Closed)
Patch Set: Created 3 years, 7 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.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/test/widget_test.h" 5 #include "ui/views/test/widget_test.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "ui/gfx/native_widget_types.h" 8 #include "ui/gfx/native_widget_types.h"
9 #include "ui/views/test/native_widget_factory.h" 9 #include "ui/views/test/native_widget_factory.h"
10 #include "ui/views/widget/root_view.h" 10 #include "ui/views/widget/root_view.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 Widget* WidgetTest::CreateChildNativeWidgetWithParent(Widget* parent) { 61 Widget* WidgetTest::CreateChildNativeWidgetWithParent(Widget* parent) {
62 Widget* child = new Widget; 62 Widget* child = new Widget;
63 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_CONTROL); 63 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_CONTROL);
64 params.parent = parent->GetNativeView(); 64 params.parent = parent->GetNativeView();
65 child->Init(params); 65 child->Init(params);
66 child->SetContentsView(new View); 66 child->SetContentsView(new View);
67 return child; 67 return child;
68 } 68 }
69 69
70 Widget* WidgetTest::CreateChildNativeWidget() { 70 Widget* WidgetTest::CreateChildNativeWidget() {
71 return CreateChildNativeWidgetWithParent(NULL); 71 return CreateChildNativeWidgetWithParent(nullptr);
72 } 72 }
73 73
74 Widget* WidgetTest::CreateNativeDesktopWidget() { 74 Widget* WidgetTest::CreateNativeDesktopWidget() {
75 Widget* widget = new Widget; 75 Widget* widget = new Widget;
76 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); 76 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
77 params.native_widget = 77 params.native_widget =
78 CreatePlatformDesktopNativeWidgetImpl(params, widget, nullptr); 78 CreatePlatformDesktopNativeWidgetImpl(params, widget, nullptr);
79 widget->Init(params); 79 widget->Init(params);
80 return widget; 80 return widget;
81 } 81 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 bool active) { 170 bool active) {
171 if (active_ != active) 171 if (active_ != active)
172 return; 172 return;
173 173
174 observed_ = true; 174 observed_ = true;
175 widget->RemoveObserver(this); 175 widget->RemoveObserver(this);
176 if (run_loop_.running()) 176 if (run_loop_.running())
177 run_loop_.Quit(); 177 run_loop_.Quit();
178 } 178 }
179 179
180 WidgetClosingObserver::WidgetClosingObserver(Widget* widget) : widget_(widget) {
181 widget_->AddObserver(this);
182 }
183
184 WidgetClosingObserver::~WidgetClosingObserver() {
185 if (widget_)
186 widget_->RemoveObserver(this);
187 }
188
189 void WidgetClosingObserver::OnWidgetClosing(Widget* widget) {
190 DCHECK_EQ(widget_, widget);
191 widget_->RemoveObserver(this);
192 widget_ = nullptr;
193 }
194
180 } // namespace test 195 } // namespace test
181 } // namespace views 196 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/test/widget_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698