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/platform/platform_event_source.h"
11 #include "ui/ozone/common/native_display_delegate_ozone.h"
12 #include "ui/ozone/platform/test/test_window.h"
13 #include "ui/ozone/platform/test/test_window_manager.h"
14 #include "ui/ozone/public/cursor_factory_ozone.h"
15 #include "ui/ozone/public/gpu_platform_support.h"
16 #include "ui/ozone/public/gpu_platform_support_host.h"
17 #include "ui/ozone/public/ozone_platform.h"
18 #include "ui/ozone/public/ozone_switches.h"
24 // OzonePlatform for testing
26 // This platform dumps images to a file for testing purposes.
27 class OzonePlatformTest
: public OzonePlatform
{
29 OzonePlatformTest(const base::FilePath
& dump_file
) : file_path_(dump_file
) {}
30 ~OzonePlatformTest() override
{}
33 ui::SurfaceFactoryOzone
* GetSurfaceFactoryOzone() override
{
34 return window_manager_
.get();
36 CursorFactoryOzone
* GetCursorFactoryOzone() override
{
37 return cursor_factory_ozone_
.get();
39 GpuPlatformSupport
* GetGpuPlatformSupport() override
{
40 return gpu_platform_support_
.get();
42 GpuPlatformSupportHost
* GetGpuPlatformSupportHost() override
{
43 return gpu_platform_support_host_
.get();
45 scoped_ptr
<PlatformWindow
> CreatePlatformWindow(
46 PlatformWindowDelegate
* delegate
,
47 const gfx::Rect
& bounds
) override
{
48 return make_scoped_ptr
<PlatformWindow
>(
49 new TestWindow(delegate
, window_manager_
.get(), bounds
));
51 scoped_ptr
<NativeDisplayDelegate
> CreateNativeDisplayDelegate() override
{
52 return scoped_ptr
<NativeDisplayDelegate
>(new NativeDisplayDelegateOzone());
55 void InitializeUI() override
{
56 window_manager_
.reset(new TestWindowManager(file_path_
));
57 window_manager_
->Initialize();
58 // This unbreaks tests that create their own.
59 if (!PlatformEventSource::GetInstance())
60 platform_event_source_
= PlatformEventSource::CreateDefault();
62 cursor_factory_ozone_
.reset(new BitmapCursorFactoryOzone
);
63 gpu_platform_support_host_
.reset(CreateStubGpuPlatformSupportHost());
66 void InitializeGPU() override
{
67 gpu_platform_support_
.reset(CreateStubGpuPlatformSupport());
71 scoped_ptr
<TestWindowManager
> window_manager_
;
72 scoped_ptr
<PlatformEventSource
> platform_event_source_
;
73 scoped_ptr
<CursorFactoryOzone
> cursor_factory_ozone_
;
74 scoped_ptr
<GpuPlatformSupport
> gpu_platform_support_
;
75 scoped_ptr
<GpuPlatformSupportHost
> gpu_platform_support_host_
;
76 base::FilePath file_path_
;
78 DISALLOW_COPY_AND_ASSIGN(OzonePlatformTest
);
83 OzonePlatform
* CreateOzonePlatformTest() {
84 CommandLine
* cmd
= CommandLine::ForCurrentProcess();
85 base::FilePath location
;
86 if (cmd
->HasSwitch(switches::kOzoneDumpFile
))
87 location
= cmd
->GetSwitchValuePath(switches::kOzoneDumpFile
);
88 return new OzonePlatformTest(location
);