Home | History | Annotate | Download | only in google
      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/files/file_util.h"
      8 #include "base/path_service.h"
      9 #include "base/test/scoped_path_override.h"
     10 #include "chrome/browser/google/google_brand.h"
     11 #include "chrome/common/chrome_paths.h"
     12 #include "chrome/installer/util/google_update_settings.h"
     13 #include "testing/gtest/include/gtest/gtest.h"
     14 #include "testing/platform_test.h"
     15 
     16 class GoogleUpdateTest : public PlatformTest {
     17  protected:
     18   GoogleUpdateTest() : user_data_dir_override_(chrome::DIR_USER_DATA) {}
     19   virtual ~GoogleUpdateTest() {}
     20 
     21  private:
     22   base::ScopedPathOverride user_data_dir_override_;
     23 
     24   DISALLOW_COPY_AND_ASSIGN(GoogleUpdateTest);
     25 };
     26 
     27 TEST_F(GoogleUpdateTest, StatsConsent) {
     28   // Stats are off by default.
     29   EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsent());
     30   // Stats reporting is ON.
     31   EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsent(true));
     32   EXPECT_TRUE(GoogleUpdateSettings::GetCollectStatsConsent());
     33   // Stats reporting is OFF.
     34   EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsent(false));
     35   EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsent());
     36 }
     37 
     38 #if defined(OS_WIN)
     39 
     40 TEST_F(GoogleUpdateTest, LastRunTime) {
     41   // Querying the value that does not exists should fail.
     42   EXPECT_TRUE(GoogleUpdateSettings::RemoveLastRunTime());
     43   EXPECT_EQ(-1, GoogleUpdateSettings::GetLastRunTime());
     44   // Setting and querying the last update time in fast sequence
     45   // should give 0 days.
     46   EXPECT_TRUE(GoogleUpdateSettings::SetLastRunTime());
     47   EXPECT_EQ(0, GoogleUpdateSettings::GetLastRunTime());
     48 }
     49 
     50 #endif  // defined(OS_WIN)
     51 
     52 TEST_F(GoogleUpdateTest, IsOrganicFirstRunBrandCodes) {
     53   // Test some brand codes to ensure that future changes to this method won't
     54   // go unnoticed.
     55   EXPECT_FALSE(google_brand::IsOrganicFirstRun("CHFO"));
     56   EXPECT_FALSE(google_brand::IsOrganicFirstRun("CHMA"));
     57   EXPECT_TRUE(google_brand::IsOrganicFirstRun("EUBA"));
     58   EXPECT_TRUE(google_brand::IsOrganicFirstRun("GGRA"));
     59 
     60 #if defined(OS_MACOSX)
     61   // An empty brand string on Mac is used for channels other than stable,
     62   // which are always organic.
     63   EXPECT_TRUE(google_brand::IsOrganicFirstRun(""));
     64 #endif
     65 }
     66 
     67 #if defined(OS_CHROMEOS)
     68 // Test for http://crbug.com/383003
     69 TEST_F(GoogleUpdateTest, ConsentFileIsWorldReadable) {
     70   // Turn on stats reporting.
     71   EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsent(true));
     72 
     73   base::FilePath consent_dir;
     74   ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &consent_dir));
     75   ASSERT_TRUE(base::DirectoryExists(consent_dir));
     76 
     77   base::FilePath consent_file = consent_dir.Append("Consent To Send Stats");
     78   ASSERT_TRUE(base::PathExists(consent_file));
     79   int permissions;
     80   ASSERT_TRUE(base::GetPosixFilePermissions(consent_file, &permissions));
     81   EXPECT_TRUE(permissions & base::FILE_PERMISSION_READ_BY_OTHERS);
     82 }
     83 #endif
     84