| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "ui/app_list/test/app_list_test_model.h" | 5 #include "ui/app_list/test/app_list_test_model.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "ui/app_list/app_list_item_model.h" | 8 #include "ui/app_list/app_list_item_model.h" |
| 9 | 9 |
| 10 namespace app_list { | 10 namespace app_list { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 AppListTestModel* model_; | 26 AppListTestModel* model_; |
| 27 DISALLOW_COPY_AND_ASSIGN(AppListTestItemModel); | 27 DISALLOW_COPY_AND_ASSIGN(AppListTestItemModel); |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 AppListTestModel::AppListTestModel() | 30 AppListTestModel::AppListTestModel() |
| 31 : activate_count_(0), | 31 : activate_count_(0), |
| 32 last_activated_(NULL) { | 32 last_activated_(NULL) { |
| 33 SetSignedIn(true); | 33 SetSignedIn(true); |
| 34 } | 34 } |
| 35 | 35 |
| 36 std::string AppListTestModel::GetItemName(int id) { |
| 37 return base::StringPrintf("Item %d", id); |
| 38 } |
| 39 |
| 36 void AppListTestModel::PopulateApps(int n) { | 40 void AppListTestModel::PopulateApps(int n) { |
| 41 int start_index = 0; |
| 42 for (size_t p = 0; p < GetNumAppPages(); ++p) |
| 43 start_index += GetAppItems(p).item_count(); |
| 37 for (int i = 0; i < n; ++i) | 44 for (int i = 0; i < n; ++i) |
| 38 AddItem(base::StringPrintf("Item %d", i)); | 45 CreateAndAddItem(GetItemName(start_index + i)); |
| 39 } | 46 } |
| 40 | 47 |
| 41 void AppListTestModel::PopulateAppWithId(int id) { | 48 void AppListTestModel::PopulateAppWithId(int id) { |
| 42 AddItem(base::StringPrintf("Item %d", id)); | 49 CreateAndAddItem(GetItemName(id)); |
| 43 } | 50 } |
| 44 | 51 |
| 45 std::string AppListTestModel::GetModelContent() { | 52 std::string AppListTestModel::GetModelContent() { |
| 46 std::string content; | 53 std::string content; |
| 47 for (size_t i = 0; i < apps()->item_count(); ++i) { | 54 for (size_t p = 0; p < GetNumAppPages(); ++p) { |
| 48 if (i > 0) | 55 const AppItems& apps = GetAppItems(p); |
| 49 content += ','; | 56 for (size_t i = 0; i < apps.item_count(); ++i) { |
| 50 content += apps()->GetItemAt(i)->title(); | 57 if (i > 0) |
| 58 content += ','; |
| 59 content += apps.GetItemAt(i)->title(); |
| 60 } |
| 51 } | 61 } |
| 52 return content; | 62 return content; |
| 53 } | 63 } |
| 54 | 64 |
| 55 AppListItemModel* AppListTestModel::CreateItem(const std::string& title, | 65 AppListItemModel* AppListTestModel::CreateItem(const std::string& title, |
| 56 const std::string& full_name) { | 66 const std::string& full_name) { |
| 57 AppListItemModel* item = new AppListTestItemModel(title, this); | 67 AppListItemModel* item = new AppListTestItemModel(title, this); |
| 58 item->SetTitleAndFullName(title, full_name); | 68 item->SetTitleAndFullName(title, full_name); |
| 59 return item; | 69 return item; |
| 60 } | 70 } |
| 61 | 71 |
| 62 void AppListTestModel::AddItem(const std::string& title) { | 72 void AppListTestModel::CreateAndAddItem(const std::string& title, |
| 63 apps()->Add(CreateItem(title, title)); | 73 const std::string& full_name) { |
| 74 AddItem(CreateItem(title, full_name)); |
| 64 } | 75 } |
| 65 | 76 |
| 66 void AppListTestModel::AddItem(const std::string& title, | 77 void AppListTestModel::CreateAndAddItem(const std::string& title) { |
| 67 const std::string& full_name) { | 78 CreateAndAddItem(title, title); |
| 68 apps()->Add(CreateItem(title, full_name)); | |
| 69 } | 79 } |
| 70 | 80 |
| 71 void AppListTestModel::HighlightItemAt(int index) { | 81 void AppListTestModel::HighlightItemAt(int index) { |
| 72 AppListItemModel* item = apps()->GetItemAt(index); | 82 AppListItemModel* item = GetItemAt(0, index); |
| 73 item->SetHighlighted(true); | 83 item->SetHighlighted(true); |
| 74 } | 84 } |
| 75 | 85 |
| 76 void AppListTestModel::ItemActivated(AppListTestItemModel* item) { | 86 void AppListTestModel::ItemActivated(AppListTestItemModel* item) { |
| 77 last_activated_ = item; | 87 last_activated_ = item; |
| 78 ++activate_count_; | 88 ++activate_count_; |
| 79 } | 89 } |
| 80 | 90 |
| 81 } // namespace test | 91 } // namespace test |
| 82 } // namespace app_list | 92 } // namespace app_list |
| OLD | NEW |