Chromium Code Reviews| 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 10021ff93107a0b7e7a694291742e2e107c0910b..f1adaaaed8a1bf9b1bfd62eab3c58401193810fa 100644 |
| --- a/chrome/browser/android/webapk/webapk_installer_unittest.cc |
| +++ b/chrome/browser/android/webapk/webapk_installer_unittest.cc |
| @@ -52,12 +52,17 @@ const char* kDownloadedWebApkPackageName = "party.unicode"; |
| // WebApkInstaller subclass where |
| // WebApkInstaller::StartInstallingDownloadedWebApk() and |
| -// WebApkInstaller::StartUpdateUsingDownloadedWebApk() are stubbed out. |
| +// WebApkInstaller::StartUpdateUsingDownloadedWebApk() and |
| +// WebApkInstaller::HasGooglePlayWebApkInstallDelegate() and |
| +// WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay() are stubbed out. |
| class TestWebApkInstaller : public WebApkInstaller { |
| public: |
| TestWebApkInstaller(const ShortcutInfo& shortcut_info, |
| - const SkBitmap& shortcut_icon) |
| - : WebApkInstaller(shortcut_info, shortcut_icon) {} |
| + const SkBitmap& shortcut_icon, |
| + bool has_google_play_webapk_install_delegate) |
| + : WebApkInstaller(shortcut_info, shortcut_icon), |
| + has_google_play_webapk_install_delegate_( |
| + has_google_play_webapk_install_delegate) {} |
| bool StartInstallingDownloadedWebApk( |
| JNIEnv* env, |
| @@ -73,6 +78,17 @@ class TestWebApkInstaller : public WebApkInstaller { |
| return true; |
| } |
| + bool HasGooglePlayWebApkInstallDelegate() override { |
| + return has_google_play_webapk_install_delegate_; |
| + } |
| + |
| + bool InstallOrUpdateWebApkFromGooglePlay(const std::string& package_name, |
| + int version, |
| + const std::string& token) override { |
| + PostTaskToRunSuccessCallback(); |
| + return true; |
| + } |
| + |
| void PostTaskToRunSuccessCallback() { |
| base::ThreadTaskRunnerHandle::Get()->PostTask( |
| FROM_HERE, |
| @@ -80,6 +96,9 @@ class TestWebApkInstaller : public WebApkInstaller { |
| } |
| private: |
| + // Whether installing WebApks using Google Play is enabled. |
| + bool has_google_play_webapk_install_delegate_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); |
| }; |
| @@ -89,9 +108,17 @@ class WebApkInstallerRunner { |
| explicit WebApkInstallerRunner(const GURL& best_icon_url) |
| : url_request_context_getter_(new net::TestURLRequestContextGetter( |
| base::ThreadTaskRunnerHandle::Get())), |
| - best_icon_url_(best_icon_url) {} |
| + best_icon_url_(best_icon_url), |
| + has_google_play_webapk_install_delegate_(false) {} |
| + |
| ~WebApkInstallerRunner() {} |
| + void setHasGooglePlayWebApkInstallDelegate( |
|
pkotwicz
2016/12/06 16:46:32
Nit: setHasGooglePlayWebApkInstallDelegate() -> Se
Xi Han
2016/12/06 20:30:38
Sorry for the mix of Java naming.
|
| + bool has_google_play_webapk_install_delegate) { |
|
pkotwicz
2016/12/06 16:46:32
Nit: You can rename the parameter to |has_delegate
Xi Han
2016/12/06 20:30:38
Done.
|
| + has_google_play_webapk_install_delegate_ = |
| + has_google_play_webapk_install_delegate; |
| + } |
| + |
| void RunInstallWebApk() { |
| WebApkInstaller* installer = CreateWebApkInstaller(); |
| @@ -123,7 +150,8 @@ class WebApkInstallerRunner { |
| info.best_icon_url = best_icon_url_; |
| // WebApkInstaller owns itself. |
| - WebApkInstaller* installer = new TestWebApkInstaller(info, SkBitmap()); |
| + WebApkInstaller* installer = new TestWebApkInstaller( |
| + info, SkBitmap(), has_google_play_webapk_install_delegate_); |
| installer->SetTimeoutMs(100); |
| return installer; |
| } |
| @@ -154,6 +182,9 @@ class WebApkInstallerRunner { |
| // Whether the installation process succeeded. |
| bool success_; |
| + // Whether installing WebAPKs using Google Play is enabled. |
| + bool has_google_play_webapk_install_delegate_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(WebApkInstallerRunner); |
| }; |
| @@ -331,3 +362,11 @@ TEST_F(WebApkInstallerTest, UpdateSuccess) { |
| runner->RunUpdateWebApk(); |
| EXPECT_TRUE(runner->success()); |
| } |
| + |
| +// Test installation succeeds using Google Play. |
| +TEST_F(WebApkInstallerTest, InstallFromGooglePlaySuccess) { |
| + std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
| + runner->setHasGooglePlayWebApkInstallDelegate(true); |
| + runner->RunInstallWebApk(); |
| + EXPECT_TRUE(runner->success()); |
| +} |