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

Side by Side Diff: chrome/browser/metrics/metrics_log_unittest.cc

Issue 2814005: Landing CL http://codereview.chromium.org/2767013/show on behalf of petkov@ch... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 (c) 2006-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2010 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 <string> 5 #include <string>
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "chrome/browser/metrics/metrics_log.h" 9 #include "chrome/browser/metrics/metrics_log.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 std::string encoded; 156 std::string encoded;
157 // Leave room for the NUL terminator. 157 // Leave room for the NUL terminator.
158 ASSERT_TRUE(log.GetEncodedLog(WriteInto(&encoded, size + 1), size)); 158 ASSERT_TRUE(log.GetEncodedLog(WriteInto(&encoded, size + 1), size));
159 TrimWhitespaceASCII(encoded, TRIM_ALL, &encoded); 159 TrimWhitespaceASCII(encoded, TRIM_ALL, &encoded);
160 NormalizeBuildtime(&encoded); 160 NormalizeBuildtime(&encoded);
161 NormalizeBuildtime(&expected_output); 161 NormalizeBuildtime(&expected_output);
162 162
163 ASSERT_EQ(expected_output, encoded); 163 ASSERT_EQ(expected_output, encoded);
164 } 164 }
165 165
166 #if defined(OS_CHROMEOS)
167 TEST(MetricsLogTest, ChromeOSLoadEvent) {
168 std::string expected_output = StringPrintf(
169 "<log clientid=\"bogus client ID\" buildtime=\"123456789\" "
170 "appversion=\"%s\" hardwareclass=\"sample-class\">\n"
171 " <document action=\"load\" docid=\"1\" window=\"3\" loadtime=\"7219\" "
172 "origin=\"link\" session=\"0\" time=\"\"/>\n"
173 "</log>", MetricsLog::GetVersionString().c_str());
174
175 NoTimeMetricsLog log("bogus client ID", 0);
176 log.RecordLoadEvent(3, GURL("http://google.com"), PageTransition::LINK,
177 1, TimeDelta::FromMilliseconds(7219));
178 log.set_hardware_class("sample-class");
179 log.CloseLog();
180
181 ASSERT_EQ(1, log.num_events());
182
183 int size = log.GetEncodedLogSize();
184 ASSERT_GT(size, 0);
185
186 std::string encoded;
187 // Leave room for the NUL terminator.
188 ASSERT_TRUE(log.GetEncodedLog(WriteInto(&encoded, size + 1), size));
189 TrimWhitespaceASCII(encoded, TRIM_ALL, &encoded);
190 NormalizeBuildtime(&encoded);
191 NormalizeBuildtime(&expected_output);
192
193 ASSERT_EQ(expected_output, encoded);
194 }
195 #endif // OS_CHROMEOS
196
166 // Make sure our ID hashes are the same as what we see on the server side. 197 // Make sure our ID hashes are the same as what we see on the server side.
167 TEST(MetricsLogTest, CreateHash) { 198 TEST(MetricsLogTest, CreateHash) {
168 static const struct { 199 static const struct {
169 std::string input; 200 std::string input;
170 std::string output; 201 std::string output;
171 } cases[] = { 202 } cases[] = {
172 {"Back", "0x0557fa923dcee4d0"}, 203 {"Back", "0x0557fa923dcee4d0"},
173 {"Forward", "0x67d2f6740a8eaebf"}, 204 {"Forward", "0x67d2f6740a8eaebf"},
174 {"NewTab", "0x290eb683f96572f1"}, 205 {"NewTab", "0x290eb683f96572f1"},
175 }; 206 };
176 207
177 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 208 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
178 std::string hash_string = MetricsLog::CreateHash(cases[i].input); 209 std::string hash_string = MetricsLog::CreateHash(cases[i].input);
179 210
180 // Convert to hex string 211 // Convert to hex string
181 // We're only checking the first 8 bytes, because that's what 212 // We're only checking the first 8 bytes, because that's what
182 // the metrics server uses. 213 // the metrics server uses.
183 std::string hash_hex = "0x"; 214 std::string hash_hex = "0x";
184 for (size_t j = 0; j < 8; j++) { 215 for (size_t j = 0; j < 8; j++) {
185 StringAppendF(&hash_hex, "%02x", 216 StringAppendF(&hash_hex, "%02x",
186 static_cast<uint8>(hash_string.data()[j])); 217 static_cast<uint8>(hash_string.data()[j]));
187 } 218 }
188 EXPECT_EQ(cases[i].output, hash_hex); 219 EXPECT_EQ(cases[i].output, hash_hex);
189 } 220 }
190 }; 221 };
OLDNEW
« 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