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
3 // found in the LICENSE file.
5 #include "chrome/browser/rlz/rlz.h"
7 #include "base/registry.h"
8 #include "base/path_service.h"
9 #include "testing/gtest/include/gtest/gtest.h"
12 // Gets rid of registry leftovers from testing. Returns false if there
13 // is nothing to clean.
14 bool CleanValue(const wchar_t* key_name
, const wchar_t* value
) {
16 if (!key
.Open(HKEY_CURRENT_USER
, key_name
, KEY_READ
| KEY_WRITE
))
18 EXPECT_TRUE(key
.DeleteValue(value
));
22 // The chrome events RLZ key lives here.
23 const wchar_t kKeyName
[] = L
"Software\\Google\\Common\\Rlz\\Events\\C";
27 TEST(RlzLibTest
, RecordProductEvent
) {
28 if (!RLZTracker::InitRlz(base::DIR_EXE
))
31 DWORD recorded_value
= 0;
32 EXPECT_TRUE(RLZTracker::RecordProductEvent(RLZTracker::CHROME
,
33 RLZTracker::CHROME_OMNIBOX
, RLZTracker::FIRST_SEARCH
));
34 const wchar_t kEvent1
[] = L
"C1F";
36 EXPECT_TRUE(key1
.Open(HKEY_CURRENT_USER
, kKeyName
, KEY_READ
));
37 EXPECT_TRUE(key1
.ReadValueDW(kEvent1
, &recorded_value
));
38 EXPECT_EQ(1, recorded_value
);
39 EXPECT_TRUE(CleanValue(kKeyName
, kEvent1
));
41 EXPECT_TRUE(RLZTracker::RecordProductEvent(RLZTracker::CHROME
,
42 RLZTracker::CHROME_HOME_PAGE
, RLZTracker::SET_TO_GOOGLE
));
43 const wchar_t kEvent2
[] = L
"C2S";
45 EXPECT_TRUE(key2
.Open(HKEY_CURRENT_USER
, kKeyName
, KEY_READ
));
47 EXPECT_TRUE(key2
.ReadValueDW(kEvent2
, &recorded_value
));
48 EXPECT_EQ(1, recorded_value
);
49 EXPECT_TRUE(CleanValue(kKeyName
, kEvent2
));
52 TEST(RlzLibTest
, CleanProductEvents
) {
53 if (!RLZTracker::InitRlz(base::DIR_EXE
))
56 DWORD recorded_value
= 0;
57 EXPECT_TRUE(RLZTracker::RecordProductEvent(RLZTracker::CHROME
,
58 RLZTracker::CHROME_OMNIBOX
, RLZTracker::FIRST_SEARCH
));
59 const wchar_t kEvent1
[] = L
"C1F";
61 EXPECT_TRUE(key1
.Open(HKEY_CURRENT_USER
, kKeyName
, KEY_READ
));
62 EXPECT_TRUE(key1
.ReadValueDW(kEvent1
, &recorded_value
));
63 EXPECT_EQ(1, recorded_value
);
65 EXPECT_TRUE(RLZTracker::ClearAllProductEvents(RLZTracker::CHROME
));
66 EXPECT_FALSE(CleanValue(kKeyName
, kEvent1
));