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 "chrome/browser/metrics/metrics_service.h" | |
6 | 5 |
| 6 #include <ctype.h> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "chrome/browser/metrics/metrics_service.h" |
10 | |
11 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
12 | 11 |
13 class MetricsServiceTest : public ::testing::Test { | |
14 }; | |
15 | |
16 // Ensure the ClientId is formatted as expected. | 12 // Ensure the ClientId is formatted as expected. |
17 TEST(MetricsServiceTest, ClientIdCorrectlyFormatted) { | 13 TEST(MetricsServiceTest, ClientIdCorrectlyFormatted) { |
18 std::string clientid = MetricsService::GenerateClientID(); | 14 std::string clientid = MetricsService::GenerateClientID(); |
19 EXPECT_EQ(36U, clientid.length()); | 15 EXPECT_EQ(36U, clientid.length()); |
20 std::string hexchars = "0123456789ABCDEF"; | 16 |
21 for (uint32 i = 0; i < clientid.length(); i++) { | 17 for (size_t i = 0; i < clientid.length(); ++i) { |
22 char current = clientid.at(i); | 18 char current = clientid[i]; |
23 if (i == 8 || i == 13 || i == 18 || i == 23) { | 19 if (i == 8 || i == 13 || i == 18 || i == 23) |
24 EXPECT_EQ('-', current); | 20 EXPECT_EQ('-', current); |
25 } else { | 21 else |
26 EXPECT_TRUE(std::string::npos != hexchars.find(current)); | 22 EXPECT_TRUE(isxdigit(current)); |
27 } | |
28 } | 23 } |
29 } | 24 } |
30 | 25 |
31 TEST(MetricsServiceTest, IsPluginProcess) { | 26 TEST(MetricsServiceTest, IsPluginProcess) { |
32 EXPECT_TRUE( | 27 EXPECT_TRUE( |
33 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PLUGIN)); | 28 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PLUGIN)); |
34 EXPECT_TRUE( | 29 EXPECT_TRUE( |
35 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PPAPI_PLUGIN)); | 30 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PPAPI_PLUGIN)); |
36 EXPECT_FALSE( | 31 EXPECT_FALSE( |
37 MetricsService::IsPluginProcess(content::PROCESS_TYPE_GPU)); | 32 MetricsService::IsPluginProcess(content::PROCESS_TYPE_GPU)); |
38 } | 33 } |
OLD | NEW |