OLD | NEW |
---|---|
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 // A dummy implementation of gfx::Screen, since ManifestIconSelector needs |
14 // a gfx::Display's device scale factor. | 14 // access to a gfx::Display's device scale factor. |
15 // This is inspired by web_contents_video_capture_device_unittest.cc | 15 // 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 | 16 // A bug has been opened to merge all those mocks: http://crbug.com/417227 |
17 class FakeScreen : public gfx::Screen { | 17 class FakeScreen : public gfx::Screen { |
18 public: | 18 public: |
19 FakeScreen() : display_(0x1337, gfx::Rect(0, 0, 2560, 1440)) { | 19 FakeScreen() : display_(0x1337, gfx::Rect(0, 0, 2560, 1440)) { |
20 } | 20 } |
21 virtual ~FakeScreen() {} | 21 virtual ~FakeScreen() {} |
22 | 22 |
23 void SetDisplayDeviceScaleFactor(float device_scale_factor) { | 23 void SetDisplayDeviceScaleFactor(float device_scale_factor) { |
24 display_.set_device_scale_factor(device_scale_factor); | 24 display_.set_device_scale_factor(device_scale_factor); |
(...skipping 25 matching lines...) Expand all Loading... | |
50 } | 50 } |
51 virtual void AddObserver(gfx::DisplayObserver* observer) override {} | 51 virtual void AddObserver(gfx::DisplayObserver* observer) override {} |
52 virtual void RemoveObserver(gfx::DisplayObserver* observer) override {} | 52 virtual void RemoveObserver(gfx::DisplayObserver* observer) override {} |
53 | 53 |
54 private: | 54 private: |
55 gfx::Display display_; | 55 gfx::Display display_; |
56 | 56 |
57 DISALLOW_COPY_AND_ASSIGN(FakeScreen); | 57 DISALLOW_COPY_AND_ASSIGN(FakeScreen); |
58 }; | 58 }; |
59 | 59 |
60 class ShortcutHelperTest : public ChromeRenderViewHostTestHarness { | 60 class ManifestIconSelectorTest : public ChromeRenderViewHostTestHarness { |
61 protected: | 61 protected: |
62 ShortcutHelperTest() : shortcut_helper_(NULL) {} | 62 ManifestIconSelectorTest() {} |
63 virtual ~ShortcutHelperTest() {} | 63 virtual ~ManifestIconSelectorTest() {} |
mlamouri (slow - plz ping)
2015/01/30 22:32:13
I think you should use override instead of virtual
gone
2015/01/30 22:43:30
Fixed your usage of virtual ~FakeScreen too.
| |
64 | 64 |
65 static jobject CreateShortcutHelperJava(JNIEnv* env) { | 65 void ResetManifestIconSelector() { |
66 jclass clazz = env->FindClass("org/chromium/chrome/browser/ShortcutHelper"); | 66 manifest_icon_selector_.reset(new ManifestIconSelector( |
67 jmethodID constructor = | 67 web_contents(), |
68 env->GetMethodID(clazz, "<init>", | 68 GetPreferredIconSizeInDp())); |
mlamouri (slow - plz ping)
2015/01/30 22:32:13
I guess you should update this. It probably doesn'
gone
2015/01/30 22:43:30
Yeah, the joys of juggling multiple CLs.
| |
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 } | 69 } |
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 | 75 ResetManifestIconSelector(); |
89 ResetShorcutHelper(); | |
90 } | 76 } |
91 | 77 |
92 virtual void TearDown() override { | 78 virtual void TearDown() override { |
93 delete shortcut_helper_; | 79 manifest_icon_selector_.reset(NULL); |
mlamouri (slow - plz ping)
2015/01/30 22:32:13
Feel free to s/NULL/nullptr/ in this file.
gone
2015/01/30 22:43:30
Done.
| |
94 shortcut_helper_ = NULL; | |
95 | |
96 ChromeRenderViewHostTestHarness::TearDown(); | 80 ChromeRenderViewHostTestHarness::TearDown(); |
97 | |
98 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); | 81 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); |
99 } | 82 } |
100 | 83 |
101 GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons) { | 84 GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons) { |
102 return shortcut_helper_->FindBestMatchingIcon(icons); | 85 return manifest_icon_selector_->FindBestMatchingIcon(icons, web_contents()); |
103 } | 86 } |
104 | 87 |
105 void SetDisplayDeviceScaleFactor(float device_scale_factor) { | 88 void SetDisplayDeviceScaleFactor(float device_scale_factor) { |
106 fake_screen_.SetDisplayDeviceScaleFactor(device_scale_factor); | 89 fake_screen_.SetDisplayDeviceScaleFactor(device_scale_factor); |
107 | 90 |
108 ResetShorcutHelper(); | 91 ResetManifestIconSelector(); |
109 } | 92 } |
110 | 93 |
111 static int GetPreferredIconSizeInDp() { | 94 static int GetPreferredIconSizeInDp() { |
112 return ShortcutHelper::kPreferredIconSizeInDp; | 95 return 48; |
mlamouri (slow - plz ping)
2015/01/30 22:32:13
It might be better to use a const here even if you
gone
2015/01/30 22:43:30
Done.
| |
113 } | 96 } |
114 | 97 |
115 static content::Manifest::Icon CreateIcon( | 98 static content::Manifest::Icon CreateIcon( |
116 const std::string& url, | 99 const std::string& url, |
117 const std::string& type, | 100 const std::string& type, |
118 double density, | 101 double density, |
119 const std::vector<gfx::Size> sizes) { | 102 const std::vector<gfx::Size> sizes) { |
120 content::Manifest::Icon icon; | 103 content::Manifest::Icon icon; |
121 icon.src = GURL(url); | 104 icon.src = GURL(url); |
122 if (!type.empty()) | 105 if (!type.empty()) |
123 icon.type = base::NullableString16(base::UTF8ToUTF16(type), false); | 106 icon.type = base::NullableString16(base::UTF8ToUTF16(type), false); |
124 icon.density = density; | 107 icon.density = density; |
125 icon.sizes = sizes; | 108 icon.sizes = sizes; |
126 | 109 |
127 return icon; | 110 return icon; |
128 } | 111 } |
129 | 112 |
130 private: | 113 private: |
131 ShortcutHelper* shortcut_helper_; | 114 scoped_ptr<ManifestIconSelector> manifest_icon_selector_; |
132 FakeScreen fake_screen_; | 115 FakeScreen fake_screen_; |
133 | 116 |
134 DISALLOW_COPY_AND_ASSIGN(ShortcutHelperTest); | 117 DISALLOW_COPY_AND_ASSIGN(ManifestIconSelectorTest); |
135 }; | 118 }; |
136 | 119 |
137 TEST_F(ShortcutHelperTest, NoIcons) { | 120 TEST_F(ManifestIconSelectorTest, NoIcons) { |
138 // No icons should return the empty URL. | 121 // No icons should return the empty URL. |
139 std::vector<content::Manifest::Icon> icons; | 122 std::vector<content::Manifest::Icon> icons; |
140 GURL url = FindBestMatchingIcon(icons); | 123 GURL url = FindBestMatchingIcon(icons); |
141 EXPECT_TRUE(url.is_empty()); | 124 EXPECT_TRUE(url.is_empty()); |
142 } | 125 } |
143 | 126 |
144 TEST_F(ShortcutHelperTest, NoSizes) { | 127 TEST_F(ManifestIconSelectorTest, NoSizes) { |
145 // Icon with no sizes are ignored. | 128 // Icon with no sizes are ignored. |
146 std::vector<content::Manifest::Icon> icons; | 129 std::vector<content::Manifest::Icon> icons; |
147 icons.push_back( | 130 icons.push_back( |
148 CreateIcon("http://foo.com/icon.png", "", 1.0, std::vector<gfx::Size>())); | 131 CreateIcon("http://foo.com/icon.png", "", 1.0, std::vector<gfx::Size>())); |
149 | 132 |
150 GURL url = FindBestMatchingIcon(icons); | 133 GURL url = FindBestMatchingIcon(icons); |
151 EXPECT_TRUE(url.is_empty()); | 134 EXPECT_TRUE(url.is_empty()); |
152 } | 135 } |
153 | 136 |
154 TEST_F(ShortcutHelperTest, MIMETypeFiltering) { | 137 TEST_F(ManifestIconSelectorTest, MIMETypeFiltering) { |
155 // Icons with type specified to a MIME type that isn't a valid image MIME type | 138 // Icons with type specified to a MIME type that isn't a valid image MIME type |
156 // are ignored. | 139 // are ignored. |
157 std::vector<gfx::Size> sizes; | 140 std::vector<gfx::Size> sizes; |
158 sizes.push_back(gfx::Size(10, 10)); | 141 sizes.push_back(gfx::Size(10, 10)); |
159 | 142 |
160 std::vector<content::Manifest::Icon> icons; | 143 std::vector<content::Manifest::Icon> icons; |
161 icons.push_back( | 144 icons.push_back( |
162 CreateIcon("http://foo.com/icon.png", "image/foo_bar", 1.0, sizes)); | 145 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)); | 146 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)); | 147 icons.push_back(CreateIcon("http://foo.com/icon.png", "image/", 1.0, sizes)); |
(...skipping 15 matching lines...) Expand all Loading... | |
180 url = FindBestMatchingIcon(icons); | 163 url = FindBestMatchingIcon(icons); |
181 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 164 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
182 | 165 |
183 icons.clear(); | 166 icons.clear(); |
184 icons.push_back( | 167 icons.push_back( |
185 CreateIcon("http://foo.com/icon.png", "image/jpeg", 1.0, sizes)); | 168 CreateIcon("http://foo.com/icon.png", "image/jpeg", 1.0, sizes)); |
186 url = FindBestMatchingIcon(icons); | 169 url = FindBestMatchingIcon(icons); |
187 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 170 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
188 } | 171 } |
189 | 172 |
190 TEST_F(ShortcutHelperTest, PreferredSizeOfCurrentDensityIsUsedFirst) { | 173 TEST_F(ManifestIconSelectorTest, PreferredSizeOfCurrentDensityIsUsedFirst) { |
191 // This test has three icons each are marked with sizes set to the preferred | 174 // This test has three icons each are marked with sizes set to the preferred |
192 // icon size for the associated density. | 175 // icon size for the associated density. |
193 std::vector<gfx::Size> sizes_1; | 176 std::vector<gfx::Size> sizes_1; |
194 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), | 177 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), |
195 GetPreferredIconSizeInDp())); | 178 GetPreferredIconSizeInDp())); |
196 | 179 |
197 std::vector<gfx::Size> sizes_2; | 180 std::vector<gfx::Size> sizes_2; |
198 sizes_2.push_back(gfx::Size(GetPreferredIconSizeInDp() * 2, | 181 sizes_2.push_back(gfx::Size(GetPreferredIconSizeInDp() * 2, |
199 GetPreferredIconSizeInDp() * 2)); | 182 GetPreferredIconSizeInDp() * 2)); |
200 | 183 |
(...skipping 12 matching lines...) Expand all Loading... | |
213 | 196 |
214 SetDisplayDeviceScaleFactor(2.0f); | 197 SetDisplayDeviceScaleFactor(2.0f); |
215 url = FindBestMatchingIcon(icons); | 198 url = FindBestMatchingIcon(icons); |
216 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); | 199 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); |
217 | 200 |
218 SetDisplayDeviceScaleFactor(3.0f); | 201 SetDisplayDeviceScaleFactor(3.0f); |
219 url = FindBestMatchingIcon(icons); | 202 url = FindBestMatchingIcon(icons); |
220 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); | 203 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); |
221 } | 204 } |
222 | 205 |
223 TEST_F(ShortcutHelperTest, PreferredSizeOfDefaultDensityIsUsedSecond) { | 206 TEST_F(ManifestIconSelectorTest, PreferredSizeOfDefaultDensityIsUsedSecond) { |
224 // This test has three icons. The first one is of density zero and is marked | 207 // 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. | 208 // 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. | 209 // 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 | 210 // Regardless of the device scale factor, the icon of density 1 is going to be |
228 // used because it matches the preferred size. | 211 // used because it matches the preferred size. |
229 std::vector<gfx::Size> sizes_1; | 212 std::vector<gfx::Size> sizes_1; |
230 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), | 213 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), |
231 GetPreferredIconSizeInDp())); | 214 GetPreferredIconSizeInDp())); |
232 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp() * 2, | 215 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp() * 2, |
233 GetPreferredIconSizeInDp() * 2)); | 216 GetPreferredIconSizeInDp() * 2)); |
(...skipping 17 matching lines...) Expand all Loading... | |
251 | 234 |
252 SetDisplayDeviceScaleFactor(2.0f); | 235 SetDisplayDeviceScaleFactor(2.0f); |
253 url = FindBestMatchingIcon(icons); | 236 url = FindBestMatchingIcon(icons); |
254 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); | 237 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
255 | 238 |
256 SetDisplayDeviceScaleFactor(3.0f); | 239 SetDisplayDeviceScaleFactor(3.0f); |
257 url = FindBestMatchingIcon(icons); | 240 url = FindBestMatchingIcon(icons); |
258 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); | 241 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
259 } | 242 } |
260 | 243 |
261 TEST_F(ShortcutHelperTest, DeviceDensityFirst) { | 244 TEST_F(ManifestIconSelectorTest, DeviceDensityFirst) { |
262 // If there is no perfect icon but an icon of the current device density is | 245 // If there is no perfect icon but an icon of the current device density is |
263 // present, it will be picked. | 246 // present, it will be picked. |
264 // This test has three icons each are marked with sizes set to the preferred | 247 // This test has three icons each are marked with sizes set to the preferred |
265 // icon size for the associated density. | 248 // icon size for the associated density. |
266 std::vector<gfx::Size> sizes; | 249 std::vector<gfx::Size> sizes; |
267 sizes.push_back(gfx::Size(2, 2)); | 250 sizes.push_back(gfx::Size(2, 2)); |
268 | 251 |
269 std::vector<content::Manifest::Icon> icons; | 252 std::vector<content::Manifest::Icon> icons; |
270 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes)); | 253 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)); | 254 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)); | 255 icons.push_back(CreateIcon("http://foo.com/icon_x3.png", "", 3.0, sizes)); |
273 | 256 |
274 SetDisplayDeviceScaleFactor(1.0f); | 257 SetDisplayDeviceScaleFactor(1.0f); |
275 GURL url = FindBestMatchingIcon(icons); | 258 GURL url = FindBestMatchingIcon(icons); |
276 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); | 259 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
277 | 260 |
278 SetDisplayDeviceScaleFactor(2.0f); | 261 SetDisplayDeviceScaleFactor(2.0f); |
279 url = FindBestMatchingIcon(icons); | 262 url = FindBestMatchingIcon(icons); |
280 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); | 263 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); |
281 | 264 |
282 SetDisplayDeviceScaleFactor(3.0f); | 265 SetDisplayDeviceScaleFactor(3.0f); |
283 url = FindBestMatchingIcon(icons); | 266 url = FindBestMatchingIcon(icons); |
284 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); | 267 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); |
285 } | 268 } |
286 | 269 |
287 TEST_F(ShortcutHelperTest, DeviceDensityFallback) { | 270 TEST_F(ManifestIconSelectorTest, DeviceDensityFallback) { |
288 // If there is no perfect icon but and no icon of the current display density, | 271 // 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. | 272 // an icon of density 1.0 will be used. |
290 std::vector<gfx::Size> sizes; | 273 std::vector<gfx::Size> sizes; |
291 sizes.push_back(gfx::Size(2, 2)); | 274 sizes.push_back(gfx::Size(2, 2)); |
292 | 275 |
293 std::vector<content::Manifest::Icon> icons; | 276 std::vector<content::Manifest::Icon> icons; |
294 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes)); | 277 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)); | 278 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes)); |
296 | 279 |
297 SetDisplayDeviceScaleFactor(3.0f); | 280 SetDisplayDeviceScaleFactor(3.0f); |
298 GURL url = FindBestMatchingIcon(icons); | 281 GURL url = FindBestMatchingIcon(icons); |
299 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); | 282 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
300 } | 283 } |
301 | 284 |
302 TEST_F(ShortcutHelperTest, DoNotUseOtherDensities) { | 285 TEST_F(ManifestIconSelectorTest, DoNotUseOtherDensities) { |
303 // If there are only icons of densities that are not the current display | 286 // If there are only icons of densities that are not the current display |
304 // density or the default density, they are ignored. | 287 // density or the default density, they are ignored. |
305 std::vector<gfx::Size> sizes; | 288 std::vector<gfx::Size> sizes; |
306 sizes.push_back(gfx::Size(2, 2)); | 289 sizes.push_back(gfx::Size(2, 2)); |
307 | 290 |
308 std::vector<content::Manifest::Icon> icons; | 291 std::vector<content::Manifest::Icon> icons; |
309 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes)); | 292 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes)); |
310 | 293 |
311 SetDisplayDeviceScaleFactor(3.0f); | 294 SetDisplayDeviceScaleFactor(3.0f); |
312 GURL url = FindBestMatchingIcon(icons); | 295 GURL url = FindBestMatchingIcon(icons); |
313 EXPECT_TRUE(url.is_empty()); | 296 EXPECT_TRUE(url.is_empty()); |
314 } | 297 } |
315 | 298 |
316 TEST_F(ShortcutHelperTest, NotSquareIconsAreIgnored) { | 299 TEST_F(ManifestIconSelectorTest, NotSquareIconsAreIgnored) { |
317 std::vector<gfx::Size> sizes; | 300 std::vector<gfx::Size> sizes; |
318 sizes.push_back(gfx::Size(20, 2)); | 301 sizes.push_back(gfx::Size(20, 2)); |
319 | 302 |
320 std::vector<content::Manifest::Icon> icons; | 303 std::vector<content::Manifest::Icon> icons; |
321 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes)); | 304 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes)); |
322 | 305 |
323 GURL url = FindBestMatchingIcon(icons); | 306 GURL url = FindBestMatchingIcon(icons); |
324 EXPECT_TRUE(url.is_empty()); | 307 EXPECT_TRUE(url.is_empty()); |
325 } | 308 } |
326 | 309 |
327 TEST_F(ShortcutHelperTest, ClosestIconToPreferred) { | 310 TEST_F(ManifestIconSelectorTest, ClosestIconToPreferred) { |
328 // This test verifies ShortcutHelper::FindBestMatchingIcon by passing | 311 // This test verifies ManifestIconSelector::FindBestMatchingIcon by passing |
329 // different icon sizes and checking which one is picked. | 312 // 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 | 313 // The Device Scale Factor is 1.0 and the preferred icon size is returned by |
331 // GetPreferredIconSizeInDp(). | 314 // GetPreferredIconSizeInDp(). |
332 int very_small = GetPreferredIconSizeInDp() / 4; | 315 int very_small = GetPreferredIconSizeInDp() / 4; |
333 int small = GetPreferredIconSizeInDp() / 2; | 316 int small = GetPreferredIconSizeInDp() / 2; |
334 int bit_small = GetPreferredIconSizeInDp() - 1; | 317 int bit_small = GetPreferredIconSizeInDp() - 1; |
335 int bit_big = GetPreferredIconSizeInDp() + 1; | 318 int bit_big = GetPreferredIconSizeInDp() + 1; |
336 int big = GetPreferredIconSizeInDp() * 2; | 319 int big = GetPreferredIconSizeInDp() * 2; |
337 int very_big = GetPreferredIconSizeInDp() * 4; | 320 int very_big = GetPreferredIconSizeInDp() * 4; |
338 | 321 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 | 417 |
435 std::vector<content::Manifest::Icon> icons; | 418 std::vector<content::Manifest::Icon> icons; |
436 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_1)); | 419 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)); | 420 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2)); |
438 | 421 |
439 GURL url = FindBestMatchingIcon(icons); | 422 GURL url = FindBestMatchingIcon(icons); |
440 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 423 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
441 } | 424 } |
442 } | 425 } |
443 | 426 |
444 TEST_F(ShortcutHelperTest, UseAnyIfNoPreferredSize) { | 427 TEST_F(ManifestIconSelectorTest, UseAnyIfNoPreferredSize) { |
445 // 'any' (ie. gfx::Size(0,0)) should be used if there is no icon of a | 428 // '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 | 429 // preferred size. An icon with the current device scale factor is preferred |
447 // over one with the default density. | 430 // over one with the default density. |
448 | 431 |
449 // 'any' with preferred size => preferred size | 432 // 'any' with preferred size => preferred size |
450 { | 433 { |
451 std::vector<gfx::Size> sizes_1; | 434 std::vector<gfx::Size> sizes_1; |
452 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), | 435 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), |
453 GetPreferredIconSizeInDp())); | 436 GetPreferredIconSizeInDp())); |
454 std::vector<gfx::Size> sizes_2; | 437 std::vector<gfx::Size> sizes_2; |
(...skipping 30 matching lines...) Expand all Loading... | |
485 | 468 |
486 std::vector<content::Manifest::Icon> icons; | 469 std::vector<content::Manifest::Icon> icons; |
487 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes)); | 470 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)); | 471 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 3.0, sizes)); |
489 | 472 |
490 SetDisplayDeviceScaleFactor(3.0f); | 473 SetDisplayDeviceScaleFactor(3.0f); |
491 GURL url = FindBestMatchingIcon(icons); | 474 GURL url = FindBestMatchingIcon(icons); |
492 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 475 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
493 } | 476 } |
494 } | 477 } |
OLD | NEW |