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

Side by Side Diff: ash/wm/solo_window_tracker_unittest.cc

Issue 101013002: Make sure WindowObservers are removed from window before destruction (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix shutdown order Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « ash/shell.cc ('k') | ash/wm/window_cycle_list.cc » ('j') | 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 "ash/wm/solo_window_tracker.h" 5 #include "ash/wm/solo_window_tracker.h"
6 6
7 #include "ash/ash_constants.h" 7 #include "ash/ash_constants.h"
8 #include "ash/ash_switches.h" 8 #include "ash/ash_switches.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/screen_ash.h" 10 #include "ash/screen_ash.h"
(...skipping 11 matching lines...) Expand all
22 #include "ui/base/hit_test.h" 22 #include "ui/base/hit_test.h"
23 #include "ui/gfx/screen.h" 23 #include "ui/gfx/screen.h"
24 24
25 namespace ash { 25 namespace ash {
26 26
27 namespace { 27 namespace {
28 28
29 class WindowRepaintChecker : public aura::WindowObserver { 29 class WindowRepaintChecker : public aura::WindowObserver {
30 public: 30 public:
31 explicit WindowRepaintChecker(aura::Window* window) 31 explicit WindowRepaintChecker(aura::Window* window)
32 : is_paint_scheduled_(false) { 32 : window_(window),
33 window->AddObserver(this); 33 is_paint_scheduled_(false) {
34 window_->AddObserver(this);
34 } 35 }
36
35 virtual ~WindowRepaintChecker() { 37 virtual ~WindowRepaintChecker() {
38 if (window_)
39 window_->RemoveObserver(this);
36 } 40 }
37 41
38 bool IsPaintScheduledAndReset() { 42 bool IsPaintScheduledAndReset() {
39 bool result = is_paint_scheduled_; 43 bool result = is_paint_scheduled_;
40 is_paint_scheduled_ = false; 44 is_paint_scheduled_ = false;
41 return result; 45 return result;
42 } 46 }
43 47
44 private: 48 private:
45 // aura::WindowObserver overrides: 49 // aura::WindowObserver overrides:
46 virtual void OnWindowPaintScheduled(aura::Window* window, 50 virtual void OnWindowPaintScheduled(aura::Window* window,
47 const gfx::Rect& region) OVERRIDE { 51 const gfx::Rect& region) OVERRIDE {
48 is_paint_scheduled_ = true; 52 is_paint_scheduled_ = true;
49 } 53 }
50 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { 54 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {
51 window->RemoveObserver(this); 55 DCHECK_EQ(window_, window);
56 window_ = NULL;
52 } 57 }
53 58
59 aura::Window* window_;
54 bool is_paint_scheduled_; 60 bool is_paint_scheduled_;
55 61
56 DISALLOW_COPY_AND_ASSIGN(WindowRepaintChecker); 62 DISALLOW_COPY_AND_ASSIGN(WindowRepaintChecker);
57 }; 63 };
58 64
59 } // namespace 65 } // namespace
60 66
61 class SoloWindowTrackerTest : public test::AshTestBase { 67 class SoloWindowTrackerTest : public test::AshTestBase {
62 public: 68 public:
63 SoloWindowTrackerTest() { 69 SoloWindowTrackerTest() {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 w.reset(); 420 w.reset();
415 EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary()); 421 EXPECT_EQ(NULL, GetWindowWithSoloHeaderInPrimary());
416 422
417 // Recreate another window again. 423 // Recreate another window again.
418 w.reset(CreateWindowInPrimary()); 424 w.reset(CreateWindowInPrimary());
419 w->Show(); 425 w->Show();
420 EXPECT_EQ(w.get(), GetWindowWithSoloHeaderInPrimary()); 426 EXPECT_EQ(w.get(), GetWindowWithSoloHeaderInPrimary());
421 } 427 }
422 428
423 } // namespace ash 429 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shell.cc ('k') | ash/wm/window_cycle_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698