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

Side by Side Diff: chrome/browser/extensions/extension_icon_image_unittest.cc

Issue 10825012: chromeos: Fix pixelated icons in app list and launcher (part 2) (by xiyuan) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/extensions/extension_icon_image.h"
6
7 #include "base/json/json_file_value_serializer.h"
8 #include "base/message_loop.h"
9 #include "base/path_service.h"
10 #include "chrome/common/chrome_paths.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "content/public/test/test_browser_thread.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 using content::BrowserThread;
16 using extensions::Extension;
17 using extensions::IconImage;
18
19 namespace {
20
21 class ExtensionIconImageTest : public testing::Test,
22 public IconImage::Delegate {
23 public:
24 ExtensionIconImageTest()
25 : image_loaded_count_(0),
26 quit_in_image_loaded_(false),
27 ui_thread_(BrowserThread::UI, &ui_loop_),
28 file_thread_(BrowserThread::FILE),
29 io_thread_(BrowserThread::IO) {
30 }
oshima 2012/08/07 07:43:05 virtual dtor
tbarzic 2012/08/07 18:10:26 Done.
31
32 void WaitForImageLoad() {
33 quit_in_image_loaded_ = true;
34 MessageLoop::current()->Run();
35 quit_in_image_loaded_ = false;
36 }
37
38 int image_loaded_count() {
oshima 2012/08/07 07:43:05 GetImageLoadedCount() as this is not simple access
tbarzic 2012/08/07 18:10:26 Done.
39 int result = image_loaded_count_;
40 image_loaded_count_ = 0;
41 return result;
42 }
43
44 scoped_refptr<Extension> CreateExtension(const char* name,
45 Extension::Location location) {
46 // Create and load an extension.
47 FilePath test_file;
48 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_file)) {
49 EXPECT_FALSE(true);
50 return NULL;
51 }
52 test_file = test_file.AppendASCII("extensions")
53 .AppendASCII(name);
oshima 2012/08/07 07:43:05 doesn't this fit single line?
tbarzic 2012/08/07 18:10:26 Done.
54 int error_code = 0;
55 std::string error;
56 JSONFileValueSerializer serializer(test_file.AppendASCII("app.json"));
57 scoped_ptr<DictionaryValue> valid_value(
58 static_cast<DictionaryValue*>(serializer.Deserialize(&error_code,
59 &error)));
60 EXPECT_EQ(0, error_code) << error;
61 if (error_code != 0)
62 return NULL;
63
64 EXPECT_TRUE(valid_value.get());
65 if (!valid_value.get())
66 return NULL;
67
68 return Extension::Create(test_file, location, *valid_value,
69 Extension::NO_FLAGS, &error);
70 }
71
72 // testing::Test overrides:
73 virtual void SetUp() OVERRIDE {
74 file_thread_.Start();
75 io_thread_.Start();
76 }
77
78 // IconImage::Delegate overrides:
79 virtual void OnExtensionIconImageChanged(IconImage* image) OVERRIDE {
80 image_loaded_count_++;
81 if (quit_in_image_loaded_)
82 MessageLoop::current()->Quit();
83 }
84
85 private:
86 int image_loaded_count_;
87 bool quit_in_image_loaded_;
88 MessageLoop ui_loop_;
89 content::TestBrowserThread ui_thread_;
oshima 2012/08/07 07:43:05 I'm not familiar with TestBrowserThread and this m
xiyuan 2012/08/07 17:32:40 We have |ui_thread_| so that ImageLoadingTracker's
90 content::TestBrowserThread file_thread_;
91 content::TestBrowserThread io_thread_;
92
93 DISALLOW_COPY_AND_ASSIGN(ExtensionIconImageTest);
94 };
95
96 } // namespace
97
98 TEST_F(ExtensionIconImageTest, Basic) {
99 scoped_refptr<Extension> extension(CreateExtension(
100 "image_loading_tracker", Extension::INVALID));
101 ASSERT_TRUE(extension.get() != NULL);
102
103 scoped_ptr<IconImage> image(new IconImage(
oshima 2012/08/07 07:43:05 You may create an object on stack. It's up to you
tbarzic 2012/08/07 18:10:26 Done.
104 extension,
105 extension->icons(),
106 ExtensionIconSet::EXTENSION_ICON_BITTY,
107 ExtensionIconSet::MATCH_SMALLER,
108 gfx::Size(ExtensionIconSet::EXTENSION_ICON_BITTY,
109 ExtensionIconSet::EXTENSION_ICON_BITTY),
110 ImageLoadingTracker::DONT_CACHE,
111 this));
112
113 // No representations in |image_| yet.
114 gfx::ImageSkia::ImageSkiaReps image_reps = image->image_skia().image_reps();
115 ASSERT_EQ(0u, image_reps.size());
116
117 // Gets representation for a scale factor.
118 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
119 WaitForImageLoad();
120 EXPECT_EQ(1, image_loaded_count());
121
122 gfx::ImageSkiaRep image_rep =
123 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
124 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_BITTY,
125 image_rep.pixel_width());
126
127 // Gets representation for an additional scale factor.
128 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
129 WaitForImageLoad();
130 EXPECT_EQ(1, image_loaded_count());
131
132 image_rep = image->image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
133 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALL,
134 image_rep.pixel_width());
135 }
136
137 TEST_F(ExtensionIconImageTest, Missing2x) {
138 scoped_refptr<Extension> extension(CreateExtension(
139 "image_loading_tracker", Extension::INVALID));
140 ASSERT_TRUE(extension.get() != NULL);
141
142 scoped_ptr<IconImage> image(new IconImage(
143 extension,
144 extension->icons(),
145 ExtensionIconSet::EXTENSION_ICON_SMALLISH,
146 ExtensionIconSet::MATCH_BIGGER,
147 gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALLISH,
148 ExtensionIconSet::EXTENSION_ICON_SMALLISH),
149 ImageLoadingTracker::DONT_CACHE,
150 this));
151
152 // Gets representation for 1x.
153 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
154 WaitForImageLoad();
155 EXPECT_EQ(1, image_loaded_count());
156
157 gfx::ImageSkiaRep image_rep =
158 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
159 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH,
160 image_rep.pixel_width());
161
162 // Get representation for 2x.
163 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
164
165 image_rep = image->image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
166
167 // 1x representation would be returned since there is no 2x resource.
168 EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor());
169 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH,
170 image_rep.pixel_width());
171 }
172
173 // Similar to Missing2x test but go directly for the missing 2x resource first.
174 TEST_F(ExtensionIconImageTest, FallbackTo1x) {
175 scoped_refptr<Extension> extension(CreateExtension(
176 "image_loading_tracker", Extension::INVALID));
177 ASSERT_TRUE(extension.get() != NULL);
178
179 scoped_ptr<IconImage> image(new IconImage(
180 extension,
181 extension->icons(),
182 ExtensionIconSet::EXTENSION_ICON_SMALLISH,
183 ExtensionIconSet::MATCH_BIGGER,
184 gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALLISH,
185 ExtensionIconSet::EXTENSION_ICON_SMALLISH),
186 ImageLoadingTracker::DONT_CACHE,
187 this));
188
189 // Attempt to get representation for 2x.
190 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
191
192 WaitForImageLoad();
193 EXPECT_EQ(1, image_loaded_count());
194
195 // 1x representation would be returned since there is no 2x resource.
196 gfx::ImageSkiaRep image_rep =
197 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
198 EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor());
199 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH,
200 image_rep.pixel_width());
201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698