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 "testing/gtest/include/gtest/gtest.h" |
9 #include "content/public/browser/web_contents.h" | |
10 #include "ui/gfx/screen.h" | 9 #include "ui/gfx/screen.h" |
11 #include "ui/gfx/screen_type_delegate.h" | 10 #include "ui/gfx/screen_type_delegate.h" |
12 | 11 |
13 // A dummy implementation of gfx::Screen, since ShortcutHelper needs access to | 12 namespace { |
14 // a gfx::Display's device scale factor. | 13 |
| 14 const int kPreferredIconSize = 48; |
| 15 |
| 16 } |
| 17 |
| 18 // A dummy implementation of gfx::Screen, since ManifestIconSelector needs |
| 19 // access to a gfx::Display's device scale factor. |
15 // This is inspired by web_contents_video_capture_device_unittest.cc | 20 // 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 | 21 // A bug has been opened to merge all those mocks: http://crbug.com/417227 |
17 class FakeScreen : public gfx::Screen { | 22 class FakeScreen : public gfx::Screen { |
18 public: | 23 public: |
19 FakeScreen() : display_(0x1337, gfx::Rect(0, 0, 2560, 1440)) { | 24 FakeScreen() : display_(0x1337, gfx::Rect(0, 0, 2560, 1440)) { |
20 } | 25 } |
21 virtual ~FakeScreen() {} | 26 ~FakeScreen() override {} |
22 | 27 |
23 void SetDisplayDeviceScaleFactor(float device_scale_factor) { | 28 void SetDisplayDeviceScaleFactor(float device_scale_factor) { |
24 display_.set_device_scale_factor(device_scale_factor); | 29 display_.set_device_scale_factor(device_scale_factor); |
25 } | 30 } |
26 | 31 |
27 // gfx::Screen implementation (only what's needed for testing). | 32 // gfx::Screen implementation (only what's needed for testing). |
28 virtual gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } | 33 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } |
29 virtual gfx::NativeWindow GetWindowUnderCursor() override { return NULL; } | 34 gfx::NativeWindow GetWindowUnderCursor() override { return nullptr; } |
30 virtual gfx::NativeWindow GetWindowAtScreenPoint( | 35 gfx::NativeWindow GetWindowAtScreenPoint( |
31 const gfx::Point& point) override { return NULL; } | 36 const gfx::Point& point) override { return nullptr; } |
32 virtual int GetNumDisplays() const override { return 1; } | 37 int GetNumDisplays() const override { return 1; } |
33 virtual std::vector<gfx::Display> GetAllDisplays() const override { | 38 std::vector<gfx::Display> GetAllDisplays() const override { |
34 return std::vector<gfx::Display>(1, display_); | 39 return std::vector<gfx::Display>(1, display_); |
35 } | 40 } |
36 virtual gfx::Display GetDisplayNearestWindow( | 41 gfx::Display GetDisplayNearestWindow( |
37 gfx::NativeView view) const override { | 42 gfx::NativeView view) const override { |
38 return display_; | 43 return display_; |
39 } | 44 } |
40 virtual gfx::Display GetDisplayNearestPoint( | 45 gfx::Display GetDisplayNearestPoint( |
41 const gfx::Point& point) const override { | 46 const gfx::Point& point) const override { |
42 return display_; | 47 return display_; |
43 } | 48 } |
44 virtual gfx::Display GetDisplayMatching( | 49 gfx::Display GetDisplayMatching( |
45 const gfx::Rect& match_rect) const override { | 50 const gfx::Rect& match_rect) const override { |
46 return display_; | 51 return display_; |
47 } | 52 } |
48 virtual gfx::Display GetPrimaryDisplay() const override { | 53 gfx::Display GetPrimaryDisplay() const override { |
49 return display_; | 54 return display_; |
50 } | 55 } |
51 virtual void AddObserver(gfx::DisplayObserver* observer) override {} | 56 void AddObserver(gfx::DisplayObserver* observer) override {} |
52 virtual void RemoveObserver(gfx::DisplayObserver* observer) override {} | 57 void RemoveObserver(gfx::DisplayObserver* observer) override {} |
53 | 58 |
54 private: | 59 private: |
55 gfx::Display display_; | 60 gfx::Display display_; |
56 | 61 |
57 DISALLOW_COPY_AND_ASSIGN(FakeScreen); | 62 DISALLOW_COPY_AND_ASSIGN(FakeScreen); |
58 }; | 63 }; |
59 | 64 |
60 class ShortcutHelperTest : public ChromeRenderViewHostTestHarness { | 65 class ManifestIconSelectorTest : public testing::Test { |
61 protected: | 66 protected: |
62 ShortcutHelperTest() : shortcut_helper_(NULL) {} | 67 ManifestIconSelectorTest() {} |
63 virtual ~ShortcutHelperTest() {} | 68 ~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 | |
83 virtual void SetUp() override { | |
84 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, &fake_screen_); | |
85 ASSERT_EQ(&fake_screen_, gfx::Screen::GetNativeScreen()); | |
86 | |
87 ChromeRenderViewHostTestHarness::SetUp(); | |
88 | |
89 ResetShorcutHelper(); | |
90 } | |
91 | |
92 virtual void TearDown() override { | |
93 delete shortcut_helper_; | |
94 shortcut_helper_ = NULL; | |
95 | |
96 ChromeRenderViewHostTestHarness::TearDown(); | |
97 | |
98 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); | |
99 } | |
100 | 69 |
101 GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons) { | 70 GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons) { |
102 return shortcut_helper_->FindBestMatchingIcon(icons); | 71 return ManifestIconSelector::FindBestMatchingIcon( |
| 72 icons, |
| 73 GetPreferredIconSizeInDp(), |
| 74 &fake_screen_); |
103 } | 75 } |
104 | 76 |
105 void SetDisplayDeviceScaleFactor(float device_scale_factor) { | 77 void SetDisplayDeviceScaleFactor(float device_scale_factor) { |
106 fake_screen_.SetDisplayDeviceScaleFactor(device_scale_factor); | 78 fake_screen_.SetDisplayDeviceScaleFactor(device_scale_factor); |
107 | |
108 ResetShorcutHelper(); | |
109 } | 79 } |
110 | 80 |
111 static int GetPreferredIconSizeInDp() { | 81 static int GetPreferredIconSizeInDp() { |
112 return ShortcutHelper::kPreferredIconSizeInDp; | 82 return kPreferredIconSize; |
113 } | 83 } |
114 | 84 |
115 static content::Manifest::Icon CreateIcon( | 85 static content::Manifest::Icon CreateIcon( |
116 const std::string& url, | 86 const std::string& url, |
117 const std::string& type, | 87 const std::string& type, |
118 double density, | 88 double density, |
119 const std::vector<gfx::Size> sizes) { | 89 const std::vector<gfx::Size> sizes) { |
120 content::Manifest::Icon icon; | 90 content::Manifest::Icon icon; |
121 icon.src = GURL(url); | 91 icon.src = GURL(url); |
122 if (!type.empty()) | 92 if (!type.empty()) |
123 icon.type = base::NullableString16(base::UTF8ToUTF16(type), false); | 93 icon.type = base::NullableString16(base::UTF8ToUTF16(type), false); |
124 icon.density = density; | 94 icon.density = density; |
125 icon.sizes = sizes; | 95 icon.sizes = sizes; |
126 | 96 |
127 return icon; | 97 return icon; |
128 } | 98 } |
129 | 99 |
130 private: | 100 private: |
131 ShortcutHelper* shortcut_helper_; | |
132 FakeScreen fake_screen_; | 101 FakeScreen fake_screen_; |
133 | 102 |
134 DISALLOW_COPY_AND_ASSIGN(ShortcutHelperTest); | 103 DISALLOW_COPY_AND_ASSIGN(ManifestIconSelectorTest); |
135 }; | 104 }; |
136 | 105 |
137 TEST_F(ShortcutHelperTest, NoIcons) { | 106 TEST_F(ManifestIconSelectorTest, NoIcons) { |
138 // No icons should return the empty URL. | 107 // No icons should return the empty URL. |
139 std::vector<content::Manifest::Icon> icons; | 108 std::vector<content::Manifest::Icon> icons; |
140 GURL url = FindBestMatchingIcon(icons); | 109 GURL url = FindBestMatchingIcon(icons); |
141 EXPECT_TRUE(url.is_empty()); | 110 EXPECT_TRUE(url.is_empty()); |
142 } | 111 } |
143 | 112 |
144 TEST_F(ShortcutHelperTest, NoSizes) { | 113 TEST_F(ManifestIconSelectorTest, NoSizes) { |
145 // Icon with no sizes are ignored. | 114 // Icon with no sizes are ignored. |
146 std::vector<content::Manifest::Icon> icons; | 115 std::vector<content::Manifest::Icon> icons; |
147 icons.push_back( | 116 icons.push_back( |
148 CreateIcon("http://foo.com/icon.png", "", 1.0, std::vector<gfx::Size>())); | 117 CreateIcon("http://foo.com/icon.png", "", 1.0, std::vector<gfx::Size>())); |
149 | 118 |
150 GURL url = FindBestMatchingIcon(icons); | 119 GURL url = FindBestMatchingIcon(icons); |
151 EXPECT_TRUE(url.is_empty()); | 120 EXPECT_TRUE(url.is_empty()); |
152 } | 121 } |
153 | 122 |
154 TEST_F(ShortcutHelperTest, MIMETypeFiltering) { | 123 TEST_F(ManifestIconSelectorTest, MIMETypeFiltering) { |
155 // Icons with type specified to a MIME type that isn't a valid image MIME type | 124 // Icons with type specified to a MIME type that isn't a valid image MIME type |
156 // are ignored. | 125 // are ignored. |
157 std::vector<gfx::Size> sizes; | 126 std::vector<gfx::Size> sizes; |
158 sizes.push_back(gfx::Size(10, 10)); | 127 sizes.push_back(gfx::Size(10, 10)); |
159 | 128 |
160 std::vector<content::Manifest::Icon> icons; | 129 std::vector<content::Manifest::Icon> icons; |
161 icons.push_back( | 130 icons.push_back( |
162 CreateIcon("http://foo.com/icon.png", "image/foo_bar", 1.0, sizes)); | 131 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)); | 132 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)); | 133 icons.push_back(CreateIcon("http://foo.com/icon.png", "image/", 1.0, sizes)); |
(...skipping 15 matching lines...) Expand all Loading... |
180 url = FindBestMatchingIcon(icons); | 149 url = FindBestMatchingIcon(icons); |
181 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 150 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
182 | 151 |
183 icons.clear(); | 152 icons.clear(); |
184 icons.push_back( | 153 icons.push_back( |
185 CreateIcon("http://foo.com/icon.png", "image/jpeg", 1.0, sizes)); | 154 CreateIcon("http://foo.com/icon.png", "image/jpeg", 1.0, sizes)); |
186 url = FindBestMatchingIcon(icons); | 155 url = FindBestMatchingIcon(icons); |
187 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 156 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
188 } | 157 } |
189 | 158 |
190 TEST_F(ShortcutHelperTest, PreferredSizeOfCurrentDensityIsUsedFirst) { | 159 TEST_F(ManifestIconSelectorTest, PreferredSizeOfCurrentDensityIsUsedFirst) { |
191 // This test has three icons each are marked with sizes set to the preferred | 160 // This test has three icons each are marked with sizes set to the preferred |
192 // icon size for the associated density. | 161 // icon size for the associated density. |
193 std::vector<gfx::Size> sizes_1; | 162 std::vector<gfx::Size> sizes_1; |
194 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), | 163 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), |
195 GetPreferredIconSizeInDp())); | 164 GetPreferredIconSizeInDp())); |
196 | 165 |
197 std::vector<gfx::Size> sizes_2; | 166 std::vector<gfx::Size> sizes_2; |
198 sizes_2.push_back(gfx::Size(GetPreferredIconSizeInDp() * 2, | 167 sizes_2.push_back(gfx::Size(GetPreferredIconSizeInDp() * 2, |
199 GetPreferredIconSizeInDp() * 2)); | 168 GetPreferredIconSizeInDp() * 2)); |
200 | 169 |
(...skipping 12 matching lines...) Expand all Loading... |
213 | 182 |
214 SetDisplayDeviceScaleFactor(2.0f); | 183 SetDisplayDeviceScaleFactor(2.0f); |
215 url = FindBestMatchingIcon(icons); | 184 url = FindBestMatchingIcon(icons); |
216 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); | 185 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); |
217 | 186 |
218 SetDisplayDeviceScaleFactor(3.0f); | 187 SetDisplayDeviceScaleFactor(3.0f); |
219 url = FindBestMatchingIcon(icons); | 188 url = FindBestMatchingIcon(icons); |
220 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); | 189 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); |
221 } | 190 } |
222 | 191 |
223 TEST_F(ShortcutHelperTest, PreferredSizeOfDefaultDensityIsUsedSecond) { | 192 TEST_F(ManifestIconSelectorTest, PreferredSizeOfDefaultDensityIsUsedSecond) { |
224 // This test has three icons. The first one is of density zero and is marked | 193 // 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. | 194 // 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. | 195 // 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 | 196 // Regardless of the device scale factor, the icon of density 1 is going to be |
228 // used because it matches the preferred size. | 197 // used because it matches the preferred size. |
229 std::vector<gfx::Size> sizes_1; | 198 std::vector<gfx::Size> sizes_1; |
230 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), | 199 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), |
231 GetPreferredIconSizeInDp())); | 200 GetPreferredIconSizeInDp())); |
232 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp() * 2, | 201 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp() * 2, |
233 GetPreferredIconSizeInDp() * 2)); | 202 GetPreferredIconSizeInDp() * 2)); |
(...skipping 17 matching lines...) Expand all Loading... |
251 | 220 |
252 SetDisplayDeviceScaleFactor(2.0f); | 221 SetDisplayDeviceScaleFactor(2.0f); |
253 url = FindBestMatchingIcon(icons); | 222 url = FindBestMatchingIcon(icons); |
254 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); | 223 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
255 | 224 |
256 SetDisplayDeviceScaleFactor(3.0f); | 225 SetDisplayDeviceScaleFactor(3.0f); |
257 url = FindBestMatchingIcon(icons); | 226 url = FindBestMatchingIcon(icons); |
258 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); | 227 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
259 } | 228 } |
260 | 229 |
261 TEST_F(ShortcutHelperTest, DeviceDensityFirst) { | 230 TEST_F(ManifestIconSelectorTest, DeviceDensityFirst) { |
262 // If there is no perfect icon but an icon of the current device density is | 231 // If there is no perfect icon but an icon of the current device density is |
263 // present, it will be picked. | 232 // present, it will be picked. |
264 // This test has three icons each are marked with sizes set to the preferred | 233 // This test has three icons each are marked with sizes set to the preferred |
265 // icon size for the associated density. | 234 // icon size for the associated density. |
266 std::vector<gfx::Size> sizes; | 235 std::vector<gfx::Size> sizes; |
267 sizes.push_back(gfx::Size(2, 2)); | 236 sizes.push_back(gfx::Size(2, 2)); |
268 | 237 |
269 std::vector<content::Manifest::Icon> icons; | 238 std::vector<content::Manifest::Icon> icons; |
270 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes)); | 239 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)); | 240 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)); | 241 icons.push_back(CreateIcon("http://foo.com/icon_x3.png", "", 3.0, sizes)); |
273 | 242 |
274 SetDisplayDeviceScaleFactor(1.0f); | 243 SetDisplayDeviceScaleFactor(1.0f); |
275 GURL url = FindBestMatchingIcon(icons); | 244 GURL url = FindBestMatchingIcon(icons); |
276 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); | 245 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
277 | 246 |
278 SetDisplayDeviceScaleFactor(2.0f); | 247 SetDisplayDeviceScaleFactor(2.0f); |
279 url = FindBestMatchingIcon(icons); | 248 url = FindBestMatchingIcon(icons); |
280 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); | 249 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); |
281 | 250 |
282 SetDisplayDeviceScaleFactor(3.0f); | 251 SetDisplayDeviceScaleFactor(3.0f); |
283 url = FindBestMatchingIcon(icons); | 252 url = FindBestMatchingIcon(icons); |
284 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); | 253 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); |
285 } | 254 } |
286 | 255 |
287 TEST_F(ShortcutHelperTest, DeviceDensityFallback) { | 256 TEST_F(ManifestIconSelectorTest, DeviceDensityFallback) { |
288 // If there is no perfect icon but and no icon of the current display density, | 257 // 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. | 258 // an icon of density 1.0 will be used. |
290 std::vector<gfx::Size> sizes; | 259 std::vector<gfx::Size> sizes; |
291 sizes.push_back(gfx::Size(2, 2)); | 260 sizes.push_back(gfx::Size(2, 2)); |
292 | 261 |
293 std::vector<content::Manifest::Icon> icons; | 262 std::vector<content::Manifest::Icon> icons; |
294 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes)); | 263 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)); | 264 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes)); |
296 | 265 |
297 SetDisplayDeviceScaleFactor(3.0f); | 266 SetDisplayDeviceScaleFactor(3.0f); |
298 GURL url = FindBestMatchingIcon(icons); | 267 GURL url = FindBestMatchingIcon(icons); |
299 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); | 268 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
300 } | 269 } |
301 | 270 |
302 TEST_F(ShortcutHelperTest, DoNotUseOtherDensities) { | 271 TEST_F(ManifestIconSelectorTest, DoNotUseOtherDensities) { |
303 // If there are only icons of densities that are not the current display | 272 // If there are only icons of densities that are not the current display |
304 // density or the default density, they are ignored. | 273 // density or the default density, they are ignored. |
305 std::vector<gfx::Size> sizes; | 274 std::vector<gfx::Size> sizes; |
306 sizes.push_back(gfx::Size(2, 2)); | 275 sizes.push_back(gfx::Size(2, 2)); |
307 | 276 |
308 std::vector<content::Manifest::Icon> icons; | 277 std::vector<content::Manifest::Icon> icons; |
309 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)); |
310 | 279 |
311 SetDisplayDeviceScaleFactor(3.0f); | 280 SetDisplayDeviceScaleFactor(3.0f); |
312 GURL url = FindBestMatchingIcon(icons); | 281 GURL url = FindBestMatchingIcon(icons); |
313 EXPECT_TRUE(url.is_empty()); | 282 EXPECT_TRUE(url.is_empty()); |
314 } | 283 } |
315 | 284 |
316 TEST_F(ShortcutHelperTest, NotSquareIconsAreIgnored) { | 285 TEST_F(ManifestIconSelectorTest, NotSquareIconsAreIgnored) { |
317 std::vector<gfx::Size> sizes; | 286 std::vector<gfx::Size> sizes; |
318 sizes.push_back(gfx::Size(20, 2)); | 287 sizes.push_back(gfx::Size(20, 2)); |
319 | 288 |
320 std::vector<content::Manifest::Icon> icons; | 289 std::vector<content::Manifest::Icon> icons; |
321 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes)); | 290 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes)); |
322 | 291 |
323 GURL url = FindBestMatchingIcon(icons); | 292 GURL url = FindBestMatchingIcon(icons); |
324 EXPECT_TRUE(url.is_empty()); | 293 EXPECT_TRUE(url.is_empty()); |
325 } | 294 } |
326 | 295 |
327 TEST_F(ShortcutHelperTest, ClosestIconToPreferred) { | 296 TEST_F(ManifestIconSelectorTest, ClosestIconToPreferred) { |
328 // This test verifies ShortcutHelper::FindBestMatchingIcon by passing | 297 // This test verifies ManifestIconSelector::FindBestMatchingIcon by passing |
329 // different icon sizes and checking which one is picked. | 298 // 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 | 299 // The Device Scale Factor is 1.0 and the preferred icon size is returned by |
331 // GetPreferredIconSizeInDp(). | 300 // GetPreferredIconSizeInDp(). |
332 int very_small = GetPreferredIconSizeInDp() / 4; | 301 int very_small = GetPreferredIconSizeInDp() / 4; |
333 int small = GetPreferredIconSizeInDp() / 2; | 302 int small = GetPreferredIconSizeInDp() / 2; |
334 int bit_small = GetPreferredIconSizeInDp() - 1; | 303 int bit_small = GetPreferredIconSizeInDp() - 1; |
335 int bit_big = GetPreferredIconSizeInDp() + 1; | 304 int bit_big = GetPreferredIconSizeInDp() + 1; |
336 int big = GetPreferredIconSizeInDp() * 2; | 305 int big = GetPreferredIconSizeInDp() * 2; |
337 int very_big = GetPreferredIconSizeInDp() * 4; | 306 int very_big = GetPreferredIconSizeInDp() * 4; |
338 | 307 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 403 |
435 std::vector<content::Manifest::Icon> icons; | 404 std::vector<content::Manifest::Icon> icons; |
436 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_1)); | 405 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)); | 406 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2)); |
438 | 407 |
439 GURL url = FindBestMatchingIcon(icons); | 408 GURL url = FindBestMatchingIcon(icons); |
440 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 409 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
441 } | 410 } |
442 } | 411 } |
443 | 412 |
444 TEST_F(ShortcutHelperTest, UseAnyIfNoPreferredSize) { | 413 TEST_F(ManifestIconSelectorTest, UseAnyIfNoPreferredSize) { |
445 // 'any' (ie. gfx::Size(0,0)) should be used if there is no icon of a | 414 // '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 | 415 // preferred size. An icon with the current device scale factor is preferred |
447 // over one with the default density. | 416 // over one with the default density. |
448 | 417 |
449 // 'any' with preferred size => preferred size | 418 // 'any' with preferred size => preferred size |
450 { | 419 { |
451 std::vector<gfx::Size> sizes_1; | 420 std::vector<gfx::Size> sizes_1; |
452 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), | 421 sizes_1.push_back(gfx::Size(GetPreferredIconSizeInDp(), |
453 GetPreferredIconSizeInDp())); | 422 GetPreferredIconSizeInDp())); |
454 std::vector<gfx::Size> sizes_2; | 423 std::vector<gfx::Size> sizes_2; |
(...skipping 30 matching lines...) Expand all Loading... |
485 | 454 |
486 std::vector<content::Manifest::Icon> icons; | 455 std::vector<content::Manifest::Icon> icons; |
487 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes)); | 456 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)); | 457 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 3.0, sizes)); |
489 | 458 |
490 SetDisplayDeviceScaleFactor(3.0f); | 459 SetDisplayDeviceScaleFactor(3.0f); |
491 GURL url = FindBestMatchingIcon(icons); | 460 GURL url = FindBestMatchingIcon(icons); |
492 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 461 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
493 } | 462 } |
494 } | 463 } |
OLD | NEW |