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

Side by Side Diff: chrome/browser/extensions/bookmark_app_helper_unittest.cc

Issue 2916753004: Use BookmarkAppConfirmationView on Mac. Delete the NSAlert Mac uses currently. (Closed)
Patch Set: alrighty Created 3 years, 6 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 unified diff | Download patch
OLDNEW
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/banners/app_banner_settings_helper.h" 9 #include "chrome/browser/banners/app_banner_settings_helper.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_service_test_base.h" 11 #include "chrome/browser/extensions/extension_service_test_base.h"
12 #include "chrome/browser/extensions/test_bookmark_app_helper.h"
12 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 13 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
13 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/test_utils.h" 17 #include "content/public/test/test_utils.h"
17 #include "content/public/test/web_contents_tester.h" 18 #include "content/public/test/web_contents_tester.h"
18 #include "extensions/browser/extension_registry.h" 19 #include "extensions/browser/extension_registry.h"
19 #include "extensions/common/constants.h" 20 #include "extensions/common/constants.h"
20 #include "extensions/common/extension_icon_set.h" 21 #include "extensions/common/extension_icon_set.h"
21 #include "extensions/common/manifest_handlers/icons_handler.h" 22 #include "extensions/common/manifest_handlers/icons_handler.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 std::map<int, BookmarkAppHelper::BitmapAndSource> size_map = 271 std::map<int, BookmarkAppHelper::BitmapAndSource> size_map =
271 BookmarkAppHelper::ResizeIconsAndGenerateMissing( 272 BookmarkAppHelper::ResizeIconsAndGenerateMissing(
272 downloaded, TestSizesToGenerate(), &web_app_info); 273 downloaded, TestSizesToGenerate(), &web_app_info);
273 274
274 ValidateIconsGeneratedAndResizedCorrectly(downloaded, size_map, 275 ValidateIconsGeneratedAndResizedCorrectly(downloaded, size_map,
275 TestSizesToGenerate(), 276 TestSizesToGenerate(),
276 expected_generated, 277 expected_generated,
277 expected_resized); 278 expected_resized);
278 } 279 }
279 280
280 } // namespace 281 class TestBookmarkAppHelperImpl : public test::TestBookmarkAppHelper {
282 public:
283 TestBookmarkAppHelperImpl(ExtensionService* service,
284 WebApplicationInfo web_app_info,
285 content::WebContents* contents)
286 : TestBookmarkAppHelper(service->profile(), web_app_info, contents) {}
281 287
282 class TestBookmarkAppHelper : public BookmarkAppHelper { 288 ~TestBookmarkAppHelperImpl() override {}
283 public:
284 TestBookmarkAppHelper(ExtensionService* service,
285 WebApplicationInfo web_app_info,
286 content::WebContents* contents)
287 : BookmarkAppHelper(service->profile(), web_app_info, contents) {}
288
289 ~TestBookmarkAppHelper() override {}
290 289
291 void CreationComplete(const extensions::Extension* extension, 290 void CreationComplete(const extensions::Extension* extension,
292 const WebApplicationInfo& web_app_info) { 291 const WebApplicationInfo& web_app_info) {
293 extension_ = extension; 292 extension_ = extension;
294 } 293 }
295 294
296 void CompleteGetManifest(const content::Manifest& manifest) { 295 void CompleteGetManifest(const content::Manifest& manifest) {
297 BookmarkAppHelper::OnDidGetManifest(GURL(), manifest); 296 TestBookmarkAppHelper::OnDidGetManifest(GURL(), manifest);
298 } 297 }
299 298
300 void CompleteIconDownload( 299 void CompleteIconDownload(
301 bool success, 300 bool success,
302 const std::map<GURL, std::vector<SkBitmap> >& bitmaps) { 301 const std::map<GURL, std::vector<SkBitmap> >& bitmaps) {
303 BookmarkAppHelper::OnIconsDownloaded(success, bitmaps); 302 TestBookmarkAppHelper::OnIconsDownloaded(success, bitmaps);
304 } 303 }
305 304
306 const Extension* extension() { return extension_; } 305 const Extension* extension() { return extension_; }
307 306
308 private: 307 private:
309 const Extension* extension_; 308 const Extension* extension_;
310 309
311 DISALLOW_COPY_AND_ASSIGN(TestBookmarkAppHelper); 310 DISALLOW_COPY_AND_ASSIGN(TestBookmarkAppHelperImpl);
312 }; 311 };
313 312
313 } // namespace
314
314 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkApp) { 315 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkApp) {
315 WebApplicationInfo web_app_info; 316 WebApplicationInfo web_app_info;
316 web_app_info.app_url = GURL(kAppUrl); 317 web_app_info.app_url = GURL(kAppUrl);
317 web_app_info.title = base::UTF8ToUTF16(kAppTitle); 318 web_app_info.title = base::UTF8ToUTF16(kAppTitle);
318 web_app_info.description = base::UTF8ToUTF16(kAppDescription); 319 web_app_info.description = base::UTF8ToUTF16(kAppDescription);
319 320
320 std::unique_ptr<content::WebContents> contents( 321 std::unique_ptr<content::WebContents> contents(
321 content::WebContentsTester::CreateTestWebContents(profile(), nullptr)); 322 content::WebContentsTester::CreateTestWebContents(profile(), nullptr));
322 TestBookmarkAppHelper helper(service_, web_app_info, contents.get()); 323 TestBookmarkAppHelperImpl helper(service_, web_app_info, contents.get());
323 helper.Create(base::Bind(&TestBookmarkAppHelper::CreationComplete, 324 helper.Create(base::Bind(&TestBookmarkAppHelperImpl::CreationComplete,
324 base::Unretained(&helper))); 325 base::Unretained(&helper)));
325 326
326 std::map<GURL, std::vector<SkBitmap> > icon_map; 327 std::map<GURL, std::vector<SkBitmap> > icon_map;
327 icon_map[GURL(kAppUrl)].push_back( 328 icon_map[GURL(kAppUrl)].push_back(
328 CreateSquareBitmapWithColor(kIconSizeSmall, SK_ColorRED)); 329 CreateSquareBitmapWithColor(kIconSizeSmall, SK_ColorRED));
329 helper.CompleteIconDownload(true, icon_map); 330 helper.CompleteIconDownload(true, icon_map);
330 331
331 content::RunAllBlockingPoolTasksUntilIdle(); 332 content::RunAllBlockingPoolTasksUntilIdle();
332 EXPECT_TRUE(helper.extension()); 333 EXPECT_TRUE(helper.extension());
333 const Extension* extension = 334 const Extension* extension =
(...skipping 12 matching lines...) Expand all
346 contents.get(), web_app_info.app_url, web_app_info.app_url.spec(), 347 contents.get(), web_app_info.app_url, web_app_info.app_url.spec(),
347 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN) 348 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN)
348 .is_null()); 349 .is_null());
349 } 350 }
350 351
351 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkAppWithManifest) { 352 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkAppWithManifest) {
352 WebApplicationInfo web_app_info; 353 WebApplicationInfo web_app_info;
353 354
354 std::unique_ptr<content::WebContents> contents( 355 std::unique_ptr<content::WebContents> contents(
355 content::WebContentsTester::CreateTestWebContents(profile(), nullptr)); 356 content::WebContentsTester::CreateTestWebContents(profile(), nullptr));
356 TestBookmarkAppHelper helper(service_, web_app_info, contents.get()); 357 TestBookmarkAppHelperImpl helper(service_, web_app_info, contents.get());
357 helper.Create(base::Bind(&TestBookmarkAppHelper::CreationComplete, 358 helper.Create(base::Bind(&TestBookmarkAppHelperImpl::CreationComplete,
358 base::Unretained(&helper))); 359 base::Unretained(&helper)));
359 360
360 content::Manifest manifest; 361 content::Manifest manifest;
361 manifest.start_url = GURL(kAppUrl); 362 manifest.start_url = GURL(kAppUrl);
362 manifest.name = base::NullableString16(base::UTF8ToUTF16(kAppTitle), false); 363 manifest.name = base::NullableString16(base::UTF8ToUTF16(kAppTitle), false);
363 helper.CompleteGetManifest(manifest); 364 helper.CompleteGetManifest(manifest);
364 365
365 std::map<GURL, std::vector<SkBitmap> > icon_map; 366 std::map<GURL, std::vector<SkBitmap> > icon_map;
366 helper.CompleteIconDownload(true, icon_map); 367 helper.CompleteIconDownload(true, icon_map);
367 368
(...skipping 14 matching lines...) Expand all
382 } 383 }
383 384
384 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkAppNoContents) { 385 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkAppNoContents) {
385 WebApplicationInfo web_app_info; 386 WebApplicationInfo web_app_info;
386 web_app_info.app_url = GURL(kAppUrl); 387 web_app_info.app_url = GURL(kAppUrl);
387 web_app_info.title = base::UTF8ToUTF16(kAppTitle); 388 web_app_info.title = base::UTF8ToUTF16(kAppTitle);
388 web_app_info.description = base::UTF8ToUTF16(kAppDescription); 389 web_app_info.description = base::UTF8ToUTF16(kAppDescription);
389 web_app_info.icons.push_back( 390 web_app_info.icons.push_back(
390 CreateIconInfoWithBitmap(kIconSizeTiny, SK_ColorRED)); 391 CreateIconInfoWithBitmap(kIconSizeTiny, SK_ColorRED));
391 392
392 TestBookmarkAppHelper helper(service_, web_app_info, NULL); 393 TestBookmarkAppHelperImpl helper(service_, web_app_info, NULL);
393 helper.Create(base::Bind(&TestBookmarkAppHelper::CreationComplete, 394 helper.Create(base::Bind(&TestBookmarkAppHelperImpl::CreationComplete,
394 base::Unretained(&helper))); 395 base::Unretained(&helper)));
395 396
396 content::RunAllBlockingPoolTasksUntilIdle(); 397 content::RunAllBlockingPoolTasksUntilIdle();
397 EXPECT_TRUE(helper.extension()); 398 EXPECT_TRUE(helper.extension());
398 const Extension* extension = 399 const Extension* extension =
399 service_->GetInstalledExtension(helper.extension()->id()); 400 service_->GetInstalledExtension(helper.extension()->id());
400 EXPECT_TRUE(extension); 401 EXPECT_TRUE(extension);
401 EXPECT_EQ(1u, registry()->enabled_extensions().size()); 402 EXPECT_EQ(1u, registry()->enabled_extensions().size());
402 EXPECT_TRUE(extension->from_bookmark()); 403 EXPECT_TRUE(extension->from_bookmark());
403 EXPECT_EQ(kAppTitle, extension->name()); 404 EXPECT_EQ(kAppTitle, extension->name());
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 TestIconGeneration(kIconSizeTiny, 0, 3); 774 TestIconGeneration(kIconSizeTiny, 0, 3);
774 } 775 }
775 776
776 TEST_F(BookmarkAppHelperTest, IconsResizedWhenOnlyAGigantorOneIsProvided) { 777 TEST_F(BookmarkAppHelperTest, IconsResizedWhenOnlyAGigantorOneIsProvided) {
777 // When an enormous icon is provided, each desired icon size should be resized 778 // When an enormous icon is provided, each desired icon size should be resized
778 // from it, and no icons should be generated. 779 // from it, and no icons should be generated.
779 TestIconGeneration(kIconSizeGigantor, 0, 3); 780 TestIconGeneration(kIconSizeGigantor, 0, 3);
780 } 781 }
781 782
782 } // namespace extensions 783 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698