Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: chrome/browser/ui/app_list/model_pref_updater_unittest.cc

Issue 2430753002: Discard unused AppListPrefs code. (Closed)
Patch Set: update Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/app_list/model_pref_updater.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/app_list/model_pref_updater.h"
6
7 #include <memory>
8
9 #include "base/macros.h"
10 #include "chrome/browser/ui/app_list/app_list_prefs.h"
11 #include "chrome/browser/ui/app_list/extension_app_item.h"
12 #include "components/pref_registry/testing_pref_service_syncable.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/app_list/app_list_folder_item.h"
15 #include "ui/app_list/app_list_item.h"
16 #include "ui/app_list/test/app_list_test_model.h"
17
18 namespace app_list {
19 namespace test {
20
21 class TestExtensionAppItem : public AppListItem {
22 public:
23 explicit TestExtensionAppItem(const std::string& id) : AppListItem(id) {}
24 ~TestExtensionAppItem() override {}
25
26 const char* GetItemType() const override {
27 return ExtensionAppItem::kItemType;
28 }
29
30 private:
31 DISALLOW_COPY_AND_ASSIGN(TestExtensionAppItem);
32 };
33
34 class ModelPrefUpdaterTest : public testing::Test {
35 public:
36 ModelPrefUpdaterTest() {}
37 ~ModelPrefUpdaterTest() override {}
38
39 void SetUp() override {
40 AppListPrefs::RegisterProfilePrefs(pref_service_.registry());
41 prefs_.reset(AppListPrefs::Create(&pref_service_));
42 model_.reset(new AppListTestModel());
43 pref_updater_.reset(new ModelPrefUpdater(prefs_.get(), model_.get()));
44 }
45
46 AppListTestModel* model() { return model_.get(); }
47
48 AppListPrefs* prefs() { return prefs_.get(); }
49
50 bool AppListItemMatchesPrefs(AppListItem* item) {
51 std::unique_ptr<AppListPrefs::AppListInfo> info =
52 prefs_->GetAppListInfo(item->id());
53 AppListPrefs::AppListInfo::ItemType expected_type =
54 AppListPrefs::AppListInfo::ITEM_TYPE_INVALID;
55 if (item->GetItemType() == ExtensionAppItem::kItemType)
56 expected_type = AppListPrefs::AppListInfo::APP_ITEM;
57 else if (item->GetItemType() == AppListFolderItem::kItemType)
58 expected_type = AppListPrefs::AppListInfo::FOLDER_ITEM;
59
60 return info && info->position.Equals(item->position()) &&
61 info->name == item->name() && info->parent_id == item->folder_id() &&
62 info->item_type == expected_type;
63 }
64
65 private:
66 user_prefs::TestingPrefServiceSyncable pref_service_;
67 std::unique_ptr<AppListTestModel> model_;
68 std::unique_ptr<AppListPrefs> prefs_;
69 std::unique_ptr<ModelPrefUpdater> pref_updater_;
70
71 DISALLOW_COPY_AND_ASSIGN(ModelPrefUpdaterTest);
72 };
73
74 TEST_F(ModelPrefUpdaterTest, ModelChange) {
75 AppListPrefs::AppListInfoMap infos;
76 prefs()->GetAllAppListInfos(&infos);
77 EXPECT_EQ(0u, infos.size());
78
79 AppListFolderItem* folder =
80 new AppListFolderItem("folder1", AppListFolderItem::FOLDER_TYPE_NORMAL);
81 model()->AddItem(folder);
82
83 prefs()->GetAllAppListInfos(&infos);
84 EXPECT_EQ(1u, infos.size());
85 EXPECT_TRUE(AppListItemMatchesPrefs(folder));
86
87 AppListItem* item = new TestExtensionAppItem("Item 0");
88 model()->AddItem(item);
89
90 prefs()->GetAllAppListInfos(&infos);
91 EXPECT_EQ(2u, infos.size());
92 EXPECT_TRUE(AppListItemMatchesPrefs(folder));
93 EXPECT_TRUE(AppListItemMatchesPrefs(item));
94
95 model()->MoveItemToFolder(item, folder->id());
96 EXPECT_EQ(folder->id(), item->folder_id());
97
98 prefs()->GetAllAppListInfos(&infos);
99 EXPECT_EQ(2u, infos.size());
100 EXPECT_TRUE(AppListItemMatchesPrefs(folder));
101 EXPECT_TRUE(AppListItemMatchesPrefs(item));
102 }
103
104 } // namespace test
105 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/model_pref_updater.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698