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 "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_syncable.h" | 7 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 8 #include "components/pref_registry/pref_registry_syncable.h" | 8 #include "components/pref_registry/pref_registry_syncable.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 // Unit tests for SessionStartupPref. | 12 // Unit tests for SessionStartupPref. |
| 13 class SessionStartupPrefTest : public testing::Test { | 13 class SessionStartupPrefTest : public testing::Test { |
| 14 public: | 14 public: |
| 15 void SetUp() override { | 15 void SetUp() override { |
| 16 pref_service_.reset(new TestingPrefServiceSyncable); | 16 pref_service_.reset(new TestingPrefServiceSyncable); |
| 17 SessionStartupPref::RegisterProfilePrefs(registry()); | 17 SessionStartupPref::RegisterProfilePrefs(registry()); |
| 18 registry()->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, true); | 18 registry()->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, true); |
| 19 } | 19 } |
| 20 | 20 |
| 21 bool IsUseLastOpenDefault() { | 21 bool IsUseLastOpenDefault() { |
|
bartfab (slow)
2015/08/31 15:36:43
Nit: This can be removed now.
sdefresne
2015/09/02 11:30:19
Removed.
| |
| 22 // On ChromeOS, the default SessionStartupPref is LAST. | 22 // On ChromeOS, the default SessionStartupPref is LAST. |
| 23 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
| 24 return true; | 24 return true; |
| 25 #else | 25 #else |
| 26 return false; | 26 return false; |
| 27 #endif | 27 #endif |
| 28 } | 28 } |
| 29 | 29 |
| 30 user_prefs::PrefRegistrySyncable* registry() { | 30 user_prefs::PrefRegistrySyncable* registry() { |
| 31 return pref_service_->registry(); | 31 return pref_service_->registry(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 override_test.urls.push_back(GURL("dev.chromium.org")); | 68 override_test.urls.push_back(GURL("dev.chromium.org")); |
| 69 SessionStartupPref::SetStartupPref(pref_service_.get(), override_test); | 69 SessionStartupPref::SetStartupPref(pref_service_.get(), override_test); |
| 70 | 70 |
| 71 result = SessionStartupPref::GetStartupPref(pref_service_.get()); | 71 result = SessionStartupPref::GetStartupPref(pref_service_.get()); |
| 72 EXPECT_EQ(3u, result.urls.size()); | 72 EXPECT_EQ(3u, result.urls.size()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Checks to make sure that if the user had previously not selected anything | 75 // Checks to make sure that if the user had previously not selected anything |
| 76 // (so that, in effect, the default value "Open the homepage" was selected), | 76 // (so that, in effect, the default value "Open the homepage" was selected), |
| 77 // their preferences are migrated on upgrade to m19. | 77 // their preferences are migrated on upgrade to m19. |
| 78 TEST_F(SessionStartupPrefTest, DefaultMigration) { | 78 TEST_F(SessionStartupPrefTest, DefaultMigration) { |
|
bartfab (slow)
2015/08/31 15:36:43
Nit: This is obsolete now as well.
sdefresne
2015/09/02 11:30:19
Removed.
| |
| 79 registry()->RegisterStringPref(prefs::kHomePage, "http://google.com/"); | 79 registry()->RegisterStringPref(prefs::kHomePage, "http://google.com/"); |
| 80 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/"); | 80 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/"); |
| 81 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, false); | 81 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, false); |
| 82 | 82 |
| 83 EXPECT_FALSE(pref_service_->HasPrefPath(prefs::kRestoreOnStartup)); | 83 EXPECT_FALSE(pref_service_->HasPrefPath(prefs::kRestoreOnStartup)); |
| 84 | 84 |
| 85 SessionStartupPref pref = SessionStartupPref::GetStartupPref( | 85 SessionStartupPref pref = SessionStartupPref::GetStartupPref( |
| 86 pref_service_.get()); | 86 pref_service_.get()); |
| 87 | 87 |
| 88 if (IsUseLastOpenDefault()) { | 88 if (IsUseLastOpenDefault()) { |
| 89 EXPECT_EQ(SessionStartupPref::LAST, pref.type); | 89 EXPECT_EQ(SessionStartupPref::LAST, pref.type); |
| 90 EXPECT_EQ(0U, pref.urls.size()); | 90 EXPECT_EQ(0U, pref.urls.size()); |
| 91 } else { | 91 } else { |
| 92 EXPECT_EQ(SessionStartupPref::URLS, pref.type); | 92 EXPECT_EQ(SessionStartupPref::URLS, pref.type); |
| 93 EXPECT_EQ(1U, pref.urls.size()); | 93 EXPECT_EQ(1U, pref.urls.size()); |
| 94 EXPECT_EQ(GURL("http://chromium.org/"), pref.urls[0]); | 94 EXPECT_EQ(GURL("http://chromium.org/"), pref.urls[0]); |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Checks to make sure that if the user had previously not selected anything | 98 // Checks to make sure that if the user had previously not selected anything |
| 99 // (so that, in effect, the default value "Open the homepage" was selected), | 99 // (so that, in effect, the default value "Open the homepage" was selected), |
| 100 // and the NTP is being used for the homepage, their preferences are migrated | 100 // and the NTP is being used for the homepage, their preferences are migrated |
| 101 // to "Open the New Tab Page" on upgrade to M19. | 101 // to "Open the New Tab Page" on upgrade to M19. |
| 102 TEST_F(SessionStartupPrefTest, DefaultMigrationHomepageIsNTP) { | 102 TEST_F(SessionStartupPrefTest, DefaultMigrationHomepageIsNTP) { |
|
bartfab (slow)
2015/08/31 15:36:43
Nit: This is obsolete now as well.
sdefresne
2015/09/02 11:30:19
Removed.
| |
| 103 registry()->RegisterStringPref(prefs::kHomePage, "http://google.com/"); | 103 registry()->RegisterStringPref(prefs::kHomePage, "http://google.com/"); |
| 104 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/"); | 104 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/"); |
| 105 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, true); | 105 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, true); |
| 106 | 106 |
| 107 EXPECT_FALSE(pref_service_->HasPrefPath(prefs::kRestoreOnStartup)); | 107 EXPECT_FALSE(pref_service_->HasPrefPath(prefs::kRestoreOnStartup)); |
| 108 | 108 |
| 109 SessionStartupPref pref = SessionStartupPref::GetStartupPref( | 109 SessionStartupPref pref = SessionStartupPref::GetStartupPref( |
| 110 pref_service_.get()); | 110 pref_service_.get()); |
| 111 | 111 |
| 112 if (IsUseLastOpenDefault()) | 112 if (IsUseLastOpenDefault()) |
| 113 EXPECT_EQ(SessionStartupPref::LAST, pref.type); | 113 EXPECT_EQ(SessionStartupPref::LAST, pref.type); |
| 114 else | 114 else |
| 115 EXPECT_EQ(SessionStartupPref::DEFAULT, pref.type); | 115 EXPECT_EQ(SessionStartupPref::DEFAULT, pref.type); |
| 116 | 116 |
| 117 // The "URLs to restore on startup" shouldn't get migrated. | 117 // The "URLs to restore on startup" shouldn't get migrated. |
| 118 EXPECT_EQ(0U, pref.urls.size()); | 118 EXPECT_EQ(0U, pref.urls.size()); |
| 119 } | 119 } |
| 120 | |
| 121 // Checks to make sure that if the user had previously selected "Open the | |
| 122 // "homepage", their preferences are migrated on upgrade to M19. | |
| 123 TEST_F(SessionStartupPrefTest, HomePageMigration) { | |
| 124 registry()->RegisterStringPref(prefs::kHomePage, "http://google.com/"); | |
| 125 | |
| 126 // By design, it's impossible to set the 'restore on startup' pref to 0 | |
| 127 // ("open the homepage") using SessionStartupPref::SetStartupPref(), so set it | |
| 128 // using the pref service directly. | |
| 129 pref_service_->SetInteger(prefs::kRestoreOnStartup, /*kPrefValueHomePage*/ 0); | |
| 130 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/"); | |
| 131 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, false); | |
| 132 | |
| 133 SessionStartupPref pref = SessionStartupPref::GetStartupPref( | |
| 134 pref_service_.get()); | |
| 135 | |
| 136 EXPECT_EQ(SessionStartupPref::URLS, pref.type); | |
| 137 EXPECT_EQ(1U, pref.urls.size()); | |
| 138 EXPECT_EQ(GURL("http://chromium.org/"), pref.urls[0]); | |
| 139 } | |
| 140 | |
| 141 // Checks to make sure that if the user had previously selected "Open the | |
| 142 // "homepage", and the NTP is being used for the homepage, their preferences | |
| 143 // are migrated on upgrade to M19. | |
| 144 TEST_F(SessionStartupPrefTest, HomePageMigrationHomepageIsNTP) { | |
| 145 registry()->RegisterStringPref(prefs::kHomePage, "http://google.com/"); | |
| 146 | |
| 147 // By design, it's impossible to set the 'restore on startup' pref to 0 | |
| 148 // ("open the homepage") using SessionStartupPref::SetStartupPref(), so set it | |
| 149 // using the pref service directly. | |
| 150 pref_service_->SetInteger(prefs::kRestoreOnStartup, /*kPrefValueHomePage*/ 0); | |
| 151 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/"); | |
| 152 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, true); | |
| 153 | |
| 154 SessionStartupPref pref = SessionStartupPref::GetStartupPref( | |
| 155 pref_service_.get()); | |
| 156 | |
| 157 EXPECT_EQ(SessionStartupPref::DEFAULT, pref.type); | |
| 158 } | |
| OLD | NEW |