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

Side by Side Diff: chrome/browser/installable/installable_manager_browsertest.cc

Issue 2611623003: Use exact pixel sizes instead of dip in webapp/WebAPK installability code (Closed)
Patch Set: Rebased version of pkotwicz@'s original patch Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/installable/installable_manager.h" 5 #include "chrome/browser/installable/installable_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/base/in_process_browser_test.h" 13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h" 15 #include "net/test/embedded_test_server/embedded_test_server.h"
16 16
17 namespace { 17 namespace {
18 18
19 InstallableParams GetManifestParams() { 19 InstallableParams GetManifestParams() {
20 InstallableParams params; 20 InstallableParams params;
21 params.check_installable = false; 21 params.check_installable = false;
22 params.fetch_valid_icon = false; 22 params.fetch_valid_icon = false;
23 return params; 23 return params;
24 } 24 }
25 25
26 InstallableParams GetWebAppParams() { 26 InstallableParams GetWebAppParams() {
27 InstallableParams params = GetManifestParams(); 27 InstallableParams params = GetManifestParams();
28 params.ideal_icon_size_in_dp = 48; 28 params.ideal_icon_size_in_px = 144;
29 params.minimum_icon_size_in_dp = 48; 29 params.minimum_icon_size_in_px = 144;
30 params.check_installable = true; 30 params.check_installable = true;
31 params.fetch_valid_icon = true; 31 params.fetch_valid_icon = true;
32 return params; 32 return params;
33 } 33 }
34 34
35 InstallableParams GetIconParams() { 35 InstallableParams GetIconParams() {
36 InstallableParams params = GetManifestParams(); 36 InstallableParams params = GetManifestParams();
37 params.ideal_icon_size_in_dp = 48; 37 params.ideal_icon_size_in_px = 144;
38 params.minimum_icon_size_in_dp = 48; 38 params.minimum_icon_size_in_px = 144;
39 params.fetch_valid_icon = true; 39 params.fetch_valid_icon = true;
40 return params; 40 return params;
41 } 41 }
42 42
43 } // anonymous namespace 43 } // anonymous namespace
44 44
45 class CallbackTester { 45 class CallbackTester {
46 public: 46 public:
47 explicit CallbackTester(base::Closure quit_closure) 47 explicit CallbackTester(base::Closure quit_closure)
48 : quit_closure_(quit_closure) { } 48 : quit_closure_(quit_closure) { }
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 341 }
342 342
343 // Ask for a different size icon. This should fail with START_URL_NOT_VALID 343 // Ask for a different size icon. This should fail with START_URL_NOT_VALID
344 // since we won't have a cached icon error. 344 // since we won't have a cached icon error.
345 { 345 {
346 base::RunLoop run_loop; 346 base::RunLoop run_loop;
347 std::unique_ptr<CallbackTester> tester( 347 std::unique_ptr<CallbackTester> tester(
348 new CallbackTester(run_loop.QuitClosure())); 348 new CallbackTester(run_loop.QuitClosure()));
349 349
350 InstallableParams params = GetWebAppParams(); 350 InstallableParams params = GetWebAppParams();
351 params.ideal_icon_size_in_dp = 32; 351 params.ideal_icon_size_in_px = 96;
352 params.minimum_icon_size_in_dp = 32; 352 params.minimum_icon_size_in_px = 96;
353 RunInstallableManager(tester.get(), params); 353 RunInstallableManager(tester.get(), params);
354 run_loop.Run(); 354 run_loop.Run();
355 355
356 EXPECT_FALSE(tester->manifest().IsEmpty()); 356 EXPECT_FALSE(tester->manifest().IsEmpty());
357 EXPECT_FALSE(tester->manifest_url().is_empty()); 357 EXPECT_FALSE(tester->manifest_url().is_empty());
358 EXPECT_TRUE(tester->manifest().prefer_related_applications); 358 EXPECT_TRUE(tester->manifest().prefer_related_applications);
359 359
360 EXPECT_TRUE(tester->icon_url().is_empty()); 360 EXPECT_TRUE(tester->icon_url().is_empty());
361 EXPECT_EQ(nullptr, tester->icon()); 361 EXPECT_EQ(nullptr, tester->icon());
362 EXPECT_FALSE(tester->is_installable()); 362 EXPECT_FALSE(tester->is_installable());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 EXPECT_NE(nullptr, tester->icon()); 402 EXPECT_NE(nullptr, tester->icon());
403 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code()); 403 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code());
404 404
405 // Verify that the returned state matches manager internal state. 405 // Verify that the returned state matches manager internal state.
406 InstallableManager* manager = GetManager(); 406 InstallableManager* manager = GetManager();
407 407
408 EXPECT_FALSE(manager->manifest().IsEmpty()); 408 EXPECT_FALSE(manager->manifest().IsEmpty());
409 EXPECT_FALSE(manager->manifest_url().is_empty()); 409 EXPECT_FALSE(manager->manifest_url().is_empty());
410 EXPECT_TRUE(manager->is_installable()); 410 EXPECT_TRUE(manager->is_installable());
411 EXPECT_EQ(1u, manager->icons_.size()); 411 EXPECT_EQ(1u, manager->icons_.size());
412 EXPECT_FALSE((manager->icon_url({48,48}).is_empty())); 412 EXPECT_FALSE((manager->icon_url({144,144}).is_empty()));
413 EXPECT_NE(nullptr, (manager->icon({48,48}))); 413 EXPECT_NE(nullptr, (manager->icon({144,144})));
414 EXPECT_EQ(NO_ERROR_DETECTED, manager->manifest_error()); 414 EXPECT_EQ(NO_ERROR_DETECTED, manager->manifest_error());
415 EXPECT_EQ(NO_ERROR_DETECTED, manager->installable_error()); 415 EXPECT_EQ(NO_ERROR_DETECTED, manager->installable_error());
416 EXPECT_EQ(NO_ERROR_DETECTED, (manager->icon_error({48,48}))); 416 EXPECT_EQ(NO_ERROR_DETECTED, (manager->icon_error({144,144})));
417 EXPECT_TRUE(manager->tasks_.empty()); 417 EXPECT_TRUE(manager->tasks_.empty());
418 } 418 }
419 419
420 // Request everything again without navigating away. This should work fine. 420 // Request everything again without navigating away. This should work fine.
421 { 421 {
422 base::RunLoop run_loop; 422 base::RunLoop run_loop;
423 std::unique_ptr<CallbackTester> tester( 423 std::unique_ptr<CallbackTester> tester(
424 new CallbackTester(run_loop.QuitClosure())); 424 new CallbackTester(run_loop.QuitClosure()));
425 425
426 RunInstallableManager(tester.get(), GetWebAppParams()); 426 RunInstallableManager(tester.get(), GetWebAppParams());
427 run_loop.Run(); 427 run_loop.Run();
428 428
429 EXPECT_FALSE(tester->manifest().IsEmpty()); 429 EXPECT_FALSE(tester->manifest().IsEmpty());
430 EXPECT_FALSE(tester->manifest_url().is_empty()); 430 EXPECT_FALSE(tester->manifest_url().is_empty());
431 EXPECT_TRUE(tester->is_installable()); 431 EXPECT_TRUE(tester->is_installable());
432 EXPECT_FALSE(tester->icon_url().is_empty()); 432 EXPECT_FALSE(tester->icon_url().is_empty());
433 EXPECT_NE(nullptr, tester->icon()); 433 EXPECT_NE(nullptr, tester->icon());
434 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code()); 434 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code());
435 435
436 // Verify that the returned state matches manager internal state. 436 // Verify that the returned state matches manager internal state.
437 InstallableManager* manager = GetManager(); 437 InstallableManager* manager = GetManager();
438 438
439 EXPECT_FALSE(manager->manifest().IsEmpty()); 439 EXPECT_FALSE(manager->manifest().IsEmpty());
440 EXPECT_FALSE(manager->manifest_url().is_empty()); 440 EXPECT_FALSE(manager->manifest_url().is_empty());
441 EXPECT_TRUE(manager->is_installable()); 441 EXPECT_TRUE(manager->is_installable());
442 EXPECT_EQ(1u, manager->icons_.size()); 442 EXPECT_EQ(1u, manager->icons_.size());
443 EXPECT_FALSE((manager->icon_url({48,48}).is_empty())); 443 EXPECT_FALSE((manager->icon_url({144,144}).is_empty()));
444 EXPECT_NE(nullptr, (manager->icon({48,48}))); 444 EXPECT_NE(nullptr, (manager->icon({144,144})));
445 EXPECT_EQ(NO_ERROR_DETECTED, manager->manifest_error()); 445 EXPECT_EQ(NO_ERROR_DETECTED, manager->manifest_error());
446 EXPECT_EQ(NO_ERROR_DETECTED, manager->installable_error()); 446 EXPECT_EQ(NO_ERROR_DETECTED, manager->installable_error());
447 EXPECT_EQ(NO_ERROR_DETECTED, (manager->icon_error({48,48}))); 447 EXPECT_EQ(NO_ERROR_DETECTED, (manager->icon_error({144,144})));
448 EXPECT_TRUE(manager->tasks_.empty()); 448 EXPECT_TRUE(manager->tasks_.empty());
449 } 449 }
450 450
451 { 451 {
452 // Check that a subsequent navigation resets state. 452 // Check that a subsequent navigation resets state.
453 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 453 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
454 InstallableManager* manager = GetManager(); 454 InstallableManager* manager = GetManager();
455 455
456 EXPECT_TRUE(manager->manifest().IsEmpty()); 456 EXPECT_TRUE(manager->manifest().IsEmpty());
457 EXPECT_TRUE(manager->manifest_url().is_empty()); 457 EXPECT_TRUE(manager->manifest_url().is_empty());
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 } 565 }
566 566
567 { 567 {
568 base::RunLoop run_loop; 568 base::RunLoop run_loop;
569 std::unique_ptr<CallbackTester> tester( 569 std::unique_ptr<CallbackTester> tester(
570 new CallbackTester(run_loop.QuitClosure())); 570 new CallbackTester(run_loop.QuitClosure()));
571 571
572 // Dial up the icon size requirements to something that isn't available. 572 // Dial up the icon size requirements to something that isn't available.
573 // This should now fail with NoIconMatchingRequirements. 573 // This should now fail with NoIconMatchingRequirements.
574 InstallableParams params = GetWebAppParams(); 574 InstallableParams params = GetWebAppParams();
575 params.ideal_icon_size_in_dp = 2000; 575 params.ideal_icon_size_in_px = 2000;
576 params.minimum_icon_size_in_dp = 2000; 576 params.minimum_icon_size_in_px = 2000;
577 RunInstallableManager(tester.get(), params); 577 RunInstallableManager(tester.get(), params);
578 run_loop.Run(); 578 run_loop.Run();
579 579
580 EXPECT_FALSE(tester->manifest_url().is_empty()); 580 EXPECT_FALSE(tester->manifest_url().is_empty());
581 EXPECT_FALSE(tester->manifest().IsEmpty()); 581 EXPECT_FALSE(tester->manifest().IsEmpty());
582 EXPECT_TRUE(tester->is_installable()); 582 EXPECT_TRUE(tester->is_installable());
583 EXPECT_TRUE(tester->icon_url().is_empty()); 583 EXPECT_TRUE(tester->icon_url().is_empty());
584 EXPECT_EQ(nullptr, tester->icon()); 584 EXPECT_EQ(nullptr, tester->icon());
585 EXPECT_EQ(NO_ACCEPTABLE_ICON, tester->error_code()); 585 EXPECT_EQ(NO_ACCEPTABLE_ICON, tester->error_code());
586 } 586 }
587 587
588 // Navigate and verify the reverse: an overly large icon requested first 588 // Navigate and verify the reverse: an overly large icon requested first
589 // fails, but a smaller icon requested second passes. 589 // fails, but a smaller icon requested second passes.
590 { 590 {
591 base::RunLoop run_loop; 591 base::RunLoop run_loop;
592 std::unique_ptr<CallbackTester> tester( 592 std::unique_ptr<CallbackTester> tester(
593 new CallbackTester(run_loop.QuitClosure())); 593 new CallbackTester(run_loop.QuitClosure()));
594 594
595 // This should fail with NoIconMatchingRequirements. 595 // This should fail with NoIconMatchingRequirements.
596 InstallableParams params = GetWebAppParams(); 596 InstallableParams params = GetWebAppParams();
597 params.ideal_icon_size_in_dp = 2000; 597 params.ideal_icon_size_in_px = 2000;
598 params.minimum_icon_size_in_dp = 2000; 598 params.minimum_icon_size_in_px = 2000;
599 NavigateAndRunInstallableManager(tester.get(), params, 599 NavigateAndRunInstallableManager(tester.get(), params,
600 "/banners/manifest_test_page.html"); 600 "/banners/manifest_test_page.html");
601 run_loop.Run(); 601 run_loop.Run();
602 602
603 EXPECT_FALSE(tester->manifest_url().is_empty()); 603 EXPECT_FALSE(tester->manifest_url().is_empty());
604 EXPECT_FALSE(tester->manifest().IsEmpty()); 604 EXPECT_FALSE(tester->manifest().IsEmpty());
605 EXPECT_TRUE(tester->is_installable()); 605 EXPECT_TRUE(tester->is_installable());
606 EXPECT_TRUE(tester->icon_url().is_empty()); 606 EXPECT_TRUE(tester->icon_url().is_empty());
607 EXPECT_EQ(nullptr, tester->icon()); 607 EXPECT_EQ(nullptr, tester->icon());
608 EXPECT_EQ(NO_ACCEPTABLE_ICON, tester->error_code()); 608 EXPECT_EQ(NO_ACCEPTABLE_ICON, tester->error_code());
(...skipping 21 matching lines...) Expand all
630 CheckNestedCallsToGetData) { 630 CheckNestedCallsToGetData) {
631 // Verify that we can call GetData while in a callback from GetData. 631 // Verify that we can call GetData while in a callback from GetData.
632 base::RunLoop run_loop; 632 base::RunLoop run_loop;
633 InstallableParams params = GetWebAppParams(); 633 InstallableParams params = GetWebAppParams();
634 std::unique_ptr<NestedCallbackTester> tester( 634 std::unique_ptr<NestedCallbackTester> tester(
635 new NestedCallbackTester(GetManager(), params, run_loop.QuitClosure())); 635 new NestedCallbackTester(GetManager(), params, run_loop.QuitClosure()));
636 636
637 tester->Run(); 637 tester->Run();
638 run_loop.Run(); 638 run_loop.Run();
639 } 639 }
OLDNEW
« no previous file with comments | « chrome/browser/installable/installable_manager.cc ('k') | chrome/browser/manifest/manifest_icon_downloader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698