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/chrome_thread.h" | 8 #include "chrome/browser/chrome_thread.h" |
9 #include "chrome/browser/prefs/pref_value_store.h" | 9 #include "chrome/browser/prefs/pref_value_store.h" |
10 #include "chrome/common/json_pref_store.h" | 10 #include "chrome/common/json_pref_store.h" |
11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
12 #include "chrome/test/testing_pref_service.h" | 12 #include "chrome/test/testing_pref_service.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 class ShownSectionsHandlerTest : public testing::Test { | 15 class ShownSectionsHandlerTest : public testing::Test { |
16 }; | 16 }; |
17 | 17 |
| 18 namespace { |
| 19 |
| 20 int MigratePrefValue(PrefService* prefs, int starting_value) { |
| 21 prefs->SetInteger(prefs::kNTPShownSections, starting_value); |
| 22 ShownSectionsHandler::MigrateUserPrefs(prefs, 1, 3); |
| 23 return prefs->GetInteger(prefs::kNTPShownSections); |
| 24 } |
| 25 |
| 26 } |
| 27 |
18 TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) { | 28 TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) { |
19 scoped_ptr<PrefService> pref(new TestingPrefService); | 29 scoped_ptr<PrefService> pref(new TestingPrefService); |
20 | 30 |
21 // Set an *old* value | |
22 pref->RegisterIntegerPref(prefs::kNTPShownSections, 0); | 31 pref->RegisterIntegerPref(prefs::kNTPShownSections, 0); |
23 pref->SetInteger(prefs::kNTPShownSections, THUMB); | |
24 | 32 |
25 ShownSectionsHandler::MigrateUserPrefs(pref.get(), 0, 1); | 33 EXPECT_EQ(APPS, MigratePrefValue(pref.get(), APPS)); |
| 34 EXPECT_EQ(THUMB, MigratePrefValue(pref.get(), THUMB)); |
| 35 EXPECT_EQ(APPS, MigratePrefValue(pref.get(), APPS | THUMB)); |
26 | 36 |
27 int shown_sections = pref->GetInteger(prefs::kNTPShownSections); | 37 // 2 is not currently used, but older state may contain it and we should do |
| 38 // something reasonable. |
| 39 EXPECT_EQ(THUMB, MigratePrefValue(pref.get(), 3)); |
28 | 40 |
29 EXPECT_TRUE(shown_sections & THUMB); | 41 // 0 can't correspond to any section, but we should still do something |
30 EXPECT_FALSE(shown_sections & LIST); | 42 // reasonable. |
31 EXPECT_FALSE(shown_sections & RECENT); | 43 EXPECT_EQ(THUMB, MigratePrefValue(pref.get(), 0)); |
32 EXPECT_TRUE(shown_sections & TIPS); | |
33 EXPECT_TRUE(shown_sections & SYNC); | |
34 } | 44 } |
35 | |
36 TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs1To2) { | |
37 scoped_ptr<PrefService> pref(new TestingPrefService); | |
38 | |
39 // Set an *old* value | |
40 pref->RegisterIntegerPref(prefs::kNTPShownSections, 0); | |
41 pref->SetInteger(prefs::kNTPShownSections, LIST); | |
42 | |
43 ShownSectionsHandler::MigrateUserPrefs(pref.get(), 1, 2); | |
44 | |
45 int shown_sections = pref->GetInteger(prefs::kNTPShownSections); | |
46 | |
47 EXPECT_TRUE(shown_sections & THUMB); | |
48 EXPECT_FALSE(shown_sections & LIST); | |
49 } | |
OLD | NEW |