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

Side by Side Diff: ash/common/wm_window_unittest.cc

Issue 2699033002: Replace WmWindowObserver with aura::WindowObserver. (Closed)
Patch Set: Check for null images in ShelfWindowWatcher. Created 3 years, 10 months 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
« no previous file with comments | « ash/common/wm_window_tracker.h ('k') | ash/common/wm_window_user_data.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/common/wm_window.h" 5 #include "ash/common/wm_window.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/common/test/ash_test.h" 9 #include "ash/common/test/ash_test.h"
10 #include "ash/common/wm_window_observer.h" 10 #include "ui/aura/window.h"
11 #include "ui/aura/window_observer.h"
11 12
12 namespace ash { 13 namespace ash {
13 14
14 using WmWindowTest = AshTest; 15 using WmWindowTest = AshTest;
15 16
16 namespace { 17 namespace {
17 18
18 // Tracks calls to OnWindowVisibilityChanged(). 19 // Tracks calls to OnWindowVisibilityChanged().
19 class VisibilityObserver : public WmWindowObserver { 20 class VisibilityObserver : public aura::WindowObserver {
20 public: 21 public:
21 // Attaches a WmWindowObserver to |window_to_add_observer_to| and sets 22 // Attaches a aura::WindowObserver to |window_to_add_observer_to| and sets
22 // |last_observed_window_| and |last_observed_visible_value_| to the values 23 // |last_observed_window_| and |last_observed_visible_value_| to the values
23 // of the last call to OnWindowVisibilityChanged(). 24 // of the last call to OnWindowVisibilityChanged().
24 explicit VisibilityObserver(WmWindow* window_to_add_observer_to) 25 explicit VisibilityObserver(WmWindow* window_to_add_observer_to)
25 : window_to_add_observer_to_(window_to_add_observer_to) { 26 : window_to_add_observer_to_(window_to_add_observer_to) {
26 window_to_add_observer_to_->AddObserver(this); 27 window_to_add_observer_to_->aura_window()->AddObserver(this);
27 } 28 }
28 ~VisibilityObserver() override { 29 ~VisibilityObserver() override {
29 window_to_add_observer_to_->RemoveObserver(this); 30 window_to_add_observer_to_->aura_window()->RemoveObserver(this);
30 } 31 }
31 32
32 // The values last supplied to OnWindowVisibilityChanged(). 33 // The values last supplied to OnWindowVisibilityChanged().
33 WmWindow* last_observed_window() { return last_observed_window_; } 34 WmWindow* last_observed_window() { return last_observed_window_; }
34 bool last_observed_visible_value() const { 35 bool last_observed_visible_value() const {
35 return last_observed_visible_value_; 36 return last_observed_visible_value_;
36 } 37 }
37 38
38 // WmWindowObserver: 39 // aura::WindowObserver:
39 void OnWindowVisibilityChanged(WmWindow* window, bool visible) override { 40 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override {
40 last_observed_window_ = window; 41 last_observed_window_ = WmWindow::Get(window);
41 last_observed_visible_value_ = visible; 42 last_observed_visible_value_ = visible;
42 } 43 }
43 44
44 private: 45 private:
45 WmWindow* window_to_add_observer_to_; 46 WmWindow* window_to_add_observer_to_;
46 WmWindow* last_observed_window_ = nullptr; 47 WmWindow* last_observed_window_ = nullptr;
47 bool last_observed_visible_value_ = false; 48 bool last_observed_visible_value_ = false;
48 49
49 DISALLOW_COPY_AND_ASSIGN(VisibilityObserver); 50 DISALLOW_COPY_AND_ASSIGN(VisibilityObserver);
50 }; 51 };
51 52
52 } // namespace 53 } // namespace
53 54
54 // Verifies OnWindowVisibilityChanged() is called on a WmWindowObserver attached 55 // Verifies OnWindowVisibilityChanged() is called on a aura::WindowObserver
56 // attached
55 // to the parent when the child window's visibility changes. 57 // to the parent when the child window's visibility changes.
56 TEST_F(WmWindowTest, OnWindowVisibilityChangedCalledOnAncestor) { 58 TEST_F(WmWindowTest, OnWindowVisibilityChangedCalledOnAncestor) {
57 std::unique_ptr<WindowOwner> window_owner = CreateTestWindow(); 59 std::unique_ptr<WindowOwner> window_owner = CreateTestWindow();
58 WmWindow* window = window_owner->window(); 60 WmWindow* window = window_owner->window();
59 std::unique_ptr<WindowOwner> child_owner = 61 std::unique_ptr<WindowOwner> child_owner =
60 CreateChildWindow(window_owner->window()); 62 CreateChildWindow(window_owner->window());
61 WmWindow* child_window = child_owner->window(); 63 WmWindow* child_window = child_owner->window();
62 VisibilityObserver observer(window); 64 VisibilityObserver observer(window);
63 child_window->Hide(); 65 child_window->Hide();
64 EXPECT_EQ(child_window, observer.last_observed_window()); 66 EXPECT_EQ(child_window, observer.last_observed_window());
65 EXPECT_FALSE(observer.last_observed_visible_value()); 67 EXPECT_FALSE(observer.last_observed_visible_value());
66 } 68 }
67 69
68 // Verifies OnWindowVisibilityChanged() is called on a WmWindowObserver attached 70 // Verifies OnWindowVisibilityChanged() is called on a aura::WindowObserver
71 // attached
69 // to a child when the parent window's visibility changes. 72 // to a child when the parent window's visibility changes.
70 TEST_F(WmWindowTest, OnWindowVisibilityChangedCalledOnChild) { 73 TEST_F(WmWindowTest, OnWindowVisibilityChangedCalledOnChild) {
71 std::unique_ptr<WindowOwner> parent_window_owner = CreateTestWindow(); 74 std::unique_ptr<WindowOwner> parent_window_owner = CreateTestWindow();
72 WmWindow* parent_window = parent_window_owner->window(); 75 WmWindow* parent_window = parent_window_owner->window();
73 std::unique_ptr<WindowOwner> child_owner = CreateChildWindow(parent_window); 76 std::unique_ptr<WindowOwner> child_owner = CreateChildWindow(parent_window);
74 WmWindow* child_window = child_owner->window(); 77 WmWindow* child_window = child_owner->window();
75 VisibilityObserver observer(child_window); 78 VisibilityObserver observer(child_window);
76 parent_window->Hide(); 79 parent_window->Hide();
77 EXPECT_EQ(parent_window, observer.last_observed_window()); 80 EXPECT_EQ(parent_window, observer.last_observed_window());
78 EXPECT_FALSE(observer.last_observed_visible_value()); 81 EXPECT_FALSE(observer.last_observed_visible_value());
79 } 82 }
80 83
81 } // namespace ash 84 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm_window_tracker.h ('k') | ash/common/wm_window_user_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698