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

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

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

Powered by Google App Engine
This is Rietveld 408576698