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

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

Issue 2377853002: Test coverage for bug in WmWindowAura::OnWindowVisibilityChanged() (Closed)
Patch Set: parent and merge Created 4 years, 2 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_observer.h ('k') | ash/mus/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/common/wm_window.h"
6
7 #include <memory>
8
9 #include "ash/common/test/ash_test.h"
10 #include "ash/common/wm_window_observer.h"
11
12 namespace ash {
13
14 using WmWindowTest = AshTest;
15
16 namespace {
17
18 // Tracks calls to OnWindowVisibilityChanged().
19 class VisibilityObserver : public WmWindowObserver {
20 public:
21 // Attaches a WmWindowObserver to |window_to_add_observer_to| and sets
22 // |last_observed_window_| and |last_observed_visible_value_| to the values
23 // of the last call to OnWindowVisibilityChanged().
24 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_->AddObserver(this);
27 }
28 ~VisibilityObserver() override {
29 window_to_add_observer_to_->RemoveObserver(this);
30 }
31
32 // The values last supplied to OnWindowVisibilityChanged().
33 WmWindow* last_observed_window() { return last_observed_window_; }
34 bool last_observed_visible_value() const {
35 return last_observed_visible_value_;
36 }
37
38 // WmWindowObserver:
39 void OnWindowVisibilityChanged(WmWindow* window, bool visible) override {
40 last_observed_window_ = window;
41 last_observed_visible_value_ = visible;
42 }
43
44 private:
45 WmWindow* window_to_add_observer_to_;
46 WmWindow* last_observed_window_ = nullptr;
47 bool last_observed_visible_value_ = false;
48
49 DISALLOW_COPY_AND_ASSIGN(VisibilityObserver);
50 };
51
52 } // namespace
53
54 // Verifies OnWindowVisibilityChanged() is called on a WmWindowObserver attached
55 // to the parent when the child window's visibility changes.
56 TEST_F(WmWindowTest, OnWindowVisibilityChangedCalledOnAncestor) {
57 std::unique_ptr<WindowOwner> window_owner = CreateTestWindow();
58 WmWindow* window = window_owner->window();
59 std::unique_ptr<WindowOwner> child_owner =
60 CreateChildWindow(window_owner->window());
61 WmWindow* child_window = child_owner->window();
62 VisibilityObserver observer(window);
63 child_window->Hide();
64 EXPECT_EQ(child_window, observer.last_observed_window());
65 EXPECT_FALSE(observer.last_observed_visible_value());
66 }
67
68 // Verifies OnWindowVisibilityChanged() is called on a WmWindowObserver attached
69 // to a child when the parent window's visibility changes.
70 TEST_F(WmWindowTest, OnWindowVisibilityChangedCalledOnChild) {
71 std::unique_ptr<WindowOwner> parent_window_owner = CreateTestWindow();
72 WmWindow* parent_window = parent_window_owner->window();
73 std::unique_ptr<WindowOwner> child_owner = CreateChildWindow(parent_window);
74 WmWindow* child_window = child_owner->window();
75 VisibilityObserver observer(child_window);
76 parent_window->Hide();
77 EXPECT_EQ(parent_window, observer.last_observed_window());
78 EXPECT_FALSE(observer.last_observed_visible_value());
79 }
80
81 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm_window_observer.h ('k') | ash/mus/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698