Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "chrome/browser/prefs/pref_service.h" | 6 #include "chrome/browser/prefs/pref_service.h" |
| 7 #include "chrome/browser/prefs/session_startup_pref.h" | 7 #include "chrome/browser/prefs/session_startup_pref.h" |
| 8 #include "chrome/browser/protector/base_setting_change.h" | 8 #include "chrome/browser/protector/base_setting_change.h" |
| 9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 class PrefsBackupInvalidChangeTest : public testing::Test { | 25 class PrefsBackupInvalidChangeTest : public testing::Test { |
| 26 protected: | 26 protected: |
| 27 TestingProfile profile_; | 27 TestingProfile profile_; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 // Test that correct default values are applied by Init. | 30 // Test that correct default values are applied by Init. |
| 31 TEST_F(PrefsBackupInvalidChangeTest, Defaults) { | 31 TEST_F(PrefsBackupInvalidChangeTest, Defaults) { |
| 32 #if defined(OS_MACOSX) | 32 // Make the test independent of the Mac startup pref migration (see |
| 33 if (base::mac::IsOSLionOrLater()) | 33 // SessionStartupPref::MigrateMacDefaultPrefIfNecessary). |
| 34 FAIL() << "Broken after r142958; http://crbug.com/134186"; | 34 PrefService* prefs = profile_.GetPrefs(); |
| 35 #endif | 35 prefs->SetString(prefs::kProfileCreatedByVersion, "22.0.0.0.0"); |
|
Ivan Korotkov
2012/06/28 09:53:50
Maybe move this to SetUp?
marja
2012/06/28 11:14:50
Done.
| |
| 36 | |
| 36 SessionStartupPref startup_pref(SessionStartupPref::URLS); | 37 SessionStartupPref startup_pref(SessionStartupPref::URLS); |
| 37 startup_pref.urls.push_back(GURL(kStartupUrl)); | 38 startup_pref.urls.push_back(GURL(kStartupUrl)); |
| 38 SessionStartupPref::SetStartupPref(&profile_, startup_pref); | 39 SessionStartupPref::SetStartupPref(&profile_, startup_pref); |
| 39 | 40 |
| 40 scoped_ptr<BaseSettingChange> change(CreatePrefsBackupInvalidChange()); | 41 scoped_ptr<BaseSettingChange> change(CreatePrefsBackupInvalidChange()); |
| 41 change->Init(&profile_); | 42 change->Init(&profile_); |
| 42 | 43 |
| 43 SessionStartupPref new_startup_pref = | 44 SessionStartupPref new_startup_pref = |
| 44 SessionStartupPref::GetStartupPref(&profile_); | 45 SessionStartupPref::GetStartupPref(&profile_); |
| 45 // Startup type should be reset to default. | 46 // Startup type should be reset to default. |
| 46 EXPECT_EQ(SessionStartupPref::GetDefaultStartupType(), new_startup_pref.type); | 47 EXPECT_EQ(SessionStartupPref::GetDefaultStartupType(), new_startup_pref.type); |
| 47 // Startup URLs should be left unchanged. | 48 // Startup URLs should be left unchanged. |
| 48 EXPECT_EQ(1UL, new_startup_pref.urls.size()); | 49 EXPECT_EQ(1UL, new_startup_pref.urls.size()); |
| 49 EXPECT_EQ(std::string(kStartupUrl), new_startup_pref.urls[0].spec()); | 50 EXPECT_EQ(std::string(kStartupUrl), new_startup_pref.urls[0].spec()); |
| 50 // Homepage prefs are reset to defaults. | 51 // Homepage prefs are reset to defaults. |
| 51 PrefService* prefs = profile_.GetPrefs(); | |
| 52 EXPECT_FALSE(prefs->HasPrefPath(prefs::kHomePageIsNewTabPage)); | 52 EXPECT_FALSE(prefs->HasPrefPath(prefs::kHomePageIsNewTabPage)); |
| 53 EXPECT_FALSE(prefs->HasPrefPath(prefs::kHomePage)); | 53 EXPECT_FALSE(prefs->HasPrefPath(prefs::kHomePage)); |
| 54 EXPECT_FALSE(prefs->HasPrefPath(prefs::kShowHomeButton)); | 54 EXPECT_FALSE(prefs->HasPrefPath(prefs::kShowHomeButton)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Test that "restore last session" setting is not changed by Init. | 57 // Test that "restore last session" setting is not changed by Init. |
| 58 TEST_F(PrefsBackupInvalidChangeTest, DefaultsWithSessionRestore) { | 58 TEST_F(PrefsBackupInvalidChangeTest, DefaultsWithSessionRestore) { |
| 59 SessionStartupPref startup_pref(SessionStartupPref::LAST); | 59 SessionStartupPref startup_pref(SessionStartupPref::LAST); |
| 60 startup_pref.urls.push_back(GURL(kStartupUrl)); | 60 startup_pref.urls.push_back(GURL(kStartupUrl)); |
| 61 SessionStartupPref::SetStartupPref(&profile_, startup_pref); | 61 SessionStartupPref::SetStartupPref(&profile_, startup_pref); |
| 62 | 62 |
| 63 scoped_ptr<BaseSettingChange> change(CreatePrefsBackupInvalidChange()); | 63 scoped_ptr<BaseSettingChange> change(CreatePrefsBackupInvalidChange()); |
| 64 change->Init(&profile_); | 64 change->Init(&profile_); |
| 65 | 65 |
| 66 SessionStartupPref new_startup_pref = | 66 SessionStartupPref new_startup_pref = |
| 67 SessionStartupPref::GetStartupPref(&profile_); | 67 SessionStartupPref::GetStartupPref(&profile_); |
| 68 // Both startup type and startup URLs should be left unchanged. | 68 // Both startup type and startup URLs should be left unchanged. |
| 69 EXPECT_EQ(SessionStartupPref::LAST, new_startup_pref.type); | 69 EXPECT_EQ(SessionStartupPref::LAST, new_startup_pref.type); |
| 70 EXPECT_EQ(1UL, new_startup_pref.urls.size()); | 70 EXPECT_EQ(1UL, new_startup_pref.urls.size()); |
| 71 EXPECT_EQ(std::string(kStartupUrl), new_startup_pref.urls[0].spec()); | 71 EXPECT_EQ(std::string(kStartupUrl), new_startup_pref.urls[0].spec()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace protector | 74 } // namespace protector |
| OLD | NEW |