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 "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr
ivate_api.h" | 8 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr
ivate_api.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/extension_function_test_utils.h" | 10 #include "chrome/browser/extensions/extension_function_test_utils.h" |
11 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
12 #include "chrome/browser/media/webrtc_log_uploader.h" | 12 #include "chrome/browser/media/webrtc_log_uploader.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/common/chrome_switches.h" |
14 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
15 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
16 #include "extensions/common/test_util.h" | 17 #include "extensions/common/test_util.h" |
17 | 18 |
18 using extensions::Extension; | 19 using extensions::Extension; |
19 using extensions::WebrtcLoggingPrivateDiscardFunction; | 20 using extensions::WebrtcLoggingPrivateDiscardFunction; |
20 using extensions::WebrtcLoggingPrivateSetMetaDataFunction; | 21 using extensions::WebrtcLoggingPrivateSetMetaDataFunction; |
21 using extensions::WebrtcLoggingPrivateStartFunction; | 22 using extensions::WebrtcLoggingPrivateStartFunction; |
22 using extensions::WebrtcLoggingPrivateStartRtpDumpFunction; | 23 using extensions::WebrtcLoggingPrivateStartRtpDumpFunction; |
23 using extensions::WebrtcLoggingPrivateStopFunction; | 24 using extensions::WebrtcLoggingPrivateStopFunction; |
24 using extensions::WebrtcLoggingPrivateStopRtpDumpFunction; | 25 using extensions::WebrtcLoggingPrivateStopRtpDumpFunction; |
25 using extensions::WebrtcLoggingPrivateStoreFunction; | 26 using extensions::WebrtcLoggingPrivateStoreFunction; |
26 using extensions::WebrtcLoggingPrivateUploadFunction; | 27 using extensions::WebrtcLoggingPrivateUploadFunction; |
27 using extensions::WebrtcLoggingPrivateUploadStoredFunction; | 28 using extensions::WebrtcLoggingPrivateUploadStoredFunction; |
| 29 using extensions::WebrtcLoggingPrivateStartAecDumpFunction; |
| 30 using extensions::WebrtcLoggingPrivateStopAecDumpFunction; |
28 | 31 |
29 namespace utils = extension_function_test_utils; | 32 namespace utils = extension_function_test_utils; |
30 | 33 |
31 namespace { | 34 namespace { |
32 | 35 |
33 static const char kTestLoggingSessionId[] = "0123456789abcdef"; | 36 static const char kTestLoggingSessionId[] = "0123456789abcdef"; |
34 static const char kTestLoggingUrl[] = "dummy url string"; | 37 static const char kTestLoggingUrl[] = "dummy url string"; |
35 | 38 |
36 std::string ParamsToString(const base::ListValue& parameters) { | 39 std::string ParamsToString(const base::ListValue& parameters) { |
37 std::string parameter_string; | 40 std::string parameter_string; |
38 EXPECT_TRUE(base::JSONWriter::Write(parameters, ¶meter_string)); | 41 EXPECT_TRUE(base::JSONWriter::Write(parameters, ¶meter_string)); |
39 return parameter_string; | 42 return parameter_string; |
40 } | 43 } |
41 | 44 |
42 void InitializeTestMetaData(base::ListValue* parameters) { | 45 void InitializeTestMetaData(base::ListValue* parameters) { |
43 base::DictionaryValue* meta_data_entry = new base::DictionaryValue(); | 46 base::DictionaryValue* meta_data_entry = new base::DictionaryValue(); |
44 meta_data_entry->SetString("key", "app_session_id"); | 47 meta_data_entry->SetString("key", "app_session_id"); |
45 meta_data_entry->SetString("value", kTestLoggingSessionId); | 48 meta_data_entry->SetString("value", kTestLoggingSessionId); |
46 base::ListValue* meta_data = new base::ListValue(); | 49 base::ListValue* meta_data = new base::ListValue(); |
47 meta_data->Append(meta_data_entry); | 50 meta_data->Append(meta_data_entry); |
48 meta_data_entry = new base::DictionaryValue(); | 51 meta_data_entry = new base::DictionaryValue(); |
49 meta_data_entry->SetString("key", "url"); | 52 meta_data_entry->SetString("key", "url"); |
50 meta_data_entry->SetString("value", kTestLoggingUrl); | 53 meta_data_entry->SetString("value", kTestLoggingUrl); |
51 meta_data->Append(meta_data_entry); | 54 meta_data->Append(meta_data_entry); |
52 parameters->Append(meta_data); | 55 parameters->Append(meta_data); |
53 } | 56 } |
54 | 57 |
55 class WebrtcLoggingPrivateApiTest : public ExtensionApiTest { | 58 class WebrtcLoggingPrivateApiTest : public ExtensionApiTest { |
56 protected: | 59 protected: |
57 | |
58 void SetUp() override { | 60 void SetUp() override { |
59 ExtensionApiTest::SetUp(); | 61 ExtensionApiTest::SetUp(); |
60 extension_ = extensions::test_util::CreateEmptyExtension(); | 62 extension_ = extensions::test_util::CreateEmptyExtension(); |
61 } | 63 } |
62 | 64 |
63 template<typename T> | 65 template<typename T> |
64 scoped_refptr<T> CreateFunction() { | 66 scoped_refptr<T> CreateFunction() { |
65 scoped_refptr<T> function(new T()); | 67 scoped_refptr<T> function(new T()); |
66 function->set_extension(extension_.get()); | 68 function->set_extension(extension_.get()); |
67 function->set_has_callback(true); | 69 function->set_has_callback(true); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 return RunFunction<WebrtcLoggingPrivateStoreFunction>(params, false); | 153 return RunFunction<WebrtcLoggingPrivateStoreFunction>(params, false); |
152 } | 154 } |
153 | 155 |
154 bool UploadStoredLog(const std::string& log_id) { | 156 bool UploadStoredLog(const std::string& log_id) { |
155 base::ListValue params; | 157 base::ListValue params; |
156 AppendTabIdAndUrl(¶ms); | 158 AppendTabIdAndUrl(¶ms); |
157 params.AppendString(log_id); | 159 params.AppendString(log_id); |
158 return RunFunction<WebrtcLoggingPrivateUploadStoredFunction>(params, true); | 160 return RunFunction<WebrtcLoggingPrivateUploadStoredFunction>(params, true); |
159 } | 161 } |
160 | 162 |
| 163 bool StartAecDump(int seconds) { |
| 164 base::ListValue params; |
| 165 params.AppendInteger(seconds); |
| 166 return RunFunction<WebrtcLoggingPrivateStartAecDumpFunction>(params, true); |
| 167 } |
| 168 |
| 169 bool StopAecDump() { |
| 170 return RunNoArgsFunction<WebrtcLoggingPrivateStopAecDumpFunction>(true); |
| 171 } |
| 172 |
161 private: | 173 private: |
162 scoped_refptr<Extension> extension_; | 174 scoped_refptr<Extension> extension_; |
163 }; | 175 }; |
164 | 176 |
165 // Helper class to temporarily tell the uploader to save the multipart buffer to | 177 // Helper class to temporarily tell the uploader to save the multipart buffer to |
166 // a test string instead of uploading. | 178 // a test string instead of uploading. |
167 class ScopedOverrideUploadBuffer { | 179 class ScopedOverrideUploadBuffer { |
168 public: | 180 public: |
169 ScopedOverrideUploadBuffer() { | 181 ScopedOverrideUploadBuffer() { |
170 g_browser_process->webrtc_log_uploader()-> | 182 g_browser_process->webrtc_log_uploader()-> |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 ASSERT_TRUE(StoreLog(kLogId)); | 398 ASSERT_TRUE(StoreLog(kLogId)); |
387 | 399 |
388 ScopedOverrideUploadBuffer buffer_override; | 400 ScopedOverrideUploadBuffer buffer_override; |
389 EXPECT_TRUE(UploadStoredLog(kLogId)); | 401 EXPECT_TRUE(UploadStoredLog(kLogId)); |
390 EXPECT_NE(std::string::npos, | 402 EXPECT_NE(std::string::npos, |
391 buffer_override.multipart().find("filename=\"webrtc_log.gz\"")); | 403 buffer_override.multipart().find("filename=\"webrtc_log.gz\"")); |
392 EXPECT_NE(std::string::npos, | 404 EXPECT_NE(std::string::npos, |
393 buffer_override.multipart().find(kTestLoggingUrl)); | 405 buffer_override.multipart().find(kTestLoggingUrl)); |
394 } | 406 } |
395 | 407 |
| 408 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopAecDump) { |
| 409 // TODO(guidou): These tests are missing verification of the actual AEC dump |
| 410 // data. This will be fixed with a separate browser test. |
| 411 // See crbug.com/569957. |
| 412 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 413 switches::kEnableAecDumpsFromExtension); |
| 414 ASSERT_TRUE(StartAecDump(0)); |
| 415 ASSERT_TRUE(StopAecDump()); |
| 416 } |
OLD | NEW |