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

Unified 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: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
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"
+
+
+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) {
+ 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);
+}

Powered by Google App Engine
This is Rietveld 408576698