ozone_platform_test.cc revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
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. 4 5#include "ui/ozone/platform/test/ozone_platform_test.h" 6 7#include "base/command_line.h" 8#include "base/files/file_path.h" 9#include "ui/events/platform/platform_event_source.h" 10#include "ui/ozone/platform/test/test_cursor_factory.h" 11#include "ui/ozone/platform/test/test_window.h" 12#include "ui/ozone/platform/test/test_window_manager.h" 13#include "ui/ozone/public/cursor_factory_ozone.h" 14#include "ui/ozone/public/gpu_platform_support.h" 15#include "ui/ozone/public/gpu_platform_support_host.h" 16#include "ui/ozone/public/ozone_platform.h" 17#include "ui/ozone/public/ozone_switches.h" 18 19#if defined(OS_CHROMEOS) 20#include "ui/ozone/common/chromeos/native_display_delegate_ozone.h" 21#include "ui/ozone/common/chromeos/touchscreen_device_manager_ozone.h" 22#endif 23 24namespace ui { 25 26namespace { 27 28// OzonePlatform for testing 29// 30// This platform dumps images to a file for testing purposes. 31class OzonePlatformTest : public OzonePlatform { 32 public: 33 OzonePlatformTest(const base::FilePath& dump_file) : file_path_(dump_file) {} 34 virtual ~OzonePlatformTest() {} 35 36 // OzonePlatform: 37 virtual ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE { 38 return window_manager_.get(); 39 } 40 virtual CursorFactoryOzone* GetCursorFactoryOzone() OVERRIDE { 41 return cursor_factory_ozone_.get(); 42 } 43 virtual GpuPlatformSupport* GetGpuPlatformSupport() OVERRIDE { 44 return gpu_platform_support_.get(); 45 } 46 virtual GpuPlatformSupportHost* GetGpuPlatformSupportHost() OVERRIDE { 47 return gpu_platform_support_host_.get(); 48 } 49 virtual scoped_ptr<PlatformWindow> CreatePlatformWindow( 50 PlatformWindowDelegate* delegate, 51 const gfx::Rect& bounds) OVERRIDE { 52 return make_scoped_ptr<PlatformWindow>( 53 new TestWindow(delegate, window_manager_.get(), bounds)); 54 } 55 56#if defined(OS_CHROMEOS) 57 virtual scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() 58 OVERRIDE { 59 return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateOzone()); 60 } 61 virtual scoped_ptr<TouchscreenDeviceManager> 62 CreateTouchscreenDeviceManager() OVERRIDE { 63 return scoped_ptr<TouchscreenDeviceManager>( 64 new TouchscreenDeviceManagerOzone()); 65 } 66#endif 67 68 virtual void InitializeUI() OVERRIDE { 69 window_manager_.reset(new TestWindowManager(file_path_)); 70 window_manager_->Initialize(); 71 // This unbreaks tests that create their own. 72 if (!PlatformEventSource::GetInstance()) 73 platform_event_source_ = PlatformEventSource::CreateDefault(); 74 75 cursor_factory_ozone_.reset(new TestCursorFactory()); 76 gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); 77 } 78 79 virtual void InitializeGPU() OVERRIDE { 80 gpu_platform_support_.reset(CreateStubGpuPlatformSupport()); 81 } 82 83 private: 84 scoped_ptr<TestWindowManager> window_manager_; 85 scoped_ptr<PlatformEventSource> platform_event_source_; 86 scoped_ptr<CursorFactoryOzone> cursor_factory_ozone_; 87 scoped_ptr<GpuPlatformSupport> gpu_platform_support_; 88 scoped_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; 89 base::FilePath file_path_; 90 91 DISALLOW_COPY_AND_ASSIGN(OzonePlatformTest); 92}; 93 94} // namespace 95 96OzonePlatform* CreateOzonePlatformTest() { 97 CommandLine* cmd = CommandLine::ForCurrentProcess(); 98 base::FilePath location; 99 if (cmd->HasSwitch(switches::kOzoneDumpFile)) 100 location = cmd->GetSwitchValuePath(switches::kOzoneDumpFile); 101 return new OzonePlatformTest(location); 102} 103 104} // namespace ui 105