| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mash/test/mash_test_suite.h" | 5 #include "mash/test/mash_test_suite.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 "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "cc/output/context_provider.h" | 11 #include "cc/output/context_provider.h" |
| 12 #include "cc/surfaces/frame_sink_id_allocator.h" | 12 #include "cc/surfaces/frame_sink_id_allocator.h" |
| 13 #include "cc/surfaces/surface_manager.h" | 13 #include "cc/surfaces/surface_manager.h" |
| 14 #include "cc/test/test_gpu_memory_buffer_manager.h" | |
| 15 #include "cc/test/test_task_graph_runner.h" | |
| 16 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/base/ui_base_paths.h" | 16 #include "ui/base/ui_base_paths.h" |
| 19 #include "ui/compositor/compositor.h" | 17 #include "ui/compositor/compositor.h" |
| 20 #include "ui/compositor/reflector.h" | 18 #include "ui/compositor/reflector.h" |
| 19 #include "ui/compositor/test/fake_context_factory.h" |
| 21 #include "ui/gl/gl_bindings.h" | 20 #include "ui/gl/gl_bindings.h" |
| 22 #include "ui/gl/gl_switches.h" | 21 #include "ui/gl/gl_switches.h" |
| 23 #include "ui/gl/test/gl_surface_test_support.h" | 22 #include "ui/gl/test/gl_surface_test_support.h" |
| 24 | 23 |
| 25 namespace mash { | 24 namespace mash { |
| 26 namespace test { | 25 namespace test { |
| 27 | 26 |
| 28 class TestContextFactory : public ui::ContextFactory, | |
| 29 public ui::ContextFactoryPrivate { | |
| 30 public: | |
| 31 TestContextFactory() : frame_sink_id_allocator_(0) {} | |
| 32 ~TestContextFactory() override {} | |
| 33 | |
| 34 private: | |
| 35 // ui::ContextFactory:: | |
| 36 void CreateCompositorFrameSink( | |
| 37 base::WeakPtr<ui::Compositor> compositor) override {} | |
| 38 scoped_refptr<cc::ContextProvider> SharedMainThreadContextProvider() | |
| 39 override { | |
| 40 return nullptr; | |
| 41 } | |
| 42 void RemoveCompositor(ui::Compositor* compositor) override {} | |
| 43 bool DoesCreateTestContexts() override { return true; } | |
| 44 uint32_t GetImageTextureTarget(gfx::BufferFormat format, | |
| 45 gfx::BufferUsage usage) override { | |
| 46 return GL_TEXTURE_2D; | |
| 47 } | |
| 48 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override { | |
| 49 return &gpu_memory_buffer_manager_; | |
| 50 } | |
| 51 cc::TaskGraphRunner* GetTaskGraphRunner() override { | |
| 52 return &task_graph_runner_; | |
| 53 } | |
| 54 void AddObserver(ui::ContextFactoryObserver* observer) override {} | |
| 55 void RemoveObserver(ui::ContextFactoryObserver* observer) override {} | |
| 56 | |
| 57 // ui::ContextFactoryPrivate: | |
| 58 std::unique_ptr<ui::Reflector> CreateReflector( | |
| 59 ui::Compositor* mirrored_compositor, | |
| 60 ui::Layer* mirroring_layer) override { | |
| 61 return nullptr; | |
| 62 } | |
| 63 void RemoveReflector(ui::Reflector* reflector) override {} | |
| 64 cc::FrameSinkId AllocateFrameSinkId() override { | |
| 65 return frame_sink_id_allocator_.NextFrameSinkId(); | |
| 66 } | |
| 67 cc::SurfaceManager* GetSurfaceManager() override { return &surface_manager_; } | |
| 68 void SetDisplayVisible(ui::Compositor* compositor, bool visible) override {} | |
| 69 void ResizeDisplay(ui::Compositor* compositor, | |
| 70 const gfx::Size& size) override {} | |
| 71 void SetDisplayColorSpace( | |
| 72 ui::Compositor* compositor, | |
| 73 const gfx::ColorSpace& blending_color_space, | |
| 74 const gfx::ColorSpace& output_color_space) override {} | |
| 75 | |
| 76 void SetAuthoritativeVSyncInterval(ui::Compositor* compositor, | |
| 77 base::TimeDelta interval) override {} | |
| 78 void SetDisplayVSyncParameters(ui::Compositor* compositor, | |
| 79 base::TimeTicks timebase, | |
| 80 base::TimeDelta interval) override {} | |
| 81 void SetOutputIsSecure(ui::Compositor* compositor, bool secure) override {} | |
| 82 | |
| 83 cc::TestTaskGraphRunner task_graph_runner_; | |
| 84 cc::TestGpuMemoryBufferManager gpu_memory_buffer_manager_; | |
| 85 cc::FrameSinkIdAllocator frame_sink_id_allocator_; | |
| 86 cc::SurfaceManager surface_manager_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(TestContextFactory); | |
| 89 }; | |
| 90 | |
| 91 MashTestSuite::MashTestSuite(int argc, char** argv) : TestSuite(argc, argv) {} | 27 MashTestSuite::MashTestSuite(int argc, char** argv) : TestSuite(argc, argv) {} |
| 92 | 28 |
| 93 MashTestSuite::~MashTestSuite() {} | 29 MashTestSuite::~MashTestSuite() {} |
| 94 | 30 |
| 95 void MashTestSuite::Initialize() { | 31 void MashTestSuite::Initialize() { |
| 96 base::TestSuite::Initialize(); | 32 base::TestSuite::Initialize(); |
| 97 gl::GLSurfaceTestSupport::InitializeOneOff(); | 33 gl::GLSurfaceTestSupport::InitializeOneOff(); |
| 98 | 34 |
| 99 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 35 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 100 switches::kOverrideUseSoftwareGLForTests); | 36 switches::kOverrideUseSoftwareGLForTests); |
| 101 | 37 |
| 102 // Load ash mus strings and resources; not 'common' (Chrome) resources. | 38 // Load ash mus strings and resources; not 'common' (Chrome) resources. |
| 103 base::FilePath resources; | 39 base::FilePath resources; |
| 104 PathService::Get(base::DIR_MODULE, &resources); | 40 PathService::Get(base::DIR_MODULE, &resources); |
| 105 resources = resources.Append(FILE_PATH_LITERAL("ash_mus_resources.pak")); | 41 resources = resources.Append(FILE_PATH_LITERAL("ash_mus_resources.pak")); |
| 106 ui::ResourceBundle::InitSharedInstanceWithPakPath(resources); | 42 ui::ResourceBundle::InitSharedInstanceWithPakPath(resources); |
| 107 | 43 |
| 108 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_); | 44 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_); |
| 109 env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS); | 45 env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS); |
| 110 | 46 |
| 111 compositor_context_factory_ = base::MakeUnique<TestContextFactory>(); | 47 context_factory_ = base::MakeUnique<ui::FakeContextFactory>(); |
| 112 env_->set_context_factory(compositor_context_factory_.get()); | 48 env_->set_context_factory(context_factory_.get()); |
| 113 env_->set_context_factory_private(compositor_context_factory_.get()); | 49 env_->set_context_factory_private(nullptr); |
| 114 } | 50 } |
| 115 | 51 |
| 116 void MashTestSuite::Shutdown() { | 52 void MashTestSuite::Shutdown() { |
| 117 env_.reset(); | 53 env_.reset(); |
| 118 ui::ResourceBundle::CleanupSharedInstance(); | 54 ui::ResourceBundle::CleanupSharedInstance(); |
| 119 base::TestSuite::Shutdown(); | 55 base::TestSuite::Shutdown(); |
| 120 } | 56 } |
| 121 | 57 |
| 122 } // namespace test | 58 } // namespace test |
| 123 } // namespace mash | 59 } // namespace mash |
| OLD | NEW |