Chromium Code Reviews| 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 |
|
please use gerrit instead
2017/06/12 23:57:22
namespace content { --- should be here.
zino
2017/06/13 16:07:45
Done.
| |
| 14 using IconPurpose = content::Manifest::Icon::IconPurpose; | 14 using IconPurpose = content::Manifest::Icon::IconPurpose; |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const int kIdealIconSize = 144; | 18 const int kIdealIconSize = 144; |
| 19 const int kMinimumIconSize = 0; | 19 const int kMinimumIconSize = 0; |
| 20 | 20 |
| 21 static content::Manifest::Icon CreateIcon(const std::string& url, | 21 static content::Manifest::Icon CreateIcon(const std::string& url, |
| 22 const std::string& type, | 22 const std::string& type, |
| 23 const std::vector<gfx::Size> sizes, | 23 const std::vector<gfx::Size> sizes, |
| 24 IconPurpose purpose) { | 24 IconPurpose purpose) { |
| 25 content::Manifest::Icon icon; | 25 content::Manifest::Icon icon; |
| 26 icon.src = GURL(url); | 26 icon.src = GURL(url); |
| 27 icon.type = base::UTF8ToUTF16(type); | 27 icon.type = base::UTF8ToUTF16(type); |
| 28 icon.sizes = sizes; | 28 icon.sizes = sizes; |
| 29 icon.purpose.push_back(purpose); | 29 icon.purpose.push_back(purpose); |
| 30 | 30 |
| 31 return icon; | 31 return icon; |
| 32 } | 32 } |
| 33 | 33 |
| 34 } // anonymous namespace | 34 } // anonymous namespace |
| 35 | 35 |
| 36 namespace content { | |
| 37 | |
| 36 TEST(ManifestIconSelector, NoIcons) { | 38 TEST(ManifestIconSelector, NoIcons) { |
| 37 // No icons should return the empty URL. | 39 // No icons should return the empty URL. |
| 38 std::vector<content::Manifest::Icon> icons; | 40 std::vector<content::Manifest::Icon> icons; |
| 39 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 41 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 40 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 42 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 41 EXPECT_TRUE(url.is_empty()); | 43 EXPECT_TRUE(url.is_empty()); |
| 42 } | 44 } |
| 43 | 45 |
| 44 TEST(ManifestIconSelector, NoSizes) { | 46 TEST(ManifestIconSelector, NoSizes) { |
| 45 // Icon with no sizes are ignored. | 47 // Icon with no sizes are ignored. |
| (...skipping 53 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 } | |
|
please use gerrit instead
2017/06/12 23:57:22
newline above.
// namespace content
zino
2017/06/13 16:07:45
Done.
| |
| OLD | NEW |