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/base/cursor/ozone/bitmap_cursor_factory_ozone.h" 10#include "ui/events/platform/platform_event_source.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#endif 22 23namespace ui { 24 25namespace { 26 27// OzonePlatform for testing 28// 29// This platform dumps images to a file for testing purposes. 30class OzonePlatformTest : public OzonePlatform { 31 public: 32 OzonePlatformTest(const base::FilePath& dump_file) : file_path_(dump_file) {} 33 virtual ~OzonePlatformTest() {} 34 35 // OzonePlatform: 36 virtual ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE { 37 return window_manager_.get(); 38 } 39 virtual CursorFactoryOzone* GetCursorFactoryOzone() OVERRIDE { 40 return cursor_factory_ozone_.get(); 41 } 42 virtual GpuPlatformSupport* GetGpuPlatformSupport() OVERRIDE { 43 return gpu_platform_support_.get(); 44 } 45 virtual GpuPlatformSupportHost* GetGpuPlatformSupportHost() OVERRIDE { 46 return gpu_platform_support_host_.get(); 47 } 48 virtual scoped_ptr<PlatformWindow> CreatePlatformWindow( 49 PlatformWindowDelegate* delegate, 50 const gfx::Rect& bounds) OVERRIDE { 51 return make_scoped_ptr<PlatformWindow>( 52 new TestWindow(delegate, window_manager_.get(), bounds)); 53 } 54 55#if defined(OS_CHROMEOS) 56 virtual scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() 57 OVERRIDE { 58 return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateOzone()); 59 } 60#endif 61 62 virtual void InitializeUI() OVERRIDE { 63 window_manager_.reset(new TestWindowManager(file_path_)); 64 window_manager_->Initialize(); 65 // This unbreaks tests that create their own. 66 if (!PlatformEventSource::GetInstance()) 67 platform_event_source_ = PlatformEventSource::CreateDefault(); 68 69 cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone); 70 gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); 71 } 72 73 virtual void InitializeGPU() OVERRIDE { 74 gpu_platform_support_.reset(CreateStubGpuPlatformSupport()); 75 } 76 77 private: 78 scoped_ptr<TestWindowManager> window_manager_; 79 scoped_ptr<PlatformEventSource> platform_event_source_; 80 scoped_ptr<CursorFactoryOzone> cursor_factory_ozone_; 81 scoped_ptr<GpuPlatformSupport> gpu_platform_support_; 82 scoped_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; 83 base::FilePath file_path_; 84 85 DISALLOW_COPY_AND_ASSIGN(OzonePlatformTest); 86}; 87 88} // namespace 89 90OzonePlatform* CreateOzonePlatformTest() { 91 CommandLine* cmd = CommandLine::ForCurrentProcess(); 92 base::FilePath location; 93 if (cmd->HasSwitch(switches::kOzoneDumpFile)) 94 location = cmd->GetSwitchValuePath(switches::kOzoneDumpFile); 95 return new OzonePlatformTest(location); 96} 97 98} // namespace ui 99