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

Side by Side Diff: chrome/browser/banners/webapp_manifest_validator_unittest.cc

Issue 2050933002: Upstream: Add additional checks before creating a WebAPK after clicking "Add to Homescreen" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'create_webapk_requirements_enum_class' into create_webapk_requirements2 Created 4 years, 5 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
« no previous file with comments | « chrome/browser/banners/webapp_manifest_validator.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/banners/webapp_manifest_validator.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "content/public/common/manifest.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/public/platform/WebDisplayMode.h"
11
12 namespace banners {
13
14 class WebappManifestValidatorUnitTest : public testing::Test {
15 public:
16 WebappManifestValidatorUnitTest() { }
17
18 protected:
19 static base::NullableString16 ToNullableUTF16(const std::string& str) {
20 return base::NullableString16(base::UTF8ToUTF16(str), false);
21 }
22
23 static content::Manifest GetValidManifest() {
24 content::Manifest manifest;
25 manifest.name = ToNullableUTF16("foo");
26 manifest.short_name = ToNullableUTF16("bar");
27 manifest.start_url = GURL("http://example.com");
28 manifest.display = blink::WebDisplayModeStandalone;
29
30 content::Manifest::Icon icon;
31 icon.type = ToNullableUTF16("image/png");
32 icon.sizes.push_back(gfx::Size(144, 144));
33 manifest.icons.push_back(icon);
34
35 return manifest;
36 }
37
38 static bool IsManifestGood(const content::Manifest& manifest) {
39 // The second argument is the web_contents pointer, which is used for
40 // developer debug logging to the console. The logging is skipped inside the
41 // method if a null web_contents pointer is provided, so this is safe.
42 // The third argument is the is_debug_mode boolean value, which is true only
43 // when it is triggered by the developer's action in DevTools.
44 OutputDeveloperMessageCode code = OutputDeveloperMessageCode::kNone;
45 return webapp_manifest_validator::IsManifestGoodForWebapp(manifest, &code);
46 }
47 };
48
49 TEST_F(WebappManifestValidatorUnitTest, EmptyManifestIsInvalid) {
50 content::Manifest manifest;
51 EXPECT_FALSE(IsManifestGood(manifest));
52 }
53
54 TEST_F(WebappManifestValidatorUnitTest, CheckMinimalValidManifest) {
55 content::Manifest manifest = GetValidManifest();
56 EXPECT_TRUE(IsManifestGood(manifest));
57 }
58
59 TEST_F(WebappManifestValidatorUnitTest, ManifestRequiresNameORShortName) {
60 content::Manifest manifest = GetValidManifest();
61
62 manifest.name = base::NullableString16();
63 EXPECT_TRUE(IsManifestGood(manifest));
64
65 manifest.name = ToNullableUTF16("foo");
66 manifest.short_name = base::NullableString16();
67 EXPECT_TRUE(IsManifestGood(manifest));
68
69 manifest.name = base::NullableString16();
70 EXPECT_FALSE(IsManifestGood(manifest));
71 }
72
73 TEST_F(WebappManifestValidatorUnitTest,
74 ManifestRequiresNonEmptyNameORShortName) {
75 content::Manifest manifest = GetValidManifest();
76
77 manifest.name = ToNullableUTF16("");
78 EXPECT_TRUE(IsManifestGood(manifest));
79
80 manifest.name = ToNullableUTF16("foo");
81 manifest.short_name = ToNullableUTF16("");
82 EXPECT_TRUE(IsManifestGood(manifest));
83
84 manifest.name = ToNullableUTF16("");
85 EXPECT_FALSE(IsManifestGood(manifest));
86 }
87
88 TEST_F(WebappManifestValidatorUnitTest, ManifestRequiresValidStartURL) {
89 content::Manifest manifest = GetValidManifest();
90
91 manifest.start_url = GURL();
92 EXPECT_FALSE(IsManifestGood(manifest));
93
94 manifest.start_url = GURL("/");
95 EXPECT_FALSE(IsManifestGood(manifest));
96 }
97
98 TEST_F(WebappManifestValidatorUnitTest, ManifestRequiresImagePNG) {
99 content::Manifest manifest = GetValidManifest();
100
101 manifest.icons[0].type = ToNullableUTF16("image/gif");
102 EXPECT_FALSE(IsManifestGood(manifest));
103 manifest.icons[0].type = base::NullableString16();
104 EXPECT_FALSE(IsManifestGood(manifest));
105 }
106
107 TEST_F(WebappManifestValidatorUnitTest, ManifestRequiresMinimalSize) {
108 content::Manifest manifest = GetValidManifest();
109
110 // The icon MUST be 144x144 size at least.
111 manifest.icons[0].sizes[0] = gfx::Size(1, 1);
112 EXPECT_FALSE(IsManifestGood(manifest));
113
114 // If one of the sizes match the requirement, it should be accepted.
115 manifest.icons[0].sizes.push_back(gfx::Size(144, 144));
116 EXPECT_TRUE(IsManifestGood(manifest));
117
118 // Higher than the required size is okay.
119 manifest.icons[0].sizes[1] = gfx::Size(200, 200);
120 EXPECT_TRUE(IsManifestGood(manifest));
121
122 // Non-square is okay.
123 manifest.icons[0].sizes[1] = gfx::Size(144, 200);
124 EXPECT_TRUE(IsManifestGood(manifest));
125
126 // The representation of the keyword 'any' should be recognized.
127 manifest.icons[0].sizes[1] = gfx::Size(0, 0);
128 EXPECT_TRUE(IsManifestGood(manifest));
129 }
130
131 TEST_F(WebappManifestValidatorUnitTest, ManifestDisplayStandaloneFullscreen) {
132 content::Manifest manifest = GetValidManifest();
133
134 manifest.display = blink::WebDisplayModeUndefined;
135 EXPECT_FALSE(IsManifestGood(manifest));
136
137 manifest.display = blink::WebDisplayModeBrowser;
138 EXPECT_FALSE(IsManifestGood(manifest));
139
140 manifest.display = blink::WebDisplayModeMinimalUi;
141 EXPECT_FALSE(IsManifestGood(manifest));
142
143 manifest.display = blink::WebDisplayModeStandalone;
144 EXPECT_TRUE(IsManifestGood(manifest));
145
146 manifest.display = blink::WebDisplayModeFullscreen;
147 EXPECT_TRUE(IsManifestGood(manifest));
148 }
149
150 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/webapp_manifest_validator.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698