| 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/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_service_test_base.h" | 10 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 11 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 11 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/test/test_web_contents_factory.h" | 15 #include "content/public/test/web_contents_tester.h" |
| 16 #include "extensions/browser/extension_registry.h" | 16 #include "extensions/browser/extension_registry.h" |
| 17 #include "extensions/common/constants.h" | 17 #include "extensions/common/constants.h" |
| 18 #include "extensions/common/extension_icon_set.h" | 18 #include "extensions/common/extension_icon_set.h" |
| 19 #include "extensions/common/manifest_handlers/icons_handler.h" | 19 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 #include "ui/gfx/skia_util.h" | 22 #include "ui/gfx/skia_util.h" |
| 23 | 23 |
| 24 namespace extensions { | 24 namespace extensions { |
| 25 | 25 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 309 |
| 310 DISALLOW_COPY_AND_ASSIGN(TestBookmarkAppHelper); | 310 DISALLOW_COPY_AND_ASSIGN(TestBookmarkAppHelper); |
| 311 }; | 311 }; |
| 312 | 312 |
| 313 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkApp) { | 313 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkApp) { |
| 314 WebApplicationInfo web_app_info; | 314 WebApplicationInfo web_app_info; |
| 315 web_app_info.app_url = GURL(kAppUrl); | 315 web_app_info.app_url = GURL(kAppUrl); |
| 316 web_app_info.title = base::UTF8ToUTF16(kAppTitle); | 316 web_app_info.title = base::UTF8ToUTF16(kAppTitle); |
| 317 web_app_info.description = base::UTF8ToUTF16(kAppDescription); | 317 web_app_info.description = base::UTF8ToUTF16(kAppDescription); |
| 318 | 318 |
| 319 content::TestWebContentsFactory web_contents_factory; | 319 std::unique_ptr<content::WebContents> contents( |
| 320 content::WebContents* contents = | 320 content::WebContentsTester::CreateTestWebContents(profile(), nullptr)); |
| 321 web_contents_factory.CreateWebContents(profile()); | 321 TestBookmarkAppHelper helper(service_, web_app_info, contents.get()); |
| 322 TestBookmarkAppHelper helper(service_, web_app_info, contents); | |
| 323 helper.Create(base::Bind(&TestBookmarkAppHelper::CreationComplete, | 322 helper.Create(base::Bind(&TestBookmarkAppHelper::CreationComplete, |
| 324 base::Unretained(&helper))); | 323 base::Unretained(&helper))); |
| 325 | 324 |
| 326 std::map<GURL, std::vector<SkBitmap> > icon_map; | 325 std::map<GURL, std::vector<SkBitmap> > icon_map; |
| 327 icon_map[GURL(kAppUrl)].push_back( | 326 icon_map[GURL(kAppUrl)].push_back( |
| 328 CreateSquareBitmapWithColor(kIconSizeSmall, SK_ColorRED)); | 327 CreateSquareBitmapWithColor(kIconSizeSmall, SK_ColorRED)); |
| 329 helper.CompleteIconDownload(true, icon_map); | 328 helper.CompleteIconDownload(true, icon_map); |
| 330 | 329 |
| 331 base::RunLoop().RunUntilIdle(); | 330 base::RunLoop().RunUntilIdle(); |
| 332 EXPECT_TRUE(helper.extension()); | 331 EXPECT_TRUE(helper.extension()); |
| 333 const Extension* extension = | 332 const Extension* extension = |
| 334 service_->GetInstalledExtension(helper.extension()->id()); | 333 service_->GetInstalledExtension(helper.extension()->id()); |
| 335 EXPECT_TRUE(extension); | 334 EXPECT_TRUE(extension); |
| 336 EXPECT_EQ(1u, registry()->enabled_extensions().size()); | 335 EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 337 EXPECT_TRUE(extension->from_bookmark()); | 336 EXPECT_TRUE(extension->from_bookmark()); |
| 338 EXPECT_EQ(kAppTitle, extension->name()); | 337 EXPECT_EQ(kAppTitle, extension->name()); |
| 339 EXPECT_EQ(kAppDescription, extension->description()); | 338 EXPECT_EQ(kAppDescription, extension->description()); |
| 340 EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension)); | 339 EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension)); |
| 341 EXPECT_FALSE( | 340 EXPECT_FALSE( |
| 342 IconsInfo::GetIconResource( | 341 IconsInfo::GetIconResource( |
| 343 extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY).empty()); | 342 extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY).empty()); |
| 344 } | 343 } |
| 345 | 344 |
| 346 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkAppWithManifest) { | 345 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkAppWithManifest) { |
| 347 WebApplicationInfo web_app_info; | 346 WebApplicationInfo web_app_info; |
| 348 | 347 |
| 349 content::TestWebContentsFactory web_contents_factory; | 348 std::unique_ptr<content::WebContents> contents( |
| 350 content::WebContents* contents = | 349 content::WebContentsTester::CreateTestWebContents(profile(), nullptr)); |
| 351 web_contents_factory.CreateWebContents(profile()); | 350 TestBookmarkAppHelper helper(service_, web_app_info, contents.get()); |
| 352 TestBookmarkAppHelper helper(service_, web_app_info, contents); | |
| 353 helper.Create(base::Bind(&TestBookmarkAppHelper::CreationComplete, | 351 helper.Create(base::Bind(&TestBookmarkAppHelper::CreationComplete, |
| 354 base::Unretained(&helper))); | 352 base::Unretained(&helper))); |
| 355 | 353 |
| 356 content::Manifest manifest; | 354 content::Manifest manifest; |
| 357 manifest.start_url = GURL(kAppUrl); | 355 manifest.start_url = GURL(kAppUrl); |
| 358 manifest.name = base::NullableString16(base::UTF8ToUTF16(kAppTitle), false); | 356 manifest.name = base::NullableString16(base::UTF8ToUTF16(kAppTitle), false); |
| 359 helper.CompleteGetManifest(manifest); | 357 helper.CompleteGetManifest(manifest); |
| 360 | 358 |
| 361 std::map<GURL, std::vector<SkBitmap> > icon_map; | 359 std::map<GURL, std::vector<SkBitmap> > icon_map; |
| 362 helper.CompleteIconDownload(true, icon_map); | 360 helper.CompleteIconDownload(true, icon_map); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 TestIconGeneration(kIconSizeTiny, 0, 3); | 762 TestIconGeneration(kIconSizeTiny, 0, 3); |
| 765 } | 763 } |
| 766 | 764 |
| 767 TEST_F(BookmarkAppHelperTest, IconsResizedWhenOnlyAGigantorOneIsProvided) { | 765 TEST_F(BookmarkAppHelperTest, IconsResizedWhenOnlyAGigantorOneIsProvided) { |
| 768 // When an enormous icon is provided, each desired icon size should be resized | 766 // When an enormous icon is provided, each desired icon size should be resized |
| 769 // from it, and no icons should be generated. | 767 // from it, and no icons should be generated. |
| 770 TestIconGeneration(kIconSizeGigantor, 0, 3); | 768 TestIconGeneration(kIconSizeGigantor, 0, 3); |
| 771 } | 769 } |
| 772 | 770 |
| 773 } // namespace extensions | 771 } // namespace extensions |
| OLD | NEW |