OLD | NEW |
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/widget/desktop_aura/desktop_native_widget_aura.h" | 5 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "ui/aura/client/cursor_client.h" | 8 #include "ui/aura/client/cursor_client.h" |
9 #include "ui/aura/test/test_window_delegate.h" | 9 #include "ui/aura/test/test_window_delegate.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // Owned by |widget|. | 182 // Owned by |widget|. |
183 aura::Window* window = new aura::Window(&delegate); | 183 aura::Window* window = new aura::Window(&delegate); |
184 window->Show(); | 184 window->Show(); |
185 widget.GetNativeWindow()->parent()->AddChild(window); | 185 widget.GetNativeWindow()->parent()->AddChild(window); |
186 | 186 |
187 widget.Show(); | 187 widget.Show(); |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 void QuitNestedLoopAndCloseWidget(scoped_ptr<Widget> widget, | 191 void QuitNestedLoopAndCloseWidget(scoped_ptr<Widget> widget, |
192 aura::client::DispatcherClient* client) { | 192 base::Closure* quit_runloop) { |
193 client->QuitNestedMessageLoop(); | 193 quit_runloop->Run(); |
194 } | 194 } |
195 | 195 |
196 // Verifies that a widget can be destroyed when running a nested message-loop. | 196 // Verifies that a widget can be destroyed when running a nested message-loop. |
197 TEST_F(DesktopNativeWidgetAuraTest, WidgetCanBeDestroyedFromNestedLoop) { | 197 TEST_F(DesktopNativeWidgetAuraTest, WidgetCanBeDestroyedFromNestedLoop) { |
198 scoped_ptr<Widget> widget(new Widget); | 198 scoped_ptr<Widget> widget(new Widget); |
199 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 199 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
200 params.bounds = gfx::Rect(0, 0, 200, 200); | 200 params.bounds = gfx::Rect(0, 0, 200, 200); |
201 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 201 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
202 params.native_widget = new DesktopNativeWidgetAura(widget.get()); | 202 params.native_widget = new DesktopNativeWidgetAura(widget.get()); |
203 widget->Init(params); | 203 widget->Init(params); |
204 widget->Show(); | 204 widget->Show(); |
205 | 205 |
206 aura::Window* window = widget->GetNativeView(); | 206 aura::Window* window = widget->GetNativeView(); |
207 aura::Window* root = window->GetRootWindow(); | 207 aura::Window* root = window->GetRootWindow(); |
208 aura::client::DispatcherClient* client = | 208 aura::client::DispatcherClient* client = |
209 aura::client::GetDispatcherClient(root); | 209 aura::client::GetDispatcherClient(root); |
210 | 210 |
211 // Post a task that terminates the nested loop and destroyes the widget. This | 211 // Post a task that terminates the nested loop and destroyes the widget. This |
212 // task will be executed from the nested loop initiated with the call to | 212 // task will be executed from the nested loop initiated with the call to |
213 // |RunWithDispatcher()| below. | 213 // |RunWithDispatcher()| below. |
| 214 aura::client::DispatcherRunLoop run_loop(client, NULL); |
| 215 base::Closure quit_runloop = run_loop.QuitClosure(); |
214 message_loop()->PostTask(FROM_HERE, | 216 message_loop()->PostTask(FROM_HERE, |
215 base::Bind(&QuitNestedLoopAndCloseWidget, base::Passed(&widget), client)); | 217 base::Bind(&QuitNestedLoopAndCloseWidget, |
216 client->RunWithDispatcher(NULL); | 218 base::Passed(&widget), |
| 219 base::Unretained(&quit_runloop))); |
| 220 run_loop.Run(); |
217 } | 221 } |
218 | 222 |
219 } // namespace views | 223 } // namespace views |
OLD | NEW |