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

Unified Diff: ui/gfx/compositor/layer_unittest.cc

Issue 10221028: Move DIP translation from ui/aura to ui/compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert change i made by accident Created 8 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
Index: ui/gfx/compositor/layer_unittest.cc
diff --git a/ui/gfx/compositor/layer_unittest.cc b/ui/gfx/compositor/layer_unittest.cc
index 65805fd6b01a3c7079f6fbb6996dd1ac843449b9..717ed72277603da2edffda0013e663d802ffa483 100644
--- a/ui/gfx/compositor/layer_unittest.cc
+++ b/ui/gfx/compositor/layer_unittest.cc
@@ -10,17 +10,18 @@
#include "base/path_service.h"
#include "base/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/compositor/compositor_observer.h"
+#include "ui/gfx/compositor/compositor_setup.h"
+#include "ui/gfx/compositor/dip_util.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/compositor/layer_animation_sequence.h"
#include "ui/gfx/compositor/test/test_compositor_host.h"
#include "ui/gfx/gfx_paths.h"
#include "ui/gfx/skia_util.h"
-#include "ui/gfx/compositor/compositor_setup.h"
-
namespace ui {
namespace {
@@ -366,7 +367,8 @@ class LayerWithDelegateTest : public testing::Test, public CompositorDelegate {
virtual void SetUp() OVERRIDE {
ui::SetupTestCompositor();
compositor_.reset(new Compositor(
- this, gfx::kNullAcceleratedWidget, gfx::Size(1000, 1000)));
+ this, gfx::kNullAcceleratedWidget));
+ compositor_->WidgetScaleOrSizeChanged(1.0f, gfx::Size(1000, 1000));
}
virtual void TearDown() OVERRIDE {
@@ -857,7 +859,7 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_CompositorObservers) {
// Checks that modifying the hierarchy correctly affects final composite.
TEST_F(LayerWithRealCompositorTest, MAYBE_ModifyHierarchy) {
- GetCompositor()->WidgetSizeChanged(gfx::Size(50, 50));
+ GetCompositor()->WidgetScaleOrSizeChanged(1.0f, gfx::Size(50, 50));
// l0
// +-l11
@@ -917,7 +919,7 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_ModifyHierarchy) {
// Opacity is rendered correctly.
// Checks that modifying the hierarchy correctly affects final composite.
TEST_F(LayerWithRealCompositorTest, MAYBE_Opacity) {
- GetCompositor()->WidgetSizeChanged(gfx::Size(50, 50));
+ GetCompositor()->WidgetScaleOrSizeChanged(1.0f, gfx::Size(50, 50));
// l0
// +-l11
@@ -1021,4 +1023,104 @@ TEST_F(LayerWithDelegateTest, SchedulePaintFromOnPaintLayer) {
gfx::Rect(10, 10, 30, 30)));
}
+TEST_F(LayerWithRealCompositorTest, ScaleUp) {
sky 2012/05/08 00:41:59 Can you also add coverage that a scale is set appr
oshima 2012/05/08 01:24:16 Done.
+ test::ScopedDIPEnablerForTest enable;
+
+ scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE,
+ gfx::Rect(10, 20, 200, 220)));
+ TestLayerDelegate root_delegate;
+ root_delegate.AddColor(SK_ColorWHITE);
+ root->set_delegate(&root_delegate);
+
+ scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE,
+ gfx::Rect(10, 20, 140, 180)));
+ TestLayerDelegate l1_delegate;
+ l1_delegate.AddColor(SK_ColorWHITE);
+ l1->set_delegate(&l1_delegate);
+
+ GetCompositor()->WidgetScaleOrSizeChanged(1.0f, gfx::Size(500, 500));
+ GetCompositor()->SetRootLayer(root.get());
+ root->Add(l1.get());
+ RunPendingMessages();
+
+ EXPECT_EQ("10,20 200x220", root->bounds().ToString());
+ EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
+ gfx::Size size_in_pixel = root->web_layer().bounds();
+ EXPECT_EQ("200x220", size_in_pixel.ToString());
+ size_in_pixel = l1->web_layer().bounds();
+ EXPECT_EQ("140x180", size_in_pixel.ToString());
+
+ SchedulePaintForLayer(root.get());
+ SchedulePaintForLayer(l1.get());
+ RunPendingMessages();
+
+ EXPECT_EQ("200x220", root_delegate.paint_size().ToString());
+ EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
+
+ // Scale up to 2.0. Changing scale doesn't change the bounds in DIP.
+ GetCompositor()->WidgetScaleOrSizeChanged(2.0f, gfx::Size(500, 500));
+ EXPECT_EQ("10,20 200x220", root->bounds().ToString());
+ EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
+ // Pixel size must have been scaled up.
+ size_in_pixel = root->web_layer().bounds();
+ EXPECT_EQ("400x440", size_in_pixel.ToString());
+ size_in_pixel = l1->web_layer().bounds();
+ EXPECT_EQ("280x360", size_in_pixel.ToString());
+
+ // Canvas size must have been scaled down too.
+ SchedulePaintForLayer(root.get());
+ SchedulePaintForLayer(l1.get());
+ RunPendingMessages();
+ EXPECT_EQ("400x440", root_delegate.paint_size().ToString());
+ EXPECT_EQ("280x360", l1_delegate.paint_size().ToString());
+
+ // Scale down back to 1.0f.
+ GetCompositor()->WidgetScaleOrSizeChanged(1.0f, gfx::Size(500, 500));
+ EXPECT_EQ("10,20 200x220", root->bounds().ToString());
+ EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
+ // Pixel size must have been scaled down.
+ size_in_pixel = root->web_layer().bounds();
+ EXPECT_EQ("200x220", size_in_pixel.ToString());
+ size_in_pixel = l1->web_layer().bounds();
+ EXPECT_EQ("140x180", size_in_pixel.ToString());
+
+ // Canvas size must have been scaled down too.
+ SchedulePaintForLayer(root.get());
+ SchedulePaintForLayer(l1.get());
+ RunPendingMessages();
+ EXPECT_EQ("200x220", root_delegate.paint_size().ToString());
+ EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
+}
+
+TEST_F(LayerWithRealCompositorTest, ScaleReparent) {
+ test::ScopedDIPEnablerForTest enable;
+ scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE,
+ gfx::Rect(10, 20, 200, 220)));
+ scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE,
+ gfx::Rect(10, 20, 140, 180)));
+ GetCompositor()->WidgetScaleOrSizeChanged(1.0f, gfx::Size(500, 500));
+ GetCompositor()->SetRootLayer(root.get());
+ RunPendingMessages();
+
+ root->Add(l1.get());
+ EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
+ gfx::Size size_in_pixel = l1->web_layer().bounds();
+ EXPECT_EQ("140x180", size_in_pixel.ToString());
+
+ // Remove l1 from root and change the scale.
+ root->Remove(l1.get());
+ EXPECT_EQ(NULL, l1->parent());
+ EXPECT_EQ(NULL, l1->GetCompositor());
+ GetCompositor()->WidgetScaleOrSizeChanged(2.0f, gfx::Size(500, 500));
+ // Sanity check on root and l1.
+ EXPECT_EQ("10,20 200x220", root->bounds().ToString());
+ size_in_pixel = l1->web_layer().bounds();
+ EXPECT_EQ("140x180", size_in_pixel.ToString());
+
+ root->Add(l1.get());
+ EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
+ size_in_pixel = l1->web_layer().bounds();
+ EXPECT_EQ("280x360", size_in_pixel.ToString());
+}
+
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698