Add ICU message format support
[chromium-blink-merge.git] / content / browser / compositor / software_output_device_ozone_unittest.cc
blob935fafa2b9ca11c192b48f8863eadf972e22765e
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/thread_task_runner_handle.h"
8 #include "content/browser/compositor/software_output_device_ozone.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkDevice.h"
11 #include "third_party/skia/include/core/SkSurface.h"
12 #include "ui/compositor/compositor.h"
13 #include "ui/compositor/test/context_factories_for_test.h"
14 #include "ui/gfx/geometry/size.h"
15 #include "ui/gfx/skia_util.h"
16 #include "ui/gfx/vsync_provider.h"
17 #include "ui/gl/gl_implementation.h"
18 #include "ui/ozone/public/ozone_platform.h"
19 #include "ui/ozone/public/surface_ozone_canvas.h"
20 #include "ui/platform_window/platform_window.h"
21 #include "ui/platform_window/platform_window_delegate.h"
23 namespace {
25 class TestPlatformWindowDelegate : public ui::PlatformWindowDelegate {
26 public:
27 TestPlatformWindowDelegate() : widget_(gfx::kNullAcceleratedWidget) {}
28 ~TestPlatformWindowDelegate() override {}
30 gfx::AcceleratedWidget GetAcceleratedWidget() const { return widget_; }
32 // ui::PlatformWindowDelegate:
33 void OnBoundsChanged(const gfx::Rect& new_bounds) override {}
34 void OnDamageRect(const gfx::Rect& damaged_region) override {}
35 void DispatchEvent(ui::Event* event) override {}
36 void OnCloseRequest() override {}
37 void OnClosed() override {}
38 void OnWindowStateChanged(ui::PlatformWindowState new_state) override {}
39 void OnLostCapture() override {}
40 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
41 float device_pixel_ratio) override {
42 widget_ = widget;
44 void OnActivationChanged(bool active) override {}
46 private:
47 gfx::AcceleratedWidget widget_;
49 DISALLOW_COPY_AND_ASSIGN(TestPlatformWindowDelegate);
52 } // namespace
54 class SoftwareOutputDeviceOzoneTest : public testing::Test {
55 public:
56 SoftwareOutputDeviceOzoneTest();
57 ~SoftwareOutputDeviceOzoneTest() override;
59 void SetUp() override;
60 void TearDown() override;
62 protected:
63 scoped_ptr<content::SoftwareOutputDeviceOzone> output_device_;
64 bool enable_pixel_output_;
66 private:
67 scoped_ptr<ui::Compositor> compositor_;
68 scoped_ptr<base::MessageLoop> message_loop_;
69 TestPlatformWindowDelegate window_delegate_;
70 scoped_ptr<ui::PlatformWindow> window_;
72 DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceOzoneTest);
75 SoftwareOutputDeviceOzoneTest::SoftwareOutputDeviceOzoneTest()
76 : enable_pixel_output_(false) {
77 message_loop_.reset(new base::MessageLoopForUI);
80 SoftwareOutputDeviceOzoneTest::~SoftwareOutputDeviceOzoneTest() {
83 void SoftwareOutputDeviceOzoneTest::SetUp() {
84 ui::ContextFactory* context_factory =
85 ui::InitializeContextFactoryForTests(enable_pixel_output_);
87 const gfx::Size size(500, 400);
88 window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
89 &window_delegate_, gfx::Rect(size));
90 compositor_.reset(new ui::Compositor(window_delegate_.GetAcceleratedWidget(),
91 context_factory,
92 base::ThreadTaskRunnerHandle::Get()));
93 compositor_->SetScaleAndSize(1.0f, size);
95 output_device_.reset(new content::SoftwareOutputDeviceOzone(
96 compositor_.get()));
97 output_device_->Resize(size, 1.f);
100 void SoftwareOutputDeviceOzoneTest::TearDown() {
101 output_device_.reset();
102 compositor_.reset();
103 window_.reset();
104 ui::TerminateContextFactoryForTests();
107 class SoftwareOutputDeviceOzonePixelTest
108 : public SoftwareOutputDeviceOzoneTest {
109 protected:
110 void SetUp() override;
113 void SoftwareOutputDeviceOzonePixelTest::SetUp() {
114 enable_pixel_output_ = true;
115 SoftwareOutputDeviceOzoneTest::SetUp();
118 TEST_F(SoftwareOutputDeviceOzoneTest, CheckCorrectResizeBehavior) {
119 gfx::Rect damage(0, 0, 100, 100);
120 gfx::Size size(200, 100);
121 // Reduce size.
122 output_device_->Resize(size, 1.f);
124 SkCanvas* canvas = output_device_->BeginPaint(damage);
125 gfx::Size canvas_size(canvas->getDeviceSize().width(),
126 canvas->getDeviceSize().height());
127 EXPECT_EQ(size.ToString(), canvas_size.ToString());
129 size.SetSize(1000, 500);
130 // Increase size.
131 output_device_->Resize(size, 1.f);
133 canvas = output_device_->BeginPaint(damage);
134 canvas_size.SetSize(canvas->getDeviceSize().width(),
135 canvas->getDeviceSize().height());
136 EXPECT_EQ(size.ToString(), canvas_size.ToString());