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 "base/json/json_writer.h" | 5 #include "base/json/json_writer.h" |
6 #include "base/strings/string_split.h" | 6 #include "base/strings/string_split.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr
ivate_api.h" | 9 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr
ivate_api.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
11 #include "chrome/browser/extensions/extension_function_test_utils.h" | 11 #include "chrome/browser/extensions/extension_function_test_utils.h" |
12 #include "chrome/browser/extensions/extension_tab_util.h" | 12 #include "chrome/browser/extensions/extension_tab_util.h" |
13 #include "chrome/browser/media/webrtc_log_uploader.h" | 13 #include "chrome/browser/media/webrtc_log_uploader.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/common/chrome_switches.h" |
15 #include "components/compression/compression_utils.h" | 16 #include "components/compression/compression_utils.h" |
16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
17 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
18 #include "extensions/common/test_util.h" | 19 #include "extensions/common/test_util.h" |
19 | 20 |
20 using compression::GzipUncompress; | 21 using compression::GzipUncompress; |
21 using extensions::Extension; | 22 using extensions::Extension; |
22 using extensions::WebrtcLoggingPrivateDiscardFunction; | 23 using extensions::WebrtcLoggingPrivateDiscardFunction; |
23 using extensions::WebrtcLoggingPrivateSetMetaDataFunction; | 24 using extensions::WebrtcLoggingPrivateSetMetaDataFunction; |
24 using extensions::WebrtcLoggingPrivateStartFunction; | 25 using extensions::WebrtcLoggingPrivateStartFunction; |
25 using extensions::WebrtcLoggingPrivateStartRtpDumpFunction; | 26 using extensions::WebrtcLoggingPrivateStartRtpDumpFunction; |
26 using extensions::WebrtcLoggingPrivateStopFunction; | 27 using extensions::WebrtcLoggingPrivateStopFunction; |
27 using extensions::WebrtcLoggingPrivateStopRtpDumpFunction; | 28 using extensions::WebrtcLoggingPrivateStopRtpDumpFunction; |
28 using extensions::WebrtcLoggingPrivateStoreFunction; | 29 using extensions::WebrtcLoggingPrivateStoreFunction; |
29 using extensions::WebrtcLoggingPrivateUploadFunction; | 30 using extensions::WebrtcLoggingPrivateUploadFunction; |
30 using extensions::WebrtcLoggingPrivateUploadStoredFunction; | 31 using extensions::WebrtcLoggingPrivateUploadStoredFunction; |
| 32 using extensions::WebrtcLoggingPrivateStartAudioDebugRecordingsFunction; |
| 33 using extensions::WebrtcLoggingPrivateStopAudioDebugRecordingsFunction; |
31 | 34 |
32 namespace utils = extension_function_test_utils; | 35 namespace utils = extension_function_test_utils; |
33 | 36 |
34 namespace { | 37 namespace { |
35 | 38 |
36 static const char kTestLoggingSessionIdKey[] = "app_session_id"; | 39 static const char kTestLoggingSessionIdKey[] = "app_session_id"; |
37 static const char kTestLoggingSessionIdValue[] = "0123456789abcdef"; | 40 static const char kTestLoggingSessionIdValue[] = "0123456789abcdef"; |
38 static const char kTestLoggingUrl[] = "dummy url string"; | 41 static const char kTestLoggingUrl[] = "dummy url string"; |
39 | 42 |
40 std::string ParamsToString(const base::ListValue& parameters) { | 43 std::string ParamsToString(const base::ListValue& parameters) { |
(...skipping 10 matching lines...) Expand all Loading... |
51 meta_data->Append(meta_data_entry); | 54 meta_data->Append(meta_data_entry); |
52 meta_data_entry = new base::DictionaryValue(); | 55 meta_data_entry = new base::DictionaryValue(); |
53 meta_data_entry->SetString("key", "url"); | 56 meta_data_entry->SetString("key", "url"); |
54 meta_data_entry->SetString("value", kTestLoggingUrl); | 57 meta_data_entry->SetString("value", kTestLoggingUrl); |
55 meta_data->Append(meta_data_entry); | 58 meta_data->Append(meta_data_entry); |
56 parameters->Append(meta_data); | 59 parameters->Append(meta_data); |
57 } | 60 } |
58 | 61 |
59 class WebrtcLoggingPrivateApiTest : public ExtensionApiTest { | 62 class WebrtcLoggingPrivateApiTest : public ExtensionApiTest { |
60 protected: | 63 protected: |
61 | |
62 void SetUp() override { | 64 void SetUp() override { |
63 ExtensionApiTest::SetUp(); | 65 ExtensionApiTest::SetUp(); |
64 extension_ = extensions::test_util::CreateEmptyExtension(); | 66 extension_ = extensions::test_util::CreateEmptyExtension(); |
65 } | 67 } |
66 | 68 |
67 template<typename T> | 69 template<typename T> |
68 scoped_refptr<T> CreateFunction() { | 70 scoped_refptr<T> CreateFunction() { |
69 scoped_refptr<T> function(new T()); | 71 scoped_refptr<T> function(new T()); |
70 function->set_extension(extension_.get()); | 72 function->set_extension(extension_.get()); |
71 function->set_has_callback(true); | 73 function->set_has_callback(true); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 return RunFunction<WebrtcLoggingPrivateStoreFunction>(params, false); | 157 return RunFunction<WebrtcLoggingPrivateStoreFunction>(params, false); |
156 } | 158 } |
157 | 159 |
158 bool UploadStoredLog(const std::string& log_id) { | 160 bool UploadStoredLog(const std::string& log_id) { |
159 base::ListValue params; | 161 base::ListValue params; |
160 AppendTabIdAndUrl(¶ms); | 162 AppendTabIdAndUrl(¶ms); |
161 params.AppendString(log_id); | 163 params.AppendString(log_id); |
162 return RunFunction<WebrtcLoggingPrivateUploadStoredFunction>(params, true); | 164 return RunFunction<WebrtcLoggingPrivateUploadStoredFunction>(params, true); |
163 } | 165 } |
164 | 166 |
| 167 bool StartAudioDebugRecordings(int seconds) { |
| 168 base::ListValue params; |
| 169 AppendTabIdAndUrl(¶ms); |
| 170 params.AppendInteger(seconds); |
| 171 return RunFunction<WebrtcLoggingPrivateStartAudioDebugRecordingsFunction>( |
| 172 params, true); |
| 173 } |
| 174 |
| 175 bool StopAudioDebugRecordings() { |
| 176 base::ListValue params; |
| 177 AppendTabIdAndUrl(¶ms); |
| 178 return RunFunction<WebrtcLoggingPrivateStopAudioDebugRecordingsFunction>( |
| 179 params, true); |
| 180 } |
| 181 |
165 private: | 182 private: |
166 scoped_refptr<Extension> extension_; | 183 scoped_refptr<Extension> extension_; |
167 }; | 184 }; |
168 | 185 |
169 // Helper class to temporarily tell the uploader to save the multipart buffer to | 186 // Helper class to temporarily tell the uploader to save the multipart buffer to |
170 // a test string instead of uploading. | 187 // a test string instead of uploading. |
171 class ScopedOverrideUploadBuffer { | 188 class ScopedOverrideUploadBuffer { |
172 public: | 189 public: |
173 ScopedOverrideUploadBuffer() { | 190 ScopedOverrideUploadBuffer() { |
174 g_browser_process->webrtc_log_uploader()-> | 191 g_browser_process->webrtc_log_uploader()-> |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 ASSERT_TRUE(StoreLog(kLogId)); | 417 ASSERT_TRUE(StoreLog(kLogId)); |
401 | 418 |
402 ScopedOverrideUploadBuffer buffer_override; | 419 ScopedOverrideUploadBuffer buffer_override; |
403 EXPECT_TRUE(UploadStoredLog(kLogId)); | 420 EXPECT_TRUE(UploadStoredLog(kLogId)); |
404 EXPECT_NE(std::string::npos, | 421 EXPECT_NE(std::string::npos, |
405 buffer_override.multipart().find("filename=\"webrtc_log.gz\"")); | 422 buffer_override.multipart().find("filename=\"webrtc_log.gz\"")); |
406 EXPECT_NE(std::string::npos, | 423 EXPECT_NE(std::string::npos, |
407 buffer_override.multipart().find(kTestLoggingUrl)); | 424 buffer_override.multipart().find(kTestLoggingUrl)); |
408 } | 425 } |
409 | 426 |
| 427 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, |
| 428 TestStartStopAudioDebugRecordings) { |
| 429 // TODO(guidou): These tests are missing verification of the actual AEC dump |
| 430 // data. This will be fixed with a separate browser test. |
| 431 // See crbug.com/569957. |
| 432 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 433 switches::kEnableAudioDebugRecordingsFromExtension); |
| 434 ASSERT_TRUE(StartAudioDebugRecordings(0)); |
| 435 ASSERT_TRUE(StopAudioDebugRecordings()); |
| 436 } |
| 437 |
| 438 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, |
| 439 TestStartTimedAudioDebugRecordings) { |
| 440 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 441 switches::kEnableAudioDebugRecordingsFromExtension); |
| 442 ASSERT_TRUE(StartAudioDebugRecordings(1)); |
| 443 } |
OLD | NEW |