ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / android / banners / app_banner_manager_unittest.cc
blob93b94eaa2ff37149e736fb83a34e465e1e194b22
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/android/banners/app_banner_manager.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace banners {
12 class AppBannerManagerTest : public testing::Test {
13 protected:
14 static base::NullableString16 ToNullableUTF16(const std::string& str) {
15 return base::NullableString16(base::UTF8ToUTF16(str), false);
18 static content::Manifest GetValidManifest() {
19 content::Manifest manifest;
20 manifest.name = ToNullableUTF16("foo");
21 manifest.short_name = ToNullableUTF16("bar");
22 manifest.start_url = GURL("http://example.com");
24 content::Manifest::Icon icon;
25 icon.type = ToNullableUTF16("image/png");
26 icon.sizes.push_back(gfx::Size(144, 144));
27 manifest.icons.push_back(icon);
29 return manifest;
31 static bool IsManifestValid(const content::Manifest& manifest) {
32 return AppBannerManager::IsManifestValid(manifest);
36 TEST_F(AppBannerManagerTest, EmptyManifestIsInvalid) {
37 content::Manifest manifest;
38 EXPECT_FALSE(IsManifestValid(manifest));
41 TEST_F(AppBannerManagerTest, CheckMinimalValidManifest) {
42 content::Manifest manifest = GetValidManifest();
43 EXPECT_TRUE(IsManifestValid(manifest));
46 TEST_F(AppBannerManagerTest, ManifestRequiresNameORShortName) {
47 content::Manifest manifest = GetValidManifest();
49 manifest.name = base::NullableString16();
50 EXPECT_TRUE(IsManifestValid(manifest));
52 manifest.name = ToNullableUTF16("foo");
53 manifest.short_name = base::NullableString16();
54 EXPECT_TRUE(IsManifestValid(manifest));
56 manifest.name = base::NullableString16();
57 EXPECT_FALSE(IsManifestValid(manifest));
60 TEST_F(AppBannerManagerTest, ManifestRequiresValidStartURL) {
61 content::Manifest manifest = GetValidManifest();
63 manifest.start_url = GURL();
64 EXPECT_FALSE(IsManifestValid(manifest));
66 manifest.start_url = GURL("/");
67 EXPECT_FALSE(IsManifestValid(manifest));
70 TEST_F(AppBannerManagerTest, ManifestRequiresImagePNG) {
71 content::Manifest manifest = GetValidManifest();
73 manifest.icons[0].type = ToNullableUTF16("image/gif");
74 EXPECT_FALSE(IsManifestValid(manifest));
75 manifest.icons[0].type = base::NullableString16();
76 EXPECT_FALSE(IsManifestValid(manifest));
79 TEST_F(AppBannerManagerTest, ManifestRequiresMinimalSize) {
80 content::Manifest manifest = GetValidManifest();
82 // The icon MUST be 144x144 size at least.
83 manifest.icons[0].sizes[0] = gfx::Size(1, 1);
84 EXPECT_FALSE(IsManifestValid(manifest));
86 // If one of the sizes match the requirement, it should be accepted.
87 manifest.icons[0].sizes.push_back(gfx::Size(144, 144));
88 EXPECT_TRUE(IsManifestValid(manifest));
90 // Higher than the required size is okay.
91 manifest.icons[0].sizes[1] = gfx::Size(200, 200);
92 EXPECT_TRUE(IsManifestValid(manifest));
94 // Non-square is okay.
95 manifest.icons[0].sizes[1] = gfx::Size(144, 200);
96 EXPECT_TRUE(IsManifestValid(manifest));
98 // The representation of the keyword 'any' should be recognized.
99 manifest.icons[0].sizes[1] = gfx::Size(0, 0);
100 EXPECT_TRUE(IsManifestValid(manifest));
103 } // namespace banners