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

Side by Side Diff: chrome/browser/android/manifest_icon_selector_unittest.cc

Issue 880203004: Break out manifest icon logic from ShortcutHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Other patch landed Created 5 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/shortcut_helper.h" 5 #include "chrome/browser/android/manifest_icon_selector.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 #include "ui/gfx/screen.h" 10 #include "ui/gfx/screen.h"
11 #include "ui/gfx/screen_type_delegate.h" 11 #include "ui/gfx/screen_type_delegate.h"
12 12
13 // A dummy implementation of gfx::Screen, since ShortcutHelper needs access to 13 namespace {
14 // a gfx::Display's device scale factor. 14
15 const int kPreferredIconSize = 48;
16
17 }
18
19 // A dummy implementation of gfx::Screen, since ManifestIconSelector needs
20 // access to a gfx::Display's device scale factor.
15 // This is inspired by web_contents_video_capture_device_unittest.cc 21 // This is inspired by web_contents_video_capture_device_unittest.cc
16 // A bug has been opened to merge all those mocks: http://crbug.com/417227 22 // A bug has been opened to merge all those mocks: http://crbug.com/417227
17 class FakeScreen : public gfx::Screen { 23 class FakeScreen : public gfx::Screen {
18 public: 24 public:
19 FakeScreen() : display_(0x1337, gfx::Rect(0, 0, 2560, 1440)) { 25 FakeScreen() : display_(0x1337, gfx::Rect(0, 0, 2560, 1440)) {
20 } 26 }
21 virtual ~FakeScreen() {} 27 ~FakeScreen() override {}
22 28
23 void SetDisplayDeviceScaleFactor(float device_scale_factor) { 29 void SetDisplayDeviceScaleFactor(float device_scale_factor) {
24 display_.set_device_scale_factor(device_scale_factor); 30 display_.set_device_scale_factor(device_scale_factor);
25 } 31 }
26 32
27 // gfx::Screen implementation (only what's needed for testing). 33 // gfx::Screen implementation (only what's needed for testing).
28 virtual gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } 34 virtual gfx::Point GetCursorScreenPoint() override { return gfx::Point(); }
29 virtual gfx::NativeWindow GetWindowUnderCursor() override { return NULL; } 35 virtual gfx::NativeWindow GetWindowUnderCursor() override { return nullptr; }
30 virtual gfx::NativeWindow GetWindowAtScreenPoint( 36 virtual gfx::NativeWindow GetWindowAtScreenPoint(
31 const gfx::Point& point) override { return NULL; } 37 const gfx::Point& point) override { return nullptr; }
32 virtual int GetNumDisplays() const override { return 1; } 38 virtual int GetNumDisplays() const override { return 1; }
33 virtual std::vector<gfx::Display> GetAllDisplays() const override { 39 virtual std::vector<gfx::Display> GetAllDisplays() const override {
34 return std::vector<gfx::Display>(1, display_); 40 return std::vector<gfx::Display>(1, display_);
35 } 41 }
36 virtual gfx::Display GetDisplayNearestWindow( 42 virtual gfx::Display GetDisplayNearestWindow(
37 gfx::NativeView view) const override { 43 gfx::NativeView view) const override {
38 return display_; 44 return display_;
39 } 45 }
40 virtual gfx::Display GetDisplayNearestPoint( 46 virtual gfx::Display GetDisplayNearestPoint(
41 const gfx::Point& point) const override { 47 const gfx::Point& point) const override {
42 return display_; 48 return display_;
43 } 49 }
44 virtual gfx::Display GetDisplayMatching( 50 virtual gfx::Display GetDisplayMatching(
45 const gfx::Rect& match_rect) const override { 51 const gfx::Rect& match_rect) const override {
46 return display_; 52 return display_;
47 } 53 }
48 virtual gfx::Display GetPrimaryDisplay() const override { 54 virtual gfx::Display GetPrimaryDisplay() const override {
49 return display_; 55 return display_;
50 } 56 }
51 virtual void AddObserver(gfx::DisplayObserver* observer) override {} 57 virtual void AddObserver(gfx::DisplayObserver* observer) override {}
52 virtual void RemoveObserver(gfx::DisplayObserver* observer) override {} 58 virtual void RemoveObserver(gfx::DisplayObserver* observer) override {}
53 59
54 private: 60 private:
55 gfx::Display display_; 61 gfx::Display display_;
56 62
57 DISALLOW_COPY_AND_ASSIGN(FakeScreen); 63 DISALLOW_COPY_AND_ASSIGN(FakeScreen);
58 }; 64 };
59 65
60 class ShortcutHelperTest : public ChromeRenderViewHostTestHarness { 66 class ManifestIconSelectorTest : public ChromeRenderViewHostTestHarness {
mlamouri (slow - plz ping) 2015/02/03 17:14:14 If you remove the WebContents dependency on the he
gone 2015/02/03 19:25:06 Done.
61 protected: 67 protected:
62 ShortcutHelperTest() : shortcut_helper_(NULL) {} 68 ManifestIconSelectorTest() {}
63 virtual ~ShortcutHelperTest() {} 69 ~ManifestIconSelectorTest() override {}
64
65 static jobject CreateShortcutHelperJava(JNIEnv* env) {
66 jclass clazz = env->FindClass("org/chromium/chrome/browser/ShortcutHelper");
67 jmethodID constructor =
68 env->GetMethodID(clazz, "<init>",
69 "(Landroid/content/Context;"
70 "Lorg/chromium/chrome/browser/Tab;)V");
71 return env->NewObject(clazz, constructor, jobject(), jobject());
72 }
73
74 void ResetShorcutHelper() {
75 if (shortcut_helper_)
76 delete shortcut_helper_;
77
78 JNIEnv* env = base::android::AttachCurrentThread();
79 shortcut_helper_ =
80 new ShortcutHelper(env, CreateShortcutHelperJava(env), web_contents());
81 }
82 70
83 virtual void SetUp() override { 71 virtual void SetUp() override {
84 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, &fake_screen_); 72 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, &fake_screen_);
85 ASSERT_EQ(&fake_screen_, gfx::Screen::GetNativeScreen()); 73 ASSERT_EQ(&fake_screen_, gfx::Screen::GetNativeScreen());
86
87 ChromeRenderViewHostTestHarness::SetUp(); 74 ChromeRenderViewHostTestHarness::SetUp();
88
89 ResetShorcutHelper();
90 } 75 }
91 76
92 virtual void TearDown() override { 77 virtual void TearDown() override {
93 delete shortcut_helper_;
94 shortcut_helper_ = NULL;
95
96 ChromeRenderViewHostTestHarness::TearDown(); 78 ChromeRenderViewHostTestHarness::TearDown();
97 79 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, nullptr);
98 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
99 } 80 }
100 81
101 GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons) { 82 GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons) {
102 return shortcut_helper_->FindBestMatchingIcon(icons); 83 return ManifestIconSelector::FindBestMatchingIcon(
84 icons,
85 GetPreferredIconSizeInDp(),
86 web_contents());
103 } 87 }
104 88
105 void SetDisplayDeviceScaleFactor(float device_scale_factor) { 89 void SetDisplayDeviceScaleFactor(float device_scale_factor) {
106 fake_screen_.SetDisplayDeviceScaleFactor(device_scale_factor); 90 fake_screen_.SetDisplayDeviceScaleFactor(device_scale_factor);
107
108 ResetShorcutHelper();
109 } 91 }
110 92
111 static int GetPreferredIconSizeInDp() { 93 static int GetPreferredIconSizeInDp() {
112 return ShortcutHelper::kPreferredIconSizeInDp; 94 return kPreferredIconSize;
113 } 95 }
114 96
115 static content::Manifest::Icon CreateIcon( 97 static content::Manifest::Icon CreateIcon(
116 const std::string& url, 98 const std::string& url,
117 const std::string& type, 99 const std::string& type,
118 double density, 100 double density,
119 const std::vector<gfx::Size> sizes) { 101 const std::vector<gfx::Size> sizes) {
120 content::Manifest::Icon icon; 102 content::Manifest::Icon icon;
121 icon.src = GURL(url); 103 icon.src = GURL(url);
122 if (!type.empty()) 104 if (!type.empty())
123 icon.type = base::NullableString16(base::UTF8ToUTF16(type), false); 105 icon.type = base::NullableString16(base::UTF8ToUTF16(type), false);
124 icon.density = density; 106 icon.density = density;
125 icon.sizes = sizes; 107 icon.sizes = sizes;
126 108
127 return icon; 109 return icon;
128 } 110 }
129 111
130 private: 112 private:
131 ShortcutHelper* shortcut_helper_;
132 FakeScreen fake_screen_; 113 FakeScreen fake_screen_;
133 114
134 DISALLOW_COPY_AND_ASSIGN(ShortcutHelperTest); 115 DISALLOW_COPY_AND_ASSIGN(ManifestIconSelectorTest);
135 }; 116 };
136 117
137 TEST_F(ShortcutHelperTest, NoIcons) { 118 TEST_F(ManifestIconSelectorTest, NoIcons) {
138 // No icons should return the empty URL. 119 // No icons should return the empty URL.
139 std::vector<content::Manifest::Icon> icons; 120 std::vector<content::Manifest::Icon> icons;
140 GURL url = FindBestMatchingIcon(icons); 121 GURL url = FindBestMatchingIcon(icons);
141 EXPECT_TRUE(url.is_empty()); 122 EXPECT_TRUE(url.is_empty());
142 } 123 }
143 124
144 TEST_F(ShortcutHelperTest, NoSizes) { 125 TEST_F(ManifestIconSelectorTest, NoSizes) {
145 // Icon with no sizes are ignored. 126 // Icon with no sizes are ignored.
146 std::vector<content::Manifest::Icon> icons; 127 std::vector<content::Manifest::Icon> icons;
147 icons.push_back( 128 icons.push_back(
148 CreateIcon("http://foo.com/icon.png", "", 1.0, std::vector<gfx::Size>())); 129 CreateIcon("http://foo.com/icon.png", "", 1.0, std::vector<gfx::Size>()));
149 130
150 GURL url = FindBestMatchingIcon(icons); 131 GURL url = FindBestMatchingIcon(icons);
151 EXPECT_TRUE(url.is_empty()); 132 EXPECT_TRUE(url.is_empty());
152 } 133 }
153 134
154 TEST_F(ShortcutHelperTest, MIMETypeFiltering) { 135 TEST_F(ManifestIconSelectorTest, MIMETypeFiltering) {
155 // Icons with type specified to a MIME type that isn't a valid image MIME type 136 // Icons with type specified to a MIME type that isn't a valid image MIME type
156 // are ignored. 137 // are ignored.
157 std::vector<gfx::Size> sizes; 138 std::vector<gfx::Size> sizes;
158 sizes.push_back(gfx::Size(10, 10)); 139 sizes.push_back(gfx::Size(10, 10));
159 140
160 std::vector<content::Manifest::Icon> icons; 141 std::vector<content::Manifest::Icon> icons;
161 icons.push_back( 142 icons.push_back(
162 CreateIcon("http://foo.com/icon.png", "image/foo_bar", 1.0, sizes)); 143 CreateIcon("http://foo.com/icon.png", "image/foo_bar", 1.0, sizes));
163 icons.push_back(CreateIcon("http://foo.com/icon.png", "image/", 1.0, sizes)); 144 icons.push_back(CreateIcon("http://foo.com/icon.png", "image/", 1.0, sizes));
164 icons.push_back(CreateIcon("http://foo.com/icon.png", "image/", 1.0, sizes)); 145 icons.push_back(CreateIcon("http://foo.com/icon.png", "image/", 1.0, sizes));
(...skipping 15 matching lines...) Expand all
180 url = FindBestMatchingIcon(icons); 161 url = FindBestMatchingIcon(icons);
181 EXPECT_EQ("http://foo.com/icon.png", url.spec()); 162 EXPECT_EQ("http://foo.com/icon.png", url.spec());
182 163
183 icons.clear(); 164 icons.clear();
184 icons.push_back( 165 icons.push_back(
185 CreateIcon("http://foo.com/icon.png", "image/jpeg", 1.0, sizes)); 166 CreateIcon("http://foo.com/icon.png", "image/jpeg", 1.0, sizes));
186 url = FindBestMatchingIcon(icons); 167 url = FindBestMatchingIcon(icons);
187 EXPECT_EQ("http://foo.com/icon.png", url.spec()); 168 EXPECT_EQ("http://foo.com/icon.png", url.spec());
188 } 169 }
189 170
190 TEST_F(ShortcutHelperTest, PreferredSizeOfCurrentDensityIsUsedFirst) { 171 TEST_F(ManifestIconSelectorTest, PreferredSizeOfCurrentDensityIsUsedFirst) {
191 // This test has three icons each are marked with sizes set to the preferred 172 // This test has three icons each are marked with sizes set to the preferred
192 // icon size for the associated density. 173 // icon size for the associated density.
193 std::vector<gfx::Size> sizes_1; 174 std::vector<gfx::Size> sizes_1;
194 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), 175 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(),
195 GetPreferredIconSizeInDp())); 176 GetPreferredIconSizeInDp()));
196 177
197 std::vector<gfx::Size> sizes_2; 178 std::vector<gfx::Size> sizes_2;
198 sizes_2.push_back(gfx::Size(GetPreferredIconSizeInDp() * 2, 179 sizes_2.push_back(gfx::Size(GetPreferredIconSizeInDp() * 2,
199 GetPreferredIconSizeInDp() * 2)); 180 GetPreferredIconSizeInDp() * 2));
200 181
(...skipping 12 matching lines...) Expand all
213 194
214 SetDisplayDeviceScaleFactor(2.0f); 195 SetDisplayDeviceScaleFactor(2.0f);
215 url = FindBestMatchingIcon(icons); 196 url = FindBestMatchingIcon(icons);
216 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); 197 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec());
217 198
218 SetDisplayDeviceScaleFactor(3.0f); 199 SetDisplayDeviceScaleFactor(3.0f);
219 url = FindBestMatchingIcon(icons); 200 url = FindBestMatchingIcon(icons);
220 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); 201 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec());
221 } 202 }
222 203
223 TEST_F(ShortcutHelperTest, PreferredSizeOfDefaultDensityIsUsedSecond) { 204 TEST_F(ManifestIconSelectorTest, PreferredSizeOfDefaultDensityIsUsedSecond) {
224 // This test has three icons. The first one is of density zero and is marked 205 // This test has three icons. The first one is of density zero and is marked
225 // with three sizes which are the preferred icon size for density 1, 2 and 3. 206 // with three sizes which are the preferred icon size for density 1, 2 and 3.
226 // The icon for density 2 and 3 have a size set to 2x2 and 3x3. 207 // The icon for density 2 and 3 have a size set to 2x2 and 3x3.
227 // Regardless of the device scale factor, the icon of density 1 is going to be 208 // Regardless of the device scale factor, the icon of density 1 is going to be
228 // used because it matches the preferred size. 209 // used because it matches the preferred size.
229 std::vector<gfx::Size> sizes_1; 210 std::vector<gfx::Size> sizes_1;
230 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), 211 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(),
231 GetPreferredIconSizeInDp())); 212 GetPreferredIconSizeInDp()));
232 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp() * 2, 213 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp() * 2,
233 GetPreferredIconSizeInDp() * 2)); 214 GetPreferredIconSizeInDp() * 2));
(...skipping 17 matching lines...) Expand all
251 232
252 SetDisplayDeviceScaleFactor(2.0f); 233 SetDisplayDeviceScaleFactor(2.0f);
253 url = FindBestMatchingIcon(icons); 234 url = FindBestMatchingIcon(icons);
254 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); 235 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec());
255 236
256 SetDisplayDeviceScaleFactor(3.0f); 237 SetDisplayDeviceScaleFactor(3.0f);
257 url = FindBestMatchingIcon(icons); 238 url = FindBestMatchingIcon(icons);
258 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); 239 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec());
259 } 240 }
260 241
261 TEST_F(ShortcutHelperTest, DeviceDensityFirst) { 242 TEST_F(ManifestIconSelectorTest, DeviceDensityFirst) {
262 // If there is no perfect icon but an icon of the current device density is 243 // If there is no perfect icon but an icon of the current device density is
263 // present, it will be picked. 244 // present, it will be picked.
264 // This test has three icons each are marked with sizes set to the preferred 245 // This test has three icons each are marked with sizes set to the preferred
265 // icon size for the associated density. 246 // icon size for the associated density.
266 std::vector<gfx::Size> sizes; 247 std::vector<gfx::Size> sizes;
267 sizes.push_back(gfx::Size(2, 2)); 248 sizes.push_back(gfx::Size(2, 2));
268 249
269 std::vector<content::Manifest::Icon> icons; 250 std::vector<content::Manifest::Icon> icons;
270 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes)); 251 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes));
271 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes)); 252 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes));
272 icons.push_back(CreateIcon("http://foo.com/icon_x3.png", "", 3.0, sizes)); 253 icons.push_back(CreateIcon("http://foo.com/icon_x3.png", "", 3.0, sizes));
273 254
274 SetDisplayDeviceScaleFactor(1.0f); 255 SetDisplayDeviceScaleFactor(1.0f);
275 GURL url = FindBestMatchingIcon(icons); 256 GURL url = FindBestMatchingIcon(icons);
276 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); 257 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec());
277 258
278 SetDisplayDeviceScaleFactor(2.0f); 259 SetDisplayDeviceScaleFactor(2.0f);
279 url = FindBestMatchingIcon(icons); 260 url = FindBestMatchingIcon(icons);
280 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); 261 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec());
281 262
282 SetDisplayDeviceScaleFactor(3.0f); 263 SetDisplayDeviceScaleFactor(3.0f);
283 url = FindBestMatchingIcon(icons); 264 url = FindBestMatchingIcon(icons);
284 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); 265 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec());
285 } 266 }
286 267
287 TEST_F(ShortcutHelperTest, DeviceDensityFallback) { 268 TEST_F(ManifestIconSelectorTest, DeviceDensityFallback) {
288 // If there is no perfect icon but and no icon of the current display density, 269 // If there is no perfect icon but and no icon of the current display density,
289 // an icon of density 1.0 will be used. 270 // an icon of density 1.0 will be used.
290 std::vector<gfx::Size> sizes; 271 std::vector<gfx::Size> sizes;
291 sizes.push_back(gfx::Size(2, 2)); 272 sizes.push_back(gfx::Size(2, 2));
292 273
293 std::vector<content::Manifest::Icon> icons; 274 std::vector<content::Manifest::Icon> icons;
294 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes)); 275 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes));
295 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes)); 276 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes));
296 277
297 SetDisplayDeviceScaleFactor(3.0f); 278 SetDisplayDeviceScaleFactor(3.0f);
298 GURL url = FindBestMatchingIcon(icons); 279 GURL url = FindBestMatchingIcon(icons);
299 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); 280 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec());
300 } 281 }
301 282
302 TEST_F(ShortcutHelperTest, DoNotUseOtherDensities) { 283 TEST_F(ManifestIconSelectorTest, DoNotUseOtherDensities) {
303 // If there are only icons of densities that are not the current display 284 // If there are only icons of densities that are not the current display
304 // density or the default density, they are ignored. 285 // density or the default density, they are ignored.
305 std::vector<gfx::Size> sizes; 286 std::vector<gfx::Size> sizes;
306 sizes.push_back(gfx::Size(2, 2)); 287 sizes.push_back(gfx::Size(2, 2));
307 288
308 std::vector<content::Manifest::Icon> icons; 289 std::vector<content::Manifest::Icon> icons;
309 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes)); 290 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes));
310 291
311 SetDisplayDeviceScaleFactor(3.0f); 292 SetDisplayDeviceScaleFactor(3.0f);
312 GURL url = FindBestMatchingIcon(icons); 293 GURL url = FindBestMatchingIcon(icons);
313 EXPECT_TRUE(url.is_empty()); 294 EXPECT_TRUE(url.is_empty());
314 } 295 }
315 296
316 TEST_F(ShortcutHelperTest, NotSquareIconsAreIgnored) { 297 TEST_F(ManifestIconSelectorTest, NotSquareIconsAreIgnored) {
317 std::vector<gfx::Size> sizes; 298 std::vector<gfx::Size> sizes;
318 sizes.push_back(gfx::Size(20, 2)); 299 sizes.push_back(gfx::Size(20, 2));
319 300
320 std::vector<content::Manifest::Icon> icons; 301 std::vector<content::Manifest::Icon> icons;
321 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes)); 302 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes));
322 303
323 GURL url = FindBestMatchingIcon(icons); 304 GURL url = FindBestMatchingIcon(icons);
324 EXPECT_TRUE(url.is_empty()); 305 EXPECT_TRUE(url.is_empty());
325 } 306 }
326 307
327 TEST_F(ShortcutHelperTest, ClosestIconToPreferred) { 308 TEST_F(ManifestIconSelectorTest, ClosestIconToPreferred) {
328 // This test verifies ShortcutHelper::FindBestMatchingIcon by passing 309 // This test verifies ManifestIconSelector::FindBestMatchingIcon by passing
329 // different icon sizes and checking which one is picked. 310 // different icon sizes and checking which one is picked.
330 // The Device Scale Factor is 1.0 and the preferred icon size is returned by 311 // The Device Scale Factor is 1.0 and the preferred icon size is returned by
331 // GetPreferredIconSizeInDp(). 312 // GetPreferredIconSizeInDp().
332 int very_small = GetPreferredIconSizeInDp() / 4; 313 int very_small = GetPreferredIconSizeInDp() / 4;
333 int small = GetPreferredIconSizeInDp() / 2; 314 int small = GetPreferredIconSizeInDp() / 2;
334 int bit_small = GetPreferredIconSizeInDp() - 1; 315 int bit_small = GetPreferredIconSizeInDp() - 1;
335 int bit_big = GetPreferredIconSizeInDp() + 1; 316 int bit_big = GetPreferredIconSizeInDp() + 1;
336 int big = GetPreferredIconSizeInDp() * 2; 317 int big = GetPreferredIconSizeInDp() * 2;
337 int very_big = GetPreferredIconSizeInDp() * 4; 318 int very_big = GetPreferredIconSizeInDp() * 4;
338 319
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 415
435 std::vector<content::Manifest::Icon> icons; 416 std::vector<content::Manifest::Icon> icons;
436 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_1)); 417 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_1));
437 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2)); 418 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2));
438 419
439 GURL url = FindBestMatchingIcon(icons); 420 GURL url = FindBestMatchingIcon(icons);
440 EXPECT_EQ("http://foo.com/icon.png", url.spec()); 421 EXPECT_EQ("http://foo.com/icon.png", url.spec());
441 } 422 }
442 } 423 }
443 424
444 TEST_F(ShortcutHelperTest, UseAnyIfNoPreferredSize) { 425 TEST_F(ManifestIconSelectorTest, UseAnyIfNoPreferredSize) {
445 // 'any' (ie. gfx::Size(0,0)) should be used if there is no icon of a 426 // 'any' (ie. gfx::Size(0,0)) should be used if there is no icon of a
446 // preferred size. An icon with the current device scale factor is preferred 427 // preferred size. An icon with the current device scale factor is preferred
447 // over one with the default density. 428 // over one with the default density.
448 429
449 // 'any' with preferred size => preferred size 430 // 'any' with preferred size => preferred size
450 { 431 {
451 std::vector<gfx::Size> sizes_1; 432 std::vector<gfx::Size> sizes_1;
452 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), 433 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(),
453 GetPreferredIconSizeInDp())); 434 GetPreferredIconSizeInDp()));
454 std::vector<gfx::Size> sizes_2; 435 std::vector<gfx::Size> sizes_2;
(...skipping 30 matching lines...) Expand all
485 466
486 std::vector<content::Manifest::Icon> icons; 467 std::vector<content::Manifest::Icon> icons;
487 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes)); 468 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes));
488 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 3.0, sizes)); 469 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 3.0, sizes));
489 470
490 SetDisplayDeviceScaleFactor(3.0f); 471 SetDisplayDeviceScaleFactor(3.0f);
491 GURL url = FindBestMatchingIcon(icons); 472 GURL url = FindBestMatchingIcon(icons);
492 EXPECT_EQ("http://foo.com/icon.png", url.spec()); 473 EXPECT_EQ("http://foo.com/icon.png", url.spec());
493 } 474 }
494 } 475 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698