| 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/manifest_handlers/app_launch_info.h" | 9 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" | 
| 11 #include "extensions/browser/extension_registry.h" | 11 #include "extensions/browser/extension_registry.h" | 
| 12 #include "extensions/common/extension_icon_set.h" | 12 #include "extensions/common/extension_icon_set.h" | 
| 13 #include "extensions/common/manifest_handlers/icons_handler.h" | 13 #include "extensions/common/manifest_handlers/icons_handler.h" | 
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" | 
| 15 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" | 
|  | 16 #include "ui/gfx/skia_util.h" | 
| 16 | 17 | 
| 17 namespace { | 18 namespace { | 
| 18 | 19 | 
| 19 #if !defined(OS_ANDROID) | 20 #if !defined(OS_ANDROID) | 
| 20 const char kAppUrl[] = "http://www.chromium.org"; | 21 const char kAppUrl[] = "http://www.chromium.org"; | 
| 21 const char kAppTitle[] = "Test title"; | 22 const char kAppTitle[] = "Test title"; | 
| 22 const char kAlternativeAppTitle[] = "Different test title"; | 23 const char kAlternativeAppTitle[] = "Different test title"; | 
| 23 const char kAppDescription[] = "Test description"; | 24 const char kAppDescription[] = "Test description"; | 
| 24 | 25 | 
| 25 const int kIconSizeSmall = extension_misc::EXTENSION_ICON_SMALL; | 26 const int kIconSizeSmall = extension_misc::EXTENSION_ICON_SMALL; | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 68 } | 69 } | 
| 69 | 70 | 
| 70 #if !defined(OS_ANDROID) | 71 #if !defined(OS_ANDROID) | 
| 71 WebApplicationInfo::IconInfo CreateIconInfoWithBitmap(int size, SkColor color) { | 72 WebApplicationInfo::IconInfo CreateIconInfoWithBitmap(int size, SkColor color) { | 
| 72   WebApplicationInfo::IconInfo icon_info; | 73   WebApplicationInfo::IconInfo icon_info; | 
| 73   icon_info.width = size; | 74   icon_info.width = size; | 
| 74   icon_info.height = size; | 75   icon_info.height = size; | 
| 75   icon_info.data = CreateSquareBitmapWithColor(size, color); | 76   icon_info.data = CreateSquareBitmapWithColor(size, color); | 
| 76   return icon_info; | 77   return icon_info; | 
| 77 } | 78 } | 
|  | 79 | 
|  | 80 void ValidateWebApplicationInfo(base::Closure callback, | 
|  | 81                                 const WebApplicationInfo& expected, | 
|  | 82                                 const WebApplicationInfo& actual) { | 
|  | 83   EXPECT_EQ(expected.title, actual.title); | 
|  | 84   EXPECT_EQ(expected.description, actual.description); | 
|  | 85   EXPECT_EQ(expected.app_url, actual.app_url); | 
|  | 86   EXPECT_EQ(expected.icons.size(), actual.icons.size()); | 
|  | 87   for (size_t i = 0; i < expected.icons.size(); ++i) { | 
|  | 88     EXPECT_EQ(expected.icons[i].width, actual.icons[i].width); | 
|  | 89     EXPECT_EQ(expected.icons[i].height, actual.icons[i].height); | 
|  | 90     EXPECT_EQ(expected.icons[i].url, actual.icons[i].url); | 
|  | 91     EXPECT_TRUE( | 
|  | 92         gfx::BitmapsAreEqual(expected.icons[i].data, actual.icons[i].data)); | 
|  | 93   } | 
|  | 94   callback.Run(); | 
|  | 95 } | 
| 78 #endif | 96 #endif | 
| 79 | 97 | 
| 80 }  // namespace | 98 }  // namespace | 
| 81 | 99 | 
| 82 namespace extensions { | 100 namespace extensions { | 
| 83 | 101 | 
| 84 class TestBookmarkAppHelper : public BookmarkAppHelper { | 102 class TestBookmarkAppHelper : public BookmarkAppHelper { | 
| 85  public: | 103  public: | 
| 86   TestBookmarkAppHelper(ExtensionService* service, | 104   TestBookmarkAppHelper(ExtensionService* service, | 
| 87                         WebApplicationInfo web_app_info, | 105                         WebApplicationInfo web_app_info, | 
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 179     EXPECT_EQ(kAppDescription, extension->description()); | 197     EXPECT_EQ(kAppDescription, extension->description()); | 
| 180     EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension)); | 198     EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension)); | 
| 181     EXPECT_TRUE(extensions::IconsInfo::GetIconResource( | 199     EXPECT_TRUE(extensions::IconsInfo::GetIconResource( | 
| 182                     extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY) | 200                     extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY) | 
| 183                     .empty()); | 201                     .empty()); | 
| 184     EXPECT_FALSE(extensions::IconsInfo::GetIconResource( | 202     EXPECT_FALSE(extensions::IconsInfo::GetIconResource( | 
| 185                      extension, kIconSizeLarge, ExtensionIconSet::MATCH_EXACTLY) | 203                      extension, kIconSizeLarge, ExtensionIconSet::MATCH_EXACTLY) | 
| 186                      .empty()); | 204                      .empty()); | 
| 187   } | 205   } | 
| 188 } | 206 } | 
|  | 207 | 
|  | 208 TEST_F(BookmarkAppHelperExtensionServiceTest, GetWebApplicationInfo) { | 
|  | 209   WebApplicationInfo web_app_info; | 
|  | 210   web_app_info.app_url = GURL(kAppUrl); | 
|  | 211   web_app_info.title = base::UTF8ToUTF16(kAppTitle); | 
|  | 212   web_app_info.description = base::UTF8ToUTF16(kAppDescription); | 
|  | 213 | 
|  | 214   web_app_info.icons.push_back( | 
|  | 215       CreateIconInfoWithBitmap(kIconSizeSmall, SK_ColorRED)); | 
|  | 216   web_app_info.icons.push_back( | 
|  | 217       CreateIconInfoWithBitmap(kIconSizeLarge, SK_ColorRED)); | 
|  | 218 | 
|  | 219   extensions::CreateOrUpdateBookmarkApp(service_, web_app_info); | 
|  | 220   base::RunLoop().RunUntilIdle(); | 
|  | 221 | 
|  | 222   EXPECT_EQ(1u, registry_->enabled_extensions().size()); | 
|  | 223   base::RunLoop run_loop; | 
|  | 224   extensions::GetWebApplicationInfoFromApp( | 
|  | 225       profile_.get(), | 
|  | 226       service_->extensions()->begin()->get(), | 
|  | 227       base::Bind( | 
|  | 228           &ValidateWebApplicationInfo, run_loop.QuitClosure(), web_app_info)); | 
|  | 229   run_loop.Run(); | 
|  | 230 } | 
| 189 #endif | 231 #endif | 
| 190 | 232 | 
| 191 TEST_F(BookmarkAppHelperTest, ConstrainBitmapsToSizes) { | 233 TEST_F(BookmarkAppHelperTest, ConstrainBitmapsToSizes) { | 
| 192   std::set<int> desired_sizes; | 234   std::set<int> desired_sizes; | 
| 193   desired_sizes.insert(16); | 235   desired_sizes.insert(16); | 
| 194   desired_sizes.insert(32); | 236   desired_sizes.insert(32); | 
| 195   desired_sizes.insert(128); | 237   desired_sizes.insert(128); | 
| 196   desired_sizes.insert(256); | 238   desired_sizes.insert(256); | 
| 197 | 239 | 
| 198   { | 240   { | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 252 } | 294 } | 
| 253 | 295 | 
| 254 TEST_F(BookmarkAppHelperTest, IsValidBookmarkAppUrl) { | 296 TEST_F(BookmarkAppHelperTest, IsValidBookmarkAppUrl) { | 
| 255   EXPECT_TRUE(IsValidBookmarkAppUrl(GURL("https://www.chromium.org"))); | 297   EXPECT_TRUE(IsValidBookmarkAppUrl(GURL("https://www.chromium.org"))); | 
| 256   EXPECT_TRUE(IsValidBookmarkAppUrl(GURL("http://www.chromium.org/path"))); | 298   EXPECT_TRUE(IsValidBookmarkAppUrl(GURL("http://www.chromium.org/path"))); | 
| 257   EXPECT_FALSE(IsValidBookmarkAppUrl(GURL("ftp://www.chromium.org"))); | 299   EXPECT_FALSE(IsValidBookmarkAppUrl(GURL("ftp://www.chromium.org"))); | 
| 258   EXPECT_FALSE(IsValidBookmarkAppUrl(GURL("chrome://flags"))); | 300   EXPECT_FALSE(IsValidBookmarkAppUrl(GURL("chrome://flags"))); | 
| 259 } | 301 } | 
| 260 | 302 | 
| 261 }  // namespace extensions | 303 }  // namespace extensions | 
| OLD | NEW | 
|---|