| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/dom_ui/shown_sections_handler.h" | 5 #include "chrome/browser/dom_ui/shown_sections_handler.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 9 #include "chrome/browser/chrome_thread.h" | 9 #include "chrome/browser/chrome_thread.h" |
| 10 #include "chrome/browser/pref_service.h" | 10 #include "chrome/browser/pref_service.h" |
| 11 #include "chrome/browser/pref_value_store.h" | 11 #include "chrome/browser/pref_value_store.h" |
| 12 #include "chrome/common/json_pref_store.h" | 12 #include "chrome/common/json_pref_store.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 class ShownSectionsHandlerTest : public testing::Test { | 16 class ShownSectionsHandlerTest : public testing::Test { |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) { | 19 TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) { |
| 20 // Create a preference value that has only user defined | 20 // Create a preference value that has only user defined |
| 21 // preference values. | 21 // preference values. |
| 22 PrefService pref(new PrefValueStore( | 22 FilePath user_prefs = FilePath(); |
| 23 NULL, /* no managed preference values */ | 23 scoped_ptr<PrefService> pref(PrefService::CreateUserPrefService(user_prefs)); |
| 24 new JsonPrefStore( /* user defined preference values */ | |
| 25 FilePath(), | |
| 26 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)), | |
| 27 NULL /* no suggested preference values */)); | |
| 28 | 24 |
| 29 // Set an *old* value | 25 // Set an *old* value |
| 30 pref.RegisterIntegerPref(prefs::kNTPShownSections, 0); | 26 pref->RegisterIntegerPref(prefs::kNTPShownSections, 0); |
| 31 pref.SetInteger(prefs::kNTPShownSections, THUMB); | 27 pref->SetInteger(prefs::kNTPShownSections, THUMB); |
| 32 | 28 |
| 33 ShownSectionsHandler::MigrateUserPrefs(&pref, 0, 1); | 29 ShownSectionsHandler::MigrateUserPrefs(pref.get(), 0, 1); |
| 34 | 30 |
| 35 int shown_sections = pref.GetInteger(prefs::kNTPShownSections); | 31 int shown_sections = pref->GetInteger(prefs::kNTPShownSections); |
| 36 | 32 |
| 37 EXPECT_TRUE(shown_sections & THUMB); | 33 EXPECT_TRUE(shown_sections & THUMB); |
| 38 EXPECT_FALSE(shown_sections & LIST); | 34 EXPECT_FALSE(shown_sections & LIST); |
| 39 EXPECT_FALSE(shown_sections & RECENT); | 35 EXPECT_FALSE(shown_sections & RECENT); |
| 40 EXPECT_TRUE(shown_sections & TIPS); | 36 EXPECT_TRUE(shown_sections & TIPS); |
| 41 EXPECT_TRUE(shown_sections & SYNC); | 37 EXPECT_TRUE(shown_sections & SYNC); |
| 42 } | 38 } |
| 43 | 39 |
| 44 TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs1To2) { | 40 TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs1To2) { |
| 45 PrefService pref(new PrefValueStore( | 41 FilePath user_prefs = FilePath(); |
| 46 NULL, /* no managed preferences */ | 42 scoped_ptr<PrefService> pref(PrefService::CreateUserPrefService(user_prefs)); |
| 47 new JsonPrefStore( | |
| 48 FilePath(), | |
| 49 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)), | |
| 50 NULL /* no suggested preferences */)); | |
| 51 | 43 |
| 52 // Set an *old* value | 44 // Set an *old* value |
| 53 pref.RegisterIntegerPref(prefs::kNTPShownSections, 0); | 45 pref->RegisterIntegerPref(prefs::kNTPShownSections, 0); |
| 54 pref.SetInteger(prefs::kNTPShownSections, LIST); | 46 pref->SetInteger(prefs::kNTPShownSections, LIST); |
| 55 | 47 |
| 56 ShownSectionsHandler::MigrateUserPrefs(&pref, 1, 2); | 48 ShownSectionsHandler::MigrateUserPrefs(pref.get(), 1, 2); |
| 57 | 49 |
| 58 int shown_sections = pref.GetInteger(prefs::kNTPShownSections); | 50 int shown_sections = pref->GetInteger(prefs::kNTPShownSections); |
| 59 | 51 |
| 60 EXPECT_TRUE(shown_sections & THUMB); | 52 EXPECT_TRUE(shown_sections & THUMB); |
| 61 EXPECT_FALSE(shown_sections & LIST); | 53 EXPECT_FALSE(shown_sections & LIST); |
| 62 } | 54 } |
| 63 | 55 |
| OLD | NEW |