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

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

Issue 2933783002: [Android WebAPK] Change WebAPK update into two phases (Closed)
Patch Set: 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 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 4d0a2bd798b82f8c87bd1684ee0a40e77bfe5e8f..ea2d74ddd988c0f87a62e645e905b149097c7afa 100644
--- a/chrome/browser/android/webapk/webapk_installer_unittest.cc
+++ b/chrome/browser/android/webapk/webapk_installer_unittest.cc
@@ -62,14 +62,8 @@ const char* kDownloadedWebApkPackageName = "party.unicode";
// WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay() are stubbed out.
class TestWebApkInstaller : public WebApkInstaller {
public:
- TestWebApkInstaller(content::BrowserContext* browser_context,
- const ShortcutInfo& shortcut_info,
- const SkBitmap& primary_icon,
- const SkBitmap& badge_icon)
- : WebApkInstaller(browser_context,
- shortcut_info,
- primary_icon,
- badge_icon) {}
+ TestWebApkInstaller(content::BrowserContext* browser_context)
+ : WebApkInstaller(browser_context) {}
void InstallOrUpdateWebApk(const std::string& package_name,
int version,
@@ -101,45 +95,48 @@ class WebApkInstallerRunner {
~WebApkInstallerRunner() {}
void RunInstallWebApk() {
+ base::RunLoop run_loop;
+ on_completed_callback_ = run_loop.QuitClosure();
+
+ ShortcutInfo info(GURL::EmptyGURL());
dominickn 2017/06/14 00:14:23 Use GURL() (EmptyGURL() should only be used when y
pkotwicz 2017/06/15 02:25:20 Ok. This has to be ShortcutInfo info((GURL()));
+ info.best_primary_icon_url = best_primary_icon_url_;
+ info.best_badge_icon_url = best_badge_icon_url_;
WebApkInstaller::InstallAsyncForTesting(
- CreateWebApkInstaller(), base::Bind(&WebApkInstallerRunner::OnCompleted,
- base::Unretained(this)));
- Run();
+ CreateWebApkInstaller(), info, SkBitmap(), SkBitmap(),
+ base::Bind(&WebApkInstallerRunner::OnCompleted,
+ base::Unretained(this)));
+
+ run_loop.Run();
}
- void RunUpdateWebApk() {
- const int kWebApkVersion = 1;
+ void RunUpdateWebApk(const std::string& serialized_proto) {
+ base::RunLoop run_loop;
+ on_completed_callback_ = run_loop.QuitClosure();
std::map<std::string, std::string> icon_url_to_murmur2_hash{
{best_primary_icon_url_.spec(), "0"},
{best_badge_icon_url_.spec(), "0"}};
+ std::unique_ptr<std::vector<uint8_t>> serialized_proto_vector(
+ new std::vector<uint8_t>(serialized_proto.begin(),
dominickn 2017/06/14 00:14:23 base::MakeUnique
+ serialized_proto.end()));
WebApkInstaller::UpdateAsyncForTesting(
- CreateWebApkInstaller(), kDownloadedWebApkPackageName, kWebApkVersion,
- icon_url_to_murmur2_hash, false /* is_manifest_stale */,
+ CreateWebApkInstaller(), kDownloadedWebApkPackageName,
+ GURL() /* start_url */, base::string16() /* short_name */,
+ std::move(serialized_proto_vector),
base::Bind(&WebApkInstallerRunner::OnCompleted,
base::Unretained(this)));
- Run();
+
+ run_loop.Run();
}
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(), SkBitmap());
+ WebApkInstaller* installer = new TestWebApkInstaller(browser_context_);
installer->SetTimeoutMs(100);
return installer;
}
- void Run() {
- base::RunLoop run_loop;
- on_completed_callback_ = run_loop.QuitClosure();
- run_loop.Run();
- }
-
WebApkInstallResult result() { return result_; }
private:
@@ -215,8 +212,11 @@ class BuildProtoRunner {
private:
// Called when the |webapk_request_| is populated.
- void OnBuiltWebApkProto(std::unique_ptr<webapk::WebApk> webapk) {
- webapk_request_ = std::move(webapk);
+ void OnBuiltWebApkProto(
+ std::unique_ptr<std::vector<uint8_t>> serialized_proto) {
+ webapk_request_.reset(new webapk::WebApk);
dominickn 2017/06/14 00:14:23 base::MakeUnique
+ webapk_request_->ParseFromArray(serialized_proto->data(),
+ serialized_proto->size());
on_completed_callback_.Run();
}
@@ -388,7 +388,7 @@ TEST_F(WebApkInstallerTest, UnparsableCreateWebApkResponse) {
// Test update succeeding.
TEST_F(WebApkInstallerTest, UpdateSuccess) {
std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
- runner->RunUpdateWebApk();
+ runner->RunUpdateWebApk("non-empty");
EXPECT_EQ(WebApkInstallResult::SUCCESS, runner->result());
}
@@ -403,10 +403,17 @@ TEST_F(WebApkInstallerTest, UpdateSuccessWithEmptyDownloadUrlInResponse) {
SetWebApkResponseBuilder(base::Bind(&BuildValidWebApkResponse, ""));
std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
- runner->RunUpdateWebApk();
+ runner->RunUpdateWebApk("non-empty");
EXPECT_EQ(WebApkInstallResult::SUCCESS, runner->result());
}
+// Test that an update fails if an empty proto is passed to UpdateAsync().
+TEST_F(WebApkInstallerTest, UpdateFailsEmptyProto) {
+ std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
+ runner->RunUpdateWebApk("");
+ EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result());
+}
+
// When there is no Web Manifest available for a site, an empty
// |best_primary_icon_url| is used to build a WebApk update request. Tests the
// request can be built properly.

Powered by Google App Engine
This is Rietveld 408576698