Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: content/browser/renderer_host/offscreen_canvas_surface_manager_unittest.cc

Issue 2686243002: content/ui[Android]: Remove ContextProviderFactory. (Closed)
Patch Set: more rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "cc/surfaces/local_surface_id_allocator.h" 6 #include "cc/surfaces/local_surface_id_allocator.h"
7 #include "content/browser/compositor/test/no_transport_image_transport_factory.h " 7 #include "content/browser/compositor/test/no_transport_image_transport_factory.h "
8 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" 8 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h"
9 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h" 9 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h"
10 #include "content/public/test/test_browser_thread.h" 10 #include "content/public/test/test_browser_thread.h"
11 #include "mojo/public/cpp/bindings/binding.h" 11 #include "mojo/public/cpp/bindings/binding.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 #if defined(OS_ANDROID) 14 #if defined(OS_ANDROID)
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "content/browser/renderer_host/context_provider_factory_impl_android.h"
17 #include "content/test/mock_gpu_channel_establish_factory.h"
18 #else 16 #else
19 #include "content/browser/compositor/image_transport_factory.h" 17 #include "content/browser/compositor/image_transport_factory.h"
20 #endif 18 #endif
21 19
22 namespace content { 20 namespace content {
23 21
24 class OffscreenCanvasSurfaceManagerTest : public testing::Test { 22 class OffscreenCanvasSurfaceManagerTest : public testing::Test {
25 public: 23 public:
26 int getNumSurfaceImplInstances() { 24 int getNumSurfaceImplInstances() {
27 return OffscreenCanvasSurfaceManager::GetInstance() 25 return OffscreenCanvasSurfaceManager::GetInstance()
28 ->registered_surface_instances_.size(); 26 ->registered_surface_instances_.size();
29 } 27 }
30 28
31 void OnSurfaceCreated(const cc::SurfaceId& surface_id) { 29 void OnSurfaceCreated(const cc::SurfaceId& surface_id) {
32 OffscreenCanvasSurfaceManager::GetInstance()->OnSurfaceCreated( 30 OffscreenCanvasSurfaceManager::GetInstance()->OnSurfaceCreated(
33 cc::SurfaceInfo(surface_id, 1.0f, gfx::Size(10, 10))); 31 cc::SurfaceInfo(surface_id, 1.0f, gfx::Size(10, 10)));
34 } 32 }
35 33
36 protected: 34 protected:
37 void SetUp() override; 35 void SetUp() override;
38 void TearDown() override; 36 void TearDown() override;
39 37
40 private: 38 private:
41 std::unique_ptr<TestBrowserThread> ui_thread_; 39 std::unique_ptr<TestBrowserThread> ui_thread_;
42 base::MessageLoopForUI message_loop_; 40 base::MessageLoopForUI message_loop_;
43 #if defined(OS_ANDROID)
44 MockGpuChannelEstablishFactory gpu_channel_factory_;
45 #endif
46 }; 41 };
47 42
48 void OffscreenCanvasSurfaceManagerTest::SetUp() { 43 void OffscreenCanvasSurfaceManagerTest::SetUp() {
49 #if defined(OS_ANDROID) 44 #if !defined(OS_ANDROID)
50 ContextProviderFactoryImpl::Initialize(&gpu_channel_factory_);
51 ui::ContextProviderFactory::SetInstance(
52 ContextProviderFactoryImpl::GetInstance());
53 #else
54 ImageTransportFactory::InitializeForUnitTests( 45 ImageTransportFactory::InitializeForUnitTests(
55 std::unique_ptr<ImageTransportFactory>( 46 std::unique_ptr<ImageTransportFactory>(
56 new NoTransportImageTransportFactory)); 47 new NoTransportImageTransportFactory));
57 #endif 48 #endif
58 ui_thread_.reset(new TestBrowserThread(BrowserThread::UI, &message_loop_)); 49 ui_thread_.reset(new TestBrowserThread(BrowserThread::UI, &message_loop_));
59 } 50 }
60 51
61 void OffscreenCanvasSurfaceManagerTest::TearDown() { 52 void OffscreenCanvasSurfaceManagerTest::TearDown() {
62 #if defined(OS_ANDROID) 53 #if !defined(OS_ANDROID)
63 ui::ContextProviderFactory::SetInstance(nullptr);
64 ContextProviderFactoryImpl::Terminate();
65 #else
66 ImageTransportFactory::Terminate(); 54 ImageTransportFactory::Terminate();
67 #endif 55 #endif
68 } 56 }
69 57
70 // This test mimics the workflow of OffscreenCanvas.commit() on renderer 58 // This test mimics the workflow of OffscreenCanvas.commit() on renderer
71 // process. 59 // process.
72 TEST_F(OffscreenCanvasSurfaceManagerTest, 60 TEST_F(OffscreenCanvasSurfaceManagerTest,
73 SingleHTMLCanvasElementTransferToOffscreen) { 61 SingleHTMLCanvasElementTransferToOffscreen) {
74 cc::mojom::DisplayCompositorClientPtr client; 62 cc::mojom::DisplayCompositorClientPtr client;
75 cc::FrameSinkId frame_sink_id(3, 3); 63 cc::FrameSinkId frame_sink_id(3, 3);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( 102 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance(
115 frame_sink_id_b)); 103 frame_sink_id_b));
116 104
117 surface_impl_a = nullptr; 105 surface_impl_a = nullptr;
118 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); 106 EXPECT_EQ(1, this->getNumSurfaceImplInstances());
119 surface_impl_b = nullptr; 107 surface_impl_b = nullptr;
120 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); 108 EXPECT_EQ(0, this->getNumSurfaceImplInstances());
121 } 109 }
122 110
123 } // namespace content 111 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698