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

Unified Diff: chrome/browser/android/webapk/webapk_installer_unittest.cc

Issue 2676863002: Update WebApkInstaller to support badge icon in installation. (Closed)
Patch Set: Rebase Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
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 7a12d954f3351ed2ee9ef3185600f90fb6b2caa1..22a8355d2d97083ec5a56ea48056707a7bdf377e 100644
--- a/chrome/browser/android/webapk/webapk_installer_unittest.cc
+++ b/chrome/browser/android/webapk/webapk_installer_unittest.cc
@@ -40,10 +40,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.
@@ -61,9 +62,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;
@@ -172,8 +181,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_;
@@ -216,14 +226,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)),
@@ -286,6 +298,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) {
@@ -300,8 +317,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() {
@@ -316,6 +333,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);
@@ -334,8 +353,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_;
@@ -362,6 +382,18 @@ TEST_F(WebApkInstallerTest, BestPrimaryIconUrlDownloadTimesOut) {
EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result());
}
+// 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);
pkotwicz 2017/03/30 21:49:50 Nit: You can merge lines 389 and 390
F 2017/04/03 21:57:29 Done.
+
+ std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
+ runner->RunInstallWebApk();
+ EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result());
+}
+
// Test that installation fails if the WebAPK creation request times out.
TEST_F(WebApkInstallerTest, CreateWebApkRequestTimesOut) {
GURL server_url = test_server()->GetURL("/slow?1000");
@@ -459,7 +491,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,
pkotwicz 2017/03/30 21:49:50 Nit: You can use the no-arg constructor of GURL()
F 2017/04/03 21:57:29 Done.
true /* is_manifest_stale*/);
webapk::WebApk* webapk_request = runner->GetWebApkRequest();
ASSERT_NE(nullptr, webapk_request);
@@ -489,16 +521,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);

Powered by Google App Engine
This is Rietveld 408576698