| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" | 
| 8 #include "chrome/browser/prefs/pref_value_store.h" | 8 #include "chrome/browser/prefs/pref_value_store.h" | 
| 9 #include "chrome/common/json_pref_store.h" | 9 #include "chrome/common/json_pref_store.h" | 
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" | 
| 11 #include "chrome/test/testing_pref_service.h" | 11 #include "chrome/test/testing_pref_service.h" | 
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" | 
| 13 | 13 | 
| 14 class ShownSectionsHandlerTest : public testing::Test { | 14 class ShownSectionsHandlerTest : public testing::Test { | 
| 15 }; | 15 }; | 
| 16 | 16 | 
| 17 namespace { | 17 namespace { | 
| 18 | 18 | 
| 19 int MigratePrefValue(PrefService* prefs, int starting_value) { | 19 int MigratePrefValue(PrefService* prefs, int starting_value) { | 
| 20   prefs->SetInteger(prefs::kNTPShownSections, starting_value); | 20   prefs->SetInteger(prefs::kNTPShownSections, starting_value); | 
| 21   ShownSectionsHandler::MigrateUserPrefs(prefs, 1, 3); | 21   ShownSectionsHandler::MigrateUserPrefs(prefs, 1, 3); | 
| 22   return prefs->GetInteger(prefs::kNTPShownSections); | 22   return prefs->GetInteger(prefs::kNTPShownSections); | 
| 23 } | 23 } | 
| 24 | 24 | 
| 25 }  // namespace | 25 }  // namespace | 
| 26 | 26 | 
| 27 TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) { | 27 TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) { | 
| 28   scoped_ptr<PrefService> pref(new TestingPrefService); | 28   scoped_ptr<PrefService> pref(TestingPrefService::CreateTestingPrefService()); | 
| 29 | 29 | 
| 30   pref->RegisterIntegerPref(prefs::kNTPShownSections, 0); | 30   pref->RegisterIntegerPref(prefs::kNTPShownSections, 0); | 
| 31 | 31 | 
| 32   EXPECT_EQ(APPS, MigratePrefValue(pref.get(), APPS)); | 32   EXPECT_EQ(APPS, MigratePrefValue(pref.get(), APPS)); | 
| 33   EXPECT_EQ(THUMB, MigratePrefValue(pref.get(), THUMB)); | 33   EXPECT_EQ(THUMB, MigratePrefValue(pref.get(), THUMB)); | 
| 34   EXPECT_EQ(APPS, MigratePrefValue(pref.get(), APPS | THUMB)); | 34   EXPECT_EQ(APPS, MigratePrefValue(pref.get(), APPS | THUMB)); | 
| 35 | 35 | 
| 36   // 2 is not currently used, but older state may contain it and we should do | 36   // 2 is not currently used, but older state may contain it and we should do | 
| 37   // something reasonable. | 37   // something reasonable. | 
| 38   EXPECT_EQ(THUMB, MigratePrefValue(pref.get(), 3)); | 38   EXPECT_EQ(THUMB, MigratePrefValue(pref.get(), 3)); | 
| 39 | 39 | 
| 40   // 0 can't correspond to any section, but we should still do something | 40   // 0 can't correspond to any section, but we should still do something | 
| 41   // reasonable. | 41   // reasonable. | 
| 42   EXPECT_EQ(THUMB, MigratePrefValue(pref.get(), 0)); | 42   EXPECT_EQ(THUMB, MigratePrefValue(pref.get(), 0)); | 
| 43 } | 43 } | 
| OLD | NEW | 
|---|