| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "chrome/browser/metrics/metrics_log.h" | 10 #include "chrome/browser/metrics/metrics_log.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 TEST(MetricsLogTest, LoadEvent) { | 142 TEST(MetricsLogTest, LoadEvent) { |
| 143 std::string expected_output = base::StringPrintf( | 143 std::string expected_output = base::StringPrintf( |
| 144 "<log clientid=\"bogus client ID\" buildtime=\"123456789\" " | 144 "<log clientid=\"bogus client ID\" buildtime=\"123456789\" " |
| 145 "appversion=\"%s\">\n" | 145 "appversion=\"%s\">\n" |
| 146 " <document action=\"load\" docid=\"1\" window=\"3\" loadtime=\"7219\" " | 146 " <document action=\"load\" docid=\"1\" window=\"3\" loadtime=\"7219\" " |
| 147 "origin=\"link\" session=\"0\" time=\"\"/>\n" | 147 "origin=\"link\" session=\"0\" time=\"\"/>\n" |
| 148 "</log>", MetricsLog::GetVersionString().c_str()); | 148 "</log>", MetricsLog::GetVersionString().c_str()); |
| 149 | 149 |
| 150 NoTimeMetricsLog log("bogus client ID", 0); | 150 NoTimeMetricsLog log("bogus client ID", 0); |
| 151 log.RecordLoadEvent(3, GURL("http://google.com"), PageTransition::LINK, | 151 log.RecordLoadEvent(3, GURL("http://google.com"), |
| 152 1, TimeDelta::FromMilliseconds(7219)); | 152 content::PAGE_TRANSITION_LINK, 1, |
| 153 TimeDelta::FromMilliseconds(7219)); |
| 153 | 154 |
| 154 log.CloseLog(); | 155 log.CloseLog(); |
| 155 | 156 |
| 156 ASSERT_EQ(1, log.num_events()); | 157 ASSERT_EQ(1, log.num_events()); |
| 157 | 158 |
| 158 int size = log.GetEncodedLogSize(); | 159 int size = log.GetEncodedLogSize(); |
| 159 ASSERT_GT(size, 0); | 160 ASSERT_GT(size, 0); |
| 160 | 161 |
| 161 std::string encoded; | 162 std::string encoded; |
| 162 // Leave room for the NUL terminator. | 163 // Leave room for the NUL terminator. |
| 163 ASSERT_TRUE(log.GetEncodedLog(WriteInto(&encoded, size + 1), size)); | 164 ASSERT_TRUE(log.GetEncodedLog(WriteInto(&encoded, size + 1), size)); |
| 164 TrimWhitespaceASCII(encoded, TRIM_ALL, &encoded); | 165 TrimWhitespaceASCII(encoded, TRIM_ALL, &encoded); |
| 165 NormalizeBuildtime(&encoded); | 166 NormalizeBuildtime(&encoded); |
| 166 NormalizeBuildtime(&expected_output); | 167 NormalizeBuildtime(&expected_output); |
| 167 | 168 |
| 168 ASSERT_EQ(expected_output, encoded); | 169 ASSERT_EQ(expected_output, encoded); |
| 169 } | 170 } |
| 170 | 171 |
| 171 #if defined(OS_CHROMEOS) | 172 #if defined(OS_CHROMEOS) |
| 172 TEST(MetricsLogTest, ChromeOSLoadEvent) { | 173 TEST(MetricsLogTest, ChromeOSLoadEvent) { |
| 173 std::string expected_output = base::StringPrintf( | 174 std::string expected_output = base::StringPrintf( |
| 174 "<log clientid=\"bogus client ID\" buildtime=\"123456789\" " | 175 "<log clientid=\"bogus client ID\" buildtime=\"123456789\" " |
| 175 "appversion=\"%s\" hardwareclass=\"sample-class\">\n" | 176 "appversion=\"%s\" hardwareclass=\"sample-class\">\n" |
| 176 " <document action=\"load\" docid=\"1\" window=\"3\" loadtime=\"7219\" " | 177 " <document action=\"load\" docid=\"1\" window=\"3\" loadtime=\"7219\" " |
| 177 "origin=\"link\" session=\"0\" time=\"\"/>\n" | 178 "origin=\"link\" session=\"0\" time=\"\"/>\n" |
| 178 "</log>", MetricsLog::GetVersionString().c_str()); | 179 "</log>", MetricsLog::GetVersionString().c_str()); |
| 179 | 180 |
| 180 NoTimeMetricsLog log("bogus client ID", 0); | 181 NoTimeMetricsLog log("bogus client ID", 0); |
| 181 log.RecordLoadEvent(3, GURL("http://google.com"), PageTransition::LINK, | 182 log.RecordLoadEvent(3, GURL("http://google.com"), |
| 182 1, TimeDelta::FromMilliseconds(7219)); | 183 content::PAGE_TRANSITION_LINK, 1, |
| 184 TimeDelta::FromMilliseconds(7219)); |
| 183 log.set_hardware_class("sample-class"); | 185 log.set_hardware_class("sample-class"); |
| 184 log.CloseLog(); | 186 log.CloseLog(); |
| 185 | 187 |
| 186 ASSERT_EQ(1, log.num_events()); | 188 ASSERT_EQ(1, log.num_events()); |
| 187 | 189 |
| 188 int size = log.GetEncodedLogSize(); | 190 int size = log.GetEncodedLogSize(); |
| 189 ASSERT_GT(size, 0); | 191 ASSERT_GT(size, 0); |
| 190 | 192 |
| 191 std::string encoded; | 193 std::string encoded; |
| 192 // Leave room for the NUL terminator. | 194 // Leave room for the NUL terminator. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 // We're only checking the first 8 bytes, because that's what | 265 // We're only checking the first 8 bytes, because that's what |
| 264 // the metrics server uses. | 266 // the metrics server uses. |
| 265 std::string hash_hex = "0x"; | 267 std::string hash_hex = "0x"; |
| 266 for (size_t j = 0; j < 8; j++) { | 268 for (size_t j = 0; j < 8; j++) { |
| 267 base::StringAppendF(&hash_hex, "%02x", | 269 base::StringAppendF(&hash_hex, "%02x", |
| 268 static_cast<uint8>(hash_string.data()[j])); | 270 static_cast<uint8>(hash_string.data()[j])); |
| 269 } | 271 } |
| 270 EXPECT_EQ(cases[i].output, hash_hex); | 272 EXPECT_EQ(cases[i].output, hash_hex); |
| 271 } | 273 } |
| 272 }; | 274 }; |
| OLD | NEW |