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

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

Issue 2160513002: Extract AppBannerDataFetcher into an InstallableManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments 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 2015 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/banners/app_banner_data_fetcher.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 namespace banners { 11 class InstallableManagerUnitTest : public testing::Test {
12
13 class AppBannerDataFetcherUnitTest : public testing::Test {
14 public: 12 public:
15 AppBannerDataFetcherUnitTest() { } 13 InstallableManagerUnitTest() : manager_(new InstallableManager(nullptr)) { }
16 14
17 protected: 15 protected:
18 static base::NullableString16 ToNullableUTF16(const std::string& str) { 16 static base::NullableString16 ToNullableUTF16(const std::string& str) {
19 return base::NullableString16(base::UTF8ToUTF16(str), false); 17 return base::NullableString16(base::UTF8ToUTF16(str), false);
20 } 18 }
21 19
22 static content::Manifest GetValidManifest() { 20 static content::Manifest GetValidManifest() {
23 content::Manifest manifest; 21 content::Manifest manifest;
24 manifest.name = ToNullableUTF16("foo"); 22 manifest.name = ToNullableUTF16("foo");
25 manifest.short_name = ToNullableUTF16("bar"); 23 manifest.short_name = ToNullableUTF16("bar");
26 manifest.start_url = GURL("http://example.com"); 24 manifest.start_url = GURL("http://example.com");
27 manifest.display = blink::WebDisplayModeStandalone; 25 manifest.display = blink::WebDisplayModeStandalone;
28 26
29 content::Manifest::Icon icon; 27 content::Manifest::Icon icon;
30 icon.type = ToNullableUTF16("image/png"); 28 icon.type = ToNullableUTF16("image/png");
31 icon.sizes.push_back(gfx::Size(144, 144)); 29 icon.sizes.push_back(gfx::Size(144, 144));
32 manifest.icons.push_back(icon); 30 manifest.icons.push_back(icon);
33 31
34 return manifest; 32 return manifest;
35 } 33 }
36 34
37 static bool IsManifestValid(const content::Manifest& manifest) { 35 bool IsManifestValid(const content::Manifest& manifest) {
38 // The second argument is the web_contents pointer, which is used for 36 // Explicitly reset the error code before running the method.
39 // developer debug logging to the console. The logging is skipped inside the 37 manager_->set_installable_error(NO_ERROR_DETECTED);
40 // method if a null web_contents pointer is provided, so this is safe. 38 return manager_->IsManifestValidForWebApp(manifest);
41 // The third argument is the is_debug_mode boolean value, which is true only
42 // when it is triggered by the developer's action in DevTools.
43 return AppBannerDataFetcher::IsManifestValidForWebApp(manifest, nullptr,
44 false);
45 } 39 }
40
41 InstallableErrorCode GetErrorCode() {
42 return manager_->installable_error();
43 }
44
45 private:
46 std::unique_ptr<InstallableManager> manager_;
46 }; 47 };
47 48
48 TEST_F(AppBannerDataFetcherUnitTest, EmptyManifestIsInvalid) { 49 TEST_F(InstallableManagerUnitTest, EmptyManifestIsInvalid) {
49 content::Manifest manifest; 50 content::Manifest manifest;
50 EXPECT_FALSE(IsManifestValid(manifest)); 51 EXPECT_FALSE(IsManifestValid(manifest));
52 EXPECT_EQ(MANIFEST_EMPTY, GetErrorCode());
51 } 53 }
52 54
53 TEST_F(AppBannerDataFetcherUnitTest, CheckMinimalValidManifest) { 55 TEST_F(InstallableManagerUnitTest, CheckMinimalValidManifest) {
54 content::Manifest manifest = GetValidManifest(); 56 content::Manifest manifest = GetValidManifest();
55 EXPECT_TRUE(IsManifestValid(manifest)); 57 EXPECT_TRUE(IsManifestValid(manifest));
58 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
56 } 59 }
57 60
58 TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresNameORShortName) { 61 TEST_F(InstallableManagerUnitTest, ManifestRequiresNameOrShortName) {
59 content::Manifest manifest = GetValidManifest(); 62 content::Manifest manifest = GetValidManifest();
60 63
61 manifest.name = base::NullableString16(); 64 manifest.name = base::NullableString16();
62 EXPECT_TRUE(IsManifestValid(manifest)); 65 EXPECT_TRUE(IsManifestValid(manifest));
66 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
63 67
64 manifest.name = ToNullableUTF16("foo"); 68 manifest.name = ToNullableUTF16("foo");
65 manifest.short_name = base::NullableString16(); 69 manifest.short_name = base::NullableString16();
66 EXPECT_TRUE(IsManifestValid(manifest)); 70 EXPECT_TRUE(IsManifestValid(manifest));
71 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
67 72
68 manifest.name = base::NullableString16(); 73 manifest.name = base::NullableString16();
69 EXPECT_FALSE(IsManifestValid(manifest)); 74 EXPECT_FALSE(IsManifestValid(manifest));
75 EXPECT_EQ(MANIFEST_MISSING_NAME_OR_SHORT_NAME, GetErrorCode());
70 } 76 }
71 77
72 TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresNonEmptyNameORShortName) { 78 TEST_F(InstallableManagerUnitTest, ManifestRequiresNonEmptyNameORShortName) {
73 content::Manifest manifest = GetValidManifest(); 79 content::Manifest manifest = GetValidManifest();
74 80
75 manifest.name = ToNullableUTF16(""); 81 manifest.name = ToNullableUTF16("");
76 EXPECT_TRUE(IsManifestValid(manifest)); 82 EXPECT_TRUE(IsManifestValid(manifest));
83 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
77 84
78 manifest.name = ToNullableUTF16("foo"); 85 manifest.name = ToNullableUTF16("foo");
79 manifest.short_name = ToNullableUTF16(""); 86 manifest.short_name = ToNullableUTF16("");
80 EXPECT_TRUE(IsManifestValid(manifest)); 87 EXPECT_TRUE(IsManifestValid(manifest));
88 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
81 89
82 manifest.name = ToNullableUTF16(""); 90 manifest.name = ToNullableUTF16("");
83 EXPECT_FALSE(IsManifestValid(manifest)); 91 EXPECT_FALSE(IsManifestValid(manifest));
92 EXPECT_EQ(MANIFEST_MISSING_NAME_OR_SHORT_NAME, GetErrorCode());
84 } 93 }
85 94
86 TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresValidStartURL) { 95 TEST_F(InstallableManagerUnitTest, ManifestRequiresValidStartURL) {
87 content::Manifest manifest = GetValidManifest(); 96 content::Manifest manifest = GetValidManifest();
88 97
89 manifest.start_url = GURL(); 98 manifest.start_url = GURL();
90 EXPECT_FALSE(IsManifestValid(manifest)); 99 EXPECT_FALSE(IsManifestValid(manifest));
100 EXPECT_EQ(START_URL_NOT_VALID, GetErrorCode());
91 101
92 manifest.start_url = GURL("/"); 102 manifest.start_url = GURL("/");
93 EXPECT_FALSE(IsManifestValid(manifest)); 103 EXPECT_FALSE(IsManifestValid(manifest));
104 EXPECT_EQ(START_URL_NOT_VALID, GetErrorCode());
94 } 105 }
95 106
96 TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresImagePNG) { 107 TEST_F(InstallableManagerUnitTest, ManifestRequiresImagePNG) {
97 content::Manifest manifest = GetValidManifest(); 108 content::Manifest manifest = GetValidManifest();
98 109
99 manifest.icons[0].type = ToNullableUTF16("image/gif"); 110 manifest.icons[0].type = ToNullableUTF16("image/gif");
100 EXPECT_FALSE(IsManifestValid(manifest)); 111 EXPECT_FALSE(IsManifestValid(manifest));
112 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
113
101 manifest.icons[0].type = base::NullableString16(); 114 manifest.icons[0].type = base::NullableString16();
102 EXPECT_FALSE(IsManifestValid(manifest)); 115 EXPECT_FALSE(IsManifestValid(manifest));
116 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
117
118 // If the type is null, the icon src will be checked instead.
119 manifest.icons[0].src = GURL("http://example.com/icon.png");
120 EXPECT_TRUE(IsManifestValid(manifest));
121 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
122
123 // Capital file extension is also permissible.
124 manifest.icons[0].src = GURL("http://example.com/icon.PNG");
125 EXPECT_TRUE(IsManifestValid(manifest));
126 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
127
128 // Non-png extensions are rejected.
129 manifest.icons[0].src = GURL("http://example.com/icon.gif");
130 EXPECT_FALSE(IsManifestValid(manifest));
131 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
103 } 132 }
104 133
105 TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresMinimalSize) { 134 TEST_F(InstallableManagerUnitTest, ManifestRequiresMinimalSize) {
106 content::Manifest manifest = GetValidManifest(); 135 content::Manifest manifest = GetValidManifest();
107 136
108 // The icon MUST be 144x144 size at least. 137 // The icon MUST be 144x144 size at least.
109 manifest.icons[0].sizes[0] = gfx::Size(1, 1); 138 manifest.icons[0].sizes[0] = gfx::Size(1, 1);
110 EXPECT_FALSE(IsManifestValid(manifest)); 139 EXPECT_FALSE(IsManifestValid(manifest));
140 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
141
142 manifest.icons[0].sizes[0] = gfx::Size(143, 143);
143 EXPECT_FALSE(IsManifestValid(manifest));
144 EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
111 145
112 // If one of the sizes match the requirement, it should be accepted. 146 // If one of the sizes match the requirement, it should be accepted.
113 manifest.icons[0].sizes.push_back(gfx::Size(144, 144)); 147 manifest.icons[0].sizes.push_back(gfx::Size(144, 144));
114 EXPECT_TRUE(IsManifestValid(manifest)); 148 EXPECT_TRUE(IsManifestValid(manifest));
149 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
115 150
116 // Higher than the required size is okay. 151 // Higher than the required size is okay.
117 manifest.icons[0].sizes[1] = gfx::Size(200, 200); 152 manifest.icons[0].sizes[1] = gfx::Size(200, 200);
118 EXPECT_TRUE(IsManifestValid(manifest)); 153 EXPECT_TRUE(IsManifestValid(manifest));
154 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
119 155
120 // Non-square is okay. 156 // Non-square is okay.
121 manifest.icons[0].sizes[1] = gfx::Size(144, 200); 157 manifest.icons[0].sizes[1] = gfx::Size(144, 200);
122 EXPECT_TRUE(IsManifestValid(manifest)); 158 EXPECT_TRUE(IsManifestValid(manifest));
159 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
123 160
124 // The representation of the keyword 'any' should be recognized. 161 // The representation of the keyword 'any' should be recognized.
125 manifest.icons[0].sizes[1] = gfx::Size(0, 0); 162 manifest.icons[0].sizes[1] = gfx::Size(0, 0);
126 EXPECT_TRUE(IsManifestValid(manifest)); 163 EXPECT_TRUE(IsManifestValid(manifest));
164 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
127 } 165 }
128 166
129 TEST_F(AppBannerDataFetcherUnitTest, ManifestDisplayStandaloneFullscreen) { 167 TEST_F(InstallableManagerUnitTest, ManifestDisplayStandaloneFullscreen) {
130 content::Manifest manifest = GetValidManifest(); 168 content::Manifest manifest = GetValidManifest();
131 169
132 manifest.display = blink::WebDisplayModeUndefined; 170 manifest.display = blink::WebDisplayModeUndefined;
133 EXPECT_FALSE(IsManifestValid(manifest)); 171 EXPECT_FALSE(IsManifestValid(manifest));
172 EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode());
134 173
135 manifest.display = blink::WebDisplayModeBrowser; 174 manifest.display = blink::WebDisplayModeBrowser;
136 EXPECT_FALSE(IsManifestValid(manifest)); 175 EXPECT_FALSE(IsManifestValid(manifest));
176 EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode());
137 177
138 manifest.display = blink::WebDisplayModeMinimalUi; 178 manifest.display = blink::WebDisplayModeMinimalUi;
139 EXPECT_FALSE(IsManifestValid(manifest)); 179 EXPECT_FALSE(IsManifestValid(manifest));
180 EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode());
140 181
141 manifest.display = blink::WebDisplayModeStandalone; 182 manifest.display = blink::WebDisplayModeStandalone;
142 EXPECT_TRUE(IsManifestValid(manifest)); 183 EXPECT_TRUE(IsManifestValid(manifest));
184 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
143 185
144 manifest.display = blink::WebDisplayModeFullscreen; 186 manifest.display = blink::WebDisplayModeFullscreen;
145 EXPECT_TRUE(IsManifestValid(manifest)); 187 EXPECT_TRUE(IsManifestValid(manifest));
188 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
146 } 189 }
147
148 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/installable/installable_manager_browsertest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698