Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_apitest.cc

Issue 1513313002: Verify WebRTC log contents in test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed todo. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_apitest.cc
diff --git a/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_apitest.cc b/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_apitest.cc
index cb5ab5e97f233d208432a7facc410d5051310087..835e17261760a6634f54d3eaa6cacf710d12f8c6 100644
--- a/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_apitest.cc
+++ b/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_apitest.cc
@@ -4,6 +4,7 @@
#include "base/json/json_writer.h"
#include "base/strings/string_split.h"
+#include "base/strings/stringprintf.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.h"
#include "chrome/browser/extensions/extension_apitest.h"
@@ -11,10 +12,12 @@
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/media/webrtc_log_uploader.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "components/compression/compression_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
#include "extensions/common/test_util.h"
+using compression::GzipUncompress;
using extensions::Extension;
using extensions::WebrtcLoggingPrivateDiscardFunction;
using extensions::WebrtcLoggingPrivateSetMetaDataFunction;
@@ -30,7 +33,8 @@ namespace utils = extension_function_test_utils;
namespace {
-static const char kTestLoggingSessionId[] = "0123456789abcdef";
+static const char kTestLoggingSessionIdKey[] = "app_session_id";
+static const char kTestLoggingSessionIdValue[] = "0123456789abcdef";
static const char kTestLoggingUrl[] = "dummy url string";
std::string ParamsToString(const base::ListValue& parameters) {
@@ -41,8 +45,8 @@ std::string ParamsToString(const base::ListValue& parameters) {
void InitializeTestMetaData(base::ListValue* parameters) {
base::DictionaryValue* meta_data_entry = new base::DictionaryValue();
- meta_data_entry->SetString("key", "app_session_id");
- meta_data_entry->SetString("value", kTestLoggingSessionId);
+ meta_data_entry->SetString("key", kTestLoggingSessionIdKey);
+ meta_data_entry->SetString("value", kTestLoggingSessionIdValue);
base::ListValue* meta_data = new base::ListValue();
meta_data->Append(meta_data_entry);
meta_data_entry = new base::DictionaryValue();
@@ -236,7 +240,6 @@ IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopUpload) {
InitializeTestMetaData(&parameters);
SetMetaData(parameters);
-
StartLogging();
StopLogging();
UploadLog();
@@ -248,8 +251,8 @@ IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopUpload) {
const char boundary[] = "------**--yradnuoBgoLtrapitluMklaTelgooG--**----";
- // Remove the compressed data, it may contain "\r\n". Just verify that its
- // size is > 0.
+ // Move the compressed data to its own string, since it may contain "\r\n" and
+ // it makes the tests below easier.
const char zip_content_type[] = "Content-Type: application/gzip";
size_t zip_pos = multipart.find(&zip_content_type[0]);
ASSERT_NE(std::string::npos, zip_pos);
@@ -260,8 +263,19 @@ IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopUpload) {
// Calculate length, adjust for a "\r\n".
zip_length -= zip_pos + 2;
ASSERT_GT(zip_length, 0u);
+ std::string log_part = multipart.substr(zip_pos, zip_length);
multipart.erase(zip_pos, zip_length);
+ // Uncompress log and verify contents.
+ EXPECT_TRUE(GzipUncompress(log_part, &log_part));
+ EXPECT_GT(log_part.length(), 0u);
+ // Verify that meta data exists.
+ EXPECT_NE(std::string::npos, log_part.find(base::StringPrintf("%s: %s",
+ kTestLoggingSessionIdKey, kTestLoggingSessionIdValue)));
+ // Verify that the basic info generated at logging startup exists.
+ EXPECT_NE(std::string::npos, log_part.find("Chrome version:"));
+ EXPECT_NE(std::string::npos, log_part.find("Cpu brand:"));
+
// Check the multipart contents.
std::vector<std::string> multipart_lines;
base::SplitStringUsingSubstr(multipart, "\r\n", &multipart_lines);
@@ -296,7 +310,7 @@ IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopUpload) {
EXPECT_STREQ("Content-Disposition: form-data; name=\"app_session_id\"",
multipart_lines[17].c_str());
EXPECT_TRUE(multipart_lines[18].empty());
- EXPECT_STREQ(kTestLoggingSessionId, multipart_lines[19].c_str());
+ EXPECT_STREQ(kTestLoggingSessionIdValue, multipart_lines[19].c_str());
EXPECT_STREQ(&boundary[0], multipart_lines[20].c_str());
EXPECT_STREQ("Content-Disposition: form-data; name=\"url\"",
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698