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

Side by Side Diff: components/upload_list/upload_list_unittest.cc

Issue 1405373002: Fix WebRTC log list errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 2 months 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 unified diff | Download patch
« no previous file with comments | « components/upload_list/upload_list.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/upload_list/upload_list.h" 5 #include "components/upload_list/upload_list.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/threading/sequenced_worker_pool.h" 12 #include "base/threading/sequenced_worker_pool.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 // Test that UploadList can parse a vector of log entry strings to a vector of 16 namespace {
17 // UploadInfo objects. See the UploadList declaration for a description of the 17
18 // log entry string format. 18 const char kTestUploadTime[] = "1234567890";
19 TEST(UploadListTest, ParseLogEntries) { 19 const char kTestUploadId[] = "0123456789abcdef";
20 const char kTestTime[] = "1234567890"; 20 const char kTestLocalID[] = "fedcba9876543210";
21 const char kTestID[] = "0123456789abcdef"; 21 const char kTestCaptureTime[] = "2345678901";
22 std::string test_entry = kTestTime; 22
23 } // namespace
24
25 // These tests test that UploadList can parse a vector of log entry strings of
26 // various formats to a vector of UploadInfo objects. See the UploadList
27 // declaration for a description of the log entry string formats.
28
29 // Test log entry string with upload time and upload ID.
30 // This is the format that crash reports are stored in.
31 TEST(UploadListTest, ParseUploadTimeUploadId) {
32 std::string test_entry = kTestUploadTime;
23 test_entry += ","; 33 test_entry += ",";
24 test_entry.append(kTestID, sizeof(kTestID)); 34 test_entry.append(kTestUploadId);
25 35
26 scoped_refptr<UploadList> upload_list = 36 scoped_refptr<UploadList> upload_list =
27 new UploadList(nullptr, base::FilePath(), nullptr); 37 new UploadList(nullptr, base::FilePath(), nullptr);
28 38
29 // 1 entry.
30 std::vector<std::string> log_entries; 39 std::vector<std::string> log_entries;
31 log_entries.push_back(test_entry); 40 log_entries.push_back(test_entry);
32 upload_list->ParseLogEntries(log_entries); 41 upload_list->ParseLogEntries(log_entries);
42
33 EXPECT_EQ(1u, upload_list->uploads_.size()); 43 EXPECT_EQ(1u, upload_list->uploads_.size());
34 double time_double = upload_list->uploads_[0].time.ToDoubleT(); 44 double time_double = upload_list->uploads_[0].upload_time.ToDoubleT();
35 EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str()); 45 EXPECT_STREQ(kTestUploadTime, base::DoubleToString(time_double).c_str());
36 EXPECT_STREQ(kTestID, upload_list->uploads_[0].id.c_str()); 46 EXPECT_STREQ(kTestUploadId, upload_list->uploads_[0].upload_id.c_str());
37 EXPECT_STREQ("", upload_list->uploads_[0].local_id.c_str()); 47 EXPECT_STREQ("", upload_list->uploads_[0].local_id.c_str());
38 48 time_double = upload_list->uploads_[0].capture_time.ToDoubleT();
39 // Add 3 more entries. 49 EXPECT_STREQ("0", base::DoubleToString(time_double).c_str());
40 log_entries.push_back(test_entry);
41 log_entries.push_back(test_entry);
42 upload_list->ParseLogEntries(log_entries);
43 EXPECT_EQ(4u, upload_list->uploads_.size());
44 time_double = upload_list->uploads_[3].time.ToDoubleT();
45 EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str());
46 EXPECT_STREQ(kTestID, upload_list->uploads_[3].id.c_str());
47 EXPECT_STREQ("", upload_list->uploads_[3].local_id.c_str());
48 } 50 }
49 51
50 TEST(UploadListTest, ParseLogEntriesWithLocalId) { 52 // Test log entry string with upload time, upload ID and local ID.
51 const char kTestTime[] = "1234567890"; 53 // This is the old format that WebRTC logs were stored in.
52 const char kTestID[] = "0123456789abcdef"; 54 TEST(UploadListTest, ParseUploadTimeUploadIdLocalId) {
53 const char kTestLocalID[] = "fedcba9876543210"; 55 std::string test_entry = kTestUploadTime;
54 std::string test_entry = kTestTime;
55 test_entry += ","; 56 test_entry += ",";
56 test_entry.append(kTestID, sizeof(kTestID)); 57 test_entry.append(kTestUploadId);
57 test_entry += ","; 58 test_entry += ",";
58 test_entry.append(kTestLocalID, sizeof(kTestLocalID)); 59 test_entry.append(kTestLocalID);
59 60
60 scoped_refptr<UploadList> upload_list = 61 scoped_refptr<UploadList> upload_list =
61 new UploadList(nullptr, base::FilePath(), nullptr); 62 new UploadList(nullptr, base::FilePath(), nullptr);
63
64 std::vector<std::string> log_entries;
65 log_entries.push_back(test_entry);
66 upload_list->ParseLogEntries(log_entries);
67
68 EXPECT_EQ(1u, upload_list->uploads_.size());
69 double time_double = upload_list->uploads_[0].upload_time.ToDoubleT();
70 EXPECT_STREQ(kTestUploadTime, base::DoubleToString(time_double).c_str());
71 EXPECT_STREQ(kTestUploadId, upload_list->uploads_[0].upload_id.c_str());
72 EXPECT_STREQ(kTestLocalID, upload_list->uploads_[0].local_id.c_str());
73 time_double = upload_list->uploads_[0].capture_time.ToDoubleT();
74 EXPECT_STREQ("0", base::DoubleToString(time_double).c_str());
75 }
76
77 // Test log entry string with upload time, upload ID and capture time.
78 // This is the format that WebRTC logs that only have been uploaded only are
79 // stored in.
80 TEST(UploadListTest, ParseUploadTimeUploadIdCaptureTime) {
81 std::string test_entry = kTestUploadTime;
82 test_entry += ",";
83 test_entry.append(kTestUploadId);
84 test_entry += ",,";
85 test_entry.append(kTestCaptureTime);
86
87 scoped_refptr<UploadList> upload_list =
88 new UploadList(nullptr, base::FilePath(), nullptr);
89
90 std::vector<std::string> log_entries;
91 log_entries.push_back(test_entry);
92 upload_list->ParseLogEntries(log_entries);
93
94 EXPECT_EQ(1u, upload_list->uploads_.size());
95 double time_double = upload_list->uploads_[0].upload_time.ToDoubleT();
96 EXPECT_STREQ(kTestUploadTime, base::DoubleToString(time_double).c_str());
97 EXPECT_STREQ(kTestUploadId, upload_list->uploads_[0].upload_id.c_str());
98 EXPECT_STREQ("", upload_list->uploads_[0].local_id.c_str());
99 time_double = upload_list->uploads_[0].capture_time.ToDoubleT();
100 EXPECT_STREQ(kTestCaptureTime, base::DoubleToString(time_double).c_str());
101 }
102
103 // Test log entry string with local ID and capture time.
104 // This is the format that WebRTC logs that only are stored locally are stored
105 // in.
106 TEST(UploadListTest, ParseLocalIdCaptureTime) {
107 std::string test_entry = ",,";
108 test_entry.append(kTestLocalID);
109 test_entry += ",";
110 test_entry.append(kTestCaptureTime);
111
112 scoped_refptr<UploadList> upload_list =
113 new UploadList(nullptr, base::FilePath(), nullptr);
114
115 std::vector<std::string> log_entries;
116 log_entries.push_back(test_entry);
117 upload_list->ParseLogEntries(log_entries);
118
119 EXPECT_EQ(1u, upload_list->uploads_.size());
120 double time_double = upload_list->uploads_[0].upload_time.ToDoubleT();
121 EXPECT_STREQ("0", base::DoubleToString(time_double).c_str());
122 EXPECT_STREQ("", upload_list->uploads_[0].upload_id.c_str());
123 EXPECT_STREQ(kTestLocalID, upload_list->uploads_[0].local_id.c_str());
124 time_double = upload_list->uploads_[0].capture_time.ToDoubleT();
125 EXPECT_STREQ(kTestCaptureTime, base::DoubleToString(time_double).c_str());
126 }
127
128 // Test log entry string with upload time, upload ID, local ID and capture
129 // time.
130 // This is the format that WebRTC logs that are stored locally and have been
131 // uploaded are stored in.
132 TEST(UploadListTest, ParseUploadTimeUploadIdLocalIdCaptureTime) {
133 std::string test_entry = kTestUploadTime;
134 test_entry += ",";
135 test_entry.append(kTestUploadId);
136 test_entry += ",";
137 test_entry.append(kTestLocalID);
138 test_entry += ",";
139 test_entry.append(kTestCaptureTime);
140
141 scoped_refptr<UploadList> upload_list =
142 new UploadList(nullptr, base::FilePath(), nullptr);
143
144 std::vector<std::string> log_entries;
145 log_entries.push_back(test_entry);
146 upload_list->ParseLogEntries(log_entries);
147
148 EXPECT_EQ(1u, upload_list->uploads_.size());
149 double time_double = upload_list->uploads_[0].upload_time.ToDoubleT();
150 EXPECT_STREQ(kTestUploadTime, base::DoubleToString(time_double).c_str());
151 EXPECT_STREQ(kTestUploadId, upload_list->uploads_[0].upload_id.c_str());
152 EXPECT_STREQ(kTestLocalID, upload_list->uploads_[0].local_id.c_str());
153 time_double = upload_list->uploads_[0].capture_time.ToDoubleT();
154 EXPECT_STREQ(kTestCaptureTime, base::DoubleToString(time_double).c_str());
155 }
156
157 TEST(UploadListTest, ParseMultipleEntries) {
158 std::string test_entry = kTestUploadTime;
159 test_entry += ",";
160 test_entry.append(kTestUploadId);
161 test_entry += ",";
162 test_entry.append(kTestLocalID);
163 test_entry += ",";
164 test_entry.append(kTestCaptureTime);
165
166 scoped_refptr<UploadList> upload_list =
167 new UploadList(nullptr, base::FilePath(), nullptr);
62 168
63 // 1 entry. 169 // 1 entry.
64 std::vector<std::string> log_entries; 170 std::vector<std::string> log_entries;
65 log_entries.push_back(test_entry); 171 log_entries.push_back(test_entry);
66 upload_list->ParseLogEntries(log_entries); 172 upload_list->ParseLogEntries(log_entries);
67 EXPECT_EQ(1u, upload_list->uploads_.size()); 173 EXPECT_EQ(1u, upload_list->uploads_.size());
68 double time_double = upload_list->uploads_[0].time.ToDoubleT(); 174 double time_double = upload_list->uploads_[0].upload_time.ToDoubleT();
69 EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str()); 175 EXPECT_STREQ(kTestUploadTime, base::DoubleToString(time_double).c_str());
70 EXPECT_STREQ(kTestID, upload_list->uploads_[0].id.c_str()); 176 EXPECT_STREQ(kTestUploadId, upload_list->uploads_[0].upload_id.c_str());
71 EXPECT_STREQ(kTestLocalID, upload_list->uploads_[0].local_id.c_str()); 177 EXPECT_STREQ(kTestLocalID, upload_list->uploads_[0].local_id.c_str());
178 time_double = upload_list->uploads_[0].capture_time.ToDoubleT();
179 EXPECT_STREQ(kTestCaptureTime, base::DoubleToString(time_double).c_str());
72 180
73 // Add 3 more entries. 181 // Add 3 more entries.
74 log_entries.push_back(test_entry); 182 log_entries.push_back(test_entry);
75 log_entries.push_back(test_entry); 183 log_entries.push_back(test_entry);
76 upload_list->ParseLogEntries(log_entries); 184 upload_list->ParseLogEntries(log_entries);
77 EXPECT_EQ(4u, upload_list->uploads_.size()); 185 EXPECT_EQ(4u, upload_list->uploads_.size());
78 time_double = upload_list->uploads_[3].time.ToDoubleT(); 186 for (size_t i = 0; i < upload_list->uploads_.size(); ++i) {
79 EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str()); 187 time_double = upload_list->uploads_[i].upload_time.ToDoubleT();
80 EXPECT_STREQ(kTestID, upload_list->uploads_[3].id.c_str()); 188 EXPECT_STREQ(kTestUploadTime, base::DoubleToString(time_double).c_str());
81 EXPECT_STREQ(kTestLocalID, upload_list->uploads_[3].local_id.c_str()); 189 EXPECT_STREQ(kTestUploadId, upload_list->uploads_[i].upload_id.c_str());
190 EXPECT_STREQ(kTestLocalID, upload_list->uploads_[i].local_id.c_str());
191 time_double = upload_list->uploads_[i].capture_time.ToDoubleT();
192 EXPECT_STREQ(kTestCaptureTime, base::DoubleToString(time_double).c_str());
193 }
82 } 194 }
OLDNEW
« no previous file with comments | « components/upload_list/upload_list.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698