Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: chrome/browser/ui/app_list/fast_show_pickler_unittest.cc

Issue 23684003: Introduce FastShowPickler which will be used for app list cold start. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respond to comments Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 using app_list::AppListItemModel;
15 using app_list::AppListModel;
16
17 class AppListModelPicklerUnitTest : public testing::Test {
18 protected:
19 void CheckIsSame(AppListModel* m1, AppListModel* m2) {
20 ASSERT_EQ(m1->apps()->item_count(), m2->apps()->item_count());
21 ASSERT_EQ(m1->signed_in(), m2->signed_in());
22 for (size_t i = 0; i < m1->apps()->item_count(); i++) {
23 ASSERT_EQ(m1->apps()->GetItemAt(i)->app_id(),
24 m2->apps()->GetItemAt(i)->app_id());
25 ASSERT_EQ(m1->apps()->GetItemAt(i)->title(),
26 m2->apps()->GetItemAt(i)->title());
27 CompareImages(m1->apps()->GetItemAt(i)->icon(),
28 m2->apps()->GetItemAt(i)->icon());
29 }
30 }
31
32 void CompareImages(const gfx::ImageSkia& image1,
33 const gfx::ImageSkia& image2) {
34 std::vector<gfx::ImageSkiaRep> reps1(image1.image_reps());
35 std::vector<gfx::ImageSkiaRep> reps2(image2.image_reps());
36 ASSERT_EQ(reps1.size(), reps2.size());
37 for (size_t i = 0; i < reps1.size(); ++i) {
38 ASSERT_TRUE(
39 gfx::BitmapsAreEqual(reps1[i].sk_bitmap(), reps2[i].sk_bitmap()));
40 ASSERT_EQ(reps1[i].scale_factor(), reps2[i].scale_factor());
41 }
42 }
43
44 scoped_ptr<AppListModel> CopyViaPickle(AppListModel* model) {
45 scoped_ptr<Pickle> pickle(
46 FastShowPickler::PickleAppListModelForFastShow(model));
47 return FastShowPickler::UnpickleAppListModelForFastShow(pickle.get());
48 }
49
50 void DoConsistencyChecks(AppListModel* model) {
51 scoped_ptr<AppListModel> model2(CopyViaPickle(model));
52 AppListModel dest_model;
53 FastShowPickler::CopyOver(model2.get(), &dest_model);
54
55 CheckIsSame(model, model2.get());
56 CheckIsSame(model, &dest_model);
57 CheckIsSame(model2.get(), &dest_model);
58 }
59
60 gfx::ImageSkia MakeImage() {
61 const int kWidth = 10;
62 const int kHeight = 10;
63 SkBitmap bitmap;
64 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kWidth, kHeight);
65 bitmap.allocPixels();
66 bitmap.eraseARGB(255, 1, 2, 3);
67 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
68 }
69 };
70
71 TEST_F(AppListModelPicklerUnitTest, EmptyModel) {
72 AppListModel model;
73 DoConsistencyChecks(&model);
74 }
75
76 TEST_F(AppListModelPicklerUnitTest, OneItem) {
77 AppListModel model;
78 AppListItemModel* app1 = new AppListItemModel;
79 app1->set_app_id("abc");
80 app1->SetTitle("hello, there");
81 model.apps()->Add(app1);
82
83 DoConsistencyChecks(&model);
84 }
85
86 TEST_F(AppListModelPicklerUnitTest, TwoItems) {
87 AppListModel model;
88 AppListItemModel* app1 = new AppListItemModel;
89 app1->set_app_id("abc");
90 app1->SetTitle("hello, there");
91 model.apps()->Add(app1);
92
93 AppListItemModel* app2 = new AppListItemModel;
94 app2->set_app_id("abc2");
95 app2->SetTitle("hello, there 2");
96 model.apps()->Add(app2);
97
98 DoConsistencyChecks(&model);
99 }
100
101 TEST_F(AppListModelPicklerUnitTest, Images) {
102 AppListModel model;
103 AppListItemModel* app1 = new AppListItemModel;
104 app1->set_app_id("abc");
105 app1->SetTitle("hello, there");
106 app1->SetIcon(MakeImage(), true);
107 model.apps()->Add(app1);
108
109 AppListItemModel* app2 = new AppListItemModel;
110 app2->set_app_id("abc2");
111 app2->SetTitle("hello, there 2");
112 model.apps()->Add(app2);
113
114 DoConsistencyChecks(&model);
115 }
116
117 TEST_F(AppListModelPicklerUnitTest, EmptyImage) {
118 AppListModel model;
119 AppListItemModel* app1 = new AppListItemModel;
120 app1->set_app_id("abc");
121 app1->SetTitle("hello, there");
122 app1->SetIcon(gfx::ImageSkia(), true);
123 model.apps()->Add(app1);
124
125 DoConsistencyChecks(&model);
126 }
127
128 TEST_F(AppListModelPicklerUnitTest, SignedIn) {
129 AppListModel model;
130 model.SetSignedIn(true);
131
132 DoConsistencyChecks(&model);
133 }
134
135 TEST_F(AppListModelPicklerUnitTest, SignedOut) {
136 AppListModel model;
137 model.SetSignedIn(false);
138
139 DoConsistencyChecks(&model);
140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698