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" |
15 #include "ui/aura/test/mus/test_context_factory.h" | |
17 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/base/ui_base_paths.h" | 17 #include "ui/base/ui_base_paths.h" |
19 #include "ui/compositor/compositor.h" | 18 #include "ui/compositor/compositor.h" |
20 #include "ui/compositor/reflector.h" | 19 #include "ui/compositor/reflector.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, | 27 class TestContextFactoryPrivate : public ui::ContextFactoryPrivate { |
sky
2017/03/17 15:48:16
How come mash needs this code, but not other tests
sadrul
2017/03/17 16:18:35
I had added a comment below where this is used. So
sky
2017/03/17 16:43:43
SGTM
| |
29 public ui::ContextFactoryPrivate { | |
30 public: | 28 public: |
31 TestContextFactory() : frame_sink_id_allocator_(0) {} | 29 TestContextFactoryPrivate() : frame_sink_id_allocator_(0) {} |
32 ~TestContextFactory() override {} | 30 ~TestContextFactoryPrivate() {} |
33 | 31 |
34 private: | 32 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: | 33 // ui::ContextFactoryPrivate: |
58 std::unique_ptr<ui::Reflector> CreateReflector( | 34 std::unique_ptr<ui::Reflector> CreateReflector( |
59 ui::Compositor* mirrored_compositor, | 35 ui::Compositor* mirrored_compositor, |
60 ui::Layer* mirroring_layer) override { | 36 ui::Layer* mirroring_layer) override { |
61 return nullptr; | 37 return nullptr; |
62 } | 38 } |
63 void RemoveReflector(ui::Reflector* reflector) override {} | 39 void RemoveReflector(ui::Reflector* reflector) override {} |
64 cc::FrameSinkId AllocateFrameSinkId() override { | 40 cc::FrameSinkId AllocateFrameSinkId() override { |
65 return frame_sink_id_allocator_.NextFrameSinkId(); | 41 return frame_sink_id_allocator_.NextFrameSinkId(); |
66 } | 42 } |
67 cc::SurfaceManager* GetSurfaceManager() override { return &surface_manager_; } | 43 cc::SurfaceManager* GetSurfaceManager() override { return &surface_manager_; } |
68 void SetDisplayVisible(ui::Compositor* compositor, bool visible) override {} | 44 void SetDisplayVisible(ui::Compositor* compositor, bool visible) override {} |
69 void ResizeDisplay(ui::Compositor* compositor, | 45 void ResizeDisplay(ui::Compositor* compositor, |
70 const gfx::Size& size) override {} | 46 const gfx::Size& size) override {} |
71 void SetDisplayColorSpace( | 47 void SetDisplayColorSpace( |
72 ui::Compositor* compositor, | 48 ui::Compositor* compositor, |
73 const gfx::ColorSpace& blending_color_space, | 49 const gfx::ColorSpace& blending_color_space, |
74 const gfx::ColorSpace& output_color_space) override {} | 50 const gfx::ColorSpace& output_color_space) override {} |
75 | 51 |
76 void SetAuthoritativeVSyncInterval(ui::Compositor* compositor, | 52 void SetAuthoritativeVSyncInterval(ui::Compositor* compositor, |
77 base::TimeDelta interval) override {} | 53 base::TimeDelta interval) override {} |
78 void SetDisplayVSyncParameters(ui::Compositor* compositor, | 54 void SetDisplayVSyncParameters(ui::Compositor* compositor, |
79 base::TimeTicks timebase, | 55 base::TimeTicks timebase, |
80 base::TimeDelta interval) override {} | 56 base::TimeDelta interval) override {} |
81 void SetOutputIsSecure(ui::Compositor* compositor, bool secure) override {} | 57 void SetOutputIsSecure(ui::Compositor* compositor, bool secure) override {} |
82 | 58 |
83 cc::TestTaskGraphRunner task_graph_runner_; | |
84 cc::TestGpuMemoryBufferManager gpu_memory_buffer_manager_; | |
85 cc::FrameSinkIdAllocator frame_sink_id_allocator_; | 59 cc::FrameSinkIdAllocator frame_sink_id_allocator_; |
86 cc::SurfaceManager surface_manager_; | 60 cc::SurfaceManager surface_manager_; |
87 | 61 |
88 DISALLOW_COPY_AND_ASSIGN(TestContextFactory); | 62 DISALLOW_COPY_AND_ASSIGN(TestContextFactoryPrivate); |
89 }; | 63 }; |
90 | 64 |
91 MashTestSuite::MashTestSuite(int argc, char** argv) : TestSuite(argc, argv) {} | 65 MashTestSuite::MashTestSuite(int argc, char** argv) : TestSuite(argc, argv) {} |
92 | 66 |
93 MashTestSuite::~MashTestSuite() {} | 67 MashTestSuite::~MashTestSuite() {} |
94 | 68 |
95 void MashTestSuite::Initialize() { | 69 void MashTestSuite::Initialize() { |
96 base::TestSuite::Initialize(); | 70 base::TestSuite::Initialize(); |
97 gl::GLSurfaceTestSupport::InitializeOneOff(); | 71 gl::GLSurfaceTestSupport::InitializeOneOff(); |
98 | 72 |
99 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 73 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
100 switches::kOverrideUseSoftwareGLForTests); | 74 switches::kOverrideUseSoftwareGLForTests); |
101 | 75 |
102 // Load ash mus strings and resources; not 'common' (Chrome) resources. | 76 // Load ash mus strings and resources; not 'common' (Chrome) resources. |
103 base::FilePath resources; | 77 base::FilePath resources; |
104 PathService::Get(base::DIR_MODULE, &resources); | 78 PathService::Get(base::DIR_MODULE, &resources); |
105 resources = resources.Append(FILE_PATH_LITERAL("ash_mus_resources.pak")); | 79 resources = resources.Append(FILE_PATH_LITERAL("ash_mus_resources.pak")); |
106 ui::ResourceBundle::InitSharedInstanceWithPakPath(resources); | 80 ui::ResourceBundle::InitSharedInstanceWithPakPath(resources); |
107 | 81 |
108 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_); | 82 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_); |
109 env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS); | 83 env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS); |
110 | 84 |
111 compositor_context_factory_ = base::MakeUnique<TestContextFactory>(); | 85 context_factory_ = base::MakeUnique<aura::test::TestContextFactory>(); |
112 env_->set_context_factory(compositor_context_factory_.get()); | 86 env_->set_context_factory(context_factory_.get()); |
113 env_->set_context_factory_private(compositor_context_factory_.get()); | 87 |
88 // Some tests in ash use the ContextFactoryPrivate (e.g. | |
Fady Samuel
2017/03/17 15:37:28
nit: Add a TODO to not depend on ContextFactoryPri
sadrul
2017/03/17 16:50:29
Just removed the dep instead.
| |
89 // LaserPointerControllerTest). So install a dummy factory here. | |
90 context_factory_private_ = base::MakeUnique<TestContextFactoryPrivate>(); | |
91 env_->set_context_factory_private(context_factory_private_.get()); | |
114 } | 92 } |
115 | 93 |
116 void MashTestSuite::Shutdown() { | 94 void MashTestSuite::Shutdown() { |
117 env_.reset(); | 95 env_.reset(); |
118 ui::ResourceBundle::CleanupSharedInstance(); | 96 ui::ResourceBundle::CleanupSharedInstance(); |
119 base::TestSuite::Shutdown(); | 97 base::TestSuite::Shutdown(); |
120 } | 98 } |
121 | 99 |
122 } // namespace test | 100 } // namespace test |
123 } // namespace mash | 101 } // namespace mash |
OLD | NEW |