| 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 "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 15 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
| 16 #include "extensions/common/test_util.h" | 16 #include "extensions/common/test_util.h" |
| 17 | 17 |
| 18 using extensions::Extension; | 18 using extensions::Extension; |
| 19 using extensions::WebrtcLoggingPrivateDiscardFunction; |
| 20 using extensions::WebrtcLoggingPrivateSetMetaDataFunction; |
| 21 using extensions::WebrtcLoggingPrivateStartFunction; |
| 22 using extensions::WebrtcLoggingPrivateStartRtpDumpFunction; |
| 23 using extensions::WebrtcLoggingPrivateStopFunction; |
| 24 using extensions::WebrtcLoggingPrivateStopRtpDumpFunction; |
| 25 using extensions::WebrtcLoggingPrivateStoreFunction; |
| 26 using extensions::WebrtcLoggingPrivateUploadFunction; |
| 27 using extensions::WebrtcLoggingPrivateUploadStoredFunction; |
| 19 | 28 |
| 20 namespace utils = extension_function_test_utils; | 29 namespace utils = extension_function_test_utils; |
| 21 | 30 |
| 22 namespace { | 31 namespace { |
| 23 | 32 |
| 24 static const char kTestLoggingSessionId[] = "0123456789abcdef"; | 33 static const char kTestLoggingSessionId[] = "0123456789abcdef"; |
| 25 static const char kTestLoggingUrl[] = "dummy url string"; | 34 static const char kTestLoggingUrl[] = "dummy url string"; |
| 26 | 35 |
| 36 std::string ParamsToString(const base::ListValue& parameters) { |
| 37 std::string parameter_string; |
| 38 EXPECT_TRUE(base::JSONWriter::Write(¶meters, ¶meter_string)); |
| 39 return parameter_string; |
| 40 } |
| 41 |
| 42 void InitializeTestMetaData(base::ListValue* parameters) { |
| 43 base::DictionaryValue* meta_data_entry = new base::DictionaryValue(); |
| 44 meta_data_entry->SetString("key", "app_session_id"); |
| 45 meta_data_entry->SetString("value", kTestLoggingSessionId); |
| 46 base::ListValue* meta_data = new base::ListValue(); |
| 47 meta_data->Append(meta_data_entry); |
| 48 meta_data_entry = new base::DictionaryValue(); |
| 49 meta_data_entry->SetString("key", "url"); |
| 50 meta_data_entry->SetString("value", kTestLoggingUrl); |
| 51 meta_data->Append(meta_data_entry); |
| 52 parameters->Append(meta_data); |
| 53 } |
| 54 |
| 27 class WebrtcLoggingPrivateApiTest : public ExtensionApiTest { | 55 class WebrtcLoggingPrivateApiTest : public ExtensionApiTest { |
| 56 protected: |
| 57 |
| 58 void SetUp() override { |
| 59 ExtensionApiTest::SetUp(); |
| 60 extension_ = extensions::test_util::CreateEmptyExtension(); |
| 61 } |
| 62 |
| 63 template<typename T> |
| 64 scoped_refptr<T> CreateFunction() { |
| 65 scoped_refptr<T> function(new T()); |
| 66 function->set_extension(extension_.get()); |
| 67 function->set_has_callback(true); |
| 68 return function; |
| 69 } |
| 70 |
| 71 content::WebContents* web_contents() { |
| 72 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 73 } |
| 74 |
| 75 void AppendTabIdAndUrl(base::ListValue* parameters) { |
| 76 base::DictionaryValue* request_info = new base::DictionaryValue(); |
| 77 request_info->SetInteger( |
| 78 "tabId", extensions::ExtensionTabUtil::GetTabId(web_contents())); |
| 79 parameters->Append(request_info); |
| 80 parameters->AppendString(web_contents()->GetURL().GetOrigin().spec()); |
| 81 } |
| 82 |
| 83 bool RunFunction(UIThreadExtensionFunction* function, |
| 84 const base::ListValue& parameters, |
| 85 bool expect_results) { |
| 86 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 87 function, ParamsToString(parameters), browser())); |
| 88 if (expect_results) { |
| 89 EXPECT_TRUE(result.get()); |
| 90 return result.get() != nullptr; |
| 91 } |
| 92 |
| 93 EXPECT_FALSE(result.get()); |
| 94 return result.get() == nullptr; |
| 95 } |
| 96 |
| 97 template<typename Function> |
| 98 bool RunFunction(const base::ListValue& parameters, bool expect_results) { |
| 99 scoped_refptr<Function> function(CreateFunction<Function>()); |
| 100 return RunFunction(function.get(), parameters, expect_results); |
| 101 } |
| 102 |
| 103 template<typename Function> |
| 104 bool RunNoArgsFunction(bool expect_results) { |
| 105 base::ListValue params; |
| 106 AppendTabIdAndUrl(¶ms); |
| 107 scoped_refptr<Function> function(CreateFunction<Function>()); |
| 108 return RunFunction(function.get(), params, expect_results); |
| 109 } |
| 110 |
| 111 bool StartLogging() { |
| 112 return RunNoArgsFunction<WebrtcLoggingPrivateStartFunction>(false); |
| 113 } |
| 114 |
| 115 bool StopLogging() { |
| 116 return RunNoArgsFunction<WebrtcLoggingPrivateStopFunction>(false); |
| 117 } |
| 118 |
| 119 bool DiscardLog() { |
| 120 return RunNoArgsFunction<WebrtcLoggingPrivateDiscardFunction>(false); |
| 121 } |
| 122 |
| 123 bool UploadLog() { |
| 124 return RunNoArgsFunction<WebrtcLoggingPrivateUploadFunction>(true); |
| 125 } |
| 126 |
| 127 bool SetMetaData(const base::ListValue& data) { |
| 128 return RunFunction<WebrtcLoggingPrivateSetMetaDataFunction>(data, false); |
| 129 } |
| 130 |
| 131 bool StartRtpDump(bool incoming, bool outgoing) { |
| 132 base::ListValue params; |
| 133 AppendTabIdAndUrl(¶ms); |
| 134 params.AppendBoolean(incoming); |
| 135 params.AppendBoolean(outgoing); |
| 136 return RunFunction<WebrtcLoggingPrivateStartRtpDumpFunction>(params, false); |
| 137 } |
| 138 |
| 139 bool StopRtpDump(bool incoming, bool outgoing) { |
| 140 base::ListValue params; |
| 141 AppendTabIdAndUrl(¶ms); |
| 142 params.AppendBoolean(incoming); |
| 143 params.AppendBoolean(outgoing); |
| 144 return RunFunction<WebrtcLoggingPrivateStopRtpDumpFunction>(params, false); |
| 145 } |
| 146 |
| 147 bool StoreLog(const std::string& log_id) { |
| 148 base::ListValue params; |
| 149 AppendTabIdAndUrl(¶ms); |
| 150 params.AppendString(log_id); |
| 151 return RunFunction<WebrtcLoggingPrivateStoreFunction>(params, false); |
| 152 } |
| 153 |
| 154 bool UploadStoredLog(const std::string& log_id) { |
| 155 base::ListValue params; |
| 156 AppendTabIdAndUrl(¶ms); |
| 157 params.AppendString(log_id); |
| 158 return RunFunction<WebrtcLoggingPrivateUploadStoredFunction>(params, true); |
| 159 } |
| 160 |
| 161 private: |
| 162 scoped_refptr<Extension> extension_; |
| 163 }; |
| 164 |
| 165 // Helper class to temporarily tell the uploader to save the multipart buffer to |
| 166 // a test string instead of uploading. |
| 167 class ScopedOverrideUploadBuffer { |
| 168 public: |
| 169 ScopedOverrideUploadBuffer() { |
| 170 g_browser_process->webrtc_log_uploader()-> |
| 171 OverrideUploadWithBufferForTesting(&multipart_); |
| 172 } |
| 173 |
| 174 ~ScopedOverrideUploadBuffer() { |
| 175 g_browser_process->webrtc_log_uploader()-> |
| 176 OverrideUploadWithBufferForTesting(nullptr); |
| 177 } |
| 178 |
| 179 const std::string& multipart() const { return multipart_; } |
| 180 |
| 181 private: |
| 182 std::string multipart_; |
| 28 }; | 183 }; |
| 29 | 184 |
| 30 } // namespace | 185 } // namespace |
| 31 | 186 |
| 32 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopDiscard) { | 187 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopDiscard) { |
| 33 scoped_refptr<Extension> empty_extension( | 188 ScopedOverrideUploadBuffer buffer_override; |
| 34 extensions::test_util::CreateEmptyExtension()); | |
| 35 | 189 |
| 36 // Tell the uploader to save the multipart to a buffer instead of uploading. | 190 EXPECT_TRUE(StartLogging()); |
| 37 std::string multipart; | 191 EXPECT_TRUE(StopLogging()); |
| 38 g_browser_process->webrtc_log_uploader()-> | 192 EXPECT_TRUE(DiscardLog()); |
| 39 OverrideUploadWithBufferForTesting(&multipart); | |
| 40 | 193 |
| 41 // Start | 194 EXPECT_TRUE(buffer_override.multipart().empty()); |
| 42 | |
| 43 scoped_refptr<extensions::WebrtcLoggingPrivateStartFunction> | |
| 44 start_function(new extensions::WebrtcLoggingPrivateStartFunction()); | |
| 45 start_function->set_extension(empty_extension.get()); | |
| 46 start_function->set_has_callback(true); | |
| 47 | |
| 48 content::WebContents* contents = | |
| 49 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 50 base::ListValue parameters; | |
| 51 base::DictionaryValue* request_info = new base::DictionaryValue(); | |
| 52 request_info->SetInteger("tabId", | |
| 53 extensions::ExtensionTabUtil::GetTabId(contents)); | |
| 54 parameters.Append(request_info); | |
| 55 parameters.AppendString(contents->GetURL().GetOrigin().spec()); | |
| 56 std::string parameter_string; | |
| 57 base::JSONWriter::Write(¶meters, ¶meter_string); | |
| 58 | |
| 59 // TODO(grunell): MaybeRunFunction is suitable for those calls not returning | |
| 60 // anything. | |
| 61 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | |
| 62 start_function.get(), parameter_string, browser())); | |
| 63 ASSERT_FALSE(result.get()); | |
| 64 | |
| 65 // Stop | |
| 66 | |
| 67 scoped_refptr<extensions::WebrtcLoggingPrivateStopFunction> | |
| 68 stop_function(new extensions::WebrtcLoggingPrivateStopFunction()); | |
| 69 stop_function->set_extension(empty_extension.get()); | |
| 70 stop_function->set_has_callback(true); | |
| 71 | |
| 72 result.reset(utils::RunFunctionAndReturnSingleResult( | |
| 73 stop_function.get(), parameter_string, browser())); | |
| 74 ASSERT_FALSE(result.get()); | |
| 75 | |
| 76 // Discard | |
| 77 | |
| 78 scoped_refptr<extensions::WebrtcLoggingPrivateDiscardFunction> | |
| 79 discard_function(new extensions::WebrtcLoggingPrivateDiscardFunction()); | |
| 80 discard_function->set_extension(empty_extension.get()); | |
| 81 discard_function->set_has_callback(true); | |
| 82 | |
| 83 result.reset(utils::RunFunctionAndReturnSingleResult( | |
| 84 discard_function.get(), parameter_string, browser())); | |
| 85 ASSERT_FALSE(result.get()); | |
| 86 | |
| 87 ASSERT_TRUE(multipart.empty()); | |
| 88 | |
| 89 g_browser_process->webrtc_log_uploader()->OverrideUploadWithBufferForTesting( | |
| 90 NULL); | |
| 91 } | 195 } |
| 92 | 196 |
| 93 // Tests WebRTC diagnostic logging. Sets up the browser to save the multipart | 197 // Tests WebRTC diagnostic logging. Sets up the browser to save the multipart |
| 94 // contents to a buffer instead of uploading it, then verifies it after a calls. | 198 // contents to a buffer instead of uploading it, then verifies it after a calls. |
| 95 // Example of multipart contents: | 199 // Example of multipart contents: |
| 96 // ------**--yradnuoBgoLtrapitluMklaTelgooG--**---- | 200 // ------**--yradnuoBgoLtrapitluMklaTelgooG--**---- |
| 97 // Content-Disposition: form-data; name="prod" | 201 // Content-Disposition: form-data; name="prod" |
| 98 // | 202 // |
| 99 // Chrome_Linux | 203 // Chrome_Linux |
| 100 // ------**--yradnuoBgoLtrapitluMklaTelgooG--**---- | 204 // ------**--yradnuoBgoLtrapitluMklaTelgooG--**---- |
| (...skipping 17 matching lines...) Expand all Loading... |
| 118 // | 222 // |
| 119 // http://127.0.0.1:43213/webrtc/webrtc_jsep01_test.html | 223 // http://127.0.0.1:43213/webrtc/webrtc_jsep01_test.html |
| 120 // ------**--yradnuoBgoLtrapitluMklaTelgooG--**---- | 224 // ------**--yradnuoBgoLtrapitluMklaTelgooG--**---- |
| 121 // Content-Disposition: form-data; name="webrtc_log"; filename="webrtc_log.gz" | 225 // Content-Disposition: form-data; name="webrtc_log"; filename="webrtc_log.gz" |
| 122 // Content-Type: application/gzip | 226 // Content-Type: application/gzip |
| 123 // | 227 // |
| 124 // <compressed data (zip)> | 228 // <compressed data (zip)> |
| 125 // ------**--yradnuoBgoLtrapitluMklaTelgooG--**------ | 229 // ------**--yradnuoBgoLtrapitluMklaTelgooG--**------ |
| 126 // | 230 // |
| 127 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopUpload) { | 231 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopUpload) { |
| 128 scoped_refptr<Extension> empty_extension( | 232 ScopedOverrideUploadBuffer buffer_override; |
| 129 extensions::test_util::CreateEmptyExtension()); | |
| 130 | 233 |
| 131 // Tell the uploader to save the multipart to a buffer instead of uploading. | 234 base::ListValue parameters; |
| 132 std::string multipart; | 235 AppendTabIdAndUrl(¶meters); |
| 133 g_browser_process->webrtc_log_uploader()-> | 236 InitializeTestMetaData(¶meters); |
| 134 OverrideUploadWithBufferForTesting(&multipart); | |
| 135 | 237 |
| 136 // SetMetaData. | 238 SetMetaData(parameters); |
| 137 | 239 |
| 138 scoped_refptr<extensions::WebrtcLoggingPrivateSetMetaDataFunction> | 240 StartLogging(); |
| 139 set_meta_data_function( | 241 StopLogging(); |
| 140 new extensions::WebrtcLoggingPrivateSetMetaDataFunction()); | 242 UploadLog(); |
| 141 set_meta_data_function->set_extension(empty_extension.get()); | |
| 142 set_meta_data_function->set_has_callback(true); | |
| 143 | 243 |
| 144 content::WebContents* contents = | 244 std::string multipart = buffer_override.multipart(); |
| 145 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 146 base::ListValue parameters; | |
| 147 base::DictionaryValue* request_info = new base::DictionaryValue(); | |
| 148 request_info->SetInteger("tabId", | |
| 149 extensions::ExtensionTabUtil::GetTabId(contents)); | |
| 150 parameters.Append(request_info); | |
| 151 parameters.AppendString(contents->GetURL().GetOrigin().spec()); | |
| 152 base::DictionaryValue* meta_data_entry = new base::DictionaryValue(); | |
| 153 meta_data_entry->SetString("key", "app_session_id"); | |
| 154 meta_data_entry->SetString("value", kTestLoggingSessionId); | |
| 155 base::ListValue* meta_data = new base::ListValue(); | |
| 156 meta_data->Append(meta_data_entry); | |
| 157 meta_data_entry = new base::DictionaryValue(); | |
| 158 meta_data_entry->SetString("key", "url"); | |
| 159 meta_data_entry->SetString("value", kTestLoggingUrl); | |
| 160 meta_data->Append(meta_data_entry); | |
| 161 parameters.Append(meta_data); | |
| 162 | |
| 163 std::string parameter_string; | |
| 164 base::JSONWriter::Write(¶meters, ¶meter_string); | |
| 165 | |
| 166 // TODO(grunell): MaybeRunFunction is suitable for those calls not returning | |
| 167 // anything. | |
| 168 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | |
| 169 set_meta_data_function.get(), parameter_string, browser())); | |
| 170 ASSERT_FALSE(result.get()); | |
| 171 | |
| 172 // Start. | |
| 173 | |
| 174 scoped_refptr<extensions::WebrtcLoggingPrivateStartFunction> | |
| 175 start_function(new extensions::WebrtcLoggingPrivateStartFunction()); | |
| 176 start_function->set_extension(empty_extension.get()); | |
| 177 start_function->set_has_callback(true); | |
| 178 | |
| 179 parameters.Clear(); | |
| 180 request_info = new base::DictionaryValue(); | |
| 181 request_info->SetInteger("tabId", | |
| 182 extensions::ExtensionTabUtil::GetTabId(contents)); | |
| 183 parameters.Append(request_info); | |
| 184 parameters.AppendString(contents->GetURL().GetOrigin().spec()); | |
| 185 base::JSONWriter::Write(¶meters, ¶meter_string); | |
| 186 | |
| 187 result.reset(utils::RunFunctionAndReturnSingleResult( | |
| 188 start_function.get(), parameter_string, browser())); | |
| 189 ASSERT_FALSE(result.get()); | |
| 190 | |
| 191 // Stop. | |
| 192 | |
| 193 scoped_refptr<extensions::WebrtcLoggingPrivateStopFunction> | |
| 194 stop_function(new extensions::WebrtcLoggingPrivateStopFunction()); | |
| 195 stop_function->set_extension(empty_extension.get()); | |
| 196 stop_function->set_has_callback(true); | |
| 197 | |
| 198 result.reset(utils::RunFunctionAndReturnSingleResult( | |
| 199 stop_function.get(), parameter_string, browser())); | |
| 200 ASSERT_FALSE(result.get()); | |
| 201 | |
| 202 // Upload. | |
| 203 | |
| 204 scoped_refptr<extensions::WebrtcLoggingPrivateUploadFunction> | |
| 205 upload_function(new extensions::WebrtcLoggingPrivateUploadFunction()); | |
| 206 upload_function->set_extension(empty_extension.get()); | |
| 207 upload_function->set_has_callback(true); | |
| 208 | |
| 209 result.reset(utils::RunFunctionAndReturnSingleResult( | |
| 210 upload_function.get(), parameter_string, browser())); | |
| 211 ASSERT_TRUE(result.get()); | |
| 212 | |
| 213 ASSERT_FALSE(multipart.empty()); | 245 ASSERT_FALSE(multipart.empty()); |
| 214 | 246 |
| 215 // Check multipart data. | 247 // Check multipart data. |
| 216 | 248 |
| 217 const char boundary[] = "------**--yradnuoBgoLtrapitluMklaTelgooG--**----"; | 249 const char boundary[] = "------**--yradnuoBgoLtrapitluMklaTelgooG--**----"; |
| 218 | 250 |
| 219 // Remove the compressed data, it may contain "\r\n". Just verify that its | 251 // Remove the compressed data, it may contain "\r\n". Just verify that its |
| 220 // size is > 0. | 252 // size is > 0. |
| 221 const char zip_content_type[] = "Content-Type: application/gzip"; | 253 const char zip_content_type[] = "Content-Type: application/gzip"; |
| 222 size_t zip_pos = multipart.find(&zip_content_type[0]); | 254 size_t zip_pos = multipart.find(&zip_content_type[0]); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 " filename=\"webrtc_log.gz\"", | 309 " filename=\"webrtc_log.gz\"", |
| 278 multipart_lines[25].c_str()); | 310 multipart_lines[25].c_str()); |
| 279 EXPECT_STREQ("Content-Type: application/gzip", | 311 EXPECT_STREQ("Content-Type: application/gzip", |
| 280 multipart_lines[26].c_str()); | 312 multipart_lines[26].c_str()); |
| 281 EXPECT_TRUE(multipart_lines[27].empty()); | 313 EXPECT_TRUE(multipart_lines[27].empty()); |
| 282 EXPECT_TRUE(multipart_lines[28].empty()); // The removed zip part. | 314 EXPECT_TRUE(multipart_lines[28].empty()); // The removed zip part. |
| 283 std::string final_delimiter = boundary; | 315 std::string final_delimiter = boundary; |
| 284 final_delimiter += "--"; | 316 final_delimiter += "--"; |
| 285 EXPECT_STREQ(final_delimiter.c_str(), multipart_lines[29].c_str()); | 317 EXPECT_STREQ(final_delimiter.c_str(), multipart_lines[29].c_str()); |
| 286 EXPECT_TRUE(multipart_lines[30].empty()); | 318 EXPECT_TRUE(multipart_lines[30].empty()); |
| 287 | |
| 288 g_browser_process->webrtc_log_uploader()->OverrideUploadWithBufferForTesting( | |
| 289 NULL); | |
| 290 } | 319 } |
| 291 | 320 |
| 292 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopRtpDump) { | 321 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopRtpDump) { |
| 293 scoped_refptr<Extension> empty_extension( | 322 // TODO(tommi): As is, these tests are missing verification of the actual |
| 294 extensions::test_util::CreateEmptyExtension()); | 323 // RTP dump data. We should fix that, e.g. use SetDumpWriterForTesting. |
| 324 StartRtpDump(true, true); |
| 325 StopRtpDump(true, true); |
| 326 } |
| 295 | 327 |
| 296 // Start RTP dump. | 328 // Tests trying to store a log when a log is not being captured. |
| 297 scoped_refptr<extensions::WebrtcLoggingPrivateStartRtpDumpFunction> | 329 // We should get a failure callback in this case. |
| 298 start_function( | 330 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStoreWithoutLog) { |
| 299 new extensions::WebrtcLoggingPrivateStartRtpDumpFunction()); | 331 base::ListValue parameters; |
| 300 start_function->set_extension(empty_extension.get()); | 332 AppendTabIdAndUrl(¶meters); |
| 301 start_function->set_has_callback(true); | 333 parameters.AppendString("MyLogId"); |
| 334 scoped_refptr<WebrtcLoggingPrivateStoreFunction> store( |
| 335 CreateFunction<WebrtcLoggingPrivateStoreFunction>()); |
| 336 const std::string error = utils::RunFunctionAndReturnError( |
| 337 store.get(), ParamsToString(parameters), browser()); |
| 338 ASSERT_FALSE(error.empty()); |
| 339 } |
| 302 | 340 |
| 303 content::WebContents* contents = | 341 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopStore) { |
| 304 browser()->tab_strip_model()->GetActiveWebContents(); | 342 ASSERT_TRUE(StartLogging()); |
| 343 ASSERT_TRUE(StopLogging()); |
| 344 EXPECT_TRUE(StoreLog("MyLogID")); |
| 345 } |
| 346 |
| 347 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, |
| 348 TestStartStopStoreAndUpload) { |
| 349 static const char kLogId[] = "TestStartStopStoreAndUpload"; |
| 350 ASSERT_TRUE(StartLogging()); |
| 351 ASSERT_TRUE(StopLogging()); |
| 352 ASSERT_TRUE(StoreLog(kLogId)); |
| 353 |
| 354 ScopedOverrideUploadBuffer buffer_override; |
| 355 EXPECT_TRUE(UploadStoredLog(kLogId)); |
| 356 EXPECT_NE(std::string::npos, |
| 357 buffer_override.multipart().find("filename=\"webrtc_log.gz\"")); |
| 358 } |
| 359 |
| 360 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, |
| 361 TestStartStopStoreAndUploadWithRtp) { |
| 362 static const char kLogId[] = "TestStartStopStoreAndUploadWithRtp"; |
| 363 ASSERT_TRUE(StartLogging()); |
| 364 ASSERT_TRUE(StartRtpDump(true, true)); |
| 365 ASSERT_TRUE(StopLogging()); |
| 366 ASSERT_TRUE(StopRtpDump(true, true)); |
| 367 ASSERT_TRUE(StoreLog(kLogId)); |
| 368 |
| 369 ScopedOverrideUploadBuffer buffer_override; |
| 370 EXPECT_TRUE(UploadStoredLog(kLogId)); |
| 371 EXPECT_NE(std::string::npos, |
| 372 buffer_override.multipart().find("filename=\"webrtc_log.gz\"")); |
| 373 } |
| 374 |
| 375 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, |
| 376 TestStartStopStoreAndUploadWithMetaData) { |
| 377 static const char kLogId[] = "TestStartStopStoreAndUploadWithRtp"; |
| 378 ASSERT_TRUE(StartLogging()); |
| 379 |
| 305 base::ListValue parameters; | 380 base::ListValue parameters; |
| 306 base::DictionaryValue* request_info = new base::DictionaryValue(); | 381 AppendTabIdAndUrl(¶meters); |
| 307 request_info->SetInteger("tabId", | 382 InitializeTestMetaData(¶meters); |
| 308 extensions::ExtensionTabUtil::GetTabId(contents)); | 383 SetMetaData(parameters); |
| 309 parameters.Append(request_info); | |
| 310 parameters.AppendString(contents->GetURL().GetOrigin().spec()); | |
| 311 parameters.AppendBoolean(true); | |
| 312 parameters.AppendBoolean(true); | |
| 313 std::string parameter_string; | |
| 314 base::JSONWriter::Write(¶meters, ¶meter_string); | |
| 315 | 384 |
| 316 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | 385 ASSERT_TRUE(StopLogging()); |
| 317 start_function.get(), parameter_string, browser())); | 386 ASSERT_TRUE(StoreLog(kLogId)); |
| 318 ASSERT_FALSE(result.get()); | |
| 319 | 387 |
| 320 // Stop RTP dump. | 388 ScopedOverrideUploadBuffer buffer_override; |
| 321 scoped_refptr<extensions::WebrtcLoggingPrivateStopRtpDumpFunction> | 389 EXPECT_TRUE(UploadStoredLog(kLogId)); |
| 322 stop_function(new extensions::WebrtcLoggingPrivateStopRtpDumpFunction()); | 390 EXPECT_NE(std::string::npos, |
| 323 stop_function->set_extension(empty_extension.get()); | 391 buffer_override.multipart().find("filename=\"webrtc_log.gz\"")); |
| 324 stop_function->set_has_callback(true); | 392 EXPECT_NE(std::string::npos, |
| 393 buffer_override.multipart().find(kTestLoggingUrl)); |
| 394 } |
| 325 | 395 |
| 326 result.reset(utils::RunFunctionAndReturnSingleResult( | |
| 327 stop_function.get(), parameter_string, browser())); | |
| 328 ASSERT_FALSE(result.get()); | |
| 329 } | |
| OLD | NEW |