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

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

Issue 2932593005: Simplify WebAPK proto building code (Closed)
Patch Set: Merge branch 'master' into background_updates000 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
« 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 std::unique_ptr<net::test_server::BasicHttpResponse> response( 180 std::unique_ptr<net::test_server::BasicHttpResponse> response(
181 new net::test_server::BasicHttpResponse()); 181 new net::test_server::BasicHttpResponse());
182 response->set_code(net::HTTP_OK); 182 response->set_code(net::HTTP_OK);
183 response->set_content(response_content); 183 response->set_content(response_content);
184 return std::move(response); 184 return std::move(response);
185 } 185 }
186 186
187 // Builds WebApk proto and blocks till done. 187 // Builds WebApk proto and blocks till done.
188 class BuildProtoRunner { 188 class BuildProtoRunner {
189 public: 189 public:
190 explicit BuildProtoRunner(content::BrowserContext* browser_context) 190 BuildProtoRunner() {}
191 : browser_context_(browser_context) {}
192
193 ~BuildProtoRunner() {} 191 ~BuildProtoRunner() {}
194 192
195 void BuildSync( 193 void BuildSync(
196 const GURL& best_primary_icon_url, 194 const GURL& best_primary_icon_url,
197 const GURL& best_badge_icon_url, 195 const GURL& best_badge_icon_url,
198 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, 196 const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
199 bool is_manifest_stale) { 197 bool is_manifest_stale) {
200 ShortcutInfo info(GURL::EmptyGURL()); 198 ShortcutInfo info(GURL::EmptyGURL());
201 info.best_primary_icon_url = best_primary_icon_url; 199 info.best_primary_icon_url = best_primary_icon_url;
202 info.best_badge_icon_url = best_badge_icon_url; 200 info.best_badge_icon_url = best_badge_icon_url;
203 201
204 // WebApkInstaller owns itself.
205 SkBitmap primary_icon(gfx::test::CreateBitmap(144, 144)); 202 SkBitmap primary_icon(gfx::test::CreateBitmap(144, 144));
206 SkBitmap badge_icon(gfx::test::CreateBitmap(72, 72)); 203 SkBitmap badge_icon(gfx::test::CreateBitmap(72, 72));
207 WebApkInstaller* installer = new TestWebApkInstaller( 204 WebApkInstaller::BuildProto(
208 browser_context_, info, primary_icon, badge_icon); 205 info, primary_icon, badge_icon, "" /* package_name */, "" /* version */,
209 installer->BuildWebApkProtoInBackgroundForTesting( 206 icon_url_to_murmur2_hash, is_manifest_stale,
210 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto, 207 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto,
211 base::Unretained(this)), 208 base::Unretained(this)));
212 icon_url_to_murmur2_hash, is_manifest_stale);
213 209
214 base::RunLoop run_loop; 210 base::RunLoop run_loop;
215 on_completed_callback_ = run_loop.QuitClosure(); 211 on_completed_callback_ = run_loop.QuitClosure();
216 run_loop.Run(); 212 run_loop.Run();
217 } 213 }
218 214
219 webapk::WebApk* GetWebApkRequest() { return webapk_request_.get(); } 215 webapk::WebApk* GetWebApkRequest() { return webapk_request_.get(); }
220 216
221 private: 217 private:
222 // Called when the |webapk_request_| is populated. 218 // Called when the |webapk_request_| is populated.
223 void OnBuiltWebApkProto(std::unique_ptr<webapk::WebApk> webapk) { 219 void OnBuiltWebApkProto(std::unique_ptr<webapk::WebApk> webapk) {
224 webapk_request_ = std::move(webapk); 220 webapk_request_ = std::move(webapk);
225 on_completed_callback_.Run(); 221 on_completed_callback_.Run();
226 } 222 }
227 223
228 content::BrowserContext* browser_context_;
229
230 // The populated webapk::WebApk. 224 // The populated webapk::WebApk.
231 std::unique_ptr<webapk::WebApk> webapk_request_; 225 std::unique_ptr<webapk::WebApk> webapk_request_;
232 226
233 // Called after the |webapk_request_| is built. 227 // Called after the |webapk_request_| is built.
234 base::Closure on_completed_callback_; 228 base::Closure on_completed_callback_;
235 229
236 DISALLOW_COPY_AND_ASSIGN(BuildProtoRunner); 230 DISALLOW_COPY_AND_ASSIGN(BuildProtoRunner);
237 }; 231 };
238 232
239 } // anonymous namespace 233 } // anonymous namespace
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 void SetWebApkResponseBuilder(const WebApkResponseBuilder& builder) { 279 void SetWebApkResponseBuilder(const WebApkResponseBuilder& builder) {
286 webapk_response_builder_ = builder; 280 webapk_response_builder_ = builder;
287 } 281 }
288 282
289 std::unique_ptr<WebApkInstallerRunner> CreateWebApkInstallerRunner() { 283 std::unique_ptr<WebApkInstallerRunner> CreateWebApkInstallerRunner() {
290 return std::unique_ptr<WebApkInstallerRunner>(new WebApkInstallerRunner( 284 return std::unique_ptr<WebApkInstallerRunner>(new WebApkInstallerRunner(
291 profile_.get(), best_primary_icon_url_, best_badge_icon_url_)); 285 profile_.get(), best_primary_icon_url_, best_badge_icon_url_));
292 } 286 }
293 287
294 std::unique_ptr<BuildProtoRunner> CreateBuildProtoRunner() { 288 std::unique_ptr<BuildProtoRunner> CreateBuildProtoRunner() {
295 return std::unique_ptr<BuildProtoRunner>( 289 return std::unique_ptr<BuildProtoRunner>(new BuildProtoRunner());
296 new BuildProtoRunner(profile_.get()));
297 } 290 }
298 291
299 net::test_server::EmbeddedTestServer* test_server() { return &test_server_; } 292 net::test_server::EmbeddedTestServer* test_server() { return &test_server_; }
300 293
301 private: 294 private:
302 // Sets default configuration for running WebApkInstaller. 295 // Sets default configuration for running WebApkInstaller.
303 void SetDefaults() { 296 void SetDefaults() {
304 SetBestPrimaryIconUrl(test_server_.GetURL(kBestPrimaryIconUrl)); 297 SetBestPrimaryIconUrl(test_server_.GetURL(kBestPrimaryIconUrl));
305 SetBestBadgeIconUrl(test_server_.GetURL(kBestBadgeIconUrl)); 298 SetBestBadgeIconUrl(test_server_.GetURL(kBestBadgeIconUrl));
306 SetWebApkServerUrl(test_server_.GetURL(kServerUrl)); 299 SetWebApkServerUrl(test_server_.GetURL(kServerUrl));
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 EXPECT_FALSE(icons[0].has_image_data()); 522 EXPECT_FALSE(icons[0].has_image_data());
530 523
531 // Check protobuf fields for kBestPrimaryIconUrl. 524 // Check protobuf fields for kBestPrimaryIconUrl.
532 EXPECT_EQ(best_icon_url, icons[1].src()); 525 EXPECT_EQ(best_icon_url, icons[1].src());
533 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());
534 EXPECT_THAT(icons[1].usages(), 527 EXPECT_THAT(icons[1].usages(),
535 testing::ElementsAre(webapk::Image::PRIMARY_ICON, 528 testing::ElementsAre(webapk::Image::PRIMARY_ICON,
536 webapk::Image::BADGE_ICON)); 529 webapk::Image::BADGE_ICON));
537 EXPECT_TRUE(icons[1].has_image_data()); 530 EXPECT_TRUE(icons[1].has_image_data());
538 } 531 }
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