| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/ozone/platform/test/ozone_platform_test.h" | 5 #include "ui/ozone/platform/headless/ozone_platform_headless.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" | 9 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" |
| 10 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" | 10 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
| 11 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" | 11 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" |
| 12 #include "ui/events/platform/platform_event_source.h" | 12 #include "ui/events/platform/platform_event_source.h" |
| 13 #include "ui/ozone/common/native_display_delegate_ozone.h" | 13 #include "ui/ozone/common/native_display_delegate_ozone.h" |
| 14 #include "ui/ozone/common/stub_overlay_manager.h" | 14 #include "ui/ozone/common/stub_overlay_manager.h" |
| 15 #include "ui/ozone/platform/test/test_surface_factory.h" | 15 #include "ui/ozone/platform/headless/headless_surface_factory.h" |
| 16 #include "ui/ozone/platform/test/test_window.h" | 16 #include "ui/ozone/platform/headless/headless_window.h" |
| 17 #include "ui/ozone/platform/test/test_window_manager.h" | 17 #include "ui/ozone/platform/headless/headless_window_manager.h" |
| 18 #include "ui/ozone/public/cursor_factory_ozone.h" | 18 #include "ui/ozone/public/cursor_factory_ozone.h" |
| 19 #include "ui/ozone/public/gpu_platform_support.h" | 19 #include "ui/ozone/public/gpu_platform_support.h" |
| 20 #include "ui/ozone/public/gpu_platform_support_host.h" | 20 #include "ui/ozone/public/gpu_platform_support_host.h" |
| 21 #include "ui/ozone/public/input_controller.h" | 21 #include "ui/ozone/public/input_controller.h" |
| 22 #include "ui/ozone/public/ozone_platform.h" | 22 #include "ui/ozone/public/ozone_platform.h" |
| 23 #include "ui/ozone/public/ozone_switches.h" | 23 #include "ui/ozone/public/ozone_switches.h" |
| 24 #include "ui/ozone/public/system_input_injector.h" | 24 #include "ui/ozone/public/system_input_injector.h" |
| 25 | 25 |
| 26 namespace ui { | 26 namespace ui { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // A test implementation of PlatformEventSource that we can instantiate to make | 30 // A headless implementation of PlatformEventSource that we can instantiate to |
| 31 // make |
| 31 // sure that the PlatformEventSource has an instance while in unit tests. | 32 // sure that the PlatformEventSource has an instance while in unit tests. |
| 32 class TestPlatformEventSource : public ui::PlatformEventSource { | 33 class HeadlessPlatformEventSource : public ui::PlatformEventSource { |
| 33 public: | 34 public: |
| 34 TestPlatformEventSource() {} | 35 HeadlessPlatformEventSource() {} |
| 35 ~TestPlatformEventSource() override {} | 36 ~HeadlessPlatformEventSource() override {} |
| 36 | 37 |
| 37 private: | 38 private: |
| 38 DISALLOW_COPY_AND_ASSIGN(TestPlatformEventSource); | 39 DISALLOW_COPY_AND_ASSIGN(HeadlessPlatformEventSource); |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 // OzonePlatform for testing | 42 // OzonePlatform for headless mode |
| 42 // | 43 class OzonePlatformHeadless : public OzonePlatform { |
| 43 // This platform dumps images to a file for testing purposes. | |
| 44 class OzonePlatformTest : public OzonePlatform { | |
| 45 public: | 44 public: |
| 46 OzonePlatformTest(const base::FilePath& dump_file) : file_path_(dump_file) {} | 45 OzonePlatformHeadless(const base::FilePath& dump_file) |
| 47 ~OzonePlatformTest() override {} | 46 : file_path_(dump_file) {} |
| 47 ~OzonePlatformHeadless() override {} |
| 48 | 48 |
| 49 // OzonePlatform: | 49 // OzonePlatform: |
| 50 ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override { | 50 ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override { |
| 51 return surface_factory_.get(); | 51 return surface_factory_.get(); |
| 52 } | 52 } |
| 53 OverlayManagerOzone* GetOverlayManager() override { | 53 OverlayManagerOzone* GetOverlayManager() override { |
| 54 return overlay_manager_.get(); | 54 return overlay_manager_.get(); |
| 55 } | 55 } |
| 56 CursorFactoryOzone* GetCursorFactoryOzone() override { | 56 CursorFactoryOzone* GetCursorFactoryOzone() override { |
| 57 return cursor_factory_ozone_.get(); | 57 return cursor_factory_ozone_.get(); |
| 58 } | 58 } |
| 59 InputController* GetInputController() override { | 59 InputController* GetInputController() override { |
| 60 return input_controller_.get(); | 60 return input_controller_.get(); |
| 61 } | 61 } |
| 62 GpuPlatformSupport* GetGpuPlatformSupport() override { | 62 GpuPlatformSupport* GetGpuPlatformSupport() override { |
| 63 return gpu_platform_support_.get(); | 63 return gpu_platform_support_.get(); |
| 64 } | 64 } |
| 65 GpuPlatformSupportHost* GetGpuPlatformSupportHost() override { | 65 GpuPlatformSupportHost* GetGpuPlatformSupportHost() override { |
| 66 return gpu_platform_support_host_.get(); | 66 return gpu_platform_support_host_.get(); |
| 67 } | 67 } |
| 68 scoped_ptr<SystemInputInjector> CreateSystemInputInjector() override { | 68 scoped_ptr<SystemInputInjector> CreateSystemInputInjector() override { |
| 69 return nullptr; // no input injection support. | 69 return nullptr; // no input injection support. |
| 70 } | 70 } |
| 71 scoped_ptr<PlatformWindow> CreatePlatformWindow( | 71 scoped_ptr<PlatformWindow> CreatePlatformWindow( |
| 72 PlatformWindowDelegate* delegate, | 72 PlatformWindowDelegate* delegate, |
| 73 const gfx::Rect& bounds) override { | 73 const gfx::Rect& bounds) override { |
| 74 return make_scoped_ptr<PlatformWindow>( | 74 return make_scoped_ptr<PlatformWindow>( |
| 75 new TestWindow(delegate, window_manager_.get(), bounds)); | 75 new HeadlessWindow(delegate, window_manager_.get(), bounds)); |
| 76 } | 76 } |
| 77 scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() override { | 77 scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() override { |
| 78 return make_scoped_ptr(new NativeDisplayDelegateOzone()); | 78 return make_scoped_ptr(new NativeDisplayDelegateOzone()); |
| 79 } | 79 } |
| 80 base::ScopedFD OpenClientNativePixmapDevice() const override { | 80 base::ScopedFD OpenClientNativePixmapDevice() const override { |
| 81 return base::ScopedFD(); | 81 return base::ScopedFD(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void InitializeUI() override { | 84 void InitializeUI() override { |
| 85 window_manager_.reset(new TestWindowManager(file_path_)); | 85 window_manager_.reset(new HeadlessWindowManager(file_path_)); |
| 86 window_manager_->Initialize(); | 86 window_manager_->Initialize(); |
| 87 surface_factory_.reset(new TestSurfaceFactory(window_manager_.get())); | 87 surface_factory_.reset(new HeadlessSurfaceFactory(window_manager_.get())); |
| 88 // This unbreaks tests that create their own. | 88 // This unbreaks tests that create their own. |
| 89 if (!PlatformEventSource::GetInstance()) | 89 if (!PlatformEventSource::GetInstance()) |
| 90 platform_event_source_.reset(new TestPlatformEventSource); | 90 platform_event_source_.reset(new HeadlessPlatformEventSource); |
| 91 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( | 91 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( |
| 92 make_scoped_ptr(new StubKeyboardLayoutEngine())); | 92 make_scoped_ptr(new StubKeyboardLayoutEngine())); |
| 93 | 93 |
| 94 overlay_manager_.reset(new StubOverlayManager()); | 94 overlay_manager_.reset(new StubOverlayManager()); |
| 95 input_controller_ = CreateStubInputController(); | 95 input_controller_ = CreateStubInputController(); |
| 96 cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone); | 96 cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone); |
| 97 gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); | 97 gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void InitializeGPU() override { | 100 void InitializeGPU() override { |
| 101 if (!surface_factory_) | 101 if (!surface_factory_) |
| 102 surface_factory_.reset(new TestSurfaceFactory()); | 102 surface_factory_.reset(new HeadlessSurfaceFactory()); |
| 103 gpu_platform_support_.reset(CreateStubGpuPlatformSupport()); | 103 gpu_platform_support_.reset(CreateStubGpuPlatformSupport()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 scoped_ptr<TestWindowManager> window_manager_; | 107 scoped_ptr<HeadlessWindowManager> window_manager_; |
| 108 scoped_ptr<TestSurfaceFactory> surface_factory_; | 108 scoped_ptr<HeadlessSurfaceFactory> surface_factory_; |
| 109 scoped_ptr<PlatformEventSource> platform_event_source_; | 109 scoped_ptr<PlatformEventSource> platform_event_source_; |
| 110 scoped_ptr<CursorFactoryOzone> cursor_factory_ozone_; | 110 scoped_ptr<CursorFactoryOzone> cursor_factory_ozone_; |
| 111 scoped_ptr<InputController> input_controller_; | 111 scoped_ptr<InputController> input_controller_; |
| 112 scoped_ptr<GpuPlatformSupport> gpu_platform_support_; | 112 scoped_ptr<GpuPlatformSupport> gpu_platform_support_; |
| 113 scoped_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; | 113 scoped_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; |
| 114 scoped_ptr<OverlayManagerOzone> overlay_manager_; | 114 scoped_ptr<OverlayManagerOzone> overlay_manager_; |
| 115 base::FilePath file_path_; | 115 base::FilePath file_path_; |
| 116 | 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(OzonePlatformTest); | 117 DISALLOW_COPY_AND_ASSIGN(OzonePlatformHeadless); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 } // namespace | 120 } // namespace |
| 121 | 121 |
| 122 OzonePlatform* CreateOzonePlatformTest() { | 122 OzonePlatform* CreateOzonePlatformHeadless() { |
| 123 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); | 123 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 124 base::FilePath location; | 124 base::FilePath location; |
| 125 if (cmd->HasSwitch(switches::kOzoneDumpFile)) | 125 if (cmd->HasSwitch(switches::kOzoneDumpFile)) |
| 126 location = cmd->GetSwitchValuePath(switches::kOzoneDumpFile); | 126 location = cmd->GetSwitchValuePath(switches::kOzoneDumpFile); |
| 127 return new OzonePlatformTest(location); | 127 return new OzonePlatformHeadless(location); |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace ui | 130 } // namespace ui |
| OLD | NEW |