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

Side by Side Diff: chrome/browser/android/webapk/webapk_installer_unittest.cc

Issue 2882243002: Remove ChromeWebApkHost::GetGooglePlayInstallState() check from WebApkInstaller (Closed)
Patch Set: Created 3 years, 7 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/android/webapk/webapk_installer.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/android/webapk/webapk_installer.h" 5 #include "chrome/browser/android/webapk/webapk_installer.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // WebApkInstaller subclass where 58 // WebApkInstaller subclass where
59 // WebApkInstaller::StartInstallingDownloadedWebApk() and 59 // WebApkInstaller::StartInstallingDownloadedWebApk() and
60 // WebApkInstaller::StartUpdateUsingDownloadedWebApk() and 60 // WebApkInstaller::StartUpdateUsingDownloadedWebApk() and
61 // WebApkInstaller::CanUseGooglePlayInstallService() and 61 // WebApkInstaller::CanUseGooglePlayInstallService() and
62 // WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay() are stubbed out. 62 // WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay() are stubbed out.
63 class TestWebApkInstaller : public WebApkInstaller { 63 class TestWebApkInstaller : public WebApkInstaller {
64 public: 64 public:
65 TestWebApkInstaller(content::BrowserContext* browser_context, 65 TestWebApkInstaller(content::BrowserContext* browser_context,
66 const ShortcutInfo& shortcut_info, 66 const ShortcutInfo& shortcut_info,
67 const SkBitmap& primary_icon, 67 const SkBitmap& primary_icon,
68 const SkBitmap& badge_icon, 68 const SkBitmap& badge_icon)
69 bool can_install_webapks)
70 : WebApkInstaller(browser_context, 69 : WebApkInstaller(browser_context,
71 shortcut_info, 70 shortcut_info,
72 primary_icon, 71 primary_icon,
73 badge_icon), 72 badge_icon) {}
74 can_install_webapks_(can_install_webapks) {}
75
76 bool CanInstallWebApks() override { return can_install_webapks_; }
77 73
78 void InstallOrUpdateWebApk(const std::string& package_name, 74 void InstallOrUpdateWebApk(const std::string& package_name,
79 int version, 75 int version,
80 const std::string& token) override { 76 const std::string& token) override {
81 PostTaskToRunSuccessCallback(); 77 PostTaskToRunSuccessCallback();
82 } 78 }
83 79
84 void PostTaskToRunSuccessCallback() { 80 void PostTaskToRunSuccessCallback() {
85 base::ThreadTaskRunnerHandle::Get()->PostTask( 81 base::ThreadTaskRunnerHandle::Get()->PostTask(
86 FROM_HERE, 82 FROM_HERE,
87 base::Bind(&TestWebApkInstaller::OnResult, base::Unretained(this), 83 base::Bind(&TestWebApkInstaller::OnResult, base::Unretained(this),
88 WebApkInstallResult::SUCCESS)); 84 WebApkInstallResult::SUCCESS));
89 } 85 }
90 86
91 private: 87 private:
92 // Whether the Google Play Services can be used and the install delegate is
93 // available.
94 bool can_install_webapks_;
95
96 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); 88 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller);
97 }; 89 };
98 90
99 // Runs the WebApkInstaller installation process/update and blocks till done. 91 // Runs the WebApkInstaller installation process/update and blocks till done.
100 class WebApkInstallerRunner { 92 class WebApkInstallerRunner {
101 public: 93 public:
102 WebApkInstallerRunner(content::BrowserContext* browser_context, 94 WebApkInstallerRunner(content::BrowserContext* browser_context,
103 const GURL& best_primary_icon_url, 95 const GURL& best_primary_icon_url,
104 const GURL& best_badge_icon_url) 96 const GURL& best_badge_icon_url)
105 : browser_context_(browser_context), 97 : browser_context_(browser_context),
106 best_primary_icon_url_(best_primary_icon_url), 98 best_primary_icon_url_(best_primary_icon_url),
107 best_badge_icon_url_(best_badge_icon_url), 99 best_badge_icon_url_(best_badge_icon_url) {}
108 can_install_webapks_(true) {}
109 100
110 ~WebApkInstallerRunner() {} 101 ~WebApkInstallerRunner() {}
111 102
112 void SetCanInstallWebApks(bool can_install_webapks) {
113 can_install_webapks_ = can_install_webapks;
114 }
115
116 void RunInstallWebApk() { 103 void RunInstallWebApk() {
117 WebApkInstaller::InstallAsyncForTesting( 104 WebApkInstaller::InstallAsyncForTesting(
118 CreateWebApkInstaller(), base::Bind(&WebApkInstallerRunner::OnCompleted, 105 CreateWebApkInstaller(), base::Bind(&WebApkInstallerRunner::OnCompleted,
119 base::Unretained(this))); 106 base::Unretained(this)));
120 Run(); 107 Run();
121 } 108 }
122 109
123 void RunUpdateWebApk() { 110 void RunUpdateWebApk() {
124 const int kWebApkVersion = 1; 111 const int kWebApkVersion = 1;
125 112
126 std::map<std::string, std::string> icon_url_to_murmur2_hash{ 113 std::map<std::string, std::string> icon_url_to_murmur2_hash{
127 {best_primary_icon_url_.spec(), "0"}, 114 {best_primary_icon_url_.spec(), "0"},
128 {best_badge_icon_url_.spec(), "0"}}; 115 {best_badge_icon_url_.spec(), "0"}};
129 116
130 WebApkInstaller::UpdateAsyncForTesting( 117 WebApkInstaller::UpdateAsyncForTesting(
131 CreateWebApkInstaller(), kDownloadedWebApkPackageName, kWebApkVersion, 118 CreateWebApkInstaller(), kDownloadedWebApkPackageName, kWebApkVersion,
132 icon_url_to_murmur2_hash, false /* is_manifest_stale */, 119 icon_url_to_murmur2_hash, false /* is_manifest_stale */,
133 base::Bind(&WebApkInstallerRunner::OnCompleted, 120 base::Bind(&WebApkInstallerRunner::OnCompleted,
134 base::Unretained(this))); 121 base::Unretained(this)));
135 Run(); 122 Run();
136 } 123 }
137 124
138 WebApkInstaller* CreateWebApkInstaller() { 125 WebApkInstaller* CreateWebApkInstaller() {
139 ShortcutInfo info(GURL::EmptyGURL()); 126 ShortcutInfo info(GURL::EmptyGURL());
140 info.best_primary_icon_url = best_primary_icon_url_; 127 info.best_primary_icon_url = best_primary_icon_url_;
141 info.best_badge_icon_url = best_badge_icon_url_; 128 info.best_badge_icon_url = best_badge_icon_url_;
142 129
143 // WebApkInstaller owns itself. 130 // WebApkInstaller owns itself.
144 WebApkInstaller* installer = new TestWebApkInstaller( 131 WebApkInstaller* installer =
145 browser_context_, info, SkBitmap(), SkBitmap(), can_install_webapks_); 132 new TestWebApkInstaller(browser_context_, info, SkBitmap(), SkBitmap());
146 installer->SetTimeoutMs(100); 133 installer->SetTimeoutMs(100);
147 return installer; 134 return installer;
148 } 135 }
149 136
150 void Run() { 137 void Run() {
151 base::RunLoop run_loop; 138 base::RunLoop run_loop;
152 on_completed_callback_ = run_loop.QuitClosure(); 139 on_completed_callback_ = run_loop.QuitClosure();
153 run_loop.Run(); 140 run_loop.Run();
154 } 141 }
155 142
(...skipping 12 matching lines...) Expand all
168 // The Web Manifest's icon URLs. 155 // The Web Manifest's icon URLs.
169 const GURL best_primary_icon_url_; 156 const GURL best_primary_icon_url_;
170 const GURL best_badge_icon_url_; 157 const GURL best_badge_icon_url_;
171 158
172 // Called after the installation process has succeeded or failed. 159 // Called after the installation process has succeeded or failed.
173 base::Closure on_completed_callback_; 160 base::Closure on_completed_callback_;
174 161
175 // The result of the installation process. 162 // The result of the installation process.
176 WebApkInstallResult result_; 163 WebApkInstallResult result_;
177 164
178 // Whether the device supports installation of WebApks.
179 bool can_install_webapks_;
180
181 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerRunner); 165 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerRunner);
182 }; 166 };
183 167
184 // Builds a webapk::WebApkResponse with |token| as the token from the WebAPK 168 // Builds a webapk::WebApkResponse with |token| as the token from the WebAPK
185 // server. 169 // server.
186 std::unique_ptr<net::test_server::HttpResponse> BuildValidWebApkResponse( 170 std::unique_ptr<net::test_server::HttpResponse> BuildValidWebApkResponse(
187 const std::string& token) { 171 const std::string& token) {
188 std::unique_ptr<webapk::WebApkResponse> response_proto( 172 std::unique_ptr<webapk::WebApkResponse> response_proto(
189 new webapk::WebApkResponse); 173 new webapk::WebApkResponse);
190 response_proto->set_package_name(kDownloadedWebApkPackageName); 174 response_proto->set_package_name(kDownloadedWebApkPackageName);
(...skipping 19 matching lines...) Expand all
210 void BuildSync( 194 void BuildSync(
211 const GURL& best_primary_icon_url, 195 const GURL& best_primary_icon_url,
212 const GURL& best_badge_icon_url, 196 const GURL& best_badge_icon_url,
213 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, 197 const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
214 bool is_manifest_stale) { 198 bool is_manifest_stale) {
215 ShortcutInfo info(GURL::EmptyGURL()); 199 ShortcutInfo info(GURL::EmptyGURL());
216 info.best_primary_icon_url = best_primary_icon_url; 200 info.best_primary_icon_url = best_primary_icon_url;
217 info.best_badge_icon_url = best_badge_icon_url; 201 info.best_badge_icon_url = best_badge_icon_url;
218 202
219 // WebApkInstaller owns itself. 203 // WebApkInstaller owns itself.
220 WebApkInstaller* installer = new TestWebApkInstaller( 204 WebApkInstaller* installer =
221 browser_context_, info, SkBitmap(), SkBitmap(), false); 205 new TestWebApkInstaller(browser_context_, info, SkBitmap(), SkBitmap());
222 installer->BuildWebApkProtoInBackgroundForTesting( 206 installer->BuildWebApkProtoInBackgroundForTesting(
223 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto, 207 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto,
224 base::Unretained(this)), 208 base::Unretained(this)),
225 icon_url_to_murmur2_hash, is_manifest_stale); 209 icon_url_to_murmur2_hash, is_manifest_stale);
226 210
227 base::RunLoop run_loop; 211 base::RunLoop run_loop;
228 on_completed_callback_ = run_loop.QuitClosure(); 212 on_completed_callback_ = run_loop.QuitClosure();
229 run_loop.Run(); 213 run_loop.Run();
230 } 214 }
231 215
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 EXPECT_FALSE(icons[0].has_image_data()); 522 EXPECT_FALSE(icons[0].has_image_data());
539 523
540 // Check protobuf fields for kBestPrimaryIconUrl. 524 // Check protobuf fields for kBestPrimaryIconUrl.
541 EXPECT_EQ(best_icon_url, icons[1].src()); 525 EXPECT_EQ(best_icon_url, icons[1].src());
542 EXPECT_EQ(icon_url_to_murmur2_hash[best_icon_url], icons[1].hash()); 526 EXPECT_EQ(icon_url_to_murmur2_hash[best_icon_url], icons[1].hash());
543 EXPECT_THAT(icons[1].usages(), 527 EXPECT_THAT(icons[1].usages(),
544 testing::ElementsAre(webapk::Image::PRIMARY_ICON, 528 testing::ElementsAre(webapk::Image::PRIMARY_ICON,
545 webapk::Image::BADGE_ICON)); 529 webapk::Image::BADGE_ICON));
546 EXPECT_TRUE(icons[1].has_image_data()); 530 EXPECT_TRUE(icons[1].has_image_data());
547 } 531 }
548
549 TEST_F(WebApkInstallerTest, FailsWhenInstallDisabled) {
550 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
551 runner->SetCanInstallWebApks(false);
552 runner->RunInstallWebApk();
553 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result());
554 }
OLDNEW
« no previous file with comments | « chrome/browser/android/webapk/webapk_installer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698