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

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

Issue 2625423002: Rename "icon" to "primary icon" in InstallableManager (Closed)
Patch Set: Addressing comments 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
« no previous file with comments | « chrome/browser/installable/installable_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_primary_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_px = 144; 28 params.ideal_primary_icon_size_in_px = 144;
29 params.minimum_icon_size_in_px = 144; 29 params.minimum_primary_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_primary_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_px = 144; 37 params.ideal_primary_icon_size_in_px = 144;
38 params.minimum_icon_size_in_px = 144; 38 params.minimum_primary_icon_size_in_px = 144;
39 params.fetch_valid_icon = true; 39 params.fetch_valid_primary_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) { }
49 49
50 void OnDidFinishInstallableCheck(const InstallableData& data) { 50 void OnDidFinishInstallableCheck(const InstallableData& data) {
51 error_code_ = data.error_code; 51 error_code_ = data.error_code;
52 manifest_url_ = data.manifest_url; 52 manifest_url_ = data.manifest_url;
53 manifest_ = data.manifest; 53 manifest_ = data.manifest;
54 icon_url_ = data.icon_url; 54 icon_url_ = data.primary_icon_url;
55 if (data.icon) 55 if (data.primary_icon)
56 icon_.reset(new SkBitmap(*data.icon)); 56 icon_.reset(new SkBitmap(*data.primary_icon));
57 is_installable_ = data.is_installable; 57 is_installable_ = data.is_installable;
58 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); 58 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_);
59 } 59 }
60 60
61 InstallableStatusCode error_code() const { return error_code_; } 61 InstallableStatusCode error_code() const { return error_code_; }
62 const GURL& manifest_url() const { return manifest_url_; } 62 const GURL& manifest_url() const { return manifest_url_; }
63 const content::Manifest& manifest() const { return manifest_; } 63 const content::Manifest& manifest() const { return manifest_; }
64 const GURL& icon_url() const { return icon_url_; } 64 const GURL& icon_url() const { return icon_url_; }
65 const SkBitmap* icon() const { return icon_.get(); } 65 const SkBitmap* icon() const { return icon_.get(); }
66 bool is_installable() const { return is_installable_; } 66 bool is_installable() const { return is_installable_; }
(...skipping 18 matching lines...) Expand all
85 void Run() { 85 void Run() {
86 manager_->GetData(params_, 86 manager_->GetData(params_,
87 base::Bind(&NestedCallbackTester::OnDidFinishFirstCheck, 87 base::Bind(&NestedCallbackTester::OnDidFinishFirstCheck,
88 base::Unretained(this))); 88 base::Unretained(this)));
89 } 89 }
90 90
91 void OnDidFinishFirstCheck(const InstallableData& data) { 91 void OnDidFinishFirstCheck(const InstallableData& data) {
92 error_code_ = data.error_code; 92 error_code_ = data.error_code;
93 manifest_url_ = data.manifest_url; 93 manifest_url_ = data.manifest_url;
94 manifest_ = data.manifest; 94 manifest_ = data.manifest;
95 icon_url_ = data.icon_url; 95 icon_url_ = data.primary_icon_url;
96 if (data.icon) 96 if (data.primary_icon)
97 icon_.reset(new SkBitmap(*data.icon)); 97 icon_.reset(new SkBitmap(*data.primary_icon));
98 is_installable_ = data.is_installable; 98 is_installable_ = data.is_installable;
99 99
100 manager_->GetData(params_, 100 manager_->GetData(params_,
101 base::Bind(&NestedCallbackTester::OnDidFinishSecondCheck, 101 base::Bind(&NestedCallbackTester::OnDidFinishSecondCheck,
102 base::Unretained(this))); 102 base::Unretained(this)));
103 } 103 }
104 104
105 void OnDidFinishSecondCheck(const InstallableData& data) { 105 void OnDidFinishSecondCheck(const InstallableData& data) {
106 EXPECT_EQ(error_code_, data.error_code); 106 EXPECT_EQ(error_code_, data.error_code);
107 EXPECT_EQ(manifest_url_, data.manifest_url); 107 EXPECT_EQ(manifest_url_, data.manifest_url);
108 EXPECT_EQ(icon_url_, data.icon_url); 108 EXPECT_EQ(icon_url_, data.primary_icon_url);
109 EXPECT_EQ(icon_.get(), data.icon); 109 EXPECT_EQ(icon_.get(), data.primary_icon);
110 EXPECT_EQ(is_installable_, data.is_installable); 110 EXPECT_EQ(is_installable_, data.is_installable);
111 EXPECT_EQ(manifest_.IsEmpty(), data.manifest.IsEmpty()); 111 EXPECT_EQ(manifest_.IsEmpty(), data.manifest.IsEmpty());
112 EXPECT_EQ(manifest_.start_url, data.manifest.start_url); 112 EXPECT_EQ(manifest_.start_url, data.manifest.start_url);
113 EXPECT_EQ(manifest_.display, data.manifest.display); 113 EXPECT_EQ(manifest_.display, data.manifest.display);
114 EXPECT_EQ(manifest_.name, data.manifest.name); 114 EXPECT_EQ(manifest_.name, data.manifest.name);
115 EXPECT_EQ(manifest_.short_name, data.manifest.short_name); 115 EXPECT_EQ(manifest_.short_name, data.manifest.short_name);
116 116
117 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); 117 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_);
118 } 118 }
119 119
(...skipping 221 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_px = 96; 351 params.ideal_primary_icon_size_in_px = 96;
352 params.minimum_icon_size_in_px = 96; 352 params.minimum_primary_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 202 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_px = 2000; 575 params.ideal_primary_icon_size_in_px = 2000;
576 params.minimum_icon_size_in_px = 2000; 576 params.minimum_primary_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_px = 2000; 597 params.ideal_primary_icon_size_in_px = 2000;
598 params.minimum_icon_size_in_px = 2000; 598 params.minimum_primary_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') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698