OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <queue> | 5 #include <queue> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/browser/extensions/api/desktop_capture/desktop_capture_api.h" | 13 #include "chrome/browser/extensions/api/desktop_capture/desktop_capture_api.h" |
14 #include "chrome/browser/extensions/extension_apitest.h" | 14 #include "chrome/browser/extensions/extension_apitest.h" |
15 #include "chrome/browser/media/fake_desktop_media_list.h" | 15 #include "chrome/browser/media/fake_desktop_media_list.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
20 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
| 21 #include "extensions/common/switches.h" |
21 #include "net/dns/mock_host_resolver.h" | 22 #include "net/dns/mock_host_resolver.h" |
22 #include "net/test/embedded_test_server/embedded_test_server.h" | 23 #include "net/test/embedded_test_server/embedded_test_server.h" |
23 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_types.h" | 24 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_types.h" |
24 | 25 |
25 namespace extensions { | 26 namespace extensions { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 struct TestFlags { | 30 struct TestFlags { |
30 bool expect_screens; | 31 bool expect_screens; |
31 bool expect_windows; | 32 bool expect_windows; |
| 33 bool expect_tabs; |
| 34 bool expect_audio; |
32 content::DesktopMediaID selected_source; | 35 content::DesktopMediaID selected_source; |
33 bool cancelled; | 36 bool cancelled; |
34 | 37 |
35 // Following flags are set by FakeDesktopMediaPicker when it's created and | 38 // Following flags are set by FakeDesktopMediaPicker when it's created and |
36 // deleted. | 39 // deleted. |
37 bool picker_created; | 40 bool picker_created; |
38 bool picker_deleted; | 41 bool picker_deleted; |
39 }; | 42 }; |
40 | 43 |
41 class FakeDesktopMediaPicker : public DesktopMediaPicker { | 44 class FakeDesktopMediaPicker : public DesktopMediaPicker { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 ~FakeDesktopMediaPickerFactory() override {} | 92 ~FakeDesktopMediaPickerFactory() override {} |
90 | 93 |
91 void SetTestFlags(TestFlags* test_flags, int tests_count) { | 94 void SetTestFlags(TestFlags* test_flags, int tests_count) { |
92 test_flags_ = test_flags; | 95 test_flags_ = test_flags; |
93 tests_count_ = tests_count; | 96 tests_count_ = tests_count; |
94 current_test_ = 0; | 97 current_test_ = 0; |
95 } | 98 } |
96 | 99 |
97 // DesktopCaptureChooseDesktopMediaFunction::PickerFactory interface. | 100 // DesktopCaptureChooseDesktopMediaFunction::PickerFactory interface. |
98 scoped_ptr<DesktopMediaList> CreateModel(bool show_screens, | 101 scoped_ptr<DesktopMediaList> CreateModel(bool show_screens, |
99 bool show_windows) override { | 102 bool show_windows, |
| 103 bool show_tabs, |
| 104 bool show_audio) override { |
100 EXPECT_LE(current_test_, tests_count_); | 105 EXPECT_LE(current_test_, tests_count_); |
101 if (current_test_ >= tests_count_) | 106 if (current_test_ >= tests_count_) |
102 return scoped_ptr<DesktopMediaList>(); | 107 return scoped_ptr<DesktopMediaList>(); |
103 EXPECT_EQ(test_flags_[current_test_].expect_screens, show_screens); | 108 EXPECT_EQ(test_flags_[current_test_].expect_screens, show_screens); |
104 EXPECT_EQ(test_flags_[current_test_].expect_windows, show_windows); | 109 EXPECT_EQ(test_flags_[current_test_].expect_windows, show_windows); |
| 110 EXPECT_EQ(test_flags_[current_test_].expect_tabs, show_tabs); |
| 111 EXPECT_EQ(test_flags_[current_test_].expect_audio, show_audio); |
105 return scoped_ptr<DesktopMediaList>(new FakeDesktopMediaList()); | 112 return scoped_ptr<DesktopMediaList>(new FakeDesktopMediaList()); |
106 } | 113 } |
107 | 114 |
108 scoped_ptr<DesktopMediaPicker> CreatePicker() override { | 115 scoped_ptr<DesktopMediaPicker> CreatePicker() override { |
109 EXPECT_LE(current_test_, tests_count_); | 116 EXPECT_LE(current_test_, tests_count_); |
110 if (current_test_ >= tests_count_) | 117 if (current_test_ >= tests_count_) |
111 return scoped_ptr<DesktopMediaPicker>(); | 118 return scoped_ptr<DesktopMediaPicker>(); |
112 ++current_test_; | 119 ++current_test_; |
113 return scoped_ptr<DesktopMediaPicker>( | 120 return scoped_ptr<DesktopMediaPicker>( |
114 new FakeDesktopMediaPicker(test_flags_ + current_test_ - 1)); | 121 new FakeDesktopMediaPicker(test_flags_ + current_test_ - 1)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 154 |
148 } // namespace | 155 } // namespace |
149 | 156 |
150 // Flaky on Windows: http://crbug.com/301887 | 157 // Flaky on Windows: http://crbug.com/301887 |
151 #if defined(OS_WIN) | 158 #if defined(OS_WIN) |
152 #define MAYBE_ChooseDesktopMedia DISABLED_ChooseDesktopMedia | 159 #define MAYBE_ChooseDesktopMedia DISABLED_ChooseDesktopMedia |
153 #else | 160 #else |
154 #define MAYBE_ChooseDesktopMedia ChooseDesktopMedia | 161 #define MAYBE_ChooseDesktopMedia ChooseDesktopMedia |
155 #endif | 162 #endif |
156 IN_PROC_BROWSER_TEST_F(DesktopCaptureApiTest, MAYBE_ChooseDesktopMedia) { | 163 IN_PROC_BROWSER_TEST_F(DesktopCaptureApiTest, MAYBE_ChooseDesktopMedia) { |
| 164 // For tab and audio share, we need to turn on the flag, because the |
| 165 // functionality is currently behind the flags. |
| 166 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 167 extensions::switches::kEnableTabForDesktopShare); |
| 168 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 169 extensions::switches::kEnableDesktopCaptureAudio); |
| 170 |
157 // Each element in the following array corresponds to one test in | 171 // Each element in the following array corresponds to one test in |
158 // chrome/test/data/extensions/api_test/desktop_capture/test.js . | 172 // chrome/test/data/extensions/api_test/desktop_capture/test.js . |
159 TestFlags test_flags[] = { | 173 TestFlags test_flags[] = { |
160 // pickerUiCanceled() | 174 // pickerUiCanceled() |
161 { true, true, | 175 {true, true, false, false, content::DesktopMediaID()}, |
162 content::DesktopMediaID() }, | 176 // chooseMedia() |
163 // chooseMedia() | 177 {true, true, false, false, |
164 { true, true, | 178 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
165 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | 179 content::DesktopMediaID::kNullId)}, |
166 content::DesktopMediaID::kNullId) }, | 180 // screensOnly() |
167 // screensOnly() | 181 {true, false, false, false, content::DesktopMediaID()}, |
168 { true, false, | 182 // WindowsOnly() |
169 content::DesktopMediaID() }, | 183 {false, true, false, false, content::DesktopMediaID()}, |
170 // WindowsOnly() | 184 // tabOnly() |
171 { false, true, | 185 {false, false, true, false, content::DesktopMediaID()}, |
172 content::DesktopMediaID() }, | 186 // audioShare() |
173 // chooseMediaAndGetStream() | 187 {true, true, true, true, content::DesktopMediaID()}, |
174 { true, true, | 188 // chooseMediaAndGetStream() |
175 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | 189 {true, true, false, false, |
176 webrtc::kFullDesktopScreenId) }, | 190 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
177 // chooseMediaAndTryGetStreamWithInvalidId() | 191 webrtc::kFullDesktopScreenId)}, |
178 { true, true, | 192 // chooseMediaAndTryGetStreamWithInvalidId() |
179 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | 193 {true, true, false, false, |
180 webrtc::kFullDesktopScreenId) }, | 194 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
181 // cancelDialog() | 195 webrtc::kFullDesktopScreenId)}, |
182 { true, true, | 196 // cancelDialog() |
183 content::DesktopMediaID(), true }, | 197 {true, true, false, false, content::DesktopMediaID(), true}, |
| 198 // tabShareWithAudioGetStream() |
| 199 {false, false, true, true, |
| 200 content::DesktopMediaID(content::DesktopMediaID::TYPE_WEB_CONTENTS, 0, |
| 201 true)}, |
| 202 // windowShareWithAudioGetStream() |
| 203 {false, true, false, true, |
| 204 content::DesktopMediaID(content::DesktopMediaID::TYPE_WINDOW, 0, true)}, |
| 205 // screenShareWithAudioGetStream() |
| 206 {true, false, false, true, |
| 207 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
| 208 webrtc::kFullDesktopScreenId, true)}, |
| 209 // tabShareWithoutAudioGetStream() |
| 210 {false, false, true, true, |
| 211 content::DesktopMediaID(content::DesktopMediaID::TYPE_WEB_CONTENTS, 0)}, |
| 212 // windowShareWithoutAudioGetStream() |
| 213 {false, true, false, true, |
| 214 content::DesktopMediaID(content::DesktopMediaID::TYPE_WINDOW, 0)}, |
| 215 // screenShareWithoutAudioGetStream() |
| 216 {true, false, false, true, |
| 217 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
| 218 webrtc::kFullDesktopScreenId)}, |
184 }; | 219 }; |
185 picker_factory_.SetTestFlags(test_flags, arraysize(test_flags)); | 220 picker_factory_.SetTestFlags(test_flags, arraysize(test_flags)); |
186 ASSERT_TRUE(RunExtensionTest("desktop_capture")) << message_; | 221 ASSERT_TRUE(RunExtensionTest("desktop_capture")) << message_; |
187 } | 222 } |
188 | 223 |
189 // Test is flaky http://crbug.com/301887. | 224 // Test is flaky http://crbug.com/301887. |
190 IN_PROC_BROWSER_TEST_F(DesktopCaptureApiTest, DISABLED_Delegation) { | 225 IN_PROC_BROWSER_TEST_F(DesktopCaptureApiTest, DISABLED_Delegation) { |
191 // Initialize test server. | 226 // Initialize test server. |
192 base::FilePath test_data; | 227 base::FilePath test_data; |
193 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data)); | 228 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data)); |
194 embedded_test_server()->ServeFilesFromDirectory(test_data.AppendASCII( | 229 embedded_test_server()->ServeFilesFromDirectory(test_data.AppendASCII( |
195 "extensions/api_test/desktop_capture_delegate")); | 230 "extensions/api_test/desktop_capture_delegate")); |
196 ASSERT_TRUE(embedded_test_server()->Start()); | 231 ASSERT_TRUE(embedded_test_server()->Start()); |
197 host_resolver()->AddRule("*", embedded_test_server()->base_url().host()); | 232 host_resolver()->AddRule("*", embedded_test_server()->base_url().host()); |
198 | 233 |
199 // Load extension. | 234 // Load extension. |
200 base::FilePath extension_path = | 235 base::FilePath extension_path = |
201 test_data_dir_.AppendASCII("desktop_capture_delegate"); | 236 test_data_dir_.AppendASCII("desktop_capture_delegate"); |
202 const Extension* extension = LoadExtensionWithFlags( | 237 const Extension* extension = LoadExtensionWithFlags( |
203 extension_path, ExtensionBrowserTest::kFlagNone); | 238 extension_path, ExtensionBrowserTest::kFlagNone); |
204 ASSERT_TRUE(extension); | 239 ASSERT_TRUE(extension); |
205 | 240 |
206 ui_test_utils::NavigateToURL( | 241 ui_test_utils::NavigateToURL( |
207 browser(), GetURLForPath("example.com", "/example.com.html")); | 242 browser(), GetURLForPath("example.com", "/example.com.html")); |
208 | 243 |
209 TestFlags test_flags[] = { | 244 TestFlags test_flags[] = { |
210 { true, true, | 245 {true, true, false, false, |
211 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | 246 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
212 content::DesktopMediaID::kNullId) }, | 247 content::DesktopMediaID::kNullId)}, |
213 { true, true, | 248 {true, true, false, false, |
214 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | 249 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
215 content::DesktopMediaID::kNullId) }, | 250 content::DesktopMediaID::kNullId)}, |
216 { true, true, | 251 {true, true, false, false, |
217 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | 252 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
218 content::DesktopMediaID::kNullId), true }, | 253 content::DesktopMediaID::kNullId), |
| 254 true}, |
219 }; | 255 }; |
220 picker_factory_.SetTestFlags(test_flags, arraysize(test_flags)); | 256 picker_factory_.SetTestFlags(test_flags, arraysize(test_flags)); |
221 | 257 |
222 bool result; | 258 bool result; |
223 | 259 |
224 content::WebContents* web_contents = | 260 content::WebContents* web_contents = |
225 browser()->tab_strip_model()->GetActiveWebContents(); | 261 browser()->tab_strip_model()->GetActiveWebContents(); |
226 | 262 |
227 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 263 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
228 web_contents, "getStream()", &result)); | 264 web_contents, "getStream()", &result)); |
(...skipping 10 matching lines...) Expand all Loading... |
239 EXPECT_TRUE(result); | 275 EXPECT_TRUE(result); |
240 EXPECT_TRUE(test_flags[2].picker_created); | 276 EXPECT_TRUE(test_flags[2].picker_created); |
241 EXPECT_FALSE(test_flags[2].picker_deleted); | 277 EXPECT_FALSE(test_flags[2].picker_deleted); |
242 | 278 |
243 web_contents->Close(); | 279 web_contents->Close(); |
244 destroyed_watcher.Wait(); | 280 destroyed_watcher.Wait(); |
245 EXPECT_TRUE(test_flags[2].picker_deleted); | 281 EXPECT_TRUE(test_flags[2].picker_deleted); |
246 } | 282 } |
247 | 283 |
248 } // namespace extensions | 284 } // namespace extensions |
OLD | NEW |