diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-20 22:12:35 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-20 22:12:35 +0000 |
commit | 847efe38a3c863715b2a62250ba2311165e3c9b8 (patch) | |
tree | cc00fc1aa73c2428da69afc18645234417810195 /ui | |
parent | e312acafed0b2fe4be40b57f61b679b404534f73 (diff) | |
download | chromium_src-847efe38a3c863715b2a62250ba2311165e3c9b8.zip chromium_src-847efe38a3c863715b2a62250ba2311165e3c9b8.tar.gz chromium_src-847efe38a3c863715b2a62250ba2311165e3c9b8.tar.bz2 |
Reset owner upon acquisition
BUG=351463
TEST=WindowTest.AcquireLayer, WindowUtilTest.RecreaetLayers
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=258004
Review URL: https://codereview.chromium.org/202163003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258432 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/window_unittest.cc | 6 | ||||
-rw-r--r-- | ui/compositor/layer_owner.cc | 2 | ||||
-rw-r--r-- | ui/wm/core/window_util_unittest.cc | 49 | ||||
-rw-r--r-- | ui/wm/wm.gyp | 1 |
4 files changed, 58 insertions, 0 deletions
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index d7c727f..ba183cf 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -1882,6 +1882,12 @@ TEST_F(WindowTest, AcquireLayer) { EXPECT_FALSE(window1_test_api.OwnsLayer()); EXPECT_TRUE(window1_layer.get() == window1->layer()); + // The acquired layer's owner should be set NULL and re-acquring + // should return NULL. + EXPECT_FALSE(window1_layer->owner()); + scoped_ptr<ui::Layer> window1_layer_reacquired(window1->AcquireLayer()); + EXPECT_FALSE(window1_layer_reacquired.get()); + // Upon destruction, window1's layer should still be valid, and in the layer // hierarchy, but window2's should be gone, and no longer in the hierarchy. window1.reset(); diff --git a/ui/compositor/layer_owner.cc b/ui/compositor/layer_owner.cc index 839ce0d..c00b7fc 100644 --- a/ui/compositor/layer_owner.cc +++ b/ui/compositor/layer_owner.cc @@ -20,6 +20,8 @@ void LayerOwner::SetLayer(Layer* layer) { } Layer* LayerOwner::AcquireLayer() { + if (layer_owner_) + layer_owner_->owner_ = NULL; return layer_owner_.release(); } diff --git a/ui/wm/core/window_util_unittest.cc b/ui/wm/core/window_util_unittest.cc new file mode 100644 index 0000000..fb72371 --- /dev/null +++ b/ui/wm/core/window_util_unittest.cc @@ -0,0 +1,49 @@ +// Copyright 2014 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 "ui/wm/core/window_util.h" + +#include "base/memory/scoped_ptr.h" +#include "ui/aura/test/aura_test_base.h" +#include "ui/aura/test/test_windows.h" +#include "ui/aura/window.h" +#include "ui/compositor/layer.h" +#include "ui/compositor/layer_tree_owner.h" + +namespace wm { + +typedef aura::test::AuraTestBase WindowUtilTest; + +// Test if the recreate layers does not recreate layers that have +// already been acquired. +TEST_F(WindowUtilTest, RecreateLayers) { + scoped_ptr<aura::Window> window1( + aura::test::CreateTestWindowWithId(0, NULL)); + scoped_ptr<aura::Window> window11( + aura::test::CreateTestWindowWithId(1, window1.get())); + scoped_ptr<aura::Window> window12( + aura::test::CreateTestWindowWithId(2, window1.get())); + + ASSERT_EQ(2u, window1->layer()->children().size()); + + scoped_ptr<ui::Layer> acquired(window11->AcquireLayer()); + EXPECT_TRUE(acquired.get()); + EXPECT_EQ(acquired.get(), window11->layer()); + + scoped_ptr<ui::LayerTreeOwner> tree = + wm::RecreateLayers(window1.get()); + + // The detached layer should not have the layer that has + // already been detached. + ASSERT_EQ(1u, tree->root()->children().size()); + // Child layer is new instance. + EXPECT_NE(window11->layer(), tree->root()->children()[0]); + EXPECT_NE(window12->layer(), tree->root()->children()[0]); + + // The original window should have both. + ASSERT_EQ(2u, window1->layer()->children().size()); + EXPECT_EQ(window11->layer(), window1->layer()->children()[0]); + EXPECT_EQ(window12->layer(), window1->layer()->children()[1]); +} +} // namespace wm diff --git a/ui/wm/wm.gyp b/ui/wm/wm.gyp index 9e7a308..a1960ec 100644 --- a/ui/wm/wm.gyp +++ b/ui/wm/wm.gyp @@ -130,6 +130,7 @@ 'core/transient_window_stacking_client_unittest.cc', 'core/visibility_controller_unittest.cc', 'core/window_animations_unittest.cc', + 'core/window_util_unittest.cc', ], }, ], |