Add GCMChannelStatusSyncer to schedule requests and enable/disable GCM
[chromium-blink-merge.git] / chrome / browser / google / google_update_settings_unittest.cc
blob3372044208d63dbb9b55a3dfffa7227caf0cec24
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.
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"
16 class GoogleUpdateTest : public PlatformTest {
17 protected:
18 GoogleUpdateTest() : user_data_dir_override_(chrome::DIR_USER_DATA) {}
19 virtual ~GoogleUpdateTest() {}
21 private:
22 base::ScopedPathOverride user_data_dir_override_;
24 DISALLOW_COPY_AND_ASSIGN(GoogleUpdateTest);
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());
38 #if defined(OS_WIN)
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());
50 #endif // defined(OS_WIN)
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"));
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
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));
73 base::FilePath consent_dir;
74 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &consent_dir));
75 ASSERT_TRUE(base::DirectoryExists(consent_dir));
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);
83 #endif