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

Side by Side Diff: ui/wm/core/transient_window_manager_unittest.cc

Issue 1464433002: Check that child window was not destroyed inside UpdateTransientChildVisibility. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
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
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 };
oshima 2015/11/19 18:05:40 nit: DISALLOW_COPY_AND_ASSIGN
66
47 class TransientWindowManagerTest : public aura::test::AuraTestBase { 67 class TransientWindowManagerTest : public aura::test::AuraTestBase {
48 public: 68 public:
49 TransientWindowManagerTest() {} 69 TransientWindowManagerTest() {}
50 ~TransientWindowManagerTest() override {} 70 ~TransientWindowManagerTest() override {}
51 71
52 void SetUp() override { 72 void SetUp() override {
53 AuraTestBase::SetUp(); 73 AuraTestBase::SetUp();
54 wm_state_.reset(new wm::WMState); 74 wm_state_.reset(new wm::WMState);
55 } 75 }
56 76
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 325
306 // Tests that transient windows are stacked properly when created. 326 // Tests that transient windows are stacked properly when created.
307 TEST_F(TransientWindowManagerTest, StackUponCreation) { 327 TEST_F(TransientWindowManagerTest, StackUponCreation) {
308 scoped_ptr<Window> window0(CreateTestWindowWithId(0, root_window())); 328 scoped_ptr<Window> window0(CreateTestWindowWithId(0, root_window()));
309 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); 329 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
310 330
311 scoped_ptr<Window> window2(CreateTransientChild(2, window0.get())); 331 scoped_ptr<Window> window2(CreateTransientChild(2, window0.get()));
312 EXPECT_EQ("0 2 1", ChildWindowIDsAsString(root_window())); 332 EXPECT_EQ("0 2 1", ChildWindowIDsAsString(root_window()));
313 } 333 }
314 334
335 // Tests for a crash when window destroyed inside
336 // UpdateTransientChildVisibility loop.
337 TEST_F(TransientWindowManagerTest, CrashOnVisibilityChange) {
338 scoped_ptr<Window> window1(CreateTransientChild(1, root_window()));
339 scoped_ptr<Window> window2(CreateTransientChild(2, root_window()));
340 window1->Show();
341 window2->Show();
342
343 WindowVisibilityObserver visibility_observer(window1.get(), window2.Pass());
344 root_window()->Hide();
345 }
315 // Tests that windows are restacked properly after a call to AddTransientChild() 346 // Tests that windows are restacked properly after a call to AddTransientChild()
316 // or RemoveTransientChild(). 347 // or RemoveTransientChild().
317 TEST_F(TransientWindowManagerTest, RestackUponAddOrRemoveTransientChild) { 348 TEST_F(TransientWindowManagerTest, RestackUponAddOrRemoveTransientChild) {
318 scoped_ptr<Window> windows[4]; 349 scoped_ptr<Window> windows[4];
319 for (int i = 0; i < 4; i++) 350 for (int i = 0; i < 4; i++)
320 windows[i].reset(CreateTestWindowWithId(i, root_window())); 351 windows[i].reset(CreateTestWindowWithId(i, root_window()));
321 EXPECT_EQ("0 1 2 3", ChildWindowIDsAsString(root_window())); 352 EXPECT_EQ("0 1 2 3", ChildWindowIDsAsString(root_window()));
322 353
323 AddTransientChild(windows[0].get(), windows[2].get()); 354 AddTransientChild(windows[0].get(), windows[2].get());
324 EXPECT_EQ("0 2 1 3", ChildWindowIDsAsString(root_window())); 355 EXPECT_EQ("0 2 1 3", ChildWindowIDsAsString(root_window()));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 EXPECT_EQ(0, test_observer.remove_count()); 448 EXPECT_EQ(0, test_observer.remove_count());
418 449
419 RemoveTransientChild(parent.get(), w1.get()); 450 RemoveTransientChild(parent.get(), w1.get());
420 EXPECT_EQ(1, test_observer.add_count()); 451 EXPECT_EQ(1, test_observer.add_count());
421 EXPECT_EQ(1, test_observer.remove_count()); 452 EXPECT_EQ(1, test_observer.remove_count());
422 453
423 TransientWindowManager::Get(parent.get())->RemoveObserver(&test_observer); 454 TransientWindowManager::Get(parent.get())->RemoveObserver(&test_observer);
424 } 455 }
425 456
426 } // namespace wm 457 } // namespace wm
OLDNEW
« ui/wm/core/transient_window_manager.cc ('K') | « ui/wm/core/transient_window_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698