Web MIDI: MidiManager crashes if a session is ended while initializing
[chromium-blink-merge.git] / athena / test / test_app_model_builder.cc
blobf7db8a0abe1d685354c914032ecb049b7ef409a5
1 // Copyright 2014 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 "athena/test/test_app_model_builder.h"
7 #include "ui/app_list/app_list_item.h"
8 #include "ui/app_list/app_list_model.h"
10 namespace athena {
12 namespace {
14 const int kIconSize = 64;
16 class DummyItem : public app_list::AppListItem {
17 public:
18 enum Type {
19 DUMMY_MAIL,
20 DUMMY_CALENDAR,
21 DUMMY_VIDEO,
22 DUMMY_MUSIC,
23 DUMMY_CONTACT,
24 LAST_TYPE,
27 static std::string GetTitle(Type type) {
28 switch (type) {
29 case DUMMY_MAIL:
30 return "mail";
31 case DUMMY_CALENDAR:
32 return "calendar";
33 case DUMMY_VIDEO:
34 return "video";
35 case DUMMY_MUSIC:
36 return "music";
37 case DUMMY_CONTACT:
38 return "contact";
39 case LAST_TYPE:
40 break;
42 NOTREACHED();
43 return "";
46 static std::string GetId(Type type) {
47 return std::string("id-") + GetTitle(type);
50 explicit DummyItem(Type type)
51 : app_list::AppListItem(GetId(type)),
52 type_(type) {
53 SetIcon(GetIcon(), false /* has_shadow */);
54 SetName(GetTitle(type_));
57 private:
58 gfx::ImageSkia GetIcon() const {
59 SkColor color = SK_ColorWHITE;
60 switch (type_) {
61 case DUMMY_MAIL:
62 color = SK_ColorRED;
63 break;
64 case DUMMY_CALENDAR:
65 color = SK_ColorBLUE;
66 break;
67 case DUMMY_VIDEO:
68 color = SK_ColorGREEN;
69 break;
70 case DUMMY_MUSIC:
71 color = SK_ColorYELLOW;
72 break;
73 case DUMMY_CONTACT:
74 color = SK_ColorCYAN;
75 break;
76 case LAST_TYPE:
77 NOTREACHED();
78 break;
80 SkBitmap bitmap;
81 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kIconSize, kIconSize);
82 bitmap.allocPixels();
83 bitmap.eraseColor(color);
84 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
87 Type type_;
89 DISALLOW_COPY_AND_ASSIGN(DummyItem);
92 } // namespace
94 TestAppModelBuilder::TestAppModelBuilder() {
97 TestAppModelBuilder::~TestAppModelBuilder() {
100 void TestAppModelBuilder::PopulateApps(app_list::AppListModel* model) {
101 for (int i = 0; i < static_cast<int>(DummyItem::LAST_TYPE); ++i) {
102 model->AddItem(scoped_ptr<app_list::AppListItem>(
103 new DummyItem(static_cast<DummyItem::Type>(i))));
107 } // namespace athena