OLD | NEW |
---|---|
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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 const GURL& best_primary_icon_url, | 195 const GURL& best_primary_icon_url, |
196 const GURL& best_badge_icon_url, | 196 const GURL& best_badge_icon_url, |
197 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, |
198 bool is_manifest_stale) { | 198 bool is_manifest_stale) { |
199 ShortcutInfo info(GURL::EmptyGURL()); | 199 ShortcutInfo info(GURL::EmptyGURL()); |
200 info.best_primary_icon_url = best_primary_icon_url; | 200 info.best_primary_icon_url = best_primary_icon_url; |
201 info.best_badge_icon_url = best_badge_icon_url; | 201 info.best_badge_icon_url = best_badge_icon_url; |
202 | 202 |
203 // WebApkInstaller owns itself. | 203 // WebApkInstaller owns itself. |
204 WebApkInstaller* installer = | 204 WebApkInstaller* installer = |
205 new TestWebApkInstaller(browser_context_, info, SkBitmap(), SkBitmap()); | 205 new TestWebApkInstaller(browser_context_, info, SkBitmap(), SkBitmap()); |
pkotwicz
2017/06/07 21:22:23
The WebApkInstaller should use a non-empty primary
F
2017/06/08 20:01:12
Done.
| |
206 installer->BuildWebApkProtoInBackgroundForTesting( | 206 installer->BuildWebApkProtoInBackgroundForTesting( |
207 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto, | 207 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto, |
208 base::Unretained(this)), | 208 base::Unretained(this)), |
209 icon_url_to_murmur2_hash, is_manifest_stale); | 209 icon_url_to_murmur2_hash, is_manifest_stale); |
210 | 210 |
211 base::RunLoop run_loop; | 211 base::RunLoop run_loop; |
212 on_completed_callback_ = run_loop.QuitClosure(); | 212 on_completed_callback_ = run_loop.QuitClosure(); |
213 run_loop.Run(); | 213 run_loop.Run(); |
214 } | 214 } |
215 | 215 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 // one installed on the client. | 403 // one installed on the client. |
404 TEST_F(WebApkInstallerTest, UpdateSuccessWithEmptyDownloadUrlInResponse) { | 404 TEST_F(WebApkInstallerTest, UpdateSuccessWithEmptyDownloadUrlInResponse) { |
405 SetWebApkResponseBuilder(base::Bind(&BuildValidWebApkResponse, "")); | 405 SetWebApkResponseBuilder(base::Bind(&BuildValidWebApkResponse, "")); |
406 | 406 |
407 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 407 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
408 runner->RunUpdateWebApk(); | 408 runner->RunUpdateWebApk(); |
409 EXPECT_EQ(WebApkInstallResult::SUCCESS, runner->result()); | 409 EXPECT_EQ(WebApkInstallResult::SUCCESS, runner->result()); |
410 } | 410 } |
411 | 411 |
412 // When there is no Web Manifest available for a site, an empty | 412 // When there is no Web Manifest available for a site, an empty |
413 // |best_primary_icon_url| is used to build a WebApk update request. Tests the | 413 // |best_primary_icon_url| and an empty |best_badge_icon_url| is used to build a |
414 // request can be built properly. | 414 // WebApk update request. Tests the request can be built properly. |
415 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) { | 415 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) { |
416 std::string icon_url_1 = test_server()->GetURL("/icon1.png").spec(); | 416 std::string icon_url_1 = test_server()->GetURL("/icon1.png").spec(); |
417 std::string icon_url_2 = test_server()->GetURL("/icon2.png").spec(); | 417 std::string icon_url_2 = test_server()->GetURL("/icon2.png").spec(); |
418 std::map<std::string, std::string> icon_url_to_murmur2_hash; | 418 std::map<std::string, std::string> icon_url_to_murmur2_hash; |
419 icon_url_to_murmur2_hash[icon_url_1] = "1"; | 419 icon_url_to_murmur2_hash[icon_url_1] = "1"; |
420 icon_url_to_murmur2_hash[icon_url_2] = "2"; | 420 icon_url_to_murmur2_hash[icon_url_2] = "2"; |
421 | 421 |
422 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); | 422 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); |
423 runner->BuildSync(GURL(), GURL(), icon_url_to_murmur2_hash, | 423 runner->BuildSync(GURL(), GURL(), icon_url_to_murmur2_hash, |
424 true /* is_manifest_stale*/); | 424 true /* is_manifest_stale*/); |
425 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); | 425 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); |
426 ASSERT_NE(nullptr, webapk_request); | 426 ASSERT_NE(nullptr, webapk_request); |
427 | 427 |
428 webapk::WebAppManifest manifest = webapk_request->manifest(); | 428 webapk::WebAppManifest manifest = webapk_request->manifest(); |
429 // The manifest only has 3 icons because the request is built with empty | |
430 // SKBitmaps as primary icon and badge icon, and empty badge icons are not | |
431 // added to WebAPK proto. | |
429 ASSERT_EQ(3, manifest.icons_size()); | 432 ASSERT_EQ(3, manifest.icons_size()); |
430 | 433 |
431 webapk::Image icons[3]; | 434 webapk::Image icons[3]; |
432 for (int i = 0; i < 3; ++i) | 435 for (int i = 0; i < 3; ++i) |
433 icons[i] = manifest.icons(i); | 436 icons[i] = manifest.icons(i); |
434 | 437 |
435 EXPECT_EQ("", icons[0].src()); | 438 EXPECT_EQ("", icons[0].src()); |
436 EXPECT_FALSE(icons[0].has_hash()); | 439 EXPECT_FALSE(icons[0].has_hash()); |
437 EXPECT_TRUE(icons[0].has_image_data()); | 440 EXPECT_TRUE(icons[0].has_image_data()); |
438 | 441 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 EXPECT_FALSE(icons[0].has_image_data()); | 525 EXPECT_FALSE(icons[0].has_image_data()); |
523 | 526 |
524 // Check protobuf fields for kBestPrimaryIconUrl. | 527 // Check protobuf fields for kBestPrimaryIconUrl. |
525 EXPECT_EQ(best_icon_url, icons[1].src()); | 528 EXPECT_EQ(best_icon_url, icons[1].src()); |
526 EXPECT_EQ(icon_url_to_murmur2_hash[best_icon_url], icons[1].hash()); | 529 EXPECT_EQ(icon_url_to_murmur2_hash[best_icon_url], icons[1].hash()); |
527 EXPECT_THAT(icons[1].usages(), | 530 EXPECT_THAT(icons[1].usages(), |
528 testing::ElementsAre(webapk::Image::PRIMARY_ICON, | 531 testing::ElementsAre(webapk::Image::PRIMARY_ICON, |
529 webapk::Image::BADGE_ICON)); | 532 webapk::Image::BADGE_ICON)); |
530 EXPECT_TRUE(icons[1].has_image_data()); | 533 EXPECT_TRUE(icons[1].has_image_data()); |
531 } | 534 } |
OLD | NEW |