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/strings/stringprintf.h"
8 #include "ui/app_list/app_list_item_model.h"
14 const char AppListTestModel::kAppType[] = "FolderItem";
16 class AppListTestModel::AppListTestItemModel : public AppListItemModel {
18 AppListTestItemModel(const std::string& id, AppListTestModel* model)
19 : AppListItemModel(id),
22 virtual ~AppListTestItemModel() {}
24 virtual void Activate(int event_flags) OVERRIDE {
25 model_->ItemActivated(this);
28 virtual const char* GetAppType() const OVERRIDE {
29 return AppListTestModel::kAppType;
33 AppListTestModel* model_;
34 DISALLOW_COPY_AND_ASSIGN(AppListTestItemModel);
37 AppListTestModel::AppListTestModel()
39 last_activated_(NULL) {
43 std::string AppListTestModel::GetItemName(int id) {
44 return base::StringPrintf("Item %d", id);
47 void AppListTestModel::PopulateApps(int n) {
48 int start_index = item_list()->item_count();
49 for (int i = 0; i < n; ++i)
50 CreateAndAddItem(GetItemName(start_index + i));
53 void AppListTestModel::PopulateAppWithId(int id) {
54 CreateAndAddItem(GetItemName(id));
57 std::string AppListTestModel::GetModelContent() {
59 for (size_t i = 0; i < item_list()->item_count(); ++i) {
62 content += item_list()->item_at(i)->title();
67 AppListItemModel* AppListTestModel::CreateItem(const std::string& title,
68 const std::string& full_name) {
69 AppListItemModel* item = new AppListTestItemModel(title, this);
70 size_t nitems = item_list()->item_count();
71 syncer::StringOrdinal position;
73 position = syncer::StringOrdinal::CreateInitialOrdinal();
75 position = item_list()->item_at(nitems - 1)->position().CreateAfter();
76 item->set_position(position);
77 item->SetTitleAndFullName(title, full_name);
81 void AppListTestModel::CreateAndAddItem(const std::string& title,
82 const std::string& full_name) {
83 item_list()->AddItem(CreateItem(title, full_name));
86 void AppListTestModel::CreateAndAddItem(const std::string& title) {
87 CreateAndAddItem(title, title);
90 void AppListTestModel::HighlightItemAt(int index) {
91 AppListItemModel* item = item_list()->item_at(index);
92 item->SetHighlighted(true);
95 void AppListTestModel::ItemActivated(AppListTestItemModel* item) {
96 last_activated_ = item;
101 } // namespace app_list