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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/installable/installable_manager_browsertest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/installable/installable_manager_unittest.cc
diff --git a/chrome/browser/banners/app_banner_data_fetcher_unittest.cc b/chrome/browser/installable/installable_manager_unittest.cc
similarity index 53%
copy from chrome/browser/banners/app_banner_data_fetcher_unittest.cc
copy to chrome/browser/installable/installable_manager_unittest.cc
index 1de8aefb86109a7dea0715afa8d38f0c16b42a3f..69c1eb8520e1e3fca5a752b984a08d2b5b166369 100644
--- a/chrome/browser/banners/app_banner_data_fetcher_unittest.cc
+++ b/chrome/browser/installable/installable_manager_unittest.cc
@@ -1,18 +1,16 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/banners/app_banner_data_fetcher.h"
+#include "chrome/browser/installable/installable_manager.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/WebDisplayMode.h"
-namespace banners {
-
-class AppBannerDataFetcherUnitTest : public testing::Test {
+class InstallableManagerUnitTest : public testing::Test {
public:
- AppBannerDataFetcherUnitTest() { }
+ InstallableManagerUnitTest() : manager_(new InstallableManager(nullptr)) { }
protected:
static base::NullableString16 ToNullableUTF16(const std::string& str) {
@@ -34,115 +32,158 @@ class AppBannerDataFetcherUnitTest : public testing::Test {
return manifest;
}
- static bool IsManifestValid(const content::Manifest& manifest) {
- // The second argument is the web_contents pointer, which is used for
- // developer debug logging to the console. The logging is skipped inside the
- // method if a null web_contents pointer is provided, so this is safe.
- // The third argument is the is_debug_mode boolean value, which is true only
- // when it is triggered by the developer's action in DevTools.
- return AppBannerDataFetcher::IsManifestValidForWebApp(manifest, nullptr,
- false);
+ bool IsManifestValid(const content::Manifest& manifest) {
+ // Explicitly reset the error code before running the method.
+ manager_->set_installable_error(NO_ERROR_DETECTED);
+ return manager_->IsManifestValidForWebApp(manifest);
+ }
+
+ InstallableErrorCode GetErrorCode() {
+ return manager_->installable_error();
}
+
+ private:
+ std::unique_ptr<InstallableManager> manager_;
};
-TEST_F(AppBannerDataFetcherUnitTest, EmptyManifestIsInvalid) {
+TEST_F(InstallableManagerUnitTest, EmptyManifestIsInvalid) {
content::Manifest manifest;
EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(MANIFEST_EMPTY, GetErrorCode());
}
-TEST_F(AppBannerDataFetcherUnitTest, CheckMinimalValidManifest) {
+TEST_F(InstallableManagerUnitTest, CheckMinimalValidManifest) {
content::Manifest manifest = GetValidManifest();
EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
}
-TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresNameORShortName) {
+TEST_F(InstallableManagerUnitTest, ManifestRequiresNameOrShortName) {
content::Manifest manifest = GetValidManifest();
manifest.name = base::NullableString16();
EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
manifest.name = ToNullableUTF16("foo");
manifest.short_name = base::NullableString16();
EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
manifest.name = base::NullableString16();
EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(MANIFEST_MISSING_NAME_OR_SHORT_NAME, GetErrorCode());
}
-TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresNonEmptyNameORShortName) {
+TEST_F(InstallableManagerUnitTest, ManifestRequiresNonEmptyNameORShortName) {
content::Manifest manifest = GetValidManifest();
manifest.name = ToNullableUTF16("");
EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
manifest.name = ToNullableUTF16("foo");
manifest.short_name = ToNullableUTF16("");
EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
manifest.name = ToNullableUTF16("");
EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(MANIFEST_MISSING_NAME_OR_SHORT_NAME, GetErrorCode());
}
-TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresValidStartURL) {
+TEST_F(InstallableManagerUnitTest, ManifestRequiresValidStartURL) {
content::Manifest manifest = GetValidManifest();
manifest.start_url = GURL();
EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(START_URL_NOT_VALID, GetErrorCode());
manifest.start_url = GURL("/");
EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(START_URL_NOT_VALID, GetErrorCode());
}
-TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresImagePNG) {
+TEST_F(InstallableManagerUnitTest, ManifestRequiresImagePNG) {
content::Manifest manifest = GetValidManifest();
manifest.icons[0].type = ToNullableUTF16("image/gif");
EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
+
manifest.icons[0].type = base::NullableString16();
EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
+
+ // If the type is null, the icon src will be checked instead.
+ manifest.icons[0].src = GURL("http://example.com/icon.png");
+ EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
+
+ // Capital file extension is also permissible.
+ manifest.icons[0].src = GURL("http://example.com/icon.PNG");
+ EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
+
+ // Non-png extensions are rejected.
+ manifest.icons[0].src = GURL("http://example.com/icon.gif");
+ EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
}
-TEST_F(AppBannerDataFetcherUnitTest, ManifestRequiresMinimalSize) {
+TEST_F(InstallableManagerUnitTest, ManifestRequiresMinimalSize) {
content::Manifest manifest = GetValidManifest();
// The icon MUST be 144x144 size at least.
manifest.icons[0].sizes[0] = gfx::Size(1, 1);
EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
+
+ manifest.icons[0].sizes[0] = gfx::Size(143, 143);
+ EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(MANIFEST_MISSING_SUITABLE_ICON, GetErrorCode());
// If one of the sizes match the requirement, it should be accepted.
manifest.icons[0].sizes.push_back(gfx::Size(144, 144));
EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
// Higher than the required size is okay.
manifest.icons[0].sizes[1] = gfx::Size(200, 200);
EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
// Non-square is okay.
manifest.icons[0].sizes[1] = gfx::Size(144, 200);
EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
// The representation of the keyword 'any' should be recognized.
manifest.icons[0].sizes[1] = gfx::Size(0, 0);
EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
}
-TEST_F(AppBannerDataFetcherUnitTest, ManifestDisplayStandaloneFullscreen) {
+TEST_F(InstallableManagerUnitTest, ManifestDisplayStandaloneFullscreen) {
content::Manifest manifest = GetValidManifest();
manifest.display = blink::WebDisplayModeUndefined;
EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode());
manifest.display = blink::WebDisplayModeBrowser;
EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode());
manifest.display = blink::WebDisplayModeMinimalUi;
EXPECT_FALSE(IsManifestValid(manifest));
+ EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode());
manifest.display = blink::WebDisplayModeStandalone;
EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
manifest.display = blink::WebDisplayModeFullscreen;
EXPECT_TRUE(IsManifestValid(manifest));
+ EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
}
-
-} // namespace banners
« 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