OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/gfx/canvas_skia.h" | 13 #include "ui/gfx/canvas_skia.h" |
14 #include "ui/gfx/codec/png_codec.h" | 14 #include "ui/gfx/codec/png_codec.h" |
15 #include "ui/gfx/compositor/compositor_observer.h" | 15 #include "ui/gfx/compositor/compositor_observer.h" |
16 #include "ui/gfx/compositor/layer.h" | 16 #include "ui/gfx/compositor/layer.h" |
17 #include "ui/gfx/compositor/layer_animation_sequence.h" | 17 #include "ui/gfx/compositor/layer_animation_sequence.h" |
18 #include "ui/gfx/compositor/test/test_compositor.h" | |
19 #include "ui/gfx/compositor/test/test_compositor_host.h" | 18 #include "ui/gfx/compositor/test/test_compositor_host.h" |
20 #include "ui/gfx/gfx_paths.h" | 19 #include "ui/gfx/gfx_paths.h" |
21 | 20 |
| 21 #if defined(USE_WEBKIT_COMPOSITOR) |
| 22 #include "ui/gfx/compositor/compositor_setup.h" |
| 23 #else |
| 24 #include "ui/gfx/compositor/test/test_compositor.h" |
| 25 #endif |
| 26 |
22 namespace ui { | 27 namespace ui { |
23 | 28 |
24 namespace { | 29 namespace { |
25 | 30 |
26 // Encodes a bitmap into a PNG and write to disk. Returns true on success. The | 31 // Encodes a bitmap into a PNG and write to disk. Returns true on success. The |
27 // parent directory does not have to exist. | 32 // parent directory does not have to exist. |
28 bool WritePNGFile(const SkBitmap& bitmap, const FilePath& file_path) { | 33 bool WritePNGFile(const SkBitmap& bitmap, const FilePath& file_path) { |
29 std::vector<unsigned char> png_data; | 34 std::vector<unsigned char> png_data; |
30 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data) && | 35 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data) && |
31 file_util::CreateDirectory(file_path.DirName())) { | 36 file_util::CreateDirectory(file_path.DirName())) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 if (!names.empty()) | 104 if (!names.empty()) |
100 names += ","; | 105 names += ","; |
101 names += (*it)->name(); | 106 names += (*it)->name(); |
102 } | 107 } |
103 return names; | 108 return names; |
104 } | 109 } |
105 | 110 |
106 | 111 |
107 // There are three test classes in here that configure the Compositor and | 112 // There are three test classes in here that configure the Compositor and |
108 // Layer's slightly differently: | 113 // Layer's slightly differently: |
109 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the | 114 // - LayerWithNullDelegateTest uses NullLayerDelegate as the LayerDelegate. This |
110 // LayerDelegate. This is typically the base class you want to use. | 115 // is typically the base class you want to use. |
111 // - LayerWithDelegateTest uses TestCompositor and does not set a LayerDelegate | 116 // - LayerWithDelegateTest uses LayerDelegate on the delegates. |
112 // on the delegates. | |
113 // - LayerWithRealCompositorTest when a real compositor is required for testing. | 117 // - LayerWithRealCompositorTest when a real compositor is required for testing. |
114 // - Slow because they bring up a window and run the real compositor. This | 118 // - Slow because they bring up a window and run the real compositor. This |
115 // is typically not what you want. | 119 // is typically not what you want. |
116 | 120 |
117 class ColoredLayer : public Layer, public LayerDelegate { | 121 class ColoredLayer : public Layer, public LayerDelegate { |
118 public: | 122 public: |
119 explicit ColoredLayer(SkColor color) | 123 explicit ColoredLayer(SkColor color) |
120 : Layer(Layer::LAYER_HAS_TEXTURE), | 124 : Layer(Layer::LAYER_HAS_TEXTURE), |
121 color_(color) { | 125 color_(color) { |
122 set_delegate(this); | 126 set_delegate(this); |
(...skipping 16 matching lines...) Expand all Loading... |
139 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { | 143 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { |
140 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); | 144 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); |
141 } else { | 145 } else { |
142 LOG(ERROR) << "Could not open test data directory."; | 146 LOG(ERROR) << "Could not open test data directory."; |
143 } | 147 } |
144 } | 148 } |
145 virtual ~LayerWithRealCompositorTest() {} | 149 virtual ~LayerWithRealCompositorTest() {} |
146 | 150 |
147 // Overridden from testing::Test: | 151 // Overridden from testing::Test: |
148 virtual void SetUp() OVERRIDE { | 152 virtual void SetUp() OVERRIDE { |
| 153 #if defined(USE_WEBKIT_COMPOSITOR) |
| 154 ui::DisableTestCompositor(); |
| 155 #endif |
149 const gfx::Rect host_bounds(10, 10, 500, 500); | 156 const gfx::Rect host_bounds(10, 10, 500, 500); |
150 window_.reset(TestCompositorHost::Create(host_bounds)); | 157 window_.reset(TestCompositorHost::Create(host_bounds)); |
151 window_->Show(); | 158 window_->Show(); |
152 } | 159 } |
153 | 160 |
154 virtual void TearDown() OVERRIDE { | 161 virtual void TearDown() OVERRIDE { |
155 } | 162 } |
156 | 163 |
157 Compositor* GetCompositor() { | 164 Compositor* GetCompositor() { |
158 return window_->GetCompositor(); | 165 return window_->GetCompositor(); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 DrawTree(l1.get()); | 359 DrawTree(l1.get()); |
353 } | 360 } |
354 | 361 |
355 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate { | 362 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate { |
356 public: | 363 public: |
357 LayerWithDelegateTest() : schedule_draw_invoked_(false) {} | 364 LayerWithDelegateTest() : schedule_draw_invoked_(false) {} |
358 virtual ~LayerWithDelegateTest() {} | 365 virtual ~LayerWithDelegateTest() {} |
359 | 366 |
360 // Overridden from testing::Test: | 367 // Overridden from testing::Test: |
361 virtual void SetUp() OVERRIDE { | 368 virtual void SetUp() OVERRIDE { |
| 369 #if defined(USE_WEBKIT_COMPOSITOR) |
| 370 ui::SetupTestCompositor(); |
| 371 compositor_ = ui::Compositor::Create(this, NULL, gfx::Size(1000, 1000)); |
| 372 #else |
362 compositor_ = new TestCompositor(this); | 373 compositor_ = new TestCompositor(this); |
| 374 #endif |
363 } | 375 } |
364 | 376 |
365 virtual void TearDown() OVERRIDE { | 377 virtual void TearDown() OVERRIDE { |
366 } | 378 } |
367 | 379 |
368 Compositor* compositor() { return compositor_.get(); } | 380 Compositor* compositor() { return compositor_.get(); } |
369 | 381 |
370 virtual Layer* CreateLayer(Layer::LayerType type) { | 382 virtual Layer* CreateLayer(Layer::LayerType type) { |
371 return new Layer(type); | 383 return new Layer(type); |
372 } | 384 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 // CompositorDelegate overrides. | 418 // CompositorDelegate overrides. |
407 virtual void ScheduleDraw() OVERRIDE { | 419 virtual void ScheduleDraw() OVERRIDE { |
408 schedule_draw_invoked_ = true; | 420 schedule_draw_invoked_ = true; |
409 } | 421 } |
410 | 422 |
411 protected: | 423 protected: |
412 // Set to true when ScheduleDraw (CompositorDelegate override) is invoked. | 424 // Set to true when ScheduleDraw (CompositorDelegate override) is invoked. |
413 bool schedule_draw_invoked_; | 425 bool schedule_draw_invoked_; |
414 | 426 |
415 private: | 427 private: |
416 scoped_refptr<TestCompositor> compositor_; | 428 scoped_refptr<ui::Compositor> compositor_; |
417 | 429 |
418 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); | 430 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); |
419 }; | 431 }; |
420 | 432 |
421 // L1 | 433 // L1 |
422 // +-- L2 | 434 // +-- L2 |
423 TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Simple) { | 435 TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Simple) { |
424 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 436 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
425 gfx::Rect(20, 20, 400, 400))); | 437 gfx::Rect(20, 20, 400, 400))); |
426 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 438 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 l0->Add(l11.get()); | 1350 l0->Add(l11.get()); |
1339 DrawTree(l0.get()); | 1351 DrawTree(l0.get()); |
1340 SkBitmap bitmap; | 1352 SkBitmap bitmap; |
1341 ASSERT_TRUE(ReadPixels(&bitmap)); | 1353 ASSERT_TRUE(ReadPixels(&bitmap)); |
1342 ASSERT_FALSE(bitmap.empty()); | 1354 ASSERT_FALSE(bitmap.empty()); |
1343 // WritePNGFile(bitmap, ref_img); | 1355 // WritePNGFile(bitmap, ref_img); |
1344 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img)); | 1356 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img)); |
1345 } | 1357 } |
1346 | 1358 |
1347 } // namespace ui | 1359 } // namespace ui |
OLD | NEW |