| OLD | NEW |
| 1 // Copyright 2015 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/manifest/manifest_icon_selector.h" | 5 #include "content/public/browser/manifest_icon_selector.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace content { |
| 15 |
| 14 using IconPurpose = content::Manifest::Icon::IconPurpose; | 16 using IconPurpose = content::Manifest::Icon::IconPurpose; |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 const int kIdealIconSize = 144; | 20 const int kIdealIconSize = 144; |
| 19 const int kMinimumIconSize = 0; | 21 const int kMinimumIconSize = 0; |
| 20 | 22 |
| 21 static content::Manifest::Icon CreateIcon(const std::string& url, | 23 static content::Manifest::Icon CreateIcon(const std::string& url, |
| 22 const std::string& type, | 24 const std::string& type, |
| 23 const std::vector<gfx::Size> sizes, | 25 const std::vector<gfx::Size> sizes, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 std::vector<gfx::Size> sizes_48; | 101 std::vector<gfx::Size> sizes_48; |
| 100 sizes_48.push_back(gfx::Size(48, 48)); | 102 sizes_48.push_back(gfx::Size(48, 48)); |
| 101 | 103 |
| 102 std::vector<gfx::Size> sizes_96; | 104 std::vector<gfx::Size> sizes_96; |
| 103 sizes_96.push_back(gfx::Size(96, 96)); | 105 sizes_96.push_back(gfx::Size(96, 96)); |
| 104 | 106 |
| 105 std::vector<gfx::Size> sizes_144; | 107 std::vector<gfx::Size> sizes_144; |
| 106 sizes_144.push_back(gfx::Size(144, 144)); | 108 sizes_144.push_back(gfx::Size(144, 144)); |
| 107 | 109 |
| 108 std::vector<content::Manifest::Icon> icons; | 110 std::vector<content::Manifest::Icon> icons; |
| 109 icons.push_back( | 111 icons.push_back(CreateIcon("http://foo.com/icon_48.png", "", sizes_48, |
| 110 CreateIcon("http://foo.com/icon_48.png", "", sizes_48, IconPurpose::BADGE)
); | 112 IconPurpose::BADGE)); |
| 111 icons.push_back( | 113 icons.push_back( |
| 112 CreateIcon("http://foo.com/icon_96.png", "", sizes_96, IconPurpose::ANY)); | 114 CreateIcon("http://foo.com/icon_96.png", "", sizes_96, IconPurpose::ANY)); |
| 113 icons.push_back(CreateIcon("http://foo.com/icon_144.png", "", sizes_144, | 115 icons.push_back(CreateIcon("http://foo.com/icon_144.png", "", sizes_144, |
| 114 IconPurpose::ANY)); | 116 IconPurpose::ANY)); |
| 115 | 117 |
| 116 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 118 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 117 icons, 48, kMinimumIconSize, IconPurpose::BADGE); | 119 icons, 48, kMinimumIconSize, IconPurpose::BADGE); |
| 118 EXPECT_EQ("http://foo.com/icon_48.png", url.spec()); | 120 EXPECT_EQ("http://foo.com/icon_48.png", url.spec()); |
| 119 | 121 |
| 120 url = ManifestIconSelector::FindBestMatchingIcon( | 122 url = ManifestIconSelector::FindBestMatchingIcon(icons, 48, kMinimumIconSize, |
| 121 icons, 48, kMinimumIconSize, IconPurpose::ANY); | 123 IconPurpose::ANY); |
| 122 EXPECT_EQ("http://foo.com/icon_96.png", url.spec()); | 124 EXPECT_EQ("http://foo.com/icon_96.png", url.spec()); |
| 123 | 125 |
| 124 url = ManifestIconSelector::FindBestMatchingIcon(icons, 96, kMinimumIconSize, | 126 url = ManifestIconSelector::FindBestMatchingIcon(icons, 96, kMinimumIconSize, |
| 125 IconPurpose::BADGE); | 127 IconPurpose::BADGE); |
| 126 EXPECT_EQ("http://foo.com/icon_48.png", url.spec()); | 128 EXPECT_EQ("http://foo.com/icon_48.png", url.spec()); |
| 127 | 129 |
| 128 url = ManifestIconSelector::FindBestMatchingIcon(icons, 96, 96, | 130 url = ManifestIconSelector::FindBestMatchingIcon(icons, 96, 96, |
| 129 IconPurpose::BADGE); | 131 IconPurpose::BADGE); |
| 130 EXPECT_TRUE(url.is_empty()); | 132 EXPECT_TRUE(url.is_empty()); |
| 131 | 133 |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 icons.push_back( | 488 icons.push_back( |
| 487 CreateIcon("http://foo.com/icon_no2.png", "", sizes, IconPurpose::ANY)); | 489 CreateIcon("http://foo.com/icon_no2.png", "", sizes, IconPurpose::ANY)); |
| 488 icons.push_back( | 490 icons.push_back( |
| 489 CreateIcon("http://foo.com/icon.png", "", sizes, IconPurpose::ANY)); | 491 CreateIcon("http://foo.com/icon.png", "", sizes, IconPurpose::ANY)); |
| 490 | 492 |
| 491 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 493 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 492 icons, kIdealIconSize * 3, kMinimumIconSize, IconPurpose::ANY); | 494 icons, kIdealIconSize * 3, kMinimumIconSize, IconPurpose::ANY); |
| 493 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 495 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
| 494 } | 496 } |
| 495 } | 497 } |
| 498 |
| 499 } // namespace content |
| OLD | NEW |