Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: chrome/browser/installable/installable_manager_unittest.cc

Issue 2248293002: Do not install WebAPKs with web manifests with invalid URL components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 17 matching lines...) Expand all
28 icon.type = ToNullableUTF16("image/png"); 28 icon.type = ToNullableUTF16("image/png");
29 icon.sizes.push_back(gfx::Size(144, 144)); 29 icon.sizes.push_back(gfx::Size(144, 144));
30 manifest.icons.push_back(icon); 30 manifest.icons.push_back(icon);
31 31
32 return manifest; 32 return manifest;
33 } 33 }
34 34
35 bool IsManifestValid(const content::Manifest& manifest) { 35 bool IsManifestValid(const content::Manifest& manifest) {
36 // Explicitly reset the error code before running the method. 36 // Explicitly reset the error code before running the method.
37 manager_->set_installable_error(NO_ERROR_DETECTED); 37 manager_->set_installable_error(NO_ERROR_DETECTED);
38 return manager_->IsManifestValidForWebApp(manifest); 38 return manager_->IsManifestValidForWebApp(GURL(), manifest);
39 } 39 }
40 40
41 InstallableStatusCode GetErrorCode() { 41 InstallableStatusCode GetErrorCode() {
42 return manager_->installable_error(); 42 return manager_->installable_error();
43 } 43 }
44 44
45 private: 45 private:
46 std::unique_ptr<InstallableManager> manager_; 46 std::unique_ptr<InstallableManager> manager_;
47 }; 47 };
48 48
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 manifest.start_url = GURL(); 98 manifest.start_url = GURL();
99 EXPECT_FALSE(IsManifestValid(manifest)); 99 EXPECT_FALSE(IsManifestValid(manifest));
100 EXPECT_EQ(START_URL_NOT_VALID, GetErrorCode()); 100 EXPECT_EQ(START_URL_NOT_VALID, GetErrorCode());
101 101
102 manifest.start_url = GURL("/"); 102 manifest.start_url = GURL("/");
103 EXPECT_FALSE(IsManifestValid(manifest)); 103 EXPECT_FALSE(IsManifestValid(manifest));
104 EXPECT_EQ(START_URL_NOT_VALID, GetErrorCode()); 104 EXPECT_EQ(START_URL_NOT_VALID, GetErrorCode());
105 } 105 }
106 106
107 TEST_F(InstallableManagerUnitTest, ManifestRequiresPasswordFreeUrls) {
108 content::Manifest manifest = GetValidManifest();
109 manifest.start_url = GURL("http://answer:42@life/universe/and/everything");
110 EXPECT_FALSE(IsManifestValid(manifest));
111 EXPECT_EQ(URL_USERNAME_AND_PASSWORD_NOT_SUPPORTED, GetErrorCode());
112
113 manifest = GetValidManifest();
114 manifest.icons[0].src = GURL("http://question:unknown@life/universe/and/everyt hing");
115 EXPECT_FALSE(IsManifestValid(manifest));
116 EXPECT_EQ(URL_USERNAME_AND_PASSWORD_NOT_SUPPORTED, GetErrorCode());
117 }
118
107 TEST_F(InstallableManagerUnitTest, ManifestRequiresImagePNG) { 119 TEST_F(InstallableManagerUnitTest, ManifestRequiresImagePNG) {
108 content::Manifest manifest = GetValidManifest(); 120 content::Manifest manifest = GetValidManifest();
109 121
110 manifest.icons[0].type = ToNullableUTF16("image/gif"); 122 manifest.icons[0].type = ToNullableUTF16("image/gif");
111 EXPECT_FALSE(IsManifestValid(manifest)); 123 EXPECT_FALSE(IsManifestValid(manifest));
112 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode()); 124 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
113 125
114 manifest.icons[0].type = base::NullableString16(); 126 manifest.icons[0].type = base::NullableString16();
115 EXPECT_FALSE(IsManifestValid(manifest)); 127 EXPECT_FALSE(IsManifestValid(manifest));
116 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode()); 128 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode()); 192 EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode());
181 193
182 manifest.display = blink::WebDisplayModeStandalone; 194 manifest.display = blink::WebDisplayModeStandalone;
183 EXPECT_TRUE(IsManifestValid(manifest)); 195 EXPECT_TRUE(IsManifestValid(manifest));
184 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); 196 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
185 197
186 manifest.display = blink::WebDisplayModeFullscreen; 198 manifest.display = blink::WebDisplayModeFullscreen;
187 EXPECT_TRUE(IsManifestValid(manifest)); 199 EXPECT_TRUE(IsManifestValid(manifest));
188 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); 200 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
189 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698