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

Unified Diff: chrome/browser/extensions/bookmark_app_helper_unittest.cc

Issue 202523011: Add a function to create a bookmark app from a WebApplicationInfo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor_tab_helper
Patch Set: fix the fix Created 6 years, 9 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
Index: chrome/browser/extensions/bookmark_app_helper_unittest.cc
diff --git a/chrome/browser/extensions/bookmark_app_helper_unittest.cc b/chrome/browser/extensions/bookmark_app_helper_unittest.cc
index bac705e660a15a6f13ca79235e40ee5e73a5de95..6a9d376ba8abdfd604286890dea124bacd34c706 100644
--- a/chrome/browser/extensions/bookmark_app_helper_unittest.cc
+++ b/chrome/browser/extensions/bookmark_app_helper_unittest.cc
@@ -10,6 +10,7 @@
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "chrome/common/extensions/manifest_handlers/icons_handler.h"
#include "chrome/test/base/testing_profile.h"
+#include "extensions/browser/extension_registry.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -18,9 +19,11 @@ namespace {
#if !defined(OS_ANDROID)
const char kAppUrl[] = "http://www.chromium.org";
const char kAppTitle[] = "Test title";
+const char kAlternativeAppTitle[] = "Different test title";
const char kAppDescription[] = "Test description";
const int kIconSizeSmall = extension_misc::EXTENSION_ICON_SMALL;
+const int kIconSizeLarge = extension_misc::EXTENSION_ICON_LARGE;
#endif
class BookmarkAppHelperTest : public testing::Test {
@@ -64,6 +67,16 @@ void ValidateBitmapSizeAndColor(SkBitmap bitmap, int size, SkColor color) {
EXPECT_EQ(size, bitmap.height());
}
+#if !defined(OS_ANDROID)
+WebApplicationInfo::IconInfo CreateIconInfoWithBitmap(int size, SkColor color) {
+ WebApplicationInfo::IconInfo icon_info;
+ icon_info.width = size;
+ icon_info.height = size;
+ icon_info.data = CreateSquareBitmapWithColor(size, color);
+ return icon_info;
+}
+#endif
+
} // namespace
namespace extensions {
@@ -127,6 +140,52 @@ TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkApp) {
IconsInfo::GetIconResource(
extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY).empty());
}
+
+TEST_F(BookmarkAppHelperExtensionServiceTest, CreateAndUpdateBookmarkApp) {
+ EXPECT_EQ(0u, registry_->enabled_extensions().size());
+ WebApplicationInfo web_app_info;
+ web_app_info.app_url = GURL(kAppUrl);
+ web_app_info.title = base::UTF8ToUTF16(kAppTitle);
+ web_app_info.description = base::UTF8ToUTF16(kAppDescription);
+ web_app_info.icons.push_back(
+ CreateIconInfoWithBitmap(kIconSizeSmall, SK_ColorRED));
+
+ extensions::CreateOrUpdateBookmarkApp(service_, web_app_info);
+ base::RunLoop().RunUntilIdle();
+
+ {
+ EXPECT_EQ(1u, registry_->enabled_extensions().size());
+ const Extension* extension = service_->extensions()->begin()->get();
+ EXPECT_TRUE(extension->from_bookmark());
+ EXPECT_EQ(kAppTitle, extension->name());
+ EXPECT_EQ(kAppDescription, extension->description());
+ EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension));
+ EXPECT_FALSE(extensions::IconsInfo::GetIconResource(
+ extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY)
+ .empty());
+ }
+
+ web_app_info.title = base::UTF8ToUTF16(kAlternativeAppTitle);
+ web_app_info.icons[0] = CreateIconInfoWithBitmap(kIconSizeLarge, SK_ColorRED);
+
+ extensions::CreateOrUpdateBookmarkApp(service_, web_app_info);
+ base::RunLoop().RunUntilIdle();
+
+ {
+ EXPECT_EQ(1u, registry_->enabled_extensions().size());
+ const Extension* extension = service_->extensions()->begin()->get();
+ EXPECT_TRUE(extension->from_bookmark());
+ EXPECT_EQ(kAlternativeAppTitle, extension->name());
+ EXPECT_EQ(kAppDescription, extension->description());
+ EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension));
+ EXPECT_TRUE(extensions::IconsInfo::GetIconResource(
+ extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY)
+ .empty());
+ EXPECT_FALSE(extensions::IconsInfo::GetIconResource(
+ extension, kIconSizeLarge, ExtensionIconSet::MATCH_EXACTLY)
+ .empty());
+ }
+}
#endif
TEST_F(BookmarkAppHelperTest, ConstrainBitmapsToSizes) {
« no previous file with comments | « chrome/browser/extensions/bookmark_app_helper.cc ('k') | chrome/browser/ui/views/extensions/bookmark_app_bubble_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698