OLD | NEW |
| (Empty) |
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/memory/scoped_ptr.h" | |
6 #include "chrome/browser/prefs/pref_service.h" | |
7 #include "chrome/browser/prefs/session_startup_pref.h" | |
8 #include "chrome/browser/protector/base_setting_change.h" | |
9 #include "chrome/common/pref_names.h" | |
10 #include "chrome/test/base/testing_profile.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 #if defined(OS_MACOSX) | |
14 #include "base/mac/mac_util.h" | |
15 #endif | |
16 | |
17 namespace protector { | |
18 | |
19 namespace { | |
20 | |
21 const char kStartupUrl[] = "http://example.com/"; | |
22 | |
23 } // namespace | |
24 | |
25 class PrefsBackupInvalidChangeTest : public testing::Test { | |
26 protected: | |
27 virtual void SetUp() OVERRIDE { | |
28 // Make the tests independent of the Mac startup pref migration (see | |
29 // SessionStartupPref::MigrateMacDefaultPrefIfNecessary). | |
30 PrefService* prefs = profile_.GetPrefs(); | |
31 prefs->SetString(prefs::kProfileCreatedByVersion, "22.0.0.0.0"); | |
32 } | |
33 | |
34 TestingProfile profile_; | |
35 }; | |
36 | |
37 // Test that correct default values are applied by Init. | |
38 TEST_F(PrefsBackupInvalidChangeTest, Defaults) { | |
39 SessionStartupPref startup_pref(SessionStartupPref::URLS); | |
40 startup_pref.urls.push_back(GURL(kStartupUrl)); | |
41 SessionStartupPref::SetStartupPref(&profile_, startup_pref); | |
42 | |
43 scoped_ptr<BaseSettingChange> change(CreatePrefsBackupInvalidChange()); | |
44 change->Init(&profile_); | |
45 | |
46 SessionStartupPref new_startup_pref = | |
47 SessionStartupPref::GetStartupPref(&profile_); | |
48 // Startup type should be reset to default. | |
49 EXPECT_EQ(SessionStartupPref::GetDefaultStartupType(), new_startup_pref.type); | |
50 // Startup URLs should be left unchanged. | |
51 EXPECT_EQ(1UL, new_startup_pref.urls.size()); | |
52 EXPECT_EQ(std::string(kStartupUrl), new_startup_pref.urls[0].spec()); | |
53 // Homepage prefs are reset to defaults. | |
54 PrefService* prefs = profile_.GetPrefs(); | |
55 EXPECT_FALSE(prefs->HasPrefPath(prefs::kHomePageIsNewTabPage)); | |
56 EXPECT_FALSE(prefs->HasPrefPath(prefs::kHomePage)); | |
57 EXPECT_FALSE(prefs->HasPrefPath(prefs::kShowHomeButton)); | |
58 } | |
59 | |
60 // Test that "restore last session" setting is not changed by Init. | |
61 TEST_F(PrefsBackupInvalidChangeTest, DefaultsWithSessionRestore) { | |
62 SessionStartupPref startup_pref(SessionStartupPref::LAST); | |
63 startup_pref.urls.push_back(GURL(kStartupUrl)); | |
64 SessionStartupPref::SetStartupPref(&profile_, startup_pref); | |
65 | |
66 scoped_ptr<BaseSettingChange> change(CreatePrefsBackupInvalidChange()); | |
67 change->Init(&profile_); | |
68 | |
69 SessionStartupPref new_startup_pref = | |
70 SessionStartupPref::GetStartupPref(&profile_); | |
71 // Both startup type and startup URLs should be left unchanged. | |
72 EXPECT_EQ(SessionStartupPref::LAST, new_startup_pref.type); | |
73 EXPECT_EQ(1UL, new_startup_pref.urls.size()); | |
74 EXPECT_EQ(std::string(kStartupUrl), new_startup_pref.urls[0].spec()); | |
75 } | |
76 | |
77 } // namespace protector | |
OLD | NEW |