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

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager_unittest.cc

Issue 1170623003: Revert "content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/location.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "content/browser/browser_thread_impl.h" 11 #include "content/browser/browser_thread_impl.h"
14 #include "content/browser/renderer_host/media/media_stream_manager.h" 12 #include "content/browser/renderer_host/media/media_stream_manager.h"
15 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 13 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
16 #include "content/common/media/media_stream_options.h" 14 #include "content/common/media/media_stream_options.h"
17 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
18 #include "content/public/test/test_browser_thread_bundle.h" 16 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "media/audio/audio_manager_base.h" 17 #include "media/audio/audio_manager_base.h"
20 #include "media/audio/fake_audio_log_factory.h" 18 #include "media/audio/fake_audio_log_factory.h"
21 #include "media/base/media_switches.h" 19 #include "media/base/media_switches.h"
22 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 70
73 private: 71 private:
74 media::FakeAudioLogFactory fake_audio_log_factory_; 72 media::FakeAudioLogFactory fake_audio_log_factory_;
75 DISALLOW_COPY_AND_ASSIGN(MockAudioManager); 73 DISALLOW_COPY_AND_ASSIGN(MockAudioManager);
76 }; 74 };
77 75
78 class MediaStreamManagerTest : public ::testing::Test { 76 class MediaStreamManagerTest : public ::testing::Test {
79 public: 77 public:
80 MediaStreamManagerTest() 78 MediaStreamManagerTest()
81 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 79 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
82 task_runner_(base::ThreadTaskRunnerHandle::Get()) { 80 message_loop_(base::MessageLoopProxy::current()) {
83 // Create our own MediaStreamManager. Use fake devices to run on the bots. 81 // Create our own MediaStreamManager. Use fake devices to run on the bots.
84 base::CommandLine::ForCurrentProcess()->AppendSwitch( 82 base::CommandLine::ForCurrentProcess()->AppendSwitch(
85 switches::kUseFakeDeviceForMediaStream); 83 switches::kUseFakeDeviceForMediaStream);
86 audio_manager_.reset(new MockAudioManager()); 84 audio_manager_.reset(new MockAudioManager());
87 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); 85 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
88 } 86 }
89 87
90 virtual ~MediaStreamManagerTest() { 88 virtual ~MediaStreamManagerTest() {
91 } 89 }
92 90
93 MOCK_METHOD1(Response, void(int index)); 91 MOCK_METHOD1(Response, void(int index));
94 void ResponseCallback(int index, 92 void ResponseCallback(int index,
95 const MediaStreamDevices& devices, 93 const MediaStreamDevices& devices,
96 scoped_ptr<MediaStreamUIProxy> ui_proxy) { 94 scoped_ptr<MediaStreamUIProxy> ui_proxy) {
97 Response(index); 95 Response(index);
98 task_runner_->PostTask(FROM_HERE, run_loop_.QuitClosure()); 96 message_loop_->PostTask(FROM_HERE, run_loop_.QuitClosure());
99 } 97 }
100 98
101 protected: 99 protected:
102 std::string MakeMediaAccessRequest(int index) { 100 std::string MakeMediaAccessRequest(int index) {
103 const int render_process_id = 1; 101 const int render_process_id = 1;
104 const int render_frame_id = 1; 102 const int render_frame_id = 1;
105 const int page_request_id = 1; 103 const int page_request_id = 1;
106 const GURL security_origin; 104 const GURL security_origin;
107 MediaStreamManager::MediaRequestResponseCallback callback = 105 MediaStreamManager::MediaRequestResponseCallback callback =
108 base::Bind(&MediaStreamManagerTest::ResponseCallback, 106 base::Bind(&MediaStreamManagerTest::ResponseCallback,
109 base::Unretained(this), index); 107 base::Unretained(this), index);
110 StreamOptions options(true, true); 108 StreamOptions options(true, true);
111 return media_stream_manager_->MakeMediaAccessRequest(render_process_id, 109 return media_stream_manager_->MakeMediaAccessRequest(render_process_id,
112 render_frame_id, 110 render_frame_id,
113 page_request_id, 111 page_request_id,
114 options, 112 options,
115 security_origin, 113 security_origin,
116 callback); 114 callback);
117 } 115 }
118 116
119 scoped_ptr<media::AudioManager> audio_manager_; 117 scoped_ptr<media::AudioManager> audio_manager_;
120 scoped_ptr<MediaStreamManager> media_stream_manager_; 118 scoped_ptr<MediaStreamManager> media_stream_manager_;
121 content::TestBrowserThreadBundle thread_bundle_; 119 content::TestBrowserThreadBundle thread_bundle_;
122 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 120 scoped_refptr<base::MessageLoopProxy> message_loop_;
123 base::RunLoop run_loop_; 121 base::RunLoop run_loop_;
124 122
125 private: 123 private:
126 DISALLOW_COPY_AND_ASSIGN(MediaStreamManagerTest); 124 DISALLOW_COPY_AND_ASSIGN(MediaStreamManagerTest);
127 }; 125 };
128 126
129 TEST_F(MediaStreamManagerTest, MakeMediaAccessRequest) { 127 TEST_F(MediaStreamManagerTest, MakeMediaAccessRequest) {
130 MakeMediaAccessRequest(0); 128 MakeMediaAccessRequest(0);
131 129
132 // Expecting the callback will be triggered and quit the test. 130 // Expecting the callback will be triggered and quit the test.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 std::string label2 = MakeMediaAccessRequest(1); 174 std::string label2 = MakeMediaAccessRequest(1);
177 media_stream_manager_->CancelRequest(label1); 175 media_stream_manager_->CancelRequest(label1);
178 176
179 // Expecting the callback from the second request will be triggered and 177 // Expecting the callback from the second request will be triggered and
180 // quit the test. 178 // quit the test.
181 EXPECT_CALL(*this, Response(1)); 179 EXPECT_CALL(*this, Response(1));
182 run_loop_.Run(); 180 run_loop_.Run();
183 } 181 }
184 182
185 } // namespace content 183 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698