Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 // Used to verify OnWindowVisibilityChanged() is called with a particular | |
| 19 // window and value. | |
| 20 class VisibilityObserver : public WmWindowObserver { | |
| 21 public: | |
| 22 // Attaches a WmWindowObserver to |window_to_add_observer_to| and sets | |
| 23 // |got_expected_value_| to true if OnWindowVisibilityChanged() is called | |
| 24 // with |expected_window| and |expected_value|. | |
| 25 VisibilityObserver(WmWindow* window_to_add_observer_to, | |
| 26 WmWindow* expected_window, | |
| 27 bool expected_value) | |
| 28 : window_to_add_observer_to_(window_to_add_observer_to), | |
| 29 expected_window_(expected_window), | |
| 30 expected_value_(expected_value), | |
| 31 got_expected_value_(false) { | |
| 32 window_to_add_observer_to_->AddObserver(this); | |
| 33 } | |
| 34 ~VisibilityObserver() override { | |
| 35 window_to_add_observer_to_->RemoveObserver(this); | |
| 36 } | |
| 37 | |
| 38 bool got_expected_value() const { return got_expected_value_; } | |
| 39 | |
| 40 // WmWindowObserver: | |
| 41 void OnWindowVisibilityChanged(WmWindow* window, bool visible) override { | |
| 42 if (window == expected_window_ && visible == expected_value_) | |
| 43 got_expected_value_ = true; | |
| 44 } | |
| 45 | |
| 46 private: | |
| 47 WmWindow* window_to_add_observer_to_; | |
| 48 WmWindow* expected_window_; | |
| 49 const bool expected_value_; | |
| 50 bool got_expected_value_; | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(VisibilityObserver); | |
| 53 }; | |
| 54 | |
| 55 } // namespace | |
| 56 | |
| 57 // Verifies OnWindowVisibilityChanged() is called on a WmWindowObserver attached | |
| 58 // to the parent when the child window's visibility changes. | |
| 59 TEST_F(WmWindowTest, OnWindowVisibilityChangedCalledOnAncestor) { | |
| 60 std::unique_ptr<WindowOwner> window_owner = CreateTestWindow(); | |
| 61 WmWindow* window = window_owner->window(); | |
| 62 std::unique_ptr<WindowOwner> child_owner = | |
| 63 CreateChildWindow(window_owner->window()); | |
| 64 WmWindow* child_window = child_owner->window(); | |
| 65 VisibilityObserver observer(window, child_window, false); | |
| 66 child_window->Hide(); | |
| 67 EXPECT_TRUE(observer.got_expected_value()); | |
|
James Cook
2016/09/28 01:19:58
optional: This might be easier to read if the Visi
sky
2016/09/28 18:16:36
Great idea! Done.
| |
| 68 } | |
| 69 | |
| 70 } // namespace ash | |
| OLD | NEW |