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. 4 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 "chrome/browser/first_run/first_run.h" 11 #include "chrome/browser/first_run/first_run_internal.h" 12 #include "chrome/common/chrome_paths.h" 13 #include "chrome/installer/util/master_preferences.h" 14 #include "testing/gtest/include/gtest/gtest.h" 15 16 namespace first_run { 17 18 class FirstRunTest : public testing::Test { 19 protected: 20 FirstRunTest() : user_data_dir_override_(chrome::DIR_USER_DATA) {} 21 virtual ~FirstRunTest() {} 22 23 virtual void SetUp() OVERRIDE { 24 internal::GetFirstRunSentinelFilePath(&sentinel_path_); 25 } 26 27 base::FilePath sentinel_path_; 28 29 private: 30 base::ScopedPathOverride user_data_dir_override_; 31 32 DISALLOW_COPY_AND_ASSIGN(FirstRunTest); 33 }; 34 35 TEST_F(FirstRunTest, RemoveSentinel) { 36 EXPECT_TRUE(internal::CreateSentinel()); 37 EXPECT_TRUE(base::PathExists(sentinel_path_)); 38 39 EXPECT_TRUE(RemoveSentinel()); 40 EXPECT_FALSE(base::PathExists(sentinel_path_)); 41 } 42 43 TEST_F(FirstRunTest, SetupMasterPrefsFromInstallPrefs_VariationsSeed) { 44 installer::MasterPreferences install_prefs("{ \"variations_seed\":\"xyz\" }"); 45 46 MasterPrefs out_prefs; 47 internal::SetupMasterPrefsFromInstallPrefs(install_prefs, &out_prefs); 48 EXPECT_EQ("xyz", out_prefs.variations_seed); 49 } 50 51 TEST_F(FirstRunTest, SetupMasterPrefsFromInstallPrefs_NoVariationsSeed) { 52 installer::MasterPreferences install_prefs("{ }"); 53 54 MasterPrefs out_prefs; 55 internal::SetupMasterPrefsFromInstallPrefs(install_prefs, &out_prefs); 56 EXPECT_TRUE(out_prefs.variations_seed.empty()); 57 } 58 59 } // namespace first_run 60