| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/installable/installable_manager.h" | 5 #include "chrome/browser/installable/installable_manager.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/WebKit/public/platform/WebDisplayMode.h" | 9 #include "third_party/WebKit/public/platform/WebDisplayMode.h" |
| 10 | 10 |
| 11 using IconPurpose = content::Manifest::Icon::IconPurpose; |
| 12 |
| 11 class InstallableManagerUnitTest : public testing::Test { | 13 class InstallableManagerUnitTest : public testing::Test { |
| 12 public: | 14 public: |
| 13 InstallableManagerUnitTest() : manager_(new InstallableManager(nullptr)) { } | 15 InstallableManagerUnitTest() : manager_(new InstallableManager(nullptr)) { } |
| 14 | 16 |
| 15 protected: | 17 protected: |
| 16 static base::NullableString16 ToNullableUTF16(const std::string& str) { | 18 static base::NullableString16 ToNullableUTF16(const std::string& str) { |
| 17 return base::NullableString16(base::UTF8ToUTF16(str), false); | 19 return base::NullableString16(base::UTF8ToUTF16(str), false); |
| 18 } | 20 } |
| 19 | 21 |
| 20 static content::Manifest GetValidManifest() { | 22 static content::Manifest GetValidManifest() { |
| 21 content::Manifest manifest; | 23 content::Manifest manifest; |
| 22 manifest.name = ToNullableUTF16("foo"); | 24 manifest.name = ToNullableUTF16("foo"); |
| 23 manifest.short_name = ToNullableUTF16("bar"); | 25 manifest.short_name = ToNullableUTF16("bar"); |
| 24 manifest.start_url = GURL("http://example.com"); | 26 manifest.start_url = GURL("http://example.com"); |
| 25 manifest.display = blink::WebDisplayModeStandalone; | 27 manifest.display = blink::WebDisplayModeStandalone; |
| 26 | 28 |
| 27 content::Manifest::Icon icon; | 29 content::Manifest::Icon icon; |
| 28 icon.type = base::ASCIIToUTF16("image/png"); | 30 icon.type = base::ASCIIToUTF16("image/png"); |
| 29 icon.sizes.push_back(gfx::Size(144, 144)); | 31 icon.sizes.push_back(gfx::Size(144, 144)); |
| 32 icon.purpose.push_back(IconPurpose::ANY); |
| 30 manifest.icons.push_back(icon); | 33 manifest.icons.push_back(icon); |
| 31 | 34 |
| 32 return manifest; | 35 return manifest; |
| 33 } | 36 } |
| 34 | 37 |
| 35 bool IsManifestValid(const content::Manifest& manifest) { | 38 bool IsManifestValid(const content::Manifest& manifest) { |
| 36 // Explicitly reset the error code before running the method. | 39 // Explicitly reset the error code before running the method. |
| 37 manager_->set_installable_error(NO_ERROR_DETECTED); | 40 manager_->set_installable_error(NO_ERROR_DETECTED); |
| 38 return manager_->IsManifestValidForWebApp(manifest); | 41 return manager_->IsManifestValidForWebApp(manifest); |
| 39 } | 42 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 manifest.icons[0].src = GURL("http://example.com/icon.PNG"); | 127 manifest.icons[0].src = GURL("http://example.com/icon.PNG"); |
| 125 EXPECT_TRUE(IsManifestValid(manifest)); | 128 EXPECT_TRUE(IsManifestValid(manifest)); |
| 126 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); | 129 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); |
| 127 | 130 |
| 128 // Non-png extensions are rejected. | 131 // Non-png extensions are rejected. |
| 129 manifest.icons[0].src = GURL("http://example.com/icon.gif"); | 132 manifest.icons[0].src = GURL("http://example.com/icon.gif"); |
| 130 EXPECT_FALSE(IsManifestValid(manifest)); | 133 EXPECT_FALSE(IsManifestValid(manifest)); |
| 131 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode()); | 134 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode()); |
| 132 } | 135 } |
| 133 | 136 |
| 137 TEST_F(InstallableManagerUnitTest, ManifestRequiresPurposeAny) { |
| 138 content::Manifest manifest = GetValidManifest(); |
| 139 |
| 140 // The icon MUST have IconPurpose::ANY at least. |
| 141 manifest.icons[0].purpose[0] = IconPurpose::BADGE; |
| 142 EXPECT_FALSE(IsManifestValid(manifest)); |
| 143 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode()); |
| 144 |
| 145 // If one of the icon purposes match the requirement, it should be accepted. |
| 146 manifest.icons[0].purpose.push_back(IconPurpose::ANY); |
| 147 EXPECT_TRUE(IsManifestValid(manifest)); |
| 148 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); |
| 149 } |
| 150 |
| 134 TEST_F(InstallableManagerUnitTest, ManifestRequiresMinimalSize) { | 151 TEST_F(InstallableManagerUnitTest, ManifestRequiresMinimalSize) { |
| 135 content::Manifest manifest = GetValidManifest(); | 152 content::Manifest manifest = GetValidManifest(); |
| 136 | 153 |
| 137 // The icon MUST be 144x144 size at least. | 154 // The icon MUST be 144x144 size at least. |
| 138 manifest.icons[0].sizes[0] = gfx::Size(1, 1); | 155 manifest.icons[0].sizes[0] = gfx::Size(1, 1); |
| 139 EXPECT_FALSE(IsManifestValid(manifest)); | 156 EXPECT_FALSE(IsManifestValid(manifest)); |
| 140 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode()); | 157 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode()); |
| 141 | 158 |
| 142 manifest.icons[0].sizes[0] = gfx::Size(143, 143); | 159 manifest.icons[0].sizes[0] = gfx::Size(143, 143); |
| 143 EXPECT_FALSE(IsManifestValid(manifest)); | 160 EXPECT_FALSE(IsManifestValid(manifest)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode()); | 197 EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode()); |
| 181 | 198 |
| 182 manifest.display = blink::WebDisplayModeStandalone; | 199 manifest.display = blink::WebDisplayModeStandalone; |
| 183 EXPECT_TRUE(IsManifestValid(manifest)); | 200 EXPECT_TRUE(IsManifestValid(manifest)); |
| 184 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); | 201 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); |
| 185 | 202 |
| 186 manifest.display = blink::WebDisplayModeFullscreen; | 203 manifest.display = blink::WebDisplayModeFullscreen; |
| 187 EXPECT_TRUE(IsManifestValid(manifest)); | 204 EXPECT_TRUE(IsManifestValid(manifest)); |
| 188 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); | 205 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); |
| 189 } | 206 } |
| OLD | NEW |