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

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

Issue 2921623004: Support badge icon in WebAPK update components (Closed)
Patch Set: rebase 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
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 13 matching lines...) Expand all
24 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
25 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
26 #include "content/public/test/test_browser_thread_bundle.h" 26 #include "content/public/test/test_browser_thread_bundle.h"
27 #include "net/test/embedded_test_server/embedded_test_server.h" 27 #include "net/test/embedded_test_server/embedded_test_server.h"
28 #include "net/test/embedded_test_server/http_request.h" 28 #include "net/test/embedded_test_server/http_request.h"
29 #include "net/test/embedded_test_server/http_response.h" 29 #include "net/test/embedded_test_server/http_response.h"
30 #include "net/url_request/url_request_test_util.h" 30 #include "net/url_request/url_request_test_util.h"
31 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 #include "third_party/skia/include/core/SkBitmap.h" 33 #include "third_party/skia/include/core/SkBitmap.h"
34 #include "ui/gfx/image/image_unittest_util.h"
34 #include "url/gurl.h" 35 #include "url/gurl.h"
35 36
36 namespace { 37 namespace {
37 38
38 const base::FilePath::CharType kTestDataDir[] = 39 const base::FilePath::CharType kTestDataDir[] =
39 FILE_PATH_LITERAL("chrome/test/data"); 40 FILE_PATH_LITERAL("chrome/test/data");
40 41
41 // URL of mock WebAPK server. 42 // URL of mock WebAPK server.
42 const char* kServerUrl = "/webapkserver/"; 43 const char* kServerUrl = "/webapkserver/";
43 44
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 void BuildSync( 195 void BuildSync(
195 const GURL& best_primary_icon_url, 196 const GURL& best_primary_icon_url,
196 const GURL& best_badge_icon_url, 197 const GURL& best_badge_icon_url,
197 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, 198 const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
198 bool is_manifest_stale) { 199 bool is_manifest_stale) {
199 ShortcutInfo info(GURL::EmptyGURL()); 200 ShortcutInfo info(GURL::EmptyGURL());
200 info.best_primary_icon_url = best_primary_icon_url; 201 info.best_primary_icon_url = best_primary_icon_url;
201 info.best_badge_icon_url = best_badge_icon_url; 202 info.best_badge_icon_url = best_badge_icon_url;
202 203
203 // WebApkInstaller owns itself. 204 // WebApkInstaller owns itself.
204 WebApkInstaller* installer = 205 SkBitmap primary_icon(gfx::test::CreateBitmap(144, 144));
205 new TestWebApkInstaller(browser_context_, info, SkBitmap(), SkBitmap()); 206 SkBitmap badge_icon(gfx::test::CreateBitmap(72, 72));
207 WebApkInstaller* installer = new TestWebApkInstaller(
208 browser_context_, info, primary_icon, badge_icon);
206 installer->BuildWebApkProtoInBackgroundForTesting( 209 installer->BuildWebApkProtoInBackgroundForTesting(
207 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto, 210 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto,
208 base::Unretained(this)), 211 base::Unretained(this)),
209 icon_url_to_murmur2_hash, is_manifest_stale); 212 icon_url_to_murmur2_hash, is_manifest_stale);
210 213
211 base::RunLoop run_loop; 214 base::RunLoop run_loop;
212 on_completed_callback_ = run_loop.QuitClosure(); 215 on_completed_callback_ = run_loop.QuitClosure();
213 run_loop.Run(); 216 run_loop.Run();
214 } 217 }
215 218
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 // one installed on the client. 406 // one installed on the client.
404 TEST_F(WebApkInstallerTest, UpdateSuccessWithEmptyDownloadUrlInResponse) { 407 TEST_F(WebApkInstallerTest, UpdateSuccessWithEmptyDownloadUrlInResponse) {
405 SetWebApkResponseBuilder(base::Bind(&BuildValidWebApkResponse, "")); 408 SetWebApkResponseBuilder(base::Bind(&BuildValidWebApkResponse, ""));
406 409
407 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); 410 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
408 runner->RunUpdateWebApk(); 411 runner->RunUpdateWebApk();
409 EXPECT_EQ(WebApkInstallResult::SUCCESS, runner->result()); 412 EXPECT_EQ(WebApkInstallResult::SUCCESS, runner->result());
410 } 413 }
411 414
412 // When there is no Web Manifest available for a site, an empty 415 // 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 416 // |best_primary_icon_url| and an empty |best_badge_icon_url| is used to build a
414 // request can be built properly. 417 // WebApk update request. Tests the request can be built properly.
415 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) { 418 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) {
416 std::string icon_url_1 = test_server()->GetURL("/icon1.png").spec(); 419 std::string icon_url_1 = test_server()->GetURL("/icon1.png").spec();
417 std::string icon_url_2 = test_server()->GetURL("/icon2.png").spec(); 420 std::string icon_url_2 = test_server()->GetURL("/icon2.png").spec();
418 std::map<std::string, std::string> icon_url_to_murmur2_hash; 421 std::map<std::string, std::string> icon_url_to_murmur2_hash;
419 icon_url_to_murmur2_hash[icon_url_1] = "1"; 422 icon_url_to_murmur2_hash[icon_url_1] = "1";
420 icon_url_to_murmur2_hash[icon_url_2] = "2"; 423 icon_url_to_murmur2_hash[icon_url_2] = "2";
421 424
422 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); 425 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner();
423 runner->BuildSync(GURL(), GURL(), icon_url_to_murmur2_hash, 426 runner->BuildSync(GURL(), GURL(), icon_url_to_murmur2_hash,
424 true /* is_manifest_stale*/); 427 true /* is_manifest_stale*/);
425 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); 428 webapk::WebApk* webapk_request = runner->GetWebApkRequest();
426 ASSERT_NE(nullptr, webapk_request); 429 ASSERT_NE(nullptr, webapk_request);
427 430
428 webapk::WebAppManifest manifest = webapk_request->manifest(); 431 webapk::WebAppManifest manifest = webapk_request->manifest();
429 ASSERT_EQ(3, manifest.icons_size()); 432 ASSERT_EQ(4, manifest.icons_size());
430 433
431 webapk::Image icons[3]; 434 webapk::Image icons[4];
432 for (int i = 0; i < 3; ++i) 435 for (int i = 0; i < 4; ++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
439 EXPECT_EQ(icon_url_1, icons[1].src()); 442 EXPECT_EQ("", icons[1].src());
440 EXPECT_EQ(icon_url_to_murmur2_hash[icon_url_1], icons[1].hash()); 443 EXPECT_FALSE(icons[1].has_hash());
441 EXPECT_FALSE(icons[1].has_image_data()); 444 EXPECT_TRUE(icons[1].has_image_data());
442 445
443 EXPECT_EQ(icon_url_2, icons[2].src()); 446 EXPECT_EQ(icon_url_1, icons[2].src());
444 EXPECT_EQ(icon_url_to_murmur2_hash[icon_url_2], icons[2].hash()); 447 EXPECT_EQ(icon_url_to_murmur2_hash[icon_url_1], icons[2].hash());
445 EXPECT_FALSE(icons[2].has_image_data()); 448 EXPECT_FALSE(icons[2].has_image_data());
449
450 EXPECT_EQ(icon_url_2, icons[3].src());
451 EXPECT_EQ(icon_url_to_murmur2_hash[icon_url_2], icons[3].hash());
452 EXPECT_FALSE(icons[3].has_image_data());
446 } 453 }
447 454
448 // Tests a WebApk install or update request is built properly when the Chrome 455 // Tests a WebApk install or update request is built properly when the Chrome
449 // knows the best icon URL of a site after fetching its Web Manifest. 456 // knows the best icon URL of a site after fetching its Web Manifest.
450 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsAvailable) { 457 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsAvailable) {
451 std::string icon_url_1 = test_server()->GetURL("/icon.png").spec(); 458 std::string icon_url_1 = test_server()->GetURL("/icon.png").spec();
452 std::string best_primary_icon_url = 459 std::string best_primary_icon_url =
453 test_server()->GetURL(kBestPrimaryIconUrl).spec(); 460 test_server()->GetURL(kBestPrimaryIconUrl).spec();
454 std::string best_badge_icon_url = 461 std::string best_badge_icon_url =
455 test_server()->GetURL(kBestBadgeIconUrl).spec(); 462 test_server()->GetURL(kBestBadgeIconUrl).spec();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 EXPECT_FALSE(icons[0].has_image_data()); 529 EXPECT_FALSE(icons[0].has_image_data());
523 530
524 // Check protobuf fields for kBestPrimaryIconUrl. 531 // Check protobuf fields for kBestPrimaryIconUrl.
525 EXPECT_EQ(best_icon_url, icons[1].src()); 532 EXPECT_EQ(best_icon_url, icons[1].src());
526 EXPECT_EQ(icon_url_to_murmur2_hash[best_icon_url], icons[1].hash()); 533 EXPECT_EQ(icon_url_to_murmur2_hash[best_icon_url], icons[1].hash());
527 EXPECT_THAT(icons[1].usages(), 534 EXPECT_THAT(icons[1].usages(),
528 testing::ElementsAre(webapk::Image::PRIMARY_ICON, 535 testing::ElementsAre(webapk::Image::PRIMARY_ICON,
529 webapk::Image::BADGE_ICON)); 536 webapk::Image::BADGE_ICON));
530 EXPECT_TRUE(icons[1].has_image_data()); 537 EXPECT_TRUE(icons[1].has_image_data());
531 } 538 }
OLDNEW
« no previous file with comments | « chrome/browser/android/webapk/webapk_installer.cc ('k') | chrome/browser/android/webapk/webapk_update_data_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698