OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/wm/core/transient_window_manager.h" | 5 #include "ui/wm/core/transient_window_manager.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "ui/aura/client/window_tree_client.h" | 9 #include "ui/aura/client/window_tree_client.h" |
8 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
9 #include "ui/aura/test/test_windows.h" | 11 #include "ui/aura/test/test_windows.h" |
10 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
11 #include "ui/aura/window_observer.h" | 13 #include "ui/aura/window_observer.h" |
12 #include "ui/wm/core/transient_window_observer.h" | 14 #include "ui/wm/core/transient_window_observer.h" |
13 #include "ui/wm/core/window_util.h" | 15 #include "ui/wm/core/window_util.h" |
14 #include "ui/wm/core/wm_state.h" | 16 #include "ui/wm/core/wm_state.h" |
15 | 17 |
16 using aura::Window; | 18 using aura::Window; |
(...skipping 25 matching lines...) Expand all Loading... |
42 int add_count_; | 44 int add_count_; |
43 int remove_count_; | 45 int remove_count_; |
44 | 46 |
45 DISALLOW_COPY_AND_ASSIGN(TestTransientWindowObserver); | 47 DISALLOW_COPY_AND_ASSIGN(TestTransientWindowObserver); |
46 }; | 48 }; |
47 | 49 |
48 class WindowVisibilityObserver : public aura::WindowObserver { | 50 class WindowVisibilityObserver : public aura::WindowObserver { |
49 public: | 51 public: |
50 WindowVisibilityObserver(Window* observed_window, | 52 WindowVisibilityObserver(Window* observed_window, |
51 scoped_ptr<Window> owned_window) | 53 scoped_ptr<Window> owned_window) |
52 : observed_window_(observed_window), owned_window_(owned_window.Pass()) { | 54 : observed_window_(observed_window), |
| 55 owned_window_(std::move(owned_window)) { |
53 observed_window_->AddObserver(this); | 56 observed_window_->AddObserver(this); |
54 } | 57 } |
55 ~WindowVisibilityObserver() override { | 58 ~WindowVisibilityObserver() override { |
56 observed_window_->RemoveObserver(this); | 59 observed_window_->RemoveObserver(this); |
57 } | 60 } |
58 | 61 |
59 void OnWindowVisibilityChanged(Window* window, bool visible) override { | 62 void OnWindowVisibilityChanged(Window* window, bool visible) override { |
60 owned_window_.reset(); | 63 owned_window_.reset(); |
61 } | 64 } |
62 private: | 65 private: |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 } | 338 } |
336 | 339 |
337 // Tests for a crash when window destroyed inside | 340 // Tests for a crash when window destroyed inside |
338 // UpdateTransientChildVisibility loop. | 341 // UpdateTransientChildVisibility loop. |
339 TEST_F(TransientWindowManagerTest, CrashOnVisibilityChange) { | 342 TEST_F(TransientWindowManagerTest, CrashOnVisibilityChange) { |
340 scoped_ptr<Window> window1(CreateTransientChild(1, root_window())); | 343 scoped_ptr<Window> window1(CreateTransientChild(1, root_window())); |
341 scoped_ptr<Window> window2(CreateTransientChild(2, root_window())); | 344 scoped_ptr<Window> window2(CreateTransientChild(2, root_window())); |
342 window1->Show(); | 345 window1->Show(); |
343 window2->Show(); | 346 window2->Show(); |
344 | 347 |
345 WindowVisibilityObserver visibility_observer(window1.get(), window2.Pass()); | 348 WindowVisibilityObserver visibility_observer(window1.get(), |
| 349 std::move(window2)); |
346 root_window()->Hide(); | 350 root_window()->Hide(); |
347 } | 351 } |
348 // Tests that windows are restacked properly after a call to AddTransientChild() | 352 // Tests that windows are restacked properly after a call to AddTransientChild() |
349 // or RemoveTransientChild(). | 353 // or RemoveTransientChild(). |
350 TEST_F(TransientWindowManagerTest, RestackUponAddOrRemoveTransientChild) { | 354 TEST_F(TransientWindowManagerTest, RestackUponAddOrRemoveTransientChild) { |
351 scoped_ptr<Window> windows[4]; | 355 scoped_ptr<Window> windows[4]; |
352 for (int i = 0; i < 4; i++) | 356 for (int i = 0; i < 4; i++) |
353 windows[i].reset(CreateTestWindowWithId(i, root_window())); | 357 windows[i].reset(CreateTestWindowWithId(i, root_window())); |
354 EXPECT_EQ("0 1 2 3", ChildWindowIDsAsString(root_window())); | 358 EXPECT_EQ("0 1 2 3", ChildWindowIDsAsString(root_window())); |
355 | 359 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 EXPECT_EQ(0, test_observer.remove_count()); | 454 EXPECT_EQ(0, test_observer.remove_count()); |
451 | 455 |
452 RemoveTransientChild(parent.get(), w1.get()); | 456 RemoveTransientChild(parent.get(), w1.get()); |
453 EXPECT_EQ(1, test_observer.add_count()); | 457 EXPECT_EQ(1, test_observer.add_count()); |
454 EXPECT_EQ(1, test_observer.remove_count()); | 458 EXPECT_EQ(1, test_observer.remove_count()); |
455 | 459 |
456 TransientWindowManager::Get(parent.get())->RemoveObserver(&test_observer); | 460 TransientWindowManager::Get(parent.get())->RemoveObserver(&test_observer); |
457 } | 461 } |
458 | 462 |
459 } // namespace wm | 463 } // namespace wm |
OLD | NEW |