| 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 "ui/aura/client/window_tree_client.h" | 7 #include "ui/aura/client/window_tree_client.h" |
| 8 #include "ui/aura/test/aura_test_base.h" | 8 #include "ui/aura/test/aura_test_base.h" |
| 9 #include "ui/aura/test/test_windows.h" | 9 #include "ui/aura/test/test_windows.h" |
| 10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 11 #include "ui/aura/window_observer.h" |
| 11 #include "ui/wm/core/transient_window_observer.h" | 12 #include "ui/wm/core/transient_window_observer.h" |
| 12 #include "ui/wm/core/window_util.h" | 13 #include "ui/wm/core/window_util.h" |
| 13 #include "ui/wm/core/wm_state.h" | 14 #include "ui/wm/core/wm_state.h" |
| 14 | 15 |
| 15 using aura::Window; | 16 using aura::Window; |
| 16 | 17 |
| 17 using aura::test::ChildWindowIDsAsString; | 18 using aura::test::ChildWindowIDsAsString; |
| 18 using aura::test::CreateTestWindowWithId; | 19 using aura::test::CreateTestWindowWithId; |
| 19 | 20 |
| 20 namespace wm { | 21 namespace wm { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 37 remove_count_++; | 38 remove_count_++; |
| 38 } | 39 } |
| 39 | 40 |
| 40 private: | 41 private: |
| 41 int add_count_; | 42 int add_count_; |
| 42 int remove_count_; | 43 int remove_count_; |
| 43 | 44 |
| 44 DISALLOW_COPY_AND_ASSIGN(TestTransientWindowObserver); | 45 DISALLOW_COPY_AND_ASSIGN(TestTransientWindowObserver); |
| 45 }; | 46 }; |
| 46 | 47 |
| 48 class WindowVisibilityObserver : public aura::WindowObserver { |
| 49 public: |
| 50 WindowVisibilityObserver(Window* observed_window, |
| 51 scoped_ptr<Window> owned_window) |
| 52 : observed_window_(observed_window), owned_window_(owned_window.Pass()) { |
| 53 observed_window_->AddObserver(this); |
| 54 } |
| 55 ~WindowVisibilityObserver() override { |
| 56 observed_window_->RemoveObserver(this); |
| 57 } |
| 58 |
| 59 void OnWindowVisibilityChanged(Window* window, bool visible) override { |
| 60 owned_window_.reset(); |
| 61 } |
| 62 private: |
| 63 Window* observed_window_; |
| 64 scoped_ptr<Window> owned_window_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(WindowVisibilityObserver); |
| 67 }; |
| 68 |
| 47 class TransientWindowManagerTest : public aura::test::AuraTestBase { | 69 class TransientWindowManagerTest : public aura::test::AuraTestBase { |
| 48 public: | 70 public: |
| 49 TransientWindowManagerTest() {} | 71 TransientWindowManagerTest() {} |
| 50 ~TransientWindowManagerTest() override {} | 72 ~TransientWindowManagerTest() override {} |
| 51 | 73 |
| 52 void SetUp() override { | 74 void SetUp() override { |
| 53 AuraTestBase::SetUp(); | 75 AuraTestBase::SetUp(); |
| 54 wm_state_.reset(new wm::WMState); | 76 wm_state_.reset(new wm::WMState); |
| 55 } | 77 } |
| 56 | 78 |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 327 |
| 306 // Tests that transient windows are stacked properly when created. | 328 // Tests that transient windows are stacked properly when created. |
| 307 TEST_F(TransientWindowManagerTest, StackUponCreation) { | 329 TEST_F(TransientWindowManagerTest, StackUponCreation) { |
| 308 scoped_ptr<Window> window0(CreateTestWindowWithId(0, root_window())); | 330 scoped_ptr<Window> window0(CreateTestWindowWithId(0, root_window())); |
| 309 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); | 331 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); |
| 310 | 332 |
| 311 scoped_ptr<Window> window2(CreateTransientChild(2, window0.get())); | 333 scoped_ptr<Window> window2(CreateTransientChild(2, window0.get())); |
| 312 EXPECT_EQ("0 2 1", ChildWindowIDsAsString(root_window())); | 334 EXPECT_EQ("0 2 1", ChildWindowIDsAsString(root_window())); |
| 313 } | 335 } |
| 314 | 336 |
| 337 // Tests for a crash when window destroyed inside |
| 338 // UpdateTransientChildVisibility loop. |
| 339 TEST_F(TransientWindowManagerTest, CrashOnVisibilityChange) { |
| 340 scoped_ptr<Window> window1(CreateTransientChild(1, root_window())); |
| 341 scoped_ptr<Window> window2(CreateTransientChild(2, root_window())); |
| 342 window1->Show(); |
| 343 window2->Show(); |
| 344 |
| 345 WindowVisibilityObserver visibility_observer(window1.get(), window2.Pass()); |
| 346 root_window()->Hide(); |
| 347 } |
| 315 // Tests that windows are restacked properly after a call to AddTransientChild() | 348 // Tests that windows are restacked properly after a call to AddTransientChild() |
| 316 // or RemoveTransientChild(). | 349 // or RemoveTransientChild(). |
| 317 TEST_F(TransientWindowManagerTest, RestackUponAddOrRemoveTransientChild) { | 350 TEST_F(TransientWindowManagerTest, RestackUponAddOrRemoveTransientChild) { |
| 318 scoped_ptr<Window> windows[4]; | 351 scoped_ptr<Window> windows[4]; |
| 319 for (int i = 0; i < 4; i++) | 352 for (int i = 0; i < 4; i++) |
| 320 windows[i].reset(CreateTestWindowWithId(i, root_window())); | 353 windows[i].reset(CreateTestWindowWithId(i, root_window())); |
| 321 EXPECT_EQ("0 1 2 3", ChildWindowIDsAsString(root_window())); | 354 EXPECT_EQ("0 1 2 3", ChildWindowIDsAsString(root_window())); |
| 322 | 355 |
| 323 AddTransientChild(windows[0].get(), windows[2].get()); | 356 AddTransientChild(windows[0].get(), windows[2].get()); |
| 324 EXPECT_EQ("0 2 1 3", ChildWindowIDsAsString(root_window())); | 357 EXPECT_EQ("0 2 1 3", ChildWindowIDsAsString(root_window())); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 EXPECT_EQ(0, test_observer.remove_count()); | 450 EXPECT_EQ(0, test_observer.remove_count()); |
| 418 | 451 |
| 419 RemoveTransientChild(parent.get(), w1.get()); | 452 RemoveTransientChild(parent.get(), w1.get()); |
| 420 EXPECT_EQ(1, test_observer.add_count()); | 453 EXPECT_EQ(1, test_observer.add_count()); |
| 421 EXPECT_EQ(1, test_observer.remove_count()); | 454 EXPECT_EQ(1, test_observer.remove_count()); |
| 422 | 455 |
| 423 TransientWindowManager::Get(parent.get())->RemoveObserver(&test_observer); | 456 TransientWindowManager::Get(parent.get())->RemoveObserver(&test_observer); |
| 424 } | 457 } |
| 425 | 458 |
| 426 } // namespace wm | 459 } // namespace wm |
| OLD | NEW |