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 "chrome/browser/rlz/rlz.h" | 5 #include "chrome/browser/rlz/rlz.h" |
6 | 6 |
7 #include "base/registry.h" | 7 #include "base/registry.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 // Gets rid of registry leftovers from testing. Returns false if there | 12 // Gets rid of registry leftovers from testing. Returns false if there |
13 // is nothing to clean. | 13 // is nothing to clean. |
14 bool CleanValue(const wchar_t* key_name, const wchar_t* value) { | 14 bool CleanValue(const wchar_t* key_name, const wchar_t* value) { |
15 RegKey key; | 15 RegKey key; |
16 if (!key.Open(HKEY_CURRENT_USER, key_name, KEY_READ | KEY_WRITE)) | 16 if (!key.Open(HKEY_CURRENT_USER, key_name, KEY_READ | KEY_WRITE)) |
17 return false; | 17 return false; |
18 EXPECT_TRUE(key.DeleteValue(value)); | 18 EXPECT_TRUE(key.DeleteValue(value)); |
19 return true; | 19 return true; |
20 } | 20 } |
21 | 21 |
22 // The chrome events RLZ key lives here. | 22 // The chrome events RLZ key lives here. |
23 const wchar_t kKeyName[] = L"Software\\Google\\Common\\Rlz\\Events\\C"; | 23 const wchar_t kKeyName[] = L"Software\\Google\\Common\\Rlz\\Events\\C"; |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 TEST(RlzLibTest, RecordProductEvent) { | 27 TEST(RlzLibTest, RecordProductEvent) { |
28 if (!RLZTracker::InitRlz(base::DIR_EXE)) | |
29 return; | |
30 | |
31 DWORD recorded_value = 0; | 28 DWORD recorded_value = 0; |
32 EXPECT_TRUE(RLZTracker::RecordProductEvent(RLZTracker::CHROME, | 29 EXPECT_TRUE(RLZTracker::RecordProductEvent(rlz_lib::CHROME, |
33 RLZTracker::CHROME_OMNIBOX, RLZTracker::FIRST_SEARCH)); | 30 rlz_lib::CHROME_OMNIBOX, rlz_lib::FIRST_SEARCH)); |
34 const wchar_t kEvent1[] = L"C1F"; | 31 const wchar_t kEvent1[] = L"C1F"; |
35 RegKey key1; | 32 RegKey key1; |
36 EXPECT_TRUE(key1.Open(HKEY_CURRENT_USER, kKeyName, KEY_READ)); | 33 EXPECT_TRUE(key1.Open(HKEY_CURRENT_USER, kKeyName, KEY_READ)); |
37 EXPECT_TRUE(key1.ReadValueDW(kEvent1, &recorded_value)); | 34 EXPECT_TRUE(key1.ReadValueDW(kEvent1, &recorded_value)); |
38 EXPECT_EQ(1, recorded_value); | 35 EXPECT_EQ(1, recorded_value); |
39 EXPECT_TRUE(CleanValue(kKeyName, kEvent1)); | 36 EXPECT_TRUE(CleanValue(kKeyName, kEvent1)); |
40 | 37 |
41 EXPECT_TRUE(RLZTracker::RecordProductEvent(RLZTracker::CHROME, | 38 EXPECT_TRUE(RLZTracker::RecordProductEvent(rlz_lib::CHROME, |
42 RLZTracker::CHROME_HOME_PAGE, RLZTracker::SET_TO_GOOGLE)); | 39 rlz_lib::CHROME_HOME_PAGE, rlz_lib::SET_TO_GOOGLE)); |
43 const wchar_t kEvent2[] = L"C2S"; | 40 const wchar_t kEvent2[] = L"C2S"; |
44 RegKey key2; | 41 RegKey key2; |
45 EXPECT_TRUE(key2.Open(HKEY_CURRENT_USER, kKeyName, KEY_READ)); | 42 EXPECT_TRUE(key2.Open(HKEY_CURRENT_USER, kKeyName, KEY_READ)); |
46 DWORD value = 0; | 43 DWORD value = 0; |
47 EXPECT_TRUE(key2.ReadValueDW(kEvent2, &recorded_value)); | 44 EXPECT_TRUE(key2.ReadValueDW(kEvent2, &recorded_value)); |
48 EXPECT_EQ(1, recorded_value); | 45 EXPECT_EQ(1, recorded_value); |
49 EXPECT_TRUE(CleanValue(kKeyName, kEvent2)); | 46 EXPECT_TRUE(CleanValue(kKeyName, kEvent2)); |
50 } | 47 } |
51 | 48 |
52 TEST(RlzLibTest, CleanProductEvents) { | 49 TEST(RlzLibTest, CleanProductEvents) { |
53 if (!RLZTracker::InitRlz(base::DIR_EXE)) | |
54 return; | |
55 | |
56 DWORD recorded_value = 0; | 50 DWORD recorded_value = 0; |
57 EXPECT_TRUE(RLZTracker::RecordProductEvent(RLZTracker::CHROME, | 51 EXPECT_TRUE(RLZTracker::RecordProductEvent(rlz_lib::CHROME, |
58 RLZTracker::CHROME_OMNIBOX, RLZTracker::FIRST_SEARCH)); | 52 rlz_lib::CHROME_OMNIBOX, rlz_lib::FIRST_SEARCH)); |
59 const wchar_t kEvent1[] = L"C1F"; | 53 const wchar_t kEvent1[] = L"C1F"; |
60 RegKey key1; | 54 RegKey key1; |
61 EXPECT_TRUE(key1.Open(HKEY_CURRENT_USER, kKeyName, KEY_READ)); | 55 EXPECT_TRUE(key1.Open(HKEY_CURRENT_USER, kKeyName, KEY_READ)); |
62 EXPECT_TRUE(key1.ReadValueDW(kEvent1, &recorded_value)); | 56 EXPECT_TRUE(key1.ReadValueDW(kEvent1, &recorded_value)); |
63 EXPECT_EQ(1, recorded_value); | 57 EXPECT_EQ(1, recorded_value); |
64 | 58 |
65 EXPECT_TRUE(RLZTracker::ClearAllProductEvents(RLZTracker::CHROME)); | 59 EXPECT_TRUE(RLZTracker::ClearAllProductEvents(rlz_lib::CHROME)); |
66 EXPECT_FALSE(CleanValue(kKeyName, kEvent1)); | 60 EXPECT_FALSE(CleanValue(kKeyName, kEvent1)); |
67 } | 61 } |
OLD | NEW |