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.
5 #include "chrome/browser/banners/app_banner_data_fetcher.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
12 class AppBannerDataFetcherUnitTest
: public testing::Test
{
14 AppBannerDataFetcherUnitTest() { }
17 static base::NullableString16
ToNullableUTF16(const std::string
& str
) {
18 return base::NullableString16(base::UTF8ToUTF16(str
), false);
21 static content::Manifest
GetValidManifest() {
22 content::Manifest manifest
;
23 manifest
.name
= ToNullableUTF16("foo");
24 manifest
.short_name
= ToNullableUTF16("bar");
25 manifest
.start_url
= GURL("http://example.com");
27 content::Manifest::Icon icon
;
28 icon
.type
= ToNullableUTF16("image/png");
29 icon
.sizes
.push_back(gfx::Size(144, 144));
30 manifest
.icons
.push_back(icon
);
35 static bool IsManifestValid(const content::Manifest
& manifest
) {
36 return AppBannerDataFetcher::IsManifestValid(manifest
);
40 TEST_F(AppBannerDataFetcherUnitTest
, EmptyManifestIsInvalid
) {
41 content::Manifest manifest
;
42 EXPECT_FALSE(IsManifestValid(manifest
));
45 TEST_F(AppBannerDataFetcherUnitTest
, CheckMinimalValidManifest
) {
46 content::Manifest manifest
= GetValidManifest();
47 EXPECT_TRUE(IsManifestValid(manifest
));
50 TEST_F(AppBannerDataFetcherUnitTest
, ManifestRequiresNameORShortName
) {
51 content::Manifest manifest
= GetValidManifest();
53 manifest
.name
= base::NullableString16();
54 EXPECT_TRUE(IsManifestValid(manifest
));
56 manifest
.name
= ToNullableUTF16("foo");
57 manifest
.short_name
= base::NullableString16();
58 EXPECT_TRUE(IsManifestValid(manifest
));
60 manifest
.name
= base::NullableString16();
61 EXPECT_FALSE(IsManifestValid(manifest
));
64 TEST_F(AppBannerDataFetcherUnitTest
, ManifestRequiresValidStartURL
) {
65 content::Manifest manifest
= GetValidManifest();
67 manifest
.start_url
= GURL();
68 EXPECT_FALSE(IsManifestValid(manifest
));
70 manifest
.start_url
= GURL("/");
71 EXPECT_FALSE(IsManifestValid(manifest
));
74 TEST_F(AppBannerDataFetcherUnitTest
, ManifestRequiresImagePNG
) {
75 content::Manifest manifest
= GetValidManifest();
77 manifest
.icons
[0].type
= ToNullableUTF16("image/gif");
78 EXPECT_FALSE(IsManifestValid(manifest
));
79 manifest
.icons
[0].type
= base::NullableString16();
80 EXPECT_FALSE(IsManifestValid(manifest
));
83 TEST_F(AppBannerDataFetcherUnitTest
, ManifestRequiresMinimalSize
) {
84 content::Manifest manifest
= GetValidManifest();
86 // The icon MUST be 144x144 size at least.
87 manifest
.icons
[0].sizes
[0] = gfx::Size(1, 1);
88 EXPECT_FALSE(IsManifestValid(manifest
));
90 // If one of the sizes match the requirement, it should be accepted.
91 manifest
.icons
[0].sizes
.push_back(gfx::Size(144, 144));
92 EXPECT_TRUE(IsManifestValid(manifest
));
94 // Higher than the required size is okay.
95 manifest
.icons
[0].sizes
[1] = gfx::Size(200, 200);
96 EXPECT_TRUE(IsManifestValid(manifest
));
98 // Non-square is okay.
99 manifest
.icons
[0].sizes
[1] = gfx::Size(144, 200);
100 EXPECT_TRUE(IsManifestValid(manifest
));
102 // The representation of the keyword 'any' should be recognized.
103 manifest
.icons
[0].sizes
[1] = gfx::Size(0, 0);
104 EXPECT_TRUE(IsManifestValid(manifest
));
107 } // namespace banners