1 // Copyright 2013 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.
5 #include "ui/app_list/test/app_list_test_model.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/stringprintf.h"
14 const char AppListTestModel::kItemType[] = "TestItem";
16 // AppListTestModel::AppListTestItem
18 AppListTestModel::AppListTestItem::AppListTestItem(
19 const std::string& id,
20 AppListTestModel* model)
24 AppListTestModel::AppListTestItem::~AppListTestItem() {
27 void AppListTestModel::AppListTestItem::Activate(int event_flags) {
28 model_->ItemActivated(this);
31 const char* AppListTestModel::AppListTestItem::GetItemType() const {
32 return AppListTestModel::kItemType;
35 void AppListTestModel::AppListTestItem::SetPosition(
36 const syncer::StringOrdinal& new_position) {
37 set_position(new_position);
42 AppListTestModel::AppListTestModel()
44 last_activated_(NULL) {
47 AppListItem* AppListTestModel::AddItem(AppListItem* item) {
48 return AppListModel::AddItem(make_scoped_ptr(item));
51 AppListItem* AppListTestModel::AddItemToFolder(AppListItem* item,
52 const std::string& folder_id) {
53 return AppListModel::AddItemToFolder(make_scoped_ptr(item), folder_id);
56 void AppListTestModel::MoveItemToFolder(AppListItem* item,
57 const std::string& folder_id) {
58 AppListModel::MoveItemToFolder(item, folder_id);
62 std::string AppListTestModel::GetItemName(int id) {
63 return base::StringPrintf("Item %d", id);
66 void AppListTestModel::PopulateApps(int n) {
67 int start_index = static_cast<int>(top_level_item_list()->item_count());
68 for (int i = 0; i < n; ++i)
69 CreateAndAddItem(GetItemName(start_index + i));
72 void AppListTestModel::CreateAndPopulateFolderWithApps(int n) {
74 int start_index = static_cast<int>(top_level_item_list()->item_count());
75 AppListTestItem* item = CreateAndAddItem(GetItemName(start_index));
76 std::string merged_item_id = item->id();
77 for (int i = 1; i < n; ++i) {
78 AppListTestItem* new_item = CreateAndAddItem(GetItemName(start_index + i));
79 merged_item_id = AppListModel::MergeItems(merged_item_id, new_item->id());
83 void AppListTestModel::PopulateAppWithId(int id) {
84 CreateAndAddItem(GetItemName(id));
87 std::string AppListTestModel::GetModelContent() {
89 for (size_t i = 0; i < top_level_item_list()->item_count(); ++i) {
92 content += top_level_item_list()->item_at(i)->id();
97 AppListTestModel::AppListTestItem* AppListTestModel::CreateItem(
98 const std::string& id) {
99 AppListTestItem* item = new AppListTestItem(id, this);
100 size_t nitems = top_level_item_list()->item_count();
101 syncer::StringOrdinal position;
103 position = syncer::StringOrdinal::CreateInitialOrdinal();
106 top_level_item_list()->item_at(nitems - 1)->position().CreateAfter();
108 item->SetPosition(position);
109 SetItemName(item, id);
113 AppListTestModel::AppListTestItem* AppListTestModel::CreateAndAddItem(
114 const std::string& id) {
115 scoped_ptr<AppListTestItem> test_item(CreateItem(id));
116 AppListItem* item = AppListModel::AddItem(test_item.PassAs<AppListItem>());
117 return static_cast<AppListTestItem*>(item);
119 void AppListTestModel::HighlightItemAt(int index) {
120 AppListItem* item = top_level_item_list()->item_at(index);
121 item->SetHighlighted(true);
124 void AppListTestModel::ItemActivated(AppListTestItem* item) {
125 last_activated_ = item;
130 } // namespace app_list