| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/bookmark_app_helper.h" | 5 #include "chrome/browser/extensions/bookmark_app_helper.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_service_unittest.h" | 8 #include "chrome/browser/extensions/extension_service_unittest.h" |
| 9 #include "chrome/common/extensions/extension_icon_set.h" | 9 #include "chrome/common/extensions/extension_icon_set.h" |
| 10 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 10 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 11 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 11 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "extensions/browser/extension_registry.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 #if !defined(OS_ANDROID) | 19 #if !defined(OS_ANDROID) |
| 19 const char kAppUrl[] = "http://www.chromium.org"; | 20 const char kAppUrl[] = "http://www.chromium.org"; |
| 20 const char kAppTitle[] = "Test title"; | 21 const char kAppTitle[] = "Test title"; |
| 22 const char kAlternativeAppTitle[] = "Different test title"; |
| 21 const char kAppDescription[] = "Test description"; | 23 const char kAppDescription[] = "Test description"; |
| 22 | 24 |
| 23 const int kIconSizeSmall = extension_misc::EXTENSION_ICON_SMALL; | 25 const int kIconSizeSmall = extension_misc::EXTENSION_ICON_SMALL; |
| 26 const int kIconSizeLarge = extension_misc::EXTENSION_ICON_LARGE; |
| 24 #endif | 27 #endif |
| 25 | 28 |
| 26 class BookmarkAppHelperTest : public testing::Test { | 29 class BookmarkAppHelperTest : public testing::Test { |
| 27 public: | 30 public: |
| 28 BookmarkAppHelperTest() {} | 31 BookmarkAppHelperTest() {} |
| 29 virtual ~BookmarkAppHelperTest() {} | 32 virtual ~BookmarkAppHelperTest() {} |
| 30 | 33 |
| 31 private: | 34 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(BookmarkAppHelperTest); | 35 DISALLOW_COPY_AND_ASSIGN(BookmarkAppHelperTest); |
| 33 }; | 36 }; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 57 } | 60 } |
| 58 | 61 |
| 59 void ValidateBitmapSizeAndColor(SkBitmap bitmap, int size, SkColor color) { | 62 void ValidateBitmapSizeAndColor(SkBitmap bitmap, int size, SkColor color) { |
| 60 // Obtain pixel lock to access pixels. | 63 // Obtain pixel lock to access pixels. |
| 61 SkAutoLockPixels lock(bitmap); | 64 SkAutoLockPixels lock(bitmap); |
| 62 EXPECT_EQ(color, bitmap.getColor(0, 0)); | 65 EXPECT_EQ(color, bitmap.getColor(0, 0)); |
| 63 EXPECT_EQ(size, bitmap.width()); | 66 EXPECT_EQ(size, bitmap.width()); |
| 64 EXPECT_EQ(size, bitmap.height()); | 67 EXPECT_EQ(size, bitmap.height()); |
| 65 } | 68 } |
| 66 | 69 |
| 70 #if !defined(OS_ANDROID) |
| 71 WebApplicationInfo::IconInfo CreateIconInfoWithBitmap(int size, SkColor color) { |
| 72 WebApplicationInfo::IconInfo icon_info; |
| 73 icon_info.width = size; |
| 74 icon_info.height = size; |
| 75 icon_info.data = CreateSquareBitmapWithColor(size, color); |
| 76 return icon_info; |
| 77 } |
| 78 #endif |
| 79 |
| 67 } // namespace | 80 } // namespace |
| 68 | 81 |
| 69 namespace extensions { | 82 namespace extensions { |
| 70 | 83 |
| 71 class TestBookmarkAppHelper : public BookmarkAppHelper { | 84 class TestBookmarkAppHelper : public BookmarkAppHelper { |
| 72 public: | 85 public: |
| 73 TestBookmarkAppHelper(ExtensionService* service, | 86 TestBookmarkAppHelper(ExtensionService* service, |
| 74 WebApplicationInfo web_app_info, | 87 WebApplicationInfo web_app_info, |
| 75 content::WebContents* contents) | 88 content::WebContents* contents) |
| 76 : BookmarkAppHelper(service, web_app_info, contents) {} | 89 : BookmarkAppHelper(service, web_app_info, contents) {} |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 EXPECT_TRUE(extension); | 133 EXPECT_TRUE(extension); |
| 121 EXPECT_EQ(1u, service_->extensions()->size()); | 134 EXPECT_EQ(1u, service_->extensions()->size()); |
| 122 EXPECT_TRUE(extension->from_bookmark()); | 135 EXPECT_TRUE(extension->from_bookmark()); |
| 123 EXPECT_EQ(kAppTitle, extension->name()); | 136 EXPECT_EQ(kAppTitle, extension->name()); |
| 124 EXPECT_EQ(kAppDescription, extension->description()); | 137 EXPECT_EQ(kAppDescription, extension->description()); |
| 125 EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension)); | 138 EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension)); |
| 126 EXPECT_FALSE( | 139 EXPECT_FALSE( |
| 127 IconsInfo::GetIconResource( | 140 IconsInfo::GetIconResource( |
| 128 extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY).empty()); | 141 extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY).empty()); |
| 129 } | 142 } |
| 143 |
| 144 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateAndUpdateBookmarkApp) { |
| 145 EXPECT_EQ(0u, registry_->enabled_extensions().size()); |
| 146 WebApplicationInfo web_app_info; |
| 147 web_app_info.app_url = GURL(kAppUrl); |
| 148 web_app_info.title = base::UTF8ToUTF16(kAppTitle); |
| 149 web_app_info.description = base::UTF8ToUTF16(kAppDescription); |
| 150 web_app_info.icons.push_back( |
| 151 CreateIconInfoWithBitmap(kIconSizeSmall, SK_ColorRED)); |
| 152 |
| 153 extensions::CreateOrUpdateBookmarkApp(service_, web_app_info); |
| 154 base::RunLoop().RunUntilIdle(); |
| 155 |
| 156 { |
| 157 EXPECT_EQ(1u, registry_->enabled_extensions().size()); |
| 158 const Extension* extension = service_->extensions()->begin()->get(); |
| 159 EXPECT_TRUE(extension->from_bookmark()); |
| 160 EXPECT_EQ(kAppTitle, extension->name()); |
| 161 EXPECT_EQ(kAppDescription, extension->description()); |
| 162 EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension)); |
| 163 EXPECT_FALSE(extensions::IconsInfo::GetIconResource( |
| 164 extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY) |
| 165 .empty()); |
| 166 } |
| 167 |
| 168 web_app_info.title = base::UTF8ToUTF16(kAlternativeAppTitle); |
| 169 web_app_info.icons[0] = CreateIconInfoWithBitmap(kIconSizeLarge, SK_ColorRED); |
| 170 |
| 171 extensions::CreateOrUpdateBookmarkApp(service_, web_app_info); |
| 172 base::RunLoop().RunUntilIdle(); |
| 173 |
| 174 { |
| 175 EXPECT_EQ(1u, registry_->enabled_extensions().size()); |
| 176 const Extension* extension = service_->extensions()->begin()->get(); |
| 177 EXPECT_TRUE(extension->from_bookmark()); |
| 178 EXPECT_EQ(kAlternativeAppTitle, extension->name()); |
| 179 EXPECT_EQ(kAppDescription, extension->description()); |
| 180 EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension)); |
| 181 EXPECT_TRUE(extensions::IconsInfo::GetIconResource( |
| 182 extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY) |
| 183 .empty()); |
| 184 EXPECT_FALSE(extensions::IconsInfo::GetIconResource( |
| 185 extension, kIconSizeLarge, ExtensionIconSet::MATCH_EXACTLY) |
| 186 .empty()); |
| 187 } |
| 188 } |
| 130 #endif | 189 #endif |
| 131 | 190 |
| 132 TEST_F(BookmarkAppHelperTest, ConstrainBitmapsToSizes) { | 191 TEST_F(BookmarkAppHelperTest, ConstrainBitmapsToSizes) { |
| 133 std::set<int> desired_sizes; | 192 std::set<int> desired_sizes; |
| 134 desired_sizes.insert(16); | 193 desired_sizes.insert(16); |
| 135 desired_sizes.insert(32); | 194 desired_sizes.insert(32); |
| 136 desired_sizes.insert(128); | 195 desired_sizes.insert(128); |
| 137 desired_sizes.insert(256); | 196 desired_sizes.insert(256); |
| 138 | 197 |
| 139 { | 198 { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 } | 245 } |
| 187 { | 246 { |
| 188 // The 32x32 icon should not be generated with no base icons. | 247 // The 32x32 icon should not be generated with no base icons. |
| 189 std::map<int, SkBitmap> bitmaps; | 248 std::map<int, SkBitmap> bitmaps; |
| 190 BookmarkAppHelper::GenerateContainerIcon(&bitmaps, 32); | 249 BookmarkAppHelper::GenerateContainerIcon(&bitmaps, 32); |
| 191 EXPECT_EQ(0u, bitmaps.count(32)); | 250 EXPECT_EQ(0u, bitmaps.count(32)); |
| 192 } | 251 } |
| 193 } | 252 } |
| 194 | 253 |
| 195 } // namespace extensions | 254 } // namespace extensions |
| OLD | NEW |