#include "base/memory/scoped_ptr.h"
#include "base/strings/stringprintf.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/app_list/app_list_constants.h"
+#include "ui/gfx/image/image_skia.h"
namespace app_list {
namespace test {
+gfx::ImageSkia CreateImageSkia(int width, int height) {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(width, height);
+ bitmap.eraseARGB(255, 0, 255, 0);
+ return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
+}
+
// static
const char AppListTestModel::kItemType[] = "TestItem";
AppListTestModel* model)
: AppListItem(id),
model_(model) {
+ SetIcon(CreateImageSkia(kGridIconDimension, kGridIconDimension),
+ false /* has_shadow */);
}
+
AppListTestModel::AppListTestItem::~AppListTestItem() {
}
}
void AppListTestModel::MoveItemToFolder(AppListItem* item,
- const std::string& folder_id) {
+ const std::string& folder_id) {
AppListModel::MoveItemToFolder(item, folder_id);
}
}
void AppListTestModel::PopulateApps(int n) {
- int start_index = static_cast<int>(item_list()->item_count());
+ int start_index = static_cast<int>(top_level_item_list()->item_count());
for (int i = 0; i < n; ++i)
CreateAndAddItem(GetItemName(start_index + i));
}
+AppListFolderItem* AppListTestModel::CreateAndPopulateFolderWithApps(int n) {
+ DCHECK_GT(n, 1);
+ int start_index = static_cast<int>(top_level_item_list()->item_count());
+ AppListTestItem* item = CreateAndAddItem(GetItemName(start_index));
+ std::string merged_item_id = item->id();
+ for (int i = 1; i < n; ++i) {
+ AppListTestItem* new_item = CreateAndAddItem(GetItemName(start_index + i));
+ merged_item_id = AppListModel::MergeItems(merged_item_id, new_item->id());
+ }
+ AppListItem* merged_item = FindItem(merged_item_id);
+ DCHECK(merged_item->GetItemType() == AppListFolderItem::kItemType);
+ return static_cast<AppListFolderItem*>(merged_item);
+}
+
+AppListFolderItem* AppListTestModel::CreateAndAddOemFolder(
+ const std::string& id) {
+ AppListFolderItem* folder =
+ new AppListFolderItem(id, AppListFolderItem::FOLDER_TYPE_OEM);
+ return static_cast<AppListFolderItem*>(AddItem(folder));
+}
+
+AppListFolderItem* AppListTestModel::CreateSingleItemFolder(
+ const std::string& folder_id,
+ const std::string& item_id) {
+ AppListTestItem* item = CreateItem(item_id);
+ AddItemToFolder(item, folder_id);
+ AppListItem* folder_item = FindItem(folder_id);
+ DCHECK(folder_item->GetItemType() == AppListFolderItem::kItemType);
+ return static_cast<AppListFolderItem*>(folder_item);
+}
+
void AppListTestModel::PopulateAppWithId(int id) {
CreateAndAddItem(GetItemName(id));
}
std::string AppListTestModel::GetModelContent() {
std::string content;
- for (size_t i = 0; i < item_list()->item_count(); ++i) {
+ for (size_t i = 0; i < top_level_item_list()->item_count(); ++i) {
if (i > 0)
content += ',';
- content += item_list()->item_at(i)->title();
+ content += top_level_item_list()->item_at(i)->id();
}
return content;
}
AppListTestModel::AppListTestItem* AppListTestModel::CreateItem(
- const std::string& title,
- const std::string& full_name) {
- AppListTestItem* item = new AppListTestItem(title, this);
- size_t nitems = item_list()->item_count();
+ const std::string& id) {
+ AppListTestItem* item = new AppListTestItem(id, this);
+ size_t nitems = top_level_item_list()->item_count();
syncer::StringOrdinal position;
- if (nitems == 0)
+ if (nitems == 0) {
position = syncer::StringOrdinal::CreateInitialOrdinal();
- else
- position = item_list()->item_at(nitems - 1)->position().CreateAfter();
+ } else {
+ position =
+ top_level_item_list()->item_at(nitems - 1)->position().CreateAfter();
+ }
item->SetPosition(position);
- item->SetTitleAndFullName(title, full_name);
+ SetItemName(item, id);
return item;
}
-void AppListTestModel::CreateAndAddItem(const std::string& title,
- const std::string& full_name) {
- scoped_ptr<AppListTestItem> test_item(CreateItem(title, full_name));
- AppListModel::AddItem(test_item.PassAs<AppListItem>());
+AppListTestModel::AppListTestItem* AppListTestModel::CreateAndAddItem(
+ const std::string& id) {
+ scoped_ptr<AppListTestItem> test_item(CreateItem(id));
+ AppListItem* item = AppListModel::AddItem(test_item.PassAs<AppListItem>());
+ return static_cast<AppListTestItem*>(item);
}
-
-void AppListTestModel::CreateAndAddItem(const std::string& title) {
- CreateAndAddItem(title, title);
-}
-
void AppListTestModel::HighlightItemAt(int index) {
- AppListItem* item = item_list()->item_at(index);
+ AppListItem* item = top_level_item_list()->item_at(index);
item->SetHighlighted(true);
}