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
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h"
7 #include "base/file_util.h"
8 #include "base/path_service.h"
9 #include "base/test/scoped_path_override.h"
10 #include "base/values.h"
11 #include "chrome/browser/first_run/first_run.h"
12 #include "chrome/browser/first_run/first_run_internal.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/installer/util/master_preferences.h"
15 #include "testing/gtest/include/gtest/gtest.h"
19 class FirstRunTest
: public testing::Test
{
21 FirstRunTest() : user_data_dir_override_(chrome::DIR_USER_DATA
) {}
22 virtual ~FirstRunTest() {}
25 base::ScopedPathOverride user_data_dir_override_
;
27 DISALLOW_COPY_AND_ASSIGN(FirstRunTest
);
30 TEST_F(FirstRunTest
, RemoveSentinel
) {
31 base::FilePath sentinel_path
;
32 EXPECT_TRUE(internal::GetFirstRunSentinelFilePath(&sentinel_path
));
34 EXPECT_TRUE(internal::CreateSentinel());
35 EXPECT_TRUE(base::PathExists(sentinel_path
));
37 EXPECT_TRUE(RemoveSentinel());
38 EXPECT_FALSE(base::PathExists(sentinel_path
));
41 TEST_F(FirstRunTest
, SetupMasterPrefsFromInstallPrefs_VariationsSeed
) {
42 installer::MasterPreferences
install_prefs("{ \"variations_seed\":\"xyz\" }");
43 EXPECT_EQ(1U, install_prefs
.master_dictionary().size());
45 MasterPrefs out_prefs
;
46 internal::SetupMasterPrefsFromInstallPrefs(install_prefs
, &out_prefs
);
47 EXPECT_EQ("xyz", out_prefs
.variations_seed
);
48 // Variations prefs should have been extracted (removed) from the dictionary.
49 EXPECT_TRUE(install_prefs
.master_dictionary().empty());
52 TEST_F(FirstRunTest
, SetupMasterPrefsFromInstallPrefs_NoVariationsSeed
) {
53 installer::MasterPreferences
install_prefs("{ }");
54 EXPECT_TRUE(install_prefs
.master_dictionary().empty());
56 MasterPrefs out_prefs
;
57 internal::SetupMasterPrefsFromInstallPrefs(install_prefs
, &out_prefs
);
58 EXPECT_TRUE(out_prefs
.variations_seed
.empty());
59 EXPECT_TRUE(out_prefs
.variations_seed_signature
.empty());
62 TEST_F(FirstRunTest
, SetupMasterPrefsFromInstallPrefs_VariationsSeedSignature
) {
63 installer::MasterPreferences
install_prefs(
64 "{ \"variations_seed\":\"xyz\", \"variations_seed_signature\":\"abc\" }");
65 EXPECT_EQ(2U, install_prefs
.master_dictionary().size());
67 MasterPrefs out_prefs
;
68 internal::SetupMasterPrefsFromInstallPrefs(install_prefs
, &out_prefs
);
69 EXPECT_EQ("xyz", out_prefs
.variations_seed
);
70 EXPECT_EQ("abc", out_prefs
.variations_seed_signature
);
71 // Variations prefs should have been extracted (removed) from the dictionary.
72 EXPECT_TRUE(install_prefs
.master_dictionary().empty());
75 } // namespace first_run