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

Unified Diff: chrome/browser/ui/app_list/model_pref_updater_unittest.cc

Issue 599343002: Mirror app list hierarchy data in profile prefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@app_list_folder_pref
Patch Set: add unit test Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/app_list/model_pref_updater.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/app_list/model_pref_updater_unittest.cc
diff --git a/chrome/browser/ui/app_list/model_pref_updater_unittest.cc b/chrome/browser/ui/app_list/model_pref_updater_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dd92bbf10b061a66374ab6b3ce2e7c39c99963b5
--- /dev/null
+++ b/chrome/browser/ui/app_list/model_pref_updater_unittest.cc
@@ -0,0 +1,102 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/ui/app_list/app_list_prefs.h"
+#include "chrome/browser/ui/app_list/extension_app_item.h"
+#include "chrome/browser/ui/app_list/model_pref_updater.h"
+#include "components/pref_registry/testing_pref_service_syncable.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/app_list/app_list_folder_item.h"
+#include "ui/app_list/app_list_item.h"
+#include "ui/app_list/test/app_list_test_model.h"
+
+namespace app_list {
+namespace test {
+
+class TestExtensionAppItem : public AppListItem {
+ public:
+ explicit TestExtensionAppItem(const std::string& id) : AppListItem(id) {}
+ virtual ~TestExtensionAppItem() {}
+
+ virtual const char* GetItemType() const OVERRIDE {
+ return ExtensionAppItem::kItemType;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestExtensionAppItem);
+};
+
+class ModelPrefUpdaterTest : public testing::Test {
+ public:
+ ModelPrefUpdaterTest() {}
+ virtual ~ModelPrefUpdaterTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ AppListPrefs::RegisterProfilePrefs(pref_service_.registry());
+ prefs_.reset(AppListPrefs::Create(&pref_service_));
+ model_.reset(new AppListTestModel());
+ pref_updater_.reset(new ModelPrefUpdater(prefs_.get(), model_.get()));
+ }
+
+ AppListTestModel* model() { return model_.get(); }
+
+ AppListPrefs* prefs() { return prefs_.get(); }
+
+ bool AppListItemMatchesPrefs(AppListItem* item) {
+ scoped_ptr<AppListPrefs::AppListInfo> info =
+ prefs_->GetAppListInfo(item->id());
+ AppListPrefs::AppListInfo::ItemType expected_type =
+ AppListPrefs::AppListInfo::ITEM_TYPE_INVALID;
+ if (item->GetItemType() == ExtensionAppItem::kItemType)
+ expected_type = AppListPrefs::AppListInfo::APP_ITEM;
+ else if (item->GetItemType() == AppListFolderItem::kItemType)
+ expected_type = AppListPrefs::AppListInfo::FOLDER_ITEM;
+
+ return info && info->position.Equals(item->position()) &&
+ info->name == item->name() && info->parent_id == item->folder_id() &&
+ info->item_type == expected_type;
+ }
+
+ private:
+ user_prefs::TestingPrefServiceSyncable pref_service_;
+ scoped_ptr<AppListTestModel> model_;
+ scoped_ptr<AppListPrefs> prefs_;
+ scoped_ptr<ModelPrefUpdater> pref_updater_;
+
+ DISALLOW_COPY_AND_ASSIGN(ModelPrefUpdaterTest);
+};
+
+TEST_F(ModelPrefUpdaterTest, ModelChange) {
+ AppListPrefs::AppListInfoMap infos;
+ prefs()->GetAllAppListInfos(&infos);
+ EXPECT_EQ(0u, infos.size());
+
+ AppListFolderItem* folder =
+ new AppListFolderItem("folder1", AppListFolderItem::FOLDER_TYPE_NORMAL);
+ model()->AddItem(folder);
+
+ prefs()->GetAllAppListInfos(&infos);
+ EXPECT_EQ(1u, infos.size());
+ EXPECT_TRUE(AppListItemMatchesPrefs(folder));
+
+ AppListItem* item = new TestExtensionAppItem("Item 0");
+ model()->AddItem(item);
+
+ prefs()->GetAllAppListInfos(&infos);
+ EXPECT_EQ(2u, infos.size());
+ EXPECT_TRUE(AppListItemMatchesPrefs(folder));
+ EXPECT_TRUE(AppListItemMatchesPrefs(item));
+
+ model()->MoveItemToFolder(item, folder->id());
+ EXPECT_EQ(folder->id(), item->folder_id());
+
+ prefs()->GetAllAppListInfos(&infos);
+ EXPECT_EQ(2u, infos.size());
+ EXPECT_TRUE(AppListItemMatchesPrefs(folder));
+ EXPECT_TRUE(AppListItemMatchesPrefs(item));
+}
+
+} // namespace test
+} // namespace app_list
« no previous file with comments | « chrome/browser/ui/app_list/model_pref_updater.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698