Chromium Code Reviews| Index: chrome/browser/ui/app_list/fast_show_pickler_unittest.cc |
| diff --git a/chrome/browser/ui/app_list/fast_show_pickler_unittest.cc b/chrome/browser/ui/app_list/fast_show_pickler_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5eb172d77867fb44eb75dcb3e86145331f6aba65 |
| --- /dev/null |
| +++ b/chrome/browser/ui/app_list/fast_show_pickler_unittest.cc |
| @@ -0,0 +1,116 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/app_list/fast_show_pickler.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/skia/include/core/SkBitmap.h" |
| +#include "third_party/skia/include/core/SkColorPriv.h" |
| +#include "ui/app_list/app_list_item_model.h" |
| +#include "ui/app_list/app_list_model.h" |
| +#include "ui/gfx/image/image_skia.h" |
| +#include "ui/gfx/skia_util.h" |
| + |
|
benwells
2013/08/29 04:49:28
Nit: extra blank line.
koz (OOO until 15th September)
2013/08/30 00:44:50
Done.
|
| + |
| +using app_list::AppListItemModel; |
| +using app_list::AppListModel; |
| + |
| +class AppListModelPicklerUnitTest : public testing::Test { |
| + protected: |
| + void CheckIsSame(AppListModel* m1, AppListModel* m2) { |
| + ASSERT_EQ(m1->apps()->item_count(), m2->apps()->item_count()); |
| + ASSERT_EQ(m1->signed_in(), m2->signed_in()); |
| + for (size_t i = 0; i < m1->apps()->item_count(); i++) { |
| + ASSERT_EQ(m1->apps()->GetItemAt(i)->app_id(), |
| + m2->apps()->GetItemAt(i)->app_id()); |
| + ASSERT_EQ(m1->apps()->GetItemAt(i)->title(), |
| + m2->apps()->GetItemAt(i)->title()); |
| + CompareImages(m1->apps()->GetItemAt(i)->icon(), |
| + m2->apps()->GetItemAt(i)->icon()); |
| + } |
| + } |
| + |
| + void CompareImages(const gfx::ImageSkia& image1, |
| + const gfx::ImageSkia& image2) { |
| + std::vector<gfx::ImageSkiaRep> reps1(image1.image_reps()); |
| + std::vector<gfx::ImageSkiaRep> reps2(image2.image_reps()); |
| + ASSERT_EQ(reps1.size(), reps2.size()); |
| + for (size_t i = 0; i < reps1.size(); ++i) { |
| + ASSERT_TRUE( |
| + gfx::BitmapsAreEqual(reps1[i].sk_bitmap(), reps2[i].sk_bitmap())); |
| + ASSERT_EQ(reps1[i].scale_factor(), reps2[i].scale_factor()); |
| + } |
| + } |
| + |
| + scoped_ptr<AppListModel> CopyViaPickle(AppListModel* model) { |
| + scoped_ptr<Pickle> pickle( |
| + FastShowPickler::PickleAppListModelForFastShow(model)); |
| + return FastShowPickler::UnpickleAppListModelForFastShow(pickle.get()); |
| + } |
| + |
| + void DoConsistencyChecks(AppListModel* model) { |
| + scoped_ptr<AppListModel> model2(CopyViaPickle(model)); |
| + AppListModel dest_model; |
| + FastShowPickler::CopyOver(model2.get(), &dest_model); |
| + |
| + CheckIsSame(model, model2.get()); |
| + CheckIsSame(model, &dest_model); |
| + CheckIsSame(model2.get(), &dest_model); |
| + } |
| + |
| + gfx::ImageSkia MakeImage() { |
| + const int kWidth = 10; |
| + const int kHeight = 10; |
| + SkBitmap bitmap; |
| + bitmap.setConfig(SkBitmap::kARGB_8888_Config, kWidth, kHeight); |
| + bitmap.allocPixels(); |
| + bitmap.eraseARGB(255, 1, 2, 3); |
| + return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| + } |
| +}; |
| + |
| +TEST_F(AppListModelPicklerUnitTest, EmptyModel) { |
| + AppListModel model; |
| + DoConsistencyChecks(&model); |
| +} |
| + |
| +TEST_F(AppListModelPicklerUnitTest, OneItem) { |
| + AppListModel model; |
| + AppListItemModel* app1 = new AppListItemModel; |
| + app1->set_app_id("abc"); |
| + app1->SetTitle("hello, there"); |
| + model.apps()->Add(app1); |
| + |
| + DoConsistencyChecks(&model); |
| +} |
| + |
| +TEST_F(AppListModelPicklerUnitTest, TwoItems) { |
| + AppListModel model; |
| + AppListItemModel* app1 = new AppListItemModel; |
| + app1->set_app_id("abc"); |
| + app1->SetTitle("hello, there"); |
| + model.apps()->Add(app1); |
| + |
| + AppListItemModel* app2 = new AppListItemModel; |
| + app2->set_app_id("abc2"); |
| + app2->SetTitle("hello, there 2"); |
| + model.apps()->Add(app2); |
| + |
| + DoConsistencyChecks(&model); |
| +} |
| + |
| +TEST_F(AppListModelPicklerUnitTest, Images) { |
|
benwells
2013/08/29 04:49:28
nit: pickling of signed in isn't being tested.
koz (OOO until 15th September)
2013/08/30 00:44:50
Yes, true. And indeed, wasn't implemented :-| Nice
|
| + AppListModel model; |
| + AppListItemModel* app1 = new AppListItemModel; |
| + app1->set_app_id("abc"); |
| + app1->SetTitle("hello, there"); |
| + app1->SetIcon(MakeImage(), true); |
| + model.apps()->Add(app1); |
| + |
| + AppListItemModel* app2 = new AppListItemModel; |
| + app2->set_app_id("abc2"); |
| + app2->SetTitle("hello, there 2"); |
| + model.apps()->Add(app2); |
| + |
| + DoConsistencyChecks(&model); |
| +} |