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

Unified Diff: ui/views/controls/native/native_view_host_aura_unittest.cc

Issue 564553002: When we switch tabs in chrome, the tab being switched away from gets hidden/shown/hidden. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed RemoveClippingWindowOrder views test Created 6 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: ui/views/controls/native/native_view_host_aura_unittest.cc
diff --git a/ui/views/controls/native/native_view_host_aura_unittest.cc b/ui/views/controls/native/native_view_host_aura_unittest.cc
index 93e0fe2c8642b31321436172853c7015417c3c82..73319dff81d4b79b282a5019af990b0b52669c76 100644
--- a/ui/views/controls/native/native_view_host_aura_unittest.cc
+++ b/ui/views/controls/native/native_view_host_aura_unittest.cc
@@ -55,7 +55,9 @@ class NativeViewHostWindowObserver : public aura::WindowObserver {
}
};
- NativeViewHostWindowObserver() {}
+ NativeViewHostWindowObserver()
+ : visibility_state_after_reparenting_(false) {}
+
virtual ~NativeViewHostWindowObserver() {}
const std::vector<EventDetails>& events() const { return events_; }
@@ -84,10 +86,24 @@ class NativeViewHostWindowObserver : public aura::WindowObserver {
events_.push_back(event);
}
+ virtual void OnWindowParentChanged(aura::Window* window,
sky 2014/09/11 14:55:05 Can't you at events_, since presumably OnWindowVis
ananta 2014/09/11 15:01:56 OnWindowVisibilityChanged is only called in Chrome
sky 2014/09/11 15:29:20 OnWindowVisibilityChanged is from aura::WindowObse
+ aura::Window* parent) OVERRIDE {
+ if (parent && !visibility_state_after_reparenting_)
+ visibility_state_after_reparenting_ = window->IsVisible();
+ }
+
+ int visibility_state_after_reparenting() const {
+ return visibility_state_after_reparenting_;
+ }
+
private:
std::vector<EventDetails> events_;
gfx::Rect bounds_at_visibility_changed_;
+ // Tracks the visibility state of the window after it was reparented.
+ // changed.
+ int visibility_state_after_reparenting_;
+
DISALLOW_COPY_AND_ASSIGN(NativeViewHostWindowObserver);
};
@@ -324,11 +340,11 @@ TEST_F(NativeViewHostAuraTest, RemoveClippingWindowOrder) {
ASSERT_EQ(3u, test_observer.events().size());
EXPECT_EQ(NativeViewHostWindowObserver::EVENT_HIDDEN,
test_observer.events()[0].type);
- EXPECT_EQ(clipping_window(), test_observer.events()[0].window);
- EXPECT_EQ(NativeViewHostWindowObserver::EVENT_BOUNDS_CHANGED,
- test_observer.events()[1].type);
- EXPECT_EQ(child()->GetNativeView(), test_observer.events()[1].window);
+ EXPECT_EQ(child()->GetNativeView(), test_observer.events()[0].window);
EXPECT_EQ(NativeViewHostWindowObserver::EVENT_HIDDEN,
+ test_observer.events()[1].type);
+ EXPECT_EQ(clipping_window(), test_observer.events()[1].window);
+ EXPECT_EQ(NativeViewHostWindowObserver::EVENT_BOUNDS_CHANGED,
test_observer.events()[2].type);
EXPECT_EQ(child()->GetNativeView(), test_observer.events()[2].window);
@@ -394,4 +410,33 @@ TEST_F(NativeViewHostAuraTest, SimpleShowAndHide) {
DestroyTopLevel();
}
+// This test validates that detaching the host after it has become visible with
+// valid bounds, hides the host native view before it is reparented.
+TEST_F(NativeViewHostAuraTest, DetachHidesNativeViewBeforeReparenting) {
+ CreateHost();
+
+ toplevel()->SetBounds(gfx::Rect(20, 20, 100, 100));
+ toplevel()->Show();
+
+ host()->SetBounds(10, 10, 80, 80);
+ EXPECT_TRUE(clipping_window()->IsVisible());
+ EXPECT_TRUE(child()->IsVisible());
+
+ NativeViewHostWindowObserver test_observer;
+ host()->native_view()->AddObserver(&test_observer);
+
+ // Save away the native view in a local as it is null'ed out in the Detach
+ // call.
+ aura::Window* native_view = host()->native_view();
+ host()->Detach();
+
+ EXPECT_FALSE(clipping_window()->IsVisible());
+ EXPECT_FALSE(child()->IsVisible());
+
+ EXPECT_FALSE(test_observer.visibility_state_after_reparenting());
+ native_view->RemoveObserver(&test_observer);
+ DestroyHost();
+ DestroyTopLevel();
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698