Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / browser / compositor / software_output_device_ozone_unittest.cc
blob19d5c5668788d98b6892bce59f8c38347579a311
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 "cc/output/software_frame_data.h"
9 #include "content/browser/compositor/software_output_device_ozone.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/skia/include/core/SkDevice.h"
12 #include "third_party/skia/include/core/SkSurface.h"
13 #include "ui/compositor/compositor.h"
14 #include "ui/compositor/test/context_factories_for_test.h"
15 #include "ui/gfx/geometry/size.h"
16 #include "ui/gfx/skia_util.h"
17 #include "ui/gfx/vsync_provider.h"
18 #include "ui/gl/gl_implementation.h"
19 #include "ui/ozone/public/ozone_platform.h"
20 #include "ui/ozone/public/surface_ozone_canvas.h"
21 #include "ui/platform_window/platform_window.h"
22 #include "ui/platform_window/platform_window_delegate.h"
24 namespace {
26 class TestPlatformWindowDelegate : public ui::PlatformWindowDelegate {
27 public:
28 TestPlatformWindowDelegate() : widget_(gfx::kNullAcceleratedWidget) {}
29 ~TestPlatformWindowDelegate() override {}
31 gfx::AcceleratedWidget GetAcceleratedWidget() const { return widget_; }
33 // ui::PlatformWindowDelegate:
34 void OnBoundsChanged(const gfx::Rect& new_bounds) override {}
35 void OnDamageRect(const gfx::Rect& damaged_region) override {}
36 void DispatchEvent(ui::Event* event) override {}
37 void OnCloseRequest() override {}
38 void OnClosed() override {}
39 void OnWindowStateChanged(ui::PlatformWindowState new_state) override {}
40 void OnLostCapture() override {}
41 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
42 float device_pixel_ratio) override {
43 widget_ = widget;
45 void OnActivationChanged(bool active) override {}
47 private:
48 gfx::AcceleratedWidget widget_;
50 DISALLOW_COPY_AND_ASSIGN(TestPlatformWindowDelegate);
53 } // namespace
55 class SoftwareOutputDeviceOzoneTest : public testing::Test {
56 public:
57 SoftwareOutputDeviceOzoneTest();
58 ~SoftwareOutputDeviceOzoneTest() override;
60 void SetUp() override;
61 void TearDown() override;
63 protected:
64 scoped_ptr<content::SoftwareOutputDeviceOzone> output_device_;
65 bool enable_pixel_output_;
67 private:
68 scoped_ptr<ui::Compositor> compositor_;
69 scoped_ptr<base::MessageLoop> message_loop_;
70 TestPlatformWindowDelegate window_delegate_;
71 scoped_ptr<ui::PlatformWindow> window_;
73 DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceOzoneTest);
76 SoftwareOutputDeviceOzoneTest::SoftwareOutputDeviceOzoneTest()
77 : enable_pixel_output_(false) {
78 message_loop_.reset(new base::MessageLoopForUI);
81 SoftwareOutputDeviceOzoneTest::~SoftwareOutputDeviceOzoneTest() {
84 void SoftwareOutputDeviceOzoneTest::SetUp() {
85 ui::ContextFactory* context_factory =
86 ui::InitializeContextFactoryForTests(enable_pixel_output_);
88 const gfx::Size size(500, 400);
89 window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
90 &window_delegate_, gfx::Rect(size));
91 compositor_.reset(new ui::Compositor(window_delegate_.GetAcceleratedWidget(),
92 context_factory,
93 base::ThreadTaskRunnerHandle::Get()));
94 compositor_->SetScaleAndSize(1.0f, size);
96 output_device_.reset(new content::SoftwareOutputDeviceOzone(
97 compositor_.get()));
98 output_device_->Resize(size, 1.f);
101 void SoftwareOutputDeviceOzoneTest::TearDown() {
102 output_device_.reset();
103 compositor_.reset();
104 window_.reset();
105 ui::TerminateContextFactoryForTests();
108 class SoftwareOutputDeviceOzonePixelTest
109 : public SoftwareOutputDeviceOzoneTest {
110 protected:
111 void SetUp() override;
114 void SoftwareOutputDeviceOzonePixelTest::SetUp() {
115 enable_pixel_output_ = true;
116 SoftwareOutputDeviceOzoneTest::SetUp();
119 TEST_F(SoftwareOutputDeviceOzoneTest, CheckCorrectResizeBehavior) {
120 gfx::Rect damage(0, 0, 100, 100);
121 gfx::Size size(200, 100);
122 // Reduce size.
123 output_device_->Resize(size, 1.f);
125 SkCanvas* canvas = output_device_->BeginPaint(damage);
126 gfx::Size canvas_size(canvas->getDeviceSize().width(),
127 canvas->getDeviceSize().height());
128 EXPECT_EQ(size.ToString(), canvas_size.ToString());
130 size.SetSize(1000, 500);
131 // Increase size.
132 output_device_->Resize(size, 1.f);
134 canvas = output_device_->BeginPaint(damage);
135 canvas_size.SetSize(canvas->getDeviceSize().width(),
136 canvas->getDeviceSize().height());
137 EXPECT_EQ(size.ToString(), canvas_size.ToString());