| Index: chrome/browser/android/webapk/webapk_installer_unittest.cc
|
| diff --git a/chrome/browser/android/webapk/webapk_installer_unittest.cc b/chrome/browser/android/webapk/webapk_installer_unittest.cc
|
| index 96a82320ddcfa879b3329bac06d7b79aa2cf4b52..1625246667468b870947d937fe426aaef713524f 100644
|
| --- a/chrome/browser/android/webapk/webapk_installer_unittest.cc
|
| +++ b/chrome/browser/android/webapk/webapk_installer_unittest.cc
|
| @@ -39,10 +39,11 @@ const base::FilePath::CharType kTestDataDir[] =
|
| // URL of mock WebAPK server.
|
| const char* kServerUrl = "/webapkserver/";
|
|
|
| -// The best primary icon URL from Web Manifest. We use a random file in the test
|
| +// The URLs of best icons from Web Manifest. We use a random file in the test
|
| // data directory. Since WebApkInstaller does not try to decode the file as an
|
| // image it is OK that the file is not an image.
|
| const char* kBestPrimaryIconUrl = "/simple.html";
|
| +const char* kBestBadgeIconUrl = "/simple.html";
|
|
|
| // URL of file to download from the WebAPK server. We use a random file in the
|
| // test data directory.
|
| @@ -60,9 +61,13 @@ class TestWebApkInstaller : public WebApkInstaller {
|
| public:
|
| TestWebApkInstaller(content::BrowserContext* browser_context,
|
| const ShortcutInfo& shortcut_info,
|
| - const SkBitmap& shortcut_icon,
|
| + const SkBitmap& primary_icon,
|
| + const SkBitmap& badge_icon,
|
| bool can_use_google_play_install_service)
|
| - : WebApkInstaller(browser_context, shortcut_info, shortcut_icon),
|
| + : WebApkInstaller(browser_context,
|
| + shortcut_info,
|
| + primary_icon,
|
| + badge_icon),
|
| can_use_google_play_install_service_(
|
| can_use_google_play_install_service) {}
|
|
|
| @@ -109,9 +114,11 @@ class TestWebApkInstaller : public WebApkInstaller {
|
| class WebApkInstallerRunner {
|
| public:
|
| WebApkInstallerRunner(content::BrowserContext* browser_context,
|
| - const GURL& best_primary_icon_url)
|
| + const GURL& best_primary_icon_url,
|
| + const GURL& best_badge_icon_url)
|
| : browser_context_(browser_context),
|
| best_primary_icon_url_(best_primary_icon_url),
|
| + best_badge_icon_url_(best_badge_icon_url),
|
| can_use_google_play_install_service_(false) {}
|
|
|
| ~WebApkInstallerRunner() {}
|
| @@ -132,7 +139,8 @@ class WebApkInstallerRunner {
|
| const int kWebApkVersion = 1;
|
|
|
| std::map<std::string, std::string> icon_url_to_murmur2_hash{
|
| - {best_primary_icon_url_.spec(), "0"}};
|
| + {best_primary_icon_url_.spec(), "0"},
|
| + {best_badge_icon_url_.spec(), "0"}};
|
|
|
| WebApkInstaller::UpdateAsyncForTesting(
|
| CreateWebApkInstaller(), kDownloadedWebApkPackageName, kWebApkVersion,
|
| @@ -145,10 +153,11 @@ class WebApkInstallerRunner {
|
| WebApkInstaller* CreateWebApkInstaller() {
|
| ShortcutInfo info(GURL::EmptyGURL());
|
| info.best_primary_icon_url = best_primary_icon_url_;
|
| + info.best_badge_icon_url = best_badge_icon_url_;
|
|
|
| // WebApkInstaller owns itself.
|
| WebApkInstaller* installer =
|
| - new TestWebApkInstaller(browser_context_, info, SkBitmap(),
|
| + new TestWebApkInstaller(browser_context_, info, SkBitmap(), SkBitmap(),
|
| can_use_google_play_install_service_);
|
| installer->SetTimeoutMs(100);
|
| return installer;
|
| @@ -170,8 +179,9 @@ class WebApkInstallerRunner {
|
|
|
| content::BrowserContext* browser_context_;
|
|
|
| - // The Web Manifest's icon URL.
|
| + // The Web Manifest's icon URLs.
|
| const GURL best_primary_icon_url_;
|
| + const GURL best_badge_icon_url_;
|
|
|
| // Called after the installation process has succeeded or failed.
|
| base::Closure on_completed_callback_;
|
| @@ -214,14 +224,16 @@ class BuildProtoRunner {
|
|
|
| void BuildSync(
|
| const GURL& best_primary_icon_url,
|
| + const GURL& best_badge_icon_url,
|
| const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
|
| bool is_manifest_stale) {
|
| ShortcutInfo info(GURL::EmptyGURL());
|
| info.best_primary_icon_url = best_primary_icon_url;
|
| + info.best_badge_icon_url = best_badge_icon_url;
|
|
|
| // WebApkInstaller owns itself.
|
| - WebApkInstaller* installer =
|
| - new TestWebApkInstaller(browser_context_, info, SkBitmap(), false);
|
| + WebApkInstaller* installer = new TestWebApkInstaller(
|
| + browser_context_, info, SkBitmap(), SkBitmap(), false);
|
| installer->BuildWebApkProtoInBackgroundForTesting(
|
| base::Bind(&BuildProtoRunner::OnBuiltWebApkProto,
|
| base::Unretained(this)),
|
| @@ -284,6 +296,11 @@ class WebApkInstallerTest : public ::testing::Test {
|
| best_primary_icon_url_ = best_primary_icon_url;
|
| }
|
|
|
| + // Sets the best Web Manifest's badge icon URL.
|
| + void SetBestBadgeIconUrl(const GURL& best_badge_icon_url) {
|
| + best_badge_icon_url_ = best_badge_icon_url;
|
| + }
|
| +
|
| // Sets the URL to send the webapk::CreateWebApkRequest to. WebApkInstaller
|
| // should fail if the URL is not |kServerUrl|.
|
| void SetWebApkServerUrl(const GURL& server_url) {
|
| @@ -298,8 +315,8 @@ class WebApkInstallerTest : public ::testing::Test {
|
| }
|
|
|
| std::unique_ptr<WebApkInstallerRunner> CreateWebApkInstallerRunner() {
|
| - return std::unique_ptr<WebApkInstallerRunner>(
|
| - new WebApkInstallerRunner(profile_.get(), best_primary_icon_url_));
|
| + return std::unique_ptr<WebApkInstallerRunner>(new WebApkInstallerRunner(
|
| + profile_.get(), best_primary_icon_url_, best_badge_icon_url_));
|
| }
|
|
|
| std::unique_ptr<BuildProtoRunner> CreateBuildProtoRunner() {
|
| @@ -314,6 +331,8 @@ class WebApkInstallerTest : public ::testing::Test {
|
| void SetDefaults() {
|
| GURL best_primary_icon_url = test_server_.GetURL(kBestPrimaryIconUrl);
|
| SetBestPrimaryIconUrl(best_primary_icon_url);
|
| + GURL best_badge_icon_url = test_server_.GetURL(kBestBadgeIconUrl);
|
| + SetBestBadgeIconUrl(best_badge_icon_url);
|
| GURL server_url = test_server_.GetURL(kServerUrl);
|
| SetWebApkServerUrl(server_url);
|
| GURL download_url = test_server_.GetURL(kDownloadUrl);
|
| @@ -332,8 +351,9 @@ class WebApkInstallerTest : public ::testing::Test {
|
| content::TestBrowserThreadBundle thread_bundle_;
|
| net::EmbeddedTestServer test_server_;
|
|
|
| - // Web Manifest's icon URL.
|
| + // Web Manifest's icon URLs.
|
| GURL best_primary_icon_url_;
|
| + GURL best_badge_icon_url_;
|
|
|
| // Builds response to the WebAPK creation request.
|
| WebApkResponseBuilder webapk_response_builder_;
|
| @@ -360,6 +380,18 @@ TEST_F(WebApkInstallerTest, BestPrimaryIconUrlDownloadTimesOut) {
|
| EXPECT_FALSE(runner->success());
|
| }
|
|
|
| +// Test that installation fails if fetching the bitmap at the best badge icon
|
| +// URL times out. In a perfect world the fetch would never time out because the
|
| +// bitmap at the best badge icon URL should be in the HTTP cache.
|
| +TEST_F(WebApkInstallerTest, BestBadgeIconUrlDownloadTimesOut) {
|
| + GURL best_badge_icon_url = test_server()->GetURL("/slow?1000");
|
| + SetBestBadgeIconUrl(best_badge_icon_url);
|
| +
|
| + std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
|
| + runner->RunInstallWebApk();
|
| + EXPECT_FALSE(runner->success());
|
| +}
|
| +
|
| // Test that installation fails if the WebAPK creation request times out.
|
| TEST_F(WebApkInstallerTest, CreateWebApkRequestTimesOut) {
|
| GURL server_url = test_server()->GetURL("/slow?1000");
|
| @@ -457,7 +489,7 @@ TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) {
|
| icon_url_to_murmur2_hash[icon_url_2.spec()] = icon_murmur2_hash_2;
|
|
|
| std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner();
|
| - runner->BuildSync(GURL(""), icon_url_to_murmur2_hash,
|
| + runner->BuildSync(GURL(""), GURL(""), icon_url_to_murmur2_hash,
|
| true /* is_manifest_stale*/);
|
| webapk::WebApk* webapk_request = runner->GetWebApkRequest();
|
| ASSERT_NE(nullptr, webapk_request);
|
| @@ -487,16 +519,20 @@ TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) {
|
| TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsAvailable) {
|
| GURL icon_url_1 = test_server()->GetURL("/icon.png");
|
| GURL best_primary_icon_url = test_server()->GetURL(kBestPrimaryIconUrl);
|
| + GURL best_badge_icon_url = test_server()->GetURL(kBestBadgeIconUrl);
|
| std::string icon_murmur2_hash_1 = "1";
|
| std::string best_primary_icon_murmur2_hash = "0";
|
| + std::string best_badge_icon_murmur2_hash = "0";
|
| std::map<std::string, std::string> icon_url_to_murmur2_hash;
|
| icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1;
|
| icon_url_to_murmur2_hash[best_primary_icon_url.spec()] =
|
| best_primary_icon_murmur2_hash;
|
| + icon_url_to_murmur2_hash[best_badge_icon_url.spec()] =
|
| + best_badge_icon_murmur2_hash;
|
|
|
| std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner();
|
| - runner->BuildSync(best_primary_icon_url, icon_url_to_murmur2_hash,
|
| - false /* is_manifest_stale*/);
|
| + runner->BuildSync(best_primary_icon_url, best_badge_icon_url,
|
| + icon_url_to_murmur2_hash, false /* is_manifest_stale*/);
|
| webapk::WebApk* webapk_request = runner->GetWebApkRequest();
|
| ASSERT_NE(nullptr, webapk_request);
|
|
|
|
|