Chromium Code Reviews| 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 | |
| 171 content::DesktopMediaID media_id_tab_audio( | |
| 172 content::DesktopMediaID::TYPE_WEB_CONTENTS, 0); | |
| 173 media_id_tab_audio.audio_share = true; | |
|
GeorgeZ
2016/03/01 23:23:23
You may modify constructor DesktopMediaID(Type typ
qiangchen
2016/03/03 23:56:01
Done.
| |
| 174 | |
| 175 content::DesktopMediaID media_id_win_audio( | |
| 176 content::DesktopMediaID::TYPE_WINDOW, 0); | |
| 177 media_id_win_audio.audio_share = true; | |
| 178 | |
| 157 // Each element in the following array corresponds to one test in | 179 // Each element in the following array corresponds to one test in |
| 158 // chrome/test/data/extensions/api_test/desktop_capture/test.js . | 180 // chrome/test/data/extensions/api_test/desktop_capture/test.js . |
| 159 TestFlags test_flags[] = { | 181 TestFlags test_flags[] = { |
| 160 // pickerUiCanceled() | 182 // pickerUiCanceled() |
| 161 { true, true, | 183 {true, true, false, false, content::DesktopMediaID()}, |
| 162 content::DesktopMediaID() }, | 184 // chooseMedia() |
| 163 // chooseMedia() | 185 {true, true, false, false, |
| 164 { true, true, | 186 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
| 165 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | 187 content::DesktopMediaID::kNullId)}, |
| 166 content::DesktopMediaID::kNullId) }, | 188 // screensOnly() |
| 167 // screensOnly() | 189 {true, false, false, false, content::DesktopMediaID()}, |
| 168 { true, false, | 190 // WindowsOnly() |
| 169 content::DesktopMediaID() }, | 191 {false, true, false, false, content::DesktopMediaID()}, |
| 170 // WindowsOnly() | 192 // chooseMediaAndGetStream() |
| 171 { false, true, | 193 {true, true, false, false, |
| 172 content::DesktopMediaID() }, | 194 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
| 173 // chooseMediaAndGetStream() | 195 webrtc::kFullDesktopScreenId)}, |
| 174 { true, true, | 196 // chooseMediaAndTryGetStreamWithInvalidId() |
| 175 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | 197 {true, true, false, false, |
| 176 webrtc::kFullDesktopScreenId) }, | 198 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
| 177 // chooseMediaAndTryGetStreamWithInvalidId() | 199 webrtc::kFullDesktopScreenId)}, |
| 178 { true, true, | 200 // cancelDialog() |
| 179 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | 201 {true, true, false, false, content::DesktopMediaID(), true}, |
| 180 webrtc::kFullDesktopScreenId) }, | 202 // tabShare() |
| 181 // cancelDialog() | 203 {true, true, true, false, content::DesktopMediaID()}, |
| 182 { true, true, | 204 // audioShare() |
| 183 content::DesktopMediaID(), true }, | 205 {true, true, false, true, content::DesktopMediaID()}, |
| 184 }; | 206 // tabShareWithAudioGetStream() |
| 207 {false, false, true, true, media_id_tab_audio}, | |
| 208 // windowShareWithAudioGetStream() | |
| 209 {false, true, false, true, media_id_win_audio}}; | |
| 185 picker_factory_.SetTestFlags(test_flags, arraysize(test_flags)); | 210 picker_factory_.SetTestFlags(test_flags, arraysize(test_flags)); |
| 186 ASSERT_TRUE(RunExtensionTest("desktop_capture")) << message_; | 211 ASSERT_TRUE(RunExtensionTest("desktop_capture")) << message_; |
| 187 } | 212 } |
| 188 | 213 |
| 189 // Test is flaky http://crbug.com/301887. | 214 // Test is flaky http://crbug.com/301887. |
| 190 IN_PROC_BROWSER_TEST_F(DesktopCaptureApiTest, DISABLED_Delegation) { | 215 IN_PROC_BROWSER_TEST_F(DesktopCaptureApiTest, DISABLED_Delegation) { |
| 191 // Initialize test server. | 216 // Initialize test server. |
| 192 base::FilePath test_data; | 217 base::FilePath test_data; |
| 193 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data)); | 218 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data)); |
| 194 embedded_test_server()->ServeFilesFromDirectory(test_data.AppendASCII( | 219 embedded_test_server()->ServeFilesFromDirectory(test_data.AppendASCII( |
| 195 "extensions/api_test/desktop_capture_delegate")); | 220 "extensions/api_test/desktop_capture_delegate")); |
| 196 ASSERT_TRUE(embedded_test_server()->Start()); | 221 ASSERT_TRUE(embedded_test_server()->Start()); |
| 197 host_resolver()->AddRule("*", embedded_test_server()->base_url().host()); | 222 host_resolver()->AddRule("*", embedded_test_server()->base_url().host()); |
| 198 | 223 |
| 199 // Load extension. | 224 // Load extension. |
| 200 base::FilePath extension_path = | 225 base::FilePath extension_path = |
| 201 test_data_dir_.AppendASCII("desktop_capture_delegate"); | 226 test_data_dir_.AppendASCII("desktop_capture_delegate"); |
| 202 const Extension* extension = LoadExtensionWithFlags( | 227 const Extension* extension = LoadExtensionWithFlags( |
| 203 extension_path, ExtensionBrowserTest::kFlagNone); | 228 extension_path, ExtensionBrowserTest::kFlagNone); |
| 204 ASSERT_TRUE(extension); | 229 ASSERT_TRUE(extension); |
| 205 | 230 |
| 206 ui_test_utils::NavigateToURL( | 231 ui_test_utils::NavigateToURL( |
| 207 browser(), GetURLForPath("example.com", "/example.com.html")); | 232 browser(), GetURLForPath("example.com", "/example.com.html")); |
| 208 | 233 |
| 209 TestFlags test_flags[] = { | 234 TestFlags test_flags[] = { |
| 210 { true, true, | 235 {true, true, false, false, |
| 211 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | 236 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
| 212 content::DesktopMediaID::kNullId) }, | 237 content::DesktopMediaID::kNullId)}, |
| 213 { true, true, | 238 {true, true, false, false, |
| 214 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | 239 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
| 215 content::DesktopMediaID::kNullId) }, | 240 content::DesktopMediaID::kNullId)}, |
| 216 { true, true, | 241 {true, true, false, false, |
| 217 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, | 242 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
| 218 content::DesktopMediaID::kNullId), true }, | 243 content::DesktopMediaID::kNullId), |
| 244 true}, | |
| 219 }; | 245 }; |
| 220 picker_factory_.SetTestFlags(test_flags, arraysize(test_flags)); | 246 picker_factory_.SetTestFlags(test_flags, arraysize(test_flags)); |
| 221 | 247 |
| 222 bool result; | 248 bool result; |
| 223 | 249 |
| 224 content::WebContents* web_contents = | 250 content::WebContents* web_contents = |
| 225 browser()->tab_strip_model()->GetActiveWebContents(); | 251 browser()->tab_strip_model()->GetActiveWebContents(); |
| 226 | 252 |
| 227 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 253 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 228 web_contents, "getStream()", &result)); | 254 web_contents, "getStream()", &result)); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 239 EXPECT_TRUE(result); | 265 EXPECT_TRUE(result); |
| 240 EXPECT_TRUE(test_flags[2].picker_created); | 266 EXPECT_TRUE(test_flags[2].picker_created); |
| 241 EXPECT_FALSE(test_flags[2].picker_deleted); | 267 EXPECT_FALSE(test_flags[2].picker_deleted); |
| 242 | 268 |
| 243 web_contents->Close(); | 269 web_contents->Close(); |
| 244 destroyed_watcher.Wait(); | 270 destroyed_watcher.Wait(); |
| 245 EXPECT_TRUE(test_flags[2].picker_deleted); | 271 EXPECT_TRUE(test_flags[2].picker_deleted); |
| 246 } | 272 } |
| 247 | 273 |
| 248 } // namespace extensions | 274 } // namespace extensions |
| OLD | NEW |