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/platform/test/test_window.h"
15 #include "ui/ozone/platform/test/test_window_manager.h"
16 #include "ui/ozone/public/cursor_factory_ozone.h"
17 #include "ui/ozone/public/gpu_platform_support.h"
18 #include "ui/ozone/public/gpu_platform_support_host.h"
19 #include "ui/ozone/public/input_controller.h"
20 #include "ui/ozone/public/ozone_platform.h"
21 #include "ui/ozone/public/ozone_switches.h"
22 #include "ui/ozone/public/system_input_injector.h"
28 // OzonePlatform for testing
30 // This platform dumps images to a file for testing purposes.
31 class OzonePlatformTest
: public OzonePlatform
{
33 OzonePlatformTest(const base::FilePath
& dump_file
) : file_path_(dump_file
) {}
34 ~OzonePlatformTest() override
{}
37 ui::SurfaceFactoryOzone
* GetSurfaceFactoryOzone() override
{
38 return window_manager_
.get();
40 CursorFactoryOzone
* GetCursorFactoryOzone() override
{
41 return cursor_factory_ozone_
.get();
43 InputController
* GetInputController() override
{
44 return input_controller_
.get();
46 GpuPlatformSupport
* GetGpuPlatformSupport() override
{
47 return gpu_platform_support_
.get();
49 GpuPlatformSupportHost
* GetGpuPlatformSupportHost() override
{
50 return gpu_platform_support_host_
.get();
52 scoped_ptr
<SystemInputInjector
> CreateSystemInputInjector() override
{
53 return nullptr; // no input injection support.
55 scoped_ptr
<PlatformWindow
> CreatePlatformWindow(
56 PlatformWindowDelegate
* delegate
,
57 const gfx::Rect
& bounds
) override
{
58 return make_scoped_ptr
<PlatformWindow
>(
59 new TestWindow(delegate
, window_manager_
.get(), bounds
));
61 scoped_ptr
<NativeDisplayDelegate
> CreateNativeDisplayDelegate() override
{
62 return make_scoped_ptr(new NativeDisplayDelegateOzone());
65 void InitializeUI() override
{
66 window_manager_
.reset(new TestWindowManager(file_path_
));
67 window_manager_
->Initialize();
68 // This unbreaks tests that create their own.
69 if (!PlatformEventSource::GetInstance())
70 platform_event_source_
= PlatformEventSource::CreateDefault();
71 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
72 make_scoped_ptr(new StubKeyboardLayoutEngine()));
74 input_controller_
= CreateStubInputController();
75 cursor_factory_ozone_
.reset(new BitmapCursorFactoryOzone
);
76 gpu_platform_support_host_
.reset(CreateStubGpuPlatformSupportHost());
79 void InitializeGPU() override
{
80 gpu_platform_support_
.reset(CreateStubGpuPlatformSupport());
84 scoped_ptr
<TestWindowManager
> window_manager_
;
85 scoped_ptr
<PlatformEventSource
> platform_event_source_
;
86 scoped_ptr
<CursorFactoryOzone
> cursor_factory_ozone_
;
87 scoped_ptr
<InputController
> input_controller_
;
88 scoped_ptr
<GpuPlatformSupport
> gpu_platform_support_
;
89 scoped_ptr
<GpuPlatformSupportHost
> gpu_platform_support_host_
;
90 base::FilePath file_path_
;
92 DISALLOW_COPY_AND_ASSIGN(OzonePlatformTest
);
97 OzonePlatform
* CreateOzonePlatformTest() {
98 base::CommandLine
* cmd
= base::CommandLine::ForCurrentProcess();
99 base::FilePath location
;
100 if (cmd
->HasSwitch(switches::kOzoneDumpFile
))
101 location
= cmd
->GetSwitchValuePath(switches::kOzoneDumpFile
);
102 return new OzonePlatformTest(location
);