1// Copyright (c) 2012 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/path_service.h" 8#include "base/test/scoped_path_override.h" 9#include "chrome/browser/google/google_util.h" 10#include "chrome/common/chrome_paths.h" 11#include "chrome/installer/util/google_update_settings.h" 12#include "testing/gtest/include/gtest/gtest.h" 13#include "testing/platform_test.h" 14 15class GoogleUpdateTest : public PlatformTest { 16 protected: 17 GoogleUpdateTest() : user_data_dir_override_(chrome::DIR_USER_DATA) {} 18 virtual ~GoogleUpdateTest() {} 19 20 private: 21 base::ScopedPathOverride user_data_dir_override_; 22 23 DISALLOW_COPY_AND_ASSIGN(GoogleUpdateTest); 24}; 25 26TEST_F(GoogleUpdateTest, StatsConsent) { 27 // Stats are off by default. 28 EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsent()); 29 // Stats reporting is ON. 30 EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsent(true)); 31 EXPECT_TRUE(GoogleUpdateSettings::GetCollectStatsConsent()); 32 // Stats reporting is OFF. 33 EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsent(false)); 34 EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsent()); 35} 36 37#if defined(OS_WIN) 38 39TEST_F(GoogleUpdateTest, LastRunTime) { 40 // Querying the value that does not exists should fail. 41 EXPECT_TRUE(GoogleUpdateSettings::RemoveLastRunTime()); 42 EXPECT_EQ(-1, GoogleUpdateSettings::GetLastRunTime()); 43 // Setting and querying the last update time in fast sequence 44 // should give 0 days. 45 EXPECT_TRUE(GoogleUpdateSettings::SetLastRunTime()); 46 EXPECT_EQ(0, GoogleUpdateSettings::GetLastRunTime()); 47} 48 49#endif // defined(OS_WIN) 50 51TEST_F(GoogleUpdateTest, IsOrganicFirstRunBrandCodes) { 52 // Test some brand codes to ensure that future changes to this method won't 53 // go unnoticed. 54 EXPECT_FALSE(google_util::IsOrganicFirstRun("CHFO")); 55 EXPECT_FALSE(google_util::IsOrganicFirstRun("CHMA")); 56 EXPECT_TRUE(google_util::IsOrganicFirstRun("EUBA")); 57 EXPECT_TRUE(google_util::IsOrganicFirstRun("GGRA")); 58 59#if defined(OS_MACOSX) 60 // An empty brand string on Mac is used for channels other than stable, 61 // which are always organic. 62 EXPECT_TRUE(google_util::IsOrganicFirstRun("")); 63#endif 64} 65