Fixing build: GetViewContainer changed name from under me. :)
[chromium-blink-merge.git] / chrome / browser / rlz / rlz_unittest.cc
blobee84e0c01133cc9d499682253aa59c8ee3fd2cbc
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"
11 namespace {
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) {
15 RegKey key;
16 if (!key.Open(HKEY_CURRENT_USER, key_name, KEY_READ | KEY_WRITE))
17 return false;
18 EXPECT_TRUE(key.DeleteValue(value));
19 return true;
22 // The chrome events RLZ key lives here.
23 const wchar_t kKeyName[] = L"Software\\Google\\Common\\Rlz\\Events\\C";
25 } // namespace
27 TEST(RlzLibTest, RecordProductEvent) {
28 if (!RLZTracker::InitRlz(base::DIR_EXE))
29 return;
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";
35 RegKey key1;
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";
44 RegKey key2;
45 EXPECT_TRUE(key2.Open(HKEY_CURRENT_USER, kKeyName, KEY_READ));
46 DWORD value = 0;
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))
54 return;
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";
60 RegKey key1;
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));