| 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..0213eae7932ae5c5e0aed5f51138b6d2cee88263 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,
|
| + 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);
|
| };
|
|
|
| @@ -321,16 +337,13 @@ TEST_F(NativeViewHostAuraTest, RemoveClippingWindowOrder) {
|
|
|
| host()->Detach();
|
|
|
| - ASSERT_EQ(3u, test_observer.events().size());
|
| + ASSERT_EQ(2u, 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()[2].type);
|
| - EXPECT_EQ(child()->GetNativeView(), test_observer.events()[2].window);
|
| + test_observer.events()[1].type);
|
| + EXPECT_EQ(clipping_window(), test_observer.events()[1].window);
|
|
|
| clipping_window()->RemoveObserver(&test_observer);
|
| child()->GetNativeView()->RemoveObserver(&test_observer);
|
| @@ -394,4 +407,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
|
|
|