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

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

Issue 2156113002: Replace AppBannerDataFetcher with InstallableManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@banner-refactor
Patch Set: Naming, includes 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
(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/app_banner_data_fetcher.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/WebKit/public/platform/WebDisplayMode.h"
10
11 namespace banners {
12
13 class AppBannerDataFetcherUnitTest : public testing::Test {
14 public:
15 AppBannerDataFetcherUnitTest() { }
16
17 protected:
18 static base::NullableString16 ToNullableUTF16(const std::string& str) {
19 return base::NullableString16(base::UTF8ToUTF16(str), false);
20 }
21
22 static content::Manifest GetValidManifest() {
23 content::Manifest manifest;
24 manifest.name = ToNullableUTF16("foo");
25 manifest.short_name = ToNullableUTF16("bar");
26 manifest.start_url = GURL("http://example.com");
27 manifest.display = blink::WebDisplayModeStandalone;
28
29 content::Manifest::Icon icon;
30 icon.type = ToNullableUTF16("image/png");
31 icon.sizes.push_back(gfx::Size(144, 144));
32 manifest.icons.push_back(icon);
33
34 return manifest;
35 }
36
37 static bool IsManifestValid(const content::Manifest& manifest) {
38 // The second argument is the web_contents pointer, which is used for
39 // developer debug logging to the console. The logging is skipped inside the
40 // method if a null web_contents pointer is provided, so this is safe.
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 }
46 };
47
48 TEST_F(AppBannerDataFetcherUnitTest, EmptyManifestIsInvalid) {
49 content::Manifest manifest;
50 EXPECT_FALSE(IsManifestValid(manifest));
51 }
52
53 TEST_F(AppBannerDataFetcherUnitTest, CheckMinimalValidManifest) {
54 content::Manifest manifest = GetValidManifest();
55 EXPECT_TRUE(IsManifestValid(manifest));
56 }
57
58 TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresNameORShortName) {
59 content::Manifest manifest = GetValidManifest();
60
61 manifest.name = base::NullableString16();
62 EXPECT_TRUE(IsManifestValid(manifest));
63
64 manifest.name = ToNullableUTF16("foo");
65 manifest.short_name = base::NullableString16();
66 EXPECT_TRUE(IsManifestValid(manifest));
67
68 manifest.name = base::NullableString16();
69 EXPECT_FALSE(IsManifestValid(manifest));
70 }
71
72 TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresNonEmptyNameORShortName) {
73 content::Manifest manifest = GetValidManifest();
74
75 manifest.name = ToNullableUTF16("");
76 EXPECT_TRUE(IsManifestValid(manifest));
77
78 manifest.name = ToNullableUTF16("foo");
79 manifest.short_name = ToNullableUTF16("");
80 EXPECT_TRUE(IsManifestValid(manifest));
81
82 manifest.name = ToNullableUTF16("");
83 EXPECT_FALSE(IsManifestValid(manifest));
84 }
85
86 TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresValidStartURL) {
87 content::Manifest manifest = GetValidManifest();
88
89 manifest.start_url = GURL();
90 EXPECT_FALSE(IsManifestValid(manifest));
91
92 manifest.start_url = GURL("/");
93 EXPECT_FALSE(IsManifestValid(manifest));
94 }
95
96 TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresImagePNG) {
97 content::Manifest manifest = GetValidManifest();
98
99 manifest.icons[0].type = ToNullableUTF16("image/gif");
100 EXPECT_FALSE(IsManifestValid(manifest));
101 manifest.icons[0].type = base::NullableString16();
102 EXPECT_FALSE(IsManifestValid(manifest));
103 }
104
105 TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresMinimalSize) {
106 content::Manifest manifest = GetValidManifest();
107
108 // The icon MUST be 144x144 size at least.
109 manifest.icons[0].sizes[0] = gfx::Size(1, 1);
110 EXPECT_FALSE(IsManifestValid(manifest));
111
112 // If one of the sizes match the requirement, it should be accepted.
113 manifest.icons[0].sizes.push_back(gfx::Size(144, 144));
114 EXPECT_TRUE(IsManifestValid(manifest));
115
116 // Higher than the required size is okay.
117 manifest.icons[0].sizes[1] = gfx::Size(200, 200);
118 EXPECT_TRUE(IsManifestValid(manifest));
119
120 // Non-square is okay.
121 manifest.icons[0].sizes[1] = gfx::Size(144, 200);
122 EXPECT_TRUE(IsManifestValid(manifest));
123
124 // The representation of the keyword 'any' should be recognized.
125 manifest.icons[0].sizes[1] = gfx::Size(0, 0);
126 EXPECT_TRUE(IsManifestValid(manifest));
127 }
128
129 TEST_F(AppBannerDataFetcherUnitTest, ManifestDisplayStandaloneFullscreen) {
130 content::Manifest manifest = GetValidManifest();
131
132 manifest.display = blink::WebDisplayModeUndefined;
133 EXPECT_FALSE(IsManifestValid(manifest));
134
135 manifest.display = blink::WebDisplayModeBrowser;
136 EXPECT_FALSE(IsManifestValid(manifest));
137
138 manifest.display = blink::WebDisplayModeMinimalUi;
139 EXPECT_FALSE(IsManifestValid(manifest));
140
141 manifest.display = blink::WebDisplayModeStandalone;
142 EXPECT_TRUE(IsManifestValid(manifest));
143
144 manifest.display = blink::WebDisplayModeFullscreen;
145 EXPECT_TRUE(IsManifestValid(manifest));
146 }
147
148 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_data_fetcher_desktop.cc ('k') | chrome/browser/banners/app_banner_debug_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698