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

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

Issue 8805033: Makes tests either use mock compositor or mock WebGraphicsContext3D (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweaks 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
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/compositor_setup.h"
16 #include "ui/gfx/compositor/layer.h" 17 #include "ui/gfx/compositor/layer.h"
17 #include "ui/gfx/compositor/layer_animation_sequence.h" 18 #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" 19 #include "ui/gfx/compositor/test/test_compositor_host.h"
20 #include "ui/gfx/gfx_paths.h" 20 #include "ui/gfx/gfx_paths.h"
21 21
22 namespace ui { 22 namespace ui {
23 23
24 namespace { 24 namespace {
25 25
26 // 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
27 // parent directory does not have to exist. 27 // parent directory does not have to exist.
28 bool WritePNGFile(const SkBitmap& bitmap, const FilePath& file_path) { 28 bool WritePNGFile(const SkBitmap& bitmap, const FilePath& file_path) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 if (!names.empty()) 99 if (!names.empty())
100 names += ","; 100 names += ",";
101 names += (*it)->name(); 101 names += (*it)->name();
102 } 102 }
103 return names; 103 return names;
104 } 104 }
105 105
106 106
107 // 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
108 // Layer's slightly differently: 108 // Layer's slightly differently:
109 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the 109 // - LayerWithNullDelegateTest uses NullLayerDelegate as the LayerDelegate. This
110 // LayerDelegate. This is typically the base class you want to use. 110 // is typically the base class you want to use.
111 // - LayerWithDelegateTest uses TestCompositor and does not set a LayerDelegate 111 // - LayerWithDelegateTest uses LayerDelegate on the delegates.
112 // on the delegates.
113 // - LayerWithRealCompositorTest when a real compositor is required for testing. 112 // - LayerWithRealCompositorTest when a real compositor is required for testing.
114 // - Slow because they bring up a window and run the real compositor. This 113 // - Slow because they bring up a window and run the real compositor. This
115 // is typically not what you want. 114 // is typically not what you want.
116 115
117 class ColoredLayer : public Layer, public LayerDelegate { 116 class ColoredLayer : public Layer, public LayerDelegate {
118 public: 117 public:
119 explicit ColoredLayer(SkColor color) 118 explicit ColoredLayer(SkColor color)
120 : Layer(Layer::LAYER_HAS_TEXTURE), 119 : Layer(Layer::LAYER_HAS_TEXTURE),
121 color_(color) { 120 color_(color) {
122 set_delegate(this); 121 set_delegate(this);
(...skipping 16 matching lines...) Expand all
139 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { 138 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) {
140 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); 139 test_data_directory_ = test_data_directory_.AppendASCII("compositor");
141 } else { 140 } else {
142 LOG(ERROR) << "Could not open test data directory."; 141 LOG(ERROR) << "Could not open test data directory.";
143 } 142 }
144 } 143 }
145 virtual ~LayerWithRealCompositorTest() {} 144 virtual ~LayerWithRealCompositorTest() {}
146 145
147 // Overridden from testing::Test: 146 // Overridden from testing::Test:
148 virtual void SetUp() OVERRIDE { 147 virtual void SetUp() OVERRIDE {
148 ui::DisableTestCompositor();
149 const gfx::Rect host_bounds(10, 10, 500, 500); 149 const gfx::Rect host_bounds(10, 10, 500, 500);
150 window_.reset(TestCompositorHost::Create(host_bounds)); 150 window_.reset(TestCompositorHost::Create(host_bounds));
151 window_->Show(); 151 window_->Show();
152 } 152 }
153 153
154 virtual void TearDown() OVERRIDE { 154 virtual void TearDown() OVERRIDE {
155 } 155 }
156 156
157 Compositor* GetCompositor() { 157 Compositor* GetCompositor() {
158 return window_->GetCompositor(); 158 return window_->GetCompositor();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 DrawTree(l1.get()); 352 DrawTree(l1.get());
353 } 353 }
354 354
355 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate { 355 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate {
356 public: 356 public:
357 LayerWithDelegateTest() : schedule_draw_invoked_(false) {} 357 LayerWithDelegateTest() : schedule_draw_invoked_(false) {}
358 virtual ~LayerWithDelegateTest() {} 358 virtual ~LayerWithDelegateTest() {}
359 359
360 // Overridden from testing::Test: 360 // Overridden from testing::Test:
361 virtual void SetUp() OVERRIDE { 361 virtual void SetUp() OVERRIDE {
362 compositor_ = new TestCompositor(this); 362 ui::SetupTestCompositor();
363 compositor_ = ui::Compositor::Create(this, NULL, gfx::Size(1000, 1000));
363 } 364 }
364 365
365 virtual void TearDown() OVERRIDE { 366 virtual void TearDown() OVERRIDE {
366 } 367 }
367 368
368 Compositor* compositor() { return compositor_.get(); } 369 Compositor* compositor() { return compositor_.get(); }
369 370
370 virtual Layer* CreateLayer(Layer::LayerType type) { 371 virtual Layer* CreateLayer(Layer::LayerType type) {
371 return new Layer(type); 372 return new Layer(type);
372 } 373 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 // CompositorDelegate overrides. 407 // CompositorDelegate overrides.
407 virtual void ScheduleDraw() OVERRIDE { 408 virtual void ScheduleDraw() OVERRIDE {
408 schedule_draw_invoked_ = true; 409 schedule_draw_invoked_ = true;
409 } 410 }
410 411
411 protected: 412 protected:
412 // Set to true when ScheduleDraw (CompositorDelegate override) is invoked. 413 // Set to true when ScheduleDraw (CompositorDelegate override) is invoked.
413 bool schedule_draw_invoked_; 414 bool schedule_draw_invoked_;
414 415
415 private: 416 private:
416 scoped_refptr<TestCompositor> compositor_; 417 scoped_refptr<ui::Compositor> compositor_;
417 418
418 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); 419 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest);
419 }; 420 };
420 421
421 // L1 422 // L1
422 // +-- L2 423 // +-- L2
423 TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Simple) { 424 TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Simple) {
424 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, 425 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
425 gfx::Rect(20, 20, 400, 400))); 426 gfx::Rect(20, 20, 400, 400)));
426 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, 427 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE,
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 l0->Add(l11.get()); 1339 l0->Add(l11.get());
1339 DrawTree(l0.get()); 1340 DrawTree(l0.get());
1340 SkBitmap bitmap; 1341 SkBitmap bitmap;
1341 ASSERT_TRUE(ReadPixels(&bitmap)); 1342 ASSERT_TRUE(ReadPixels(&bitmap));
1342 ASSERT_FALSE(bitmap.empty()); 1343 ASSERT_FALSE(bitmap.empty());
1343 // WritePNGFile(bitmap, ref_img); 1344 // WritePNGFile(bitmap, ref_img);
1344 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img)); 1345 EXPECT_TRUE(IsSameAsPNGFile(bitmap, ref_img));
1345 } 1346 }
1346 1347
1347 } // namespace ui 1348 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698