| 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/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "cc/output/context_provider.h" |
| 12 #include "cc/test/test_gpu_memory_buffer_manager.h" |
| 13 #include "cc/test/test_task_graph_runner.h" |
| 10 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/base/ui_base_paths.h" | 16 #include "ui/base/ui_base_paths.h" |
| 13 #include "ui/compositor/test/context_factories_for_test.h" | 17 #include "ui/compositor/compositor.h" |
| 18 #include "ui/gl/gl_bindings.h" |
| 14 #include "ui/gl/gl_switches.h" | 19 #include "ui/gl/gl_switches.h" |
| 15 #include "ui/gl/test/gl_surface_test_support.h" | |
| 16 | 20 |
| 17 namespace mash { | 21 namespace mash { |
| 18 namespace test { | 22 namespace test { |
| 19 | 23 |
| 24 class TestContextFactory : public ui::ContextFactory { |
| 25 public: |
| 26 TestContextFactory() {} |
| 27 ~TestContextFactory() override {} |
| 28 |
| 29 private: |
| 30 // ui::ContextFactory:: |
| 31 void CreateCompositorFrameSink( |
| 32 base::WeakPtr<ui::Compositor> compositor) override {} |
| 33 scoped_refptr<cc::ContextProvider> SharedMainThreadContextProvider() |
| 34 override { |
| 35 return nullptr; |
| 36 } |
| 37 void RemoveCompositor(ui::Compositor* compositor) override {} |
| 38 bool DoesCreateTestContexts() override { return true; } |
| 39 uint32_t GetImageTextureTarget(gfx::BufferFormat format, |
| 40 gfx::BufferUsage usage) override { |
| 41 return GL_TEXTURE_2D; |
| 42 } |
| 43 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override { |
| 44 return &gpu_memory_buffer_manager_; |
| 45 } |
| 46 cc::TaskGraphRunner* GetTaskGraphRunner() override { |
| 47 return &task_graph_runner_; |
| 48 } |
| 49 void AddObserver(ui::ContextFactoryObserver* observer) override {} |
| 50 void RemoveObserver(ui::ContextFactoryObserver* observer) override {} |
| 51 |
| 52 cc::TestTaskGraphRunner task_graph_runner_; |
| 53 cc::TestGpuMemoryBufferManager gpu_memory_buffer_manager_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(TestContextFactory); |
| 56 }; |
| 57 |
| 20 MashTestSuite::MashTestSuite(int argc, char** argv) : TestSuite(argc, argv) {} | 58 MashTestSuite::MashTestSuite(int argc, char** argv) : TestSuite(argc, argv) {} |
| 21 | 59 |
| 22 MashTestSuite::~MashTestSuite() {} | 60 MashTestSuite::~MashTestSuite() {} |
| 23 | 61 |
| 24 void MashTestSuite::Initialize() { | 62 void MashTestSuite::Initialize() { |
| 25 base::TestSuite::Initialize(); | 63 base::TestSuite::Initialize(); |
| 26 | 64 |
| 27 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 65 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 28 switches::kOverrideUseGLWithOSMesaForTests); | 66 switches::kOverrideUseGLWithOSMesaForTests); |
| 29 | 67 |
| 30 // Load ash mus strings and resources; not 'common' (Chrome) resources. | 68 // Load ash mus strings and resources; not 'common' (Chrome) resources. |
| 31 base::FilePath resources; | 69 base::FilePath resources; |
| 32 PathService::Get(base::DIR_MODULE, &resources); | 70 PathService::Get(base::DIR_MODULE, &resources); |
| 33 resources = resources.Append(FILE_PATH_LITERAL("ash_mus_resources.pak")); | 71 resources = resources.Append(FILE_PATH_LITERAL("ash_mus_resources.pak")); |
| 34 ui::ResourceBundle::InitSharedInstanceWithPakPath(resources); | 72 ui::ResourceBundle::InitSharedInstanceWithPakPath(resources); |
| 35 | 73 |
| 36 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_); | 74 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_); |
| 37 env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS); | 75 env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS); |
| 38 gl::GLSurfaceTestSupport::InitializeOneOff(); | |
| 39 const bool enable_pixel_output = false; | |
| 40 | 76 |
| 41 ui::ContextFactory* context_factory = nullptr; | 77 compositor_context_factory_ = base::MakeUnique<TestContextFactory>(); |
| 42 ui::ContextFactoryPrivate* context_factory_private = nullptr; | 78 env_->set_context_factory(compositor_context_factory_.get()); |
| 43 ui::InitializeContextFactoryForTests(enable_pixel_output, &context_factory, | |
| 44 &context_factory_private); | |
| 45 | |
| 46 env_->set_context_factory(context_factory); | |
| 47 env_->set_context_factory_private(context_factory_private); | |
| 48 } | 79 } |
| 49 | 80 |
| 50 void MashTestSuite::Shutdown() { | 81 void MashTestSuite::Shutdown() { |
| 51 ui::TerminateContextFactoryForTests(); | |
| 52 env_.reset(); | 82 env_.reset(); |
| 53 ui::ResourceBundle::CleanupSharedInstance(); | 83 ui::ResourceBundle::CleanupSharedInstance(); |
| 54 base::TestSuite::Shutdown(); | 84 base::TestSuite::Shutdown(); |
| 55 } | 85 } |
| 56 | 86 |
| 57 } // namespace test | 87 } // namespace test |
| 58 } // namespace mash | 88 } // namespace mash |
| OLD | NEW |