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

Side by Side Diff: ui/gfx/compositor/layer_unittest.cc

Issue 8873001: Revert 113470 - Makes tests either use mock compositor or mock WebGraphicsContext3D depending upo... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/compositor/compositor_switches.cc ('k') | ui/views/run_all_unittests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
18 #include "ui/gfx/compositor/test/test_compositor_host.h" 19 #include "ui/gfx/compositor/test/test_compositor_host.h"
19 #include "ui/gfx/gfx_paths.h" 20 #include "ui/gfx/gfx_paths.h"
20 21
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
27 namespace ui { 22 namespace ui {
28 23
29 namespace { 24 namespace {
30 25
31 // Encodes a bitmap into a PNG and write to disk. Returns true on success. The 26 // Encodes a bitmap into a PNG and write to disk. Returns true on success. The
32 // parent directory does not have to exist. 27 // parent directory does not have to exist.
33 bool WritePNGFile(const SkBitmap& bitmap, const FilePath& file_path) { 28 bool WritePNGFile(const SkBitmap& bitmap, const FilePath& file_path) {
34 std::vector<unsigned char> png_data; 29 std::vector<unsigned char> png_data;
35 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data) && 30 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data) &&
36 file_util::CreateDirectory(file_path.DirName())) { 31 file_util::CreateDirectory(file_path.DirName())) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (!names.empty()) 99 if (!names.empty())
105 names += ","; 100 names += ",";
106 names += (*it)->name(); 101 names += (*it)->name();
107 } 102 }
108 return names; 103 return names;
109 } 104 }
110 105
111 106
112 // There are three test classes in here that configure the Compositor and 107 // There are three test classes in here that configure the Compositor and
113 // Layer's slightly differently: 108 // Layer's slightly differently:
114 // - LayerWithNullDelegateTest uses NullLayerDelegate as the LayerDelegate. This 109 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the
115 // is typically the base class you want to use. 110 // LayerDelegate. This is typically the base class you want to use.
116 // - LayerWithDelegateTest uses LayerDelegate on the delegates. 111 // - LayerWithDelegateTest uses TestCompositor and does not set a LayerDelegate
112 // on the delegates.
117 // - LayerWithRealCompositorTest when a real compositor is required for testing. 113 // - LayerWithRealCompositorTest when a real compositor is required for testing.
118 // - Slow because they bring up a window and run the real compositor. This 114 // - Slow because they bring up a window and run the real compositor. This
119 // is typically not what you want. 115 // is typically not what you want.
120 116
121 class ColoredLayer : public Layer, public LayerDelegate { 117 class ColoredLayer : public Layer, public LayerDelegate {
122 public: 118 public:
123 explicit ColoredLayer(SkColor color) 119 explicit ColoredLayer(SkColor color)
124 : Layer(Layer::LAYER_HAS_TEXTURE), 120 : Layer(Layer::LAYER_HAS_TEXTURE),
125 color_(color) { 121 color_(color) {
126 set_delegate(this); 122 set_delegate(this);
(...skipping 16 matching lines...) Expand all
143 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { 139 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) {
144 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); 140 test_data_directory_ = test_data_directory_.AppendASCII("compositor");
145 } else { 141 } else {
146 LOG(ERROR) << "Could not open test data directory."; 142 LOG(ERROR) << "Could not open test data directory.";
147 } 143 }
148 } 144 }
149 virtual ~LayerWithRealCompositorTest() {} 145 virtual ~LayerWithRealCompositorTest() {}
150 146
151 // Overridden from testing::Test: 147 // Overridden from testing::Test:
152 virtual void SetUp() OVERRIDE { 148 virtual void SetUp() OVERRIDE {
153 #if defined(USE_WEBKIT_COMPOSITOR)
154 ui::DisableTestCompositor();
155 #endif
156 const gfx::Rect host_bounds(10, 10, 500, 500); 149 const gfx::Rect host_bounds(10, 10, 500, 500);
157 window_.reset(TestCompositorHost::Create(host_bounds)); 150 window_.reset(TestCompositorHost::Create(host_bounds));
158 window_->Show(); 151 window_->Show();
159 } 152 }
160 153
161 virtual void TearDown() OVERRIDE { 154 virtual void TearDown() OVERRIDE {
162 } 155 }
163 156
164 Compositor* GetCompositor() { 157 Compositor* GetCompositor() {
165 return window_->GetCompositor(); 158 return window_->GetCompositor();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 DrawTree(l1.get()); 352 DrawTree(l1.get());
360 } 353 }
361 354
362 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate { 355 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate {
363 public: 356 public:
364 LayerWithDelegateTest() : schedule_draw_invoked_(false) {} 357 LayerWithDelegateTest() : schedule_draw_invoked_(false) {}
365 virtual ~LayerWithDelegateTest() {} 358 virtual ~LayerWithDelegateTest() {}
366 359
367 // Overridden from testing::Test: 360 // Overridden from testing::Test:
368 virtual void SetUp() OVERRIDE { 361 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
373 compositor_ = new TestCompositor(this); 362 compositor_ = new TestCompositor(this);
374 #endif
375 } 363 }
376 364
377 virtual void TearDown() OVERRIDE { 365 virtual void TearDown() OVERRIDE {
378 } 366 }
379 367
380 Compositor* compositor() { return compositor_.get(); } 368 Compositor* compositor() { return compositor_.get(); }
381 369
382 virtual Layer* CreateLayer(Layer::LayerType type) { 370 virtual Layer* CreateLayer(Layer::LayerType type) {
383 return new Layer(type); 371 return new Layer(type);
384 } 372 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 // CompositorDelegate overrides. 406 // CompositorDelegate overrides.
419 virtual void ScheduleDraw() OVERRIDE { 407 virtual void ScheduleDraw() OVERRIDE {
420 schedule_draw_invoked_ = true; 408 schedule_draw_invoked_ = true;
421 } 409 }
422 410
423 protected: 411 protected:
424 // Set to true when ScheduleDraw (CompositorDelegate override) is invoked. 412 // Set to true when ScheduleDraw (CompositorDelegate override) is invoked.
425 bool schedule_draw_invoked_; 413 bool schedule_draw_invoked_;
426 414
427 private: 415 private:
428 scoped_refptr<ui::Compositor> compositor_; 416 scoped_refptr<TestCompositor> compositor_;
429 417
430 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); 418 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest);
431 }; 419 };
432 420
433 // L1 421 // L1
434 // +-- L2 422 // +-- L2
435 TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Simple) { 423 TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Simple) {
436 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, 424 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
437 gfx::Rect(20, 20, 400, 400))); 425 gfx::Rect(20, 20, 400, 400)));
438 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, 426 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE,
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 l0->Add(l11.get()); 1338 l0->Add(l11.get());
1351 DrawTree(l0.get()); 1339 DrawTree(l0.get());
1352 SkBitmap bitmap; 1340 SkBitmap bitmap;
1353 ASSERT_TRUE(ReadPixels(&bitmap)); 1341 ASSERT_TRUE(ReadPixels(&bitmap));
1354 ASSERT_FALSE(bitmap.empty()); 1342 ASSERT_FALSE(bitmap.empty());
1355 // WritePNGFile(bitmap, ref_img); 1343 // WritePNGFile(bitmap, ref_img);
1356 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img)); 1344 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img));
1357 } 1345 }
1358 1346
1359 } // namespace ui 1347 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/compositor_switches.cc ('k') | ui/views/run_all_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698