| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/ui/app_list/fast_show_pickler.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "third_party/skia/include/core/SkBitmap.h" |
| 8 #include "third_party/skia/include/core/SkColorPriv.h" |
| 9 #include "ui/app_list/app_list_item_model.h" |
| 10 #include "ui/app_list/app_list_model.h" |
| 11 #include "ui/gfx/image/image_skia.h" |
| 12 #include "ui/gfx/skia_util.h" |
| 13 |
| 14 |
| 15 using app_list::AppListItemModel; |
| 16 using app_list::AppListModel; |
| 17 |
| 18 class AppListModelPicklerUnitTest : public testing::Test { |
| 19 protected: |
| 20 void CheckIsSame(AppListModel* m1, AppListModel* m2) { |
| 21 ASSERT_EQ(m1->apps()->item_count(), m2->apps()->item_count()); |
| 22 ASSERT_EQ(m1->signed_in(), m2->signed_in()); |
| 23 for (size_t i = 0; i < m1->apps()->item_count(); i++) { |
| 24 ASSERT_EQ(m1->apps()->GetItemAt(i)->app_id(), |
| 25 m2->apps()->GetItemAt(i)->app_id()); |
| 26 ASSERT_EQ(m1->apps()->GetItemAt(i)->title(), |
| 27 m2->apps()->GetItemAt(i)->title()); |
| 28 CompareImages(m1->apps()->GetItemAt(i)->icon(), |
| 29 m2->apps()->GetItemAt(i)->icon()); |
| 30 } |
| 31 } |
| 32 |
| 33 void CompareImages(const gfx::ImageSkia& image1, |
| 34 const gfx::ImageSkia& image2) { |
| 35 std::vector<gfx::ImageSkiaRep> reps1(image1.image_reps()); |
| 36 std::vector<gfx::ImageSkiaRep> reps2(image2.image_reps()); |
| 37 ASSERT_EQ(reps1.size(), reps2.size()); |
| 38 for (size_t i = 0; i < reps1.size(); ++i) { |
| 39 ASSERT_TRUE( |
| 40 gfx::BitmapsAreEqual(reps1[i].sk_bitmap(), reps2[i].sk_bitmap())); |
| 41 ASSERT_EQ(reps1[i].scale_factor(), reps2[i].scale_factor()); |
| 42 } |
| 43 } |
| 44 |
| 45 scoped_ptr<AppListModel> CopyViaPickle(AppListModel* model) { |
| 46 scoped_ptr<Pickle> pickle( |
| 47 FastShowPickler::PickleAppListModelForFastShow(model)); |
| 48 return FastShowPickler::UnpickleAppListModelForFastShow(pickle.get()); |
| 49 } |
| 50 |
| 51 void DoConsistencyChecks(AppListModel* model) { |
| 52 scoped_ptr<AppListModel> model2(CopyViaPickle(model)); |
| 53 AppListModel dest_model; |
| 54 FastShowPickler::CopyOver(model2.get(), &dest_model); |
| 55 |
| 56 CheckIsSame(model, model2.get()); |
| 57 CheckIsSame(model, &dest_model); |
| 58 CheckIsSame(model2.get(), &dest_model); |
| 59 } |
| 60 |
| 61 gfx::ImageSkia MakeImage() { |
| 62 const int kWidth = 10; |
| 63 const int kHeight = 10; |
| 64 SkBitmap bitmap; |
| 65 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kWidth, kHeight); |
| 66 bitmap.allocPixels(); |
| 67 bitmap.eraseARGB(255, 1, 2, 3); |
| 68 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 69 } |
| 70 }; |
| 71 |
| 72 TEST_F(AppListModelPicklerUnitTest, EmptyModel) { |
| 73 AppListModel model; |
| 74 DoConsistencyChecks(&model); |
| 75 } |
| 76 |
| 77 TEST_F(AppListModelPicklerUnitTest, OneItem) { |
| 78 AppListModel model; |
| 79 AppListItemModel* app1 = new AppListItemModel; |
| 80 app1->set_app_id("abc"); |
| 81 app1->SetTitle("hello, there"); |
| 82 model.apps()->Add(app1); |
| 83 |
| 84 DoConsistencyChecks(&model); |
| 85 } |
| 86 |
| 87 TEST_F(AppListModelPicklerUnitTest, TwoItems) { |
| 88 AppListModel model; |
| 89 AppListItemModel* app1 = new AppListItemModel; |
| 90 app1->set_app_id("abc"); |
| 91 app1->SetTitle("hello, there"); |
| 92 model.apps()->Add(app1); |
| 93 |
| 94 AppListItemModel* app2 = new AppListItemModel; |
| 95 app2->set_app_id("abc2"); |
| 96 app2->SetTitle("hello, there 2"); |
| 97 model.apps()->Add(app2); |
| 98 |
| 99 DoConsistencyChecks(&model); |
| 100 } |
| 101 |
| 102 TEST_F(AppListModelPicklerUnitTest, Images) { |
| 103 AppListModel model; |
| 104 AppListItemModel* app1 = new AppListItemModel; |
| 105 app1->set_app_id("abc"); |
| 106 app1->SetTitle("hello, there"); |
| 107 app1->SetIcon(MakeImage(), true); |
| 108 model.apps()->Add(app1); |
| 109 |
| 110 AppListItemModel* app2 = new AppListItemModel; |
| 111 app2->set_app_id("abc2"); |
| 112 app2->SetTitle("hello, there 2"); |
| 113 model.apps()->Add(app2); |
| 114 |
| 115 DoConsistencyChecks(&model); |
| 116 } |
| OLD | NEW |