| 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; | 11 using IconPurpose = content::Manifest::Icon::IconPurpose; |
| 12 | 12 |
| 13 class InstallableManagerUnitTest : public testing::Test { | 13 class InstallableManagerUnitTest : public testing::Test { |
| 14 public: | 14 public: |
| 15 InstallableManagerUnitTest() : manager_(new InstallableManager(nullptr)) { } | 15 InstallableManagerUnitTest() : manager_(new InstallableManager(nullptr)) { } |
| 16 | 16 |
| 17 protected: | 17 protected: |
| 18 static base::NullableString16 ToNullableUTF16(const std::string& str) { | 18 static base::NullableString16 ToNullableUTF16(const std::string& str) { |
| 19 return base::NullableString16(base::UTF8ToUTF16(str), false); | 19 return base::NullableString16(base::UTF8ToUTF16(str), false); |
| 20 } | 20 } |
| 21 | 21 |
| 22 static content::Manifest GetValidManifest() { | 22 static content::Manifest GetValidManifest() { |
| 23 content::Manifest manifest; | 23 content::Manifest manifest; |
| 24 manifest.name = ToNullableUTF16("foo"); | 24 manifest.name = ToNullableUTF16("foo"); |
| 25 manifest.short_name = ToNullableUTF16("bar"); | 25 manifest.short_name = ToNullableUTF16("bar"); |
| 26 manifest.start_url = GURL("http://example.com"); | 26 manifest.start_url = GURL("http://example.com"); |
| 27 manifest.display = blink::WebDisplayModeStandalone; | 27 manifest.display = blink::WebDisplayModeStandalone; |
| 28 | 28 |
| 29 content::Manifest::Icon icon; | 29 content::Manifest::Icon primary_icon; |
| 30 icon.type = base::ASCIIToUTF16("image/png"); | 30 primary_icon.type = base::ASCIIToUTF16("image/png"); |
| 31 icon.sizes.push_back(gfx::Size(144, 144)); | 31 primary_icon.sizes.push_back(gfx::Size(144, 144)); |
| 32 icon.purpose.push_back(IconPurpose::ANY); | 32 primary_icon.purpose.push_back(IconPurpose::ANY); |
| 33 manifest.icons.push_back(icon); | 33 manifest.icons.push_back(primary_icon); |
| 34 | 34 |
| 35 // No need to include the optional badge icon as it does not affect the |
| 36 // unit tests. |
| 35 return manifest; | 37 return manifest; |
| 36 } | 38 } |
| 37 | 39 |
| 38 bool IsManifestValid(const content::Manifest& manifest) { | 40 bool IsManifestValid(const content::Manifest& manifest) { |
| 39 // Explicitly reset the error code before running the method. | 41 // Explicitly reset the error code before running the method. |
| 40 manager_->set_installable_error(NO_ERROR_DETECTED); | 42 manager_->set_installable_error(NO_ERROR_DETECTED); |
| 41 return manager_->IsManifestValidForWebApp(manifest); | 43 return manager_->IsManifestValidForWebApp(manifest); |
| 42 } | 44 } |
| 43 | 45 |
| 44 InstallableStatusCode GetErrorCode() { | 46 InstallableStatusCode GetErrorCode() { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode()); | 199 EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode()); |
| 198 | 200 |
| 199 manifest.display = blink::WebDisplayModeStandalone; | 201 manifest.display = blink::WebDisplayModeStandalone; |
| 200 EXPECT_TRUE(IsManifestValid(manifest)); | 202 EXPECT_TRUE(IsManifestValid(manifest)); |
| 201 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); | 203 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); |
| 202 | 204 |
| 203 manifest.display = blink::WebDisplayModeFullscreen; | 205 manifest.display = blink::WebDisplayModeFullscreen; |
| 204 EXPECT_TRUE(IsManifestValid(manifest)); | 206 EXPECT_TRUE(IsManifestValid(manifest)); |
| 205 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); | 207 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); |
| 206 } | 208 } |
| OLD | NEW |