| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_log.h" | 9 #include "chrome/browser/metrics_log.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 TEST(MetricsLogTest, CreateHash) { | 106 TEST(MetricsLogTest, CreateHash) { |
| 107 static const struct { | 107 static const struct { |
| 108 std::string input; | 108 std::string input; |
| 109 std::string output; | 109 std::string output; |
| 110 } cases[] = { | 110 } cases[] = { |
| 111 {"Back", "0x0557fa923dcee4d0"}, | 111 {"Back", "0x0557fa923dcee4d0"}, |
| 112 {"Forward", "0x67d2f6740a8eaebf"}, | 112 {"Forward", "0x67d2f6740a8eaebf"}, |
| 113 {"NewTab", "0x290eb683f96572f1"}, | 113 {"NewTab", "0x290eb683f96572f1"}, |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 for (int i = 0; i < arraysize(cases); i++) { | 116 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 117 std::string hash_string = MetricsLog::CreateHash(cases[i].input); | 117 std::string hash_string = MetricsLog::CreateHash(cases[i].input); |
| 118 | 118 |
| 119 // Convert to hex string | 119 // Convert to hex string |
| 120 // We're only checking the first 8 bytes, because that's what | 120 // We're only checking the first 8 bytes, because that's what |
| 121 // the metrics server uses. | 121 // the metrics server uses. |
| 122 std::string hash_hex = "0x"; | 122 std::string hash_hex = "0x"; |
| 123 for (size_t j = 0; j < 8; j++) { | 123 for (size_t j = 0; j < 8; j++) { |
| 124 StringAppendF(&hash_hex, "%02x", | 124 StringAppendF(&hash_hex, "%02x", |
| 125 static_cast<uint8>(hash_string.data()[j])); | 125 static_cast<uint8>(hash_string.data()[j])); |
| 126 } | 126 } |
| 127 EXPECT_EQ(cases[i].output, hash_hex); | 127 EXPECT_EQ(cases[i].output, hash_hex); |
| 128 } | 128 } |
| 129 }; | 129 }; |
| 130 | 130 |
| OLD | NEW |