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

Unified Diff: ui/wm/core/window_util_unittest.cc

Issue 1992853002: Create a LayerDelegate for recreated layers to draw when their content is invalidated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | « ui/wm/core/window_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/wm/core/window_util_unittest.cc
diff --git a/ui/wm/core/window_util_unittest.cc b/ui/wm/core/window_util_unittest.cc
index 72516bec4217ea1daf4352a96b6fefcddb2d7dab..68ecb4b600fced5bdc8fdb40fc39a5672a6319e7 100644
--- a/ui/wm/core/window_util_unittest.cc
+++ b/ui/wm/core/window_util_unittest.cc
@@ -11,8 +11,61 @@
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_tree_owner.h"
+#include "ui/compositor/paint_context.h"
namespace wm {
+namespace {
+
+// Used to check if the delegate for recreated layer is created for
+// the correct delegate.
+class TestLayerDelegate : public ui::LayerDelegate {
+ public:
+ explicit TestLayerDelegate(ui::LayerDelegate* original_delegate)
+ : original_delegate_(original_delegate) {}
+ ~TestLayerDelegate() override = default;
+
+ // ui::LayerDelegate:
+ void OnPaintLayer(const ui::PaintContext& context) override {}
+ void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {}
+ void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
+ base::Closure PrepareForLayerBoundsChange() override {
+ return base::Closure();
+ }
+
+ ui::LayerDelegate* original_delegate() { return original_delegate_; }
+
+ private:
+ ui::LayerDelegate* original_delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate);
+};
+
+// Used to create a TestLayerDelegate for recreated layers.
+class TestLayerDelegateFactory : public ::wm::LayerDelegateFactory {
+ public:
+ TestLayerDelegateFactory() = default;
+ ~TestLayerDelegateFactory() override = default;
+
+ // ::wm::LayerDelegateFactory:
+ ui::LayerDelegate* CreateDelegate(ui::LayerDelegate* delegate) override {
+ TestLayerDelegate* new_delegate = new TestLayerDelegate(delegate);
+ delegates_.push_back(base::WrapUnique(new_delegate));
+ return new_delegate;
+ }
+
+ size_t delegate_count() const { return delegates_.size(); }
+
+ TestLayerDelegate* GetDelegateAt(int index) {
+ return delegates_[index].get();
+ }
+
+ private:
+ std::vector<std::unique_ptr<TestLayerDelegate>> delegates_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestLayerDelegateFactory);
+};
+
+} // namespace
typedef aura::test::AuraTestBase WindowUtilTest;
@@ -32,7 +85,8 @@ TEST_F(WindowUtilTest, RecreateLayers) {
EXPECT_TRUE(acquired.get());
EXPECT_EQ(acquired.get(), window11->layer());
- std::unique_ptr<ui::LayerTreeOwner> tree = wm::RecreateLayers(window1.get());
+ std::unique_ptr<ui::LayerTreeOwner> tree =
+ wm::RecreateLayers(window1.get(), nullptr);
// The detached layer should not have the layer that has
// already been detached.
@@ -49,4 +103,36 @@ TEST_F(WindowUtilTest, RecreateLayers) {
// Delete the window before the acquired layer is deleted.
window11.reset();
}
+
+// Test if the LayerDelegateFactory creates new delegates for
+// recreated layers correctly.
+TEST_F(WindowUtilTest, RecreateLayersWithDelegate) {
+ TestLayerDelegateFactory factory;
+ std::unique_ptr<aura::Window> window1(
+ aura::test::CreateTestWindowWithId(0, NULL));
+ std::unique_ptr<aura::Window> window11(
+ aura::test::CreateTestWindowWithId(1, window1.get()));
+ std::unique_ptr<aura::Window> window12(
+ aura::test::CreateTestWindowWithId(2, window1.get()));
+
+ std::unique_ptr<ui::LayerTreeOwner> tree =
+ wm::RecreateLayers(window1.get(), &factory);
+
+ ASSERT_EQ(3u, factory.delegate_count());
+
+ TestLayerDelegate* new_delegate_1 = factory.GetDelegateAt(0);
+ TestLayerDelegate* new_delegate_11 = factory.GetDelegateAt(1);
+ TestLayerDelegate* new_delegate_12 = factory.GetDelegateAt(2);
+
+ EXPECT_EQ(window1->layer()->delegate(), new_delegate_1->original_delegate());
+ EXPECT_EQ(window11->layer()->delegate(),
+ new_delegate_11->original_delegate());
+ EXPECT_EQ(window12->layer()->delegate(),
+ new_delegate_12->original_delegate());
+
+ EXPECT_EQ(tree->root()->delegate(), new_delegate_1);
+ EXPECT_EQ(tree->root()->children()[0]->delegate(), new_delegate_11);
+ EXPECT_EQ(tree->root()->children()[1]->delegate(), new_delegate_12);
+}
+
} // namespace wm
« no previous file with comments | « ui/wm/core/window_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698