Home | History | Annotate | Download | only in test
      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.
      4 
      5 #include "athena/test/test_app_model_builder.h"
      6 
      7 #include "ui/app_list/app_list_item.h"
      8 #include "ui/app_list/app_list_model.h"
      9 
     10 namespace athena {
     11 
     12 namespace {
     13 
     14 const int kIconSize = 64;
     15 
     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,
     25   };
     26 
     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;
     41     }
     42     NOTREACHED();
     43     return "";
     44   }
     45 
     46   static std::string GetId(Type type) {
     47     return std::string("id-") + GetTitle(type);
     48   }
     49 
     50   explicit DummyItem(Type type)
     51       : app_list::AppListItem(GetId(type)),
     52         type_(type) {
     53     SetIcon(GetIcon(), false /* has_shadow */);
     54     SetName(GetTitle(type_));
     55   }
     56 
     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;
     79     }
     80     SkBitmap bitmap;
     81     bitmap.allocN32Pixels(kIconSize, kIconSize);
     82     bitmap.eraseColor(color);
     83     return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
     84   }
     85 
     86   Type type_;
     87 
     88   DISALLOW_COPY_AND_ASSIGN(DummyItem);
     89 };
     90 
     91 }  // namespace
     92 
     93 TestAppModelBuilder::TestAppModelBuilder() {
     94 }
     95 
     96 TestAppModelBuilder::~TestAppModelBuilder() {
     97 }
     98 
     99 void TestAppModelBuilder::PopulateApps(app_list::AppListModel* model) {
    100   for (int i = 0; i < static_cast<int>(DummyItem::LAST_TYPE); ++i) {
    101     model->AddItem(scoped_ptr<app_list::AppListItem>(
    102         new DummyItem(static_cast<DummyItem::Type>(i))));
    103   }
    104 }
    105 
    106 }  // namespace athena
    107