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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/common/wm_window_observer.h ('k') | ash/mus/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/common/wm_window_unittest.cc
diff --git a/ash/common/wm_window_unittest.cc b/ash/common/wm_window_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..58dd29d6092a2c77680be9012d26b96c47e98160
--- /dev/null
+++ b/ash/common/wm_window_unittest.cc
@@ -0,0 +1,81 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/common/wm_window.h"
+
+#include <memory>
+
+#include "ash/common/test/ash_test.h"
+#include "ash/common/wm_window_observer.h"
+
+namespace ash {
+
+using WmWindowTest = AshTest;
+
+namespace {
+
+// Tracks calls to OnWindowVisibilityChanged().
+class VisibilityObserver : public WmWindowObserver {
+ public:
+ // Attaches a WmWindowObserver to |window_to_add_observer_to| and sets
+ // |last_observed_window_| and |last_observed_visible_value_| to the values
+ // of the last call to OnWindowVisibilityChanged().
+ explicit VisibilityObserver(WmWindow* window_to_add_observer_to)
+ : window_to_add_observer_to_(window_to_add_observer_to) {
+ window_to_add_observer_to_->AddObserver(this);
+ }
+ ~VisibilityObserver() override {
+ window_to_add_observer_to_->RemoveObserver(this);
+ }
+
+ // The values last supplied to OnWindowVisibilityChanged().
+ WmWindow* last_observed_window() { return last_observed_window_; }
+ bool last_observed_visible_value() const {
+ return last_observed_visible_value_;
+ }
+
+ // WmWindowObserver:
+ void OnWindowVisibilityChanged(WmWindow* window, bool visible) override {
+ last_observed_window_ = window;
+ last_observed_visible_value_ = visible;
+ }
+
+ private:
+ WmWindow* window_to_add_observer_to_;
+ WmWindow* last_observed_window_ = nullptr;
+ bool last_observed_visible_value_ = false;
+
+ DISALLOW_COPY_AND_ASSIGN(VisibilityObserver);
+};
+
+} // namespace
+
+// Verifies OnWindowVisibilityChanged() is called on a WmWindowObserver attached
+// to the parent when the child window's visibility changes.
+TEST_F(WmWindowTest, OnWindowVisibilityChangedCalledOnAncestor) {
+ std::unique_ptr<WindowOwner> window_owner = CreateTestWindow();
+ WmWindow* window = window_owner->window();
+ std::unique_ptr<WindowOwner> child_owner =
+ CreateChildWindow(window_owner->window());
+ WmWindow* child_window = child_owner->window();
+ VisibilityObserver observer(window);
+ child_window->Hide();
+ EXPECT_EQ(child_window, observer.last_observed_window());
+ EXPECT_FALSE(observer.last_observed_visible_value());
+}
+
+// Verifies OnWindowVisibilityChanged() is called on a WmWindowObserver attached
+// to a child when the parent window's visibility changes.
+TEST_F(WmWindowTest, OnWindowVisibilityChangedCalledOnChild) {
+ std::unique_ptr<WindowOwner> parent_window_owner = CreateTestWindow();
+ WmWindow* parent_window = parent_window_owner->window();
+ std::unique_ptr<WindowOwner> child_owner = CreateChildWindow(parent_window);
+ WmWindow* child_window = child_owner->window();
+ VisibilityObserver observer(child_window);
+ parent_window->Hide();
+ EXPECT_EQ(parent_window, observer.last_observed_window());
+ EXPECT_FALSE(observer.last_observed_visible_value());
+}
+
+} // namespace ash
« 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