1 // Copyright 2013 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 "ui/ozone/platform/test/ozone_platform_test.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
10 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
11 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
12 #include "ui/events/platform/platform_event_source.h"
13 #include "ui/ozone/common/native_display_delegate_ozone.h"
14 #include "ui/ozone/common/stub_overlay_manager.h"
15 #include "ui/ozone/platform/test/test_window.h"
16 #include "ui/ozone/platform/test/test_window_manager.h"
17 #include "ui/ozone/public/cursor_factory_ozone.h"
18 #include "ui/ozone/public/gpu_platform_support.h"
19 #include "ui/ozone/public/gpu_platform_support_host.h"
20 #include "ui/ozone/public/input_controller.h"
21 #include "ui/ozone/public/ozone_platform.h"
22 #include "ui/ozone/public/ozone_switches.h"
23 #include "ui/ozone/public/system_input_injector.h"
29 // A test implementation of PlatformEventSource that we can instantiate to make
30 // sure that the PlatformEventSource has an instance while in unit tests.
31 class TestPlatformEventSource
: public ui::PlatformEventSource
{
33 TestPlatformEventSource() {}
34 ~TestPlatformEventSource() override
{}
37 DISALLOW_COPY_AND_ASSIGN(TestPlatformEventSource
);
40 // OzonePlatform for testing
42 // This platform dumps images to a file for testing purposes.
43 class OzonePlatformTest
: public OzonePlatform
{
45 OzonePlatformTest(const base::FilePath
& dump_file
) : file_path_(dump_file
) {}
46 ~OzonePlatformTest() override
{}
49 ui::SurfaceFactoryOzone
* GetSurfaceFactoryOzone() override
{
50 return window_manager_
.get();
52 OverlayManagerOzone
* GetOverlayManager() override
{
53 return overlay_manager_
.get();
55 CursorFactoryOzone
* GetCursorFactoryOzone() override
{
56 return cursor_factory_ozone_
.get();
58 InputController
* GetInputController() override
{
59 return input_controller_
.get();
61 GpuPlatformSupport
* GetGpuPlatformSupport() override
{
62 return gpu_platform_support_
.get();
64 GpuPlatformSupportHost
* GetGpuPlatformSupportHost() override
{
65 return gpu_platform_support_host_
.get();
67 scoped_ptr
<SystemInputInjector
> CreateSystemInputInjector() override
{
68 return nullptr; // no input injection support.
70 scoped_ptr
<PlatformWindow
> CreatePlatformWindow(
71 PlatformWindowDelegate
* delegate
,
72 const gfx::Rect
& bounds
) override
{
73 return make_scoped_ptr
<PlatformWindow
>(
74 new TestWindow(delegate
, window_manager_
.get(), bounds
));
76 scoped_ptr
<NativeDisplayDelegate
> CreateNativeDisplayDelegate() override
{
77 return make_scoped_ptr(new NativeDisplayDelegateOzone());
80 void InitializeUI() override
{
81 window_manager_
.reset(new TestWindowManager(file_path_
));
82 window_manager_
->Initialize();
83 // This unbreaks tests that create their own.
84 if (!PlatformEventSource::GetInstance())
85 platform_event_source_
.reset(new TestPlatformEventSource
);
86 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
87 make_scoped_ptr(new StubKeyboardLayoutEngine()));
89 overlay_manager_
.reset(new StubOverlayManager());
90 input_controller_
= CreateStubInputController();
91 cursor_factory_ozone_
.reset(new BitmapCursorFactoryOzone
);
92 gpu_platform_support_host_
.reset(CreateStubGpuPlatformSupportHost());
95 void InitializeGPU() override
{
96 gpu_platform_support_
.reset(CreateStubGpuPlatformSupport());
100 scoped_ptr
<TestWindowManager
> window_manager_
;
101 scoped_ptr
<PlatformEventSource
> platform_event_source_
;
102 scoped_ptr
<CursorFactoryOzone
> cursor_factory_ozone_
;
103 scoped_ptr
<InputController
> input_controller_
;
104 scoped_ptr
<GpuPlatformSupport
> gpu_platform_support_
;
105 scoped_ptr
<GpuPlatformSupportHost
> gpu_platform_support_host_
;
106 scoped_ptr
<OverlayManagerOzone
> overlay_manager_
;
107 base::FilePath file_path_
;
109 DISALLOW_COPY_AND_ASSIGN(OzonePlatformTest
);
114 OzonePlatform
* CreateOzonePlatformTest() {
115 base::CommandLine
* cmd
= base::CommandLine::ForCurrentProcess();
116 base::FilePath location
;
117 if (cmd
->HasSwitch(switches::kOzoneDumpFile
))
118 location
= cmd
->GetSwitchValuePath(switches::kOzoneDumpFile
);
119 return new OzonePlatformTest(location
);