| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/metrics/metrics_service.h" | 5 #include "chrome/browser/metrics/metrics_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/md5.h" | 11 #include "base/md5.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 | 13 |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 #if defined(OS_POSIX) && defined(LINUX2) | 16 class MetricsServiceTest : public ::testing::Test { |
| 17 TEST(MetricsServiceTest, ClientIdGeneratesAllZeroes) { | 17 }; |
| 18 uint64 bytes[] = { 0, 0 }; | |
| 19 std::string clientid = MetricsService::RandomBytesToGUIDString(bytes); | |
| 20 EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid); | |
| 21 } | |
| 22 TEST(MetricsServiceTest, ClientIdGeneratesCorrectly) { | |
| 23 uint64 bytes[] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL }; | |
| 24 std::string clientid = MetricsService::RandomBytesToGUIDString(bytes); | |
| 25 EXPECT_EQ("01234567-89AB-CDEF-FEDC-BA9876543210", clientid); | |
| 26 } | |
| 27 | 18 |
| 19 static const size_t kMaxLocalListSize = 3; |
| 20 |
| 21 // Ensure the ClientId is formatted as expected. |
| 28 TEST(MetricsServiceTest, ClientIdCorrectlyFormatted) { | 22 TEST(MetricsServiceTest, ClientIdCorrectlyFormatted) { |
| 29 std::string clientid = MetricsService::GenerateClientID(); | 23 std::string clientid = MetricsService::GenerateClientID(); |
| 30 EXPECT_EQ(36U, clientid.length()); | 24 EXPECT_EQ(36U, clientid.length()); |
| 31 std::string hexchars = "0123456789ABCDEF"; | 25 std::string hexchars = "0123456789ABCDEF"; |
| 32 for (uint32 i = 0; i < clientid.length(); i++) { | 26 for (uint32 i = 0; i < clientid.length(); i++) { |
| 33 char current = clientid.at(i); | 27 char current = clientid.at(i); |
| 34 if (i == 8 || i == 13 || i == 18 || i == 23) { | 28 if (i == 8 || i == 13 || i == 18 || i == 23) { |
| 35 EXPECT_EQ('-', current); | 29 EXPECT_EQ('-', current); |
| 36 } else { | 30 } else { |
| 37 EXPECT_TRUE(std::string::npos != hexchars.find(current)); | 31 EXPECT_TRUE(std::string::npos != hexchars.find(current)); |
| 38 } | 32 } |
| 39 } | 33 } |
| 40 } | 34 } |
| 41 #endif | |
| 42 | |
| 43 class MetricsServiceTest : public ::testing::Test { | |
| 44 }; | |
| 45 | |
| 46 static const size_t kMaxLocalListSize = 3; | |
| 47 | 35 |
| 48 // Store and retrieve empty list. | 36 // Store and retrieve empty list. |
| 49 TEST(MetricsServiceTest, EmptyLogList) { | 37 TEST(MetricsServiceTest, EmptyLogList) { |
| 50 ListValue list; | 38 ListValue list; |
| 51 std::vector<std::string> local_list; | 39 std::vector<std::string> local_list; |
| 52 | 40 |
| 53 MetricsService::StoreUnsentLogsHelper(local_list, kMaxLocalListSize, &list); | 41 MetricsService::StoreUnsentLogsHelper(local_list, kMaxLocalListSize, &list); |
| 54 EXPECT_EQ(0U, list.GetSize()); | 42 EXPECT_EQ(0U, list.GetSize()); |
| 55 | 43 |
| 56 local_list.clear(); // RecallUnsentLogsHelper() expects empty |local_list|. | 44 local_list.clear(); // RecallUnsentLogsHelper() expects empty |local_list|. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 std::string checksum; | 194 std::string checksum; |
| 207 EXPECT_TRUE((*(list.end() - 1))->GetAsString(&checksum)); | 195 EXPECT_TRUE((*(list.end() - 1))->GetAsString(&checksum)); |
| 208 checksum[0] = (checksum[0] == 'a') ? 'b' : 'a'; | 196 checksum[0] = (checksum[0] == 'a') ? 'b' : 'a'; |
| 209 EXPECT_TRUE(list.Set(2, Value::CreateStringValue(checksum))); | 197 EXPECT_TRUE(list.Set(2, Value::CreateStringValue(checksum))); |
| 210 EXPECT_EQ(3U, list.GetSize()); | 198 EXPECT_EQ(3U, list.GetSize()); |
| 211 | 199 |
| 212 local_list.clear(); | 200 local_list.clear(); |
| 213 EXPECT_EQ(MetricsService::CHECKSUM_CORRUPTION, | 201 EXPECT_EQ(MetricsService::CHECKSUM_CORRUPTION, |
| 214 MetricsService::RecallUnsentLogsHelper(list, &local_list)); | 202 MetricsService::RecallUnsentLogsHelper(list, &local_list)); |
| 215 } | 203 } |
| OLD | NEW |