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

Unified Diff: ash/common/wm_window_unittest.cc

Issue 2377853002: Test coverage for bug in WmWindowAura::OnWindowVisibilityChanged() (Closed)
Patch Set: order 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
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..0b51b0e055023b1efe31d9d87cee2e709710cc8e
--- /dev/null
+++ b/ash/common/wm_window_unittest.cc
@@ -0,0 +1,70 @@
+// 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 {
+
+// Used to verify OnWindowVisibilityChanged() is called with a particular
+// window and value.
+class VisibilityObserver : public WmWindowObserver {
+ public:
+ // Attaches a WmWindowObserver to |window_to_add_observer_to| and sets
+ // |got_expected_value_| to true if OnWindowVisibilityChanged() is called
+ // with |expected_window| and |expected_value|.
+ VisibilityObserver(WmWindow* window_to_add_observer_to,
+ WmWindow* expected_window,
+ bool expected_value)
+ : window_to_add_observer_to_(window_to_add_observer_to),
+ expected_window_(expected_window),
+ expected_value_(expected_value),
+ got_expected_value_(false) {
+ window_to_add_observer_to_->AddObserver(this);
+ }
+ ~VisibilityObserver() override {
+ window_to_add_observer_to_->RemoveObserver(this);
+ }
+
+ bool got_expected_value() const { return got_expected_value_; }
+
+ // WmWindowObserver:
+ void OnWindowVisibilityChanged(WmWindow* window, bool visible) override {
+ if (window == expected_window_ && visible == expected_value_)
+ got_expected_value_ = true;
+ }
+
+ private:
+ WmWindow* window_to_add_observer_to_;
+ WmWindow* expected_window_;
+ const bool expected_value_;
+ bool got_expected_value_;
+
+ 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, false);
+ child_window->Hide();
+ 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.
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698