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 "chrome/browser/prefs/session_startup_pref.h" | 5 #include "chrome/browser/prefs/session_startup_pref.h" |
6 #include "chrome/common/pref_names.h" | 6 #include "chrome/common/pref_names.h" |
7 #include "chrome/test/base/testing_pref_service.h" | 7 #include "chrome/test/base/testing_pref_service.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 // Unit tests for SessionStartupPref. | 11 // Unit tests for SessionStartupPref. |
12 class SessionStartupPrefTest : public testing::Test { | 12 class SessionStartupPrefTest : public testing::Test { |
13 public: | 13 public: |
14 virtual void SetUp() { | 14 virtual void SetUp() { |
15 pref_service_.reset(new TestingPrefService); | 15 pref_service_.reset(new TestingPrefService); |
16 SessionStartupPref::RegisterUserPrefs(pref_service_.get()); | 16 SessionStartupPref::RegisterUserPrefs(pref_service_.get()); |
| 17 pref_service_->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, true); |
17 } | 18 } |
18 | 19 |
19 scoped_ptr<TestingPrefService> pref_service_; | 20 scoped_ptr<TestingPrefService> pref_service_; |
20 }; | 21 }; |
21 | 22 |
22 TEST_F(SessionStartupPrefTest, URLListIsFixedUp) { | 23 TEST_F(SessionStartupPrefTest, URLListIsFixedUp) { |
23 ListValue* url_pref_list = new ListValue; | 24 ListValue* url_pref_list = new ListValue; |
24 url_pref_list->Set(0, Value::CreateStringValue("google.com")); | 25 url_pref_list->Set(0, Value::CreateStringValue("google.com")); |
25 url_pref_list->Set(1, Value::CreateStringValue("chromium.org")); | 26 url_pref_list->Set(1, Value::CreateStringValue("chromium.org")); |
26 pref_service_->SetUserPref(prefs::kURLsToRestoreOnStartup, url_pref_list); | 27 pref_service_->SetUserPref(prefs::kURLsToRestoreOnStartup, url_pref_list); |
(...skipping 23 matching lines...) Expand all Loading... |
50 | 51 |
51 SessionStartupPref override_test = | 52 SessionStartupPref override_test = |
52 SessionStartupPref(SessionStartupPref::URLS); | 53 SessionStartupPref(SessionStartupPref::URLS); |
53 override_test.urls.push_back(GURL("dev.chromium.org")); | 54 override_test.urls.push_back(GURL("dev.chromium.org")); |
54 SessionStartupPref::SetStartupPref(pref_service_.get(), override_test); | 55 SessionStartupPref::SetStartupPref(pref_service_.get(), override_test); |
55 | 56 |
56 result = SessionStartupPref::GetStartupPref(pref_service_.get()); | 57 result = SessionStartupPref::GetStartupPref(pref_service_.get()); |
57 EXPECT_EQ(3u, result.urls.size()); | 58 EXPECT_EQ(3u, result.urls.size()); |
58 } | 59 } |
59 | 60 |
| 61 // Checks to make sure that if the user had previously not selected anything |
| 62 // (so that, in effect, the default value "Open the homepage" was selected), |
| 63 // their preferences are migrated on upgrade to m19. |
| 64 TEST_F(SessionStartupPrefTest, DefaultMigration) { |
| 65 pref_service_->RegisterStringPref(prefs::kHomePage, "http://google.com/"); |
| 66 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/"); |
| 67 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, false); |
| 68 |
| 69 EXPECT_FALSE(pref_service_->HasPrefPath(prefs::kRestoreOnStartup)); |
| 70 |
| 71 SessionStartupPref pref = SessionStartupPref::GetStartupPref( |
| 72 pref_service_.get()); |
| 73 |
| 74 #if defined(OS_CHROMEOS) |
| 75 // On ChromeOS, the default is LAST, so no migration should happen. |
| 76 EXPECT_EQ(SessionStartupPref::LAST, pref.type); |
| 77 EXPECT_EQ(0U, pref.urls.size()); |
| 78 #else |
| 79 EXPECT_EQ(SessionStartupPref::URLS, pref.type); |
| 80 EXPECT_EQ(1U, pref.urls.size()); |
| 81 EXPECT_EQ(GURL("http://chromium.org/"), pref.urls[0]); |
| 82 #endif |
| 83 } |
| 84 |
| 85 // Checks to make sure that if the user had previously not selected anything |
| 86 // (so that, in effect, the default value "Open the homepage" was selected), |
| 87 // and the NTP is being used for the homepage, their preferences are migrated |
| 88 // to "Open the New Tab Page" on upgrade to M19. |
| 89 TEST_F(SessionStartupPrefTest, DefaultMigrationHomepageIsNTP) { |
| 90 pref_service_->RegisterStringPref(prefs::kHomePage, "http://google.com/"); |
| 91 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/"); |
| 92 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, true); |
| 93 |
| 94 EXPECT_FALSE(pref_service_->HasPrefPath(prefs::kRestoreOnStartup)); |
| 95 |
| 96 SessionStartupPref pref = SessionStartupPref::GetStartupPref( |
| 97 pref_service_.get()); |
| 98 |
| 99 #if defined(OS_CHROMEOS) |
| 100 // On ChromeOS, the default is LAST, so no migration should happen. |
| 101 EXPECT_EQ(SessionStartupPref::LAST, pref.type); |
| 102 #else |
| 103 EXPECT_EQ(SessionStartupPref::DEFAULT, pref.type); |
| 104 #endif |
| 105 |
| 106 // The "URLs to restore on startup" shouldn't get migrated. |
| 107 EXPECT_EQ(0U, pref.urls.size()); |
| 108 } |
| 109 |
| 110 // Checks to make sure that if the user had previously selected "Open the |
| 111 // "homepage", their preferences are migrated on upgrade to M19. |
60 TEST_F(SessionStartupPrefTest, HomePageMigration) { | 112 TEST_F(SessionStartupPrefTest, HomePageMigration) { |
61 pref_service_->RegisterStringPref(prefs::kHomePage, "http://google.com/"); | 113 pref_service_->RegisterStringPref(prefs::kHomePage, "http://google.com/"); |
62 | 114 |
63 // By design, it's impossible to set the 'restore on startup' pref to 0 | 115 // By design, it's impossible to set the 'restore on startup' pref to 0 |
64 // ("open the homepage") using SessionStartupPref::SetStartupPref(), so set it | 116 // ("open the homepage") using SessionStartupPref::SetStartupPref(), so set it |
65 // using the pref service directly. | 117 // using the pref service directly. |
66 pref_service_->SetInteger(prefs::kRestoreOnStartup, /*kPrefValueHomePage*/ 0); | 118 pref_service_->SetInteger(prefs::kRestoreOnStartup, /*kPrefValueHomePage*/ 0); |
67 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/"); | 119 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/"); |
| 120 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, false); |
68 | 121 |
69 SessionStartupPref pref = SessionStartupPref::GetStartupPref( | 122 SessionStartupPref pref = SessionStartupPref::GetStartupPref( |
70 pref_service_.get()); | 123 pref_service_.get()); |
| 124 |
71 EXPECT_EQ(SessionStartupPref::URLS, pref.type); | 125 EXPECT_EQ(SessionStartupPref::URLS, pref.type); |
72 EXPECT_EQ(1U, pref.urls.size()); | 126 EXPECT_EQ(1U, pref.urls.size()); |
73 EXPECT_EQ(GURL("http://chromium.org/"), pref.urls[0]); | 127 EXPECT_EQ(GURL("http://chromium.org/"), pref.urls[0]); |
74 } | 128 } |
| 129 |
| 130 // Checks to make sure that if the user had previously selected "Open the |
| 131 // "homepage", and the NTP is being used for the homepage, their preferences |
| 132 // are migrated on upgrade to M19. |
| 133 TEST_F(SessionStartupPrefTest, HomePageMigrationHomepageIsNTP) { |
| 134 pref_service_->RegisterStringPref(prefs::kHomePage, "http://google.com/"); |
| 135 |
| 136 // By design, it's impossible to set the 'restore on startup' pref to 0 |
| 137 // ("open the homepage") using SessionStartupPref::SetStartupPref(), so set it |
| 138 // using the pref service directly. |
| 139 pref_service_->SetInteger(prefs::kRestoreOnStartup, /*kPrefValueHomePage*/ 0); |
| 140 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/"); |
| 141 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, true); |
| 142 |
| 143 SessionStartupPref pref = SessionStartupPref::GetStartupPref( |
| 144 pref_service_.get()); |
| 145 |
| 146 EXPECT_EQ(SessionStartupPref::DEFAULT, pref.type); |
| 147 } |
OLD | NEW |