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

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

Issue 2515293004: Chrome talks to Play to install WebAPKs. (Closed)
Patch Set: Add a test for play install webapk. Created 4 years 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 // URL of file to download from the WebAPK server. We use a random file in the 46 // URL of file to download from the WebAPK server. We use a random file in the
47 // test data directory. 47 // test data directory.
48 const char* kDownloadUrl = "/simple.html"; 48 const char* kDownloadUrl = "/simple.html";
49 49
50 // The package name of the downloaded WebAPK. 50 // The package name of the downloaded WebAPK.
51 const char* kDownloadedWebApkPackageName = "party.unicode"; 51 const char* kDownloadedWebApkPackageName = "party.unicode";
52 52
53 // WebApkInstaller subclass where 53 // WebApkInstaller subclass where
54 // WebApkInstaller::StartInstallingDownloadedWebApk() and 54 // WebApkInstaller::StartInstallingDownloadedWebApk() and
55 // WebApkInstaller::StartUpdateUsingDownloadedWebApk() are stubbed out. 55 // WebApkInstaller::StartUpdateUsingDownloadedWebApk() and
56 // WebApkInstaller::HasGooglePlayWebApkInstallDelegate() and
57 // WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay() are stubbed out.
56 class TestWebApkInstaller : public WebApkInstaller { 58 class TestWebApkInstaller : public WebApkInstaller {
57 public: 59 public:
58 TestWebApkInstaller(const ShortcutInfo& shortcut_info, 60 TestWebApkInstaller(const ShortcutInfo& shortcut_info,
59 const SkBitmap& shortcut_icon) 61 const SkBitmap& shortcut_icon,
60 : WebApkInstaller(shortcut_info, shortcut_icon) {} 62 bool has_google_play_webapk_install_delegate)
63 : WebApkInstaller(shortcut_info, shortcut_icon),
64 has_google_play_webapk_install_delegate_(
65 has_google_play_webapk_install_delegate) {}
61 66
62 bool StartInstallingDownloadedWebApk( 67 bool StartInstallingDownloadedWebApk(
63 JNIEnv* env, 68 JNIEnv* env,
64 const base::android::ScopedJavaLocalRef<jstring>& file_path, 69 const base::android::ScopedJavaLocalRef<jstring>& file_path,
65 const base::android::ScopedJavaLocalRef<jstring>& package_name) override { 70 const base::android::ScopedJavaLocalRef<jstring>& package_name) override {
66 PostTaskToRunSuccessCallback(); 71 PostTaskToRunSuccessCallback();
67 return true; 72 return true;
68 } 73 }
69 74
70 bool StartUpdateUsingDownloadedWebApk( 75 bool StartUpdateUsingDownloadedWebApk(
71 JNIEnv* env, 76 JNIEnv* env,
72 const base::android::ScopedJavaLocalRef<jstring>& file_path) override { 77 const base::android::ScopedJavaLocalRef<jstring>& file_path) override {
73 return true; 78 return true;
74 } 79 }
75 80
81 bool HasGooglePlayWebApkInstallDelegate() override {
82 return has_google_play_webapk_install_delegate_;
83 }
84
85 bool InstallOrUpdateWebApkFromGooglePlay(const std::string& package_name,
86 int version,
87 const std::string& token) override {
88 PostTaskToRunSuccessCallback();
89 return true;
90 }
91
76 void PostTaskToRunSuccessCallback() { 92 void PostTaskToRunSuccessCallback() {
77 base::ThreadTaskRunnerHandle::Get()->PostTask( 93 base::ThreadTaskRunnerHandle::Get()->PostTask(
78 FROM_HERE, 94 FROM_HERE,
79 base::Bind(&TestWebApkInstaller::OnSuccess, base::Unretained(this))); 95 base::Bind(&TestWebApkInstaller::OnSuccess, base::Unretained(this)));
80 } 96 }
81 97
82 private: 98 private:
99 // Whether installing WebApks using Google Play is enabled.
100 bool has_google_play_webapk_install_delegate_;
101
83 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); 102 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller);
84 }; 103 };
85 104
86 // Runs the WebApkInstaller installation process/update and blocks till done. 105 // Runs the WebApkInstaller installation process/update and blocks till done.
87 class WebApkInstallerRunner { 106 class WebApkInstallerRunner {
88 public: 107 public:
89 explicit WebApkInstallerRunner(const GURL& best_icon_url) 108 explicit WebApkInstallerRunner(const GURL& best_icon_url)
90 : url_request_context_getter_(new net::TestURLRequestContextGetter( 109 : url_request_context_getter_(new net::TestURLRequestContextGetter(
91 base::ThreadTaskRunnerHandle::Get())), 110 base::ThreadTaskRunnerHandle::Get())),
92 best_icon_url_(best_icon_url) {} 111 best_icon_url_(best_icon_url),
112 has_google_play_webapk_install_delegate_(false) {}
113
93 ~WebApkInstallerRunner() {} 114 ~WebApkInstallerRunner() {}
94 115
116 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.
117 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.
118 has_google_play_webapk_install_delegate_ =
119 has_google_play_webapk_install_delegate;
120 }
121
95 void RunInstallWebApk() { 122 void RunInstallWebApk() {
96 WebApkInstaller* installer = CreateWebApkInstaller(); 123 WebApkInstaller* installer = CreateWebApkInstaller();
97 124
98 installer->InstallAsyncWithURLRequestContextGetter( 125 installer->InstallAsyncWithURLRequestContextGetter(
99 url_request_context_getter_.get(), 126 url_request_context_getter_.get(),
100 base::Bind(&WebApkInstallerRunner::OnCompleted, 127 base::Bind(&WebApkInstallerRunner::OnCompleted,
101 base::Unretained(this))); 128 base::Unretained(this)));
102 Run(); 129 Run();
103 } 130 }
104 131
(...skipping 11 matching lines...) Expand all
116 kWebApkVersion); 143 kWebApkVersion);
117 144
118 Run(); 145 Run();
119 } 146 }
120 147
121 WebApkInstaller* CreateWebApkInstaller() { 148 WebApkInstaller* CreateWebApkInstaller() {
122 ShortcutInfo info(GURL::EmptyGURL()); 149 ShortcutInfo info(GURL::EmptyGURL());
123 info.best_icon_url = best_icon_url_; 150 info.best_icon_url = best_icon_url_;
124 151
125 // WebApkInstaller owns itself. 152 // WebApkInstaller owns itself.
126 WebApkInstaller* installer = new TestWebApkInstaller(info, SkBitmap()); 153 WebApkInstaller* installer = new TestWebApkInstaller(
154 info, SkBitmap(), has_google_play_webapk_install_delegate_);
127 installer->SetTimeoutMs(100); 155 installer->SetTimeoutMs(100);
128 return installer; 156 return installer;
129 } 157 }
130 158
131 void Run() { 159 void Run() {
132 base::RunLoop run_loop; 160 base::RunLoop run_loop;
133 on_completed_callback_ = run_loop.QuitClosure(); 161 on_completed_callback_ = run_loop.QuitClosure();
134 run_loop.Run(); 162 run_loop.Run();
135 } 163 }
136 164
(...skipping 10 matching lines...) Expand all
147 175
148 // The Web Manifest's icon URL. 176 // The Web Manifest's icon URL.
149 const GURL best_icon_url_; 177 const GURL best_icon_url_;
150 178
151 // Called after the installation process has succeeded or failed. 179 // Called after the installation process has succeeded or failed.
152 base::Closure on_completed_callback_; 180 base::Closure on_completed_callback_;
153 181
154 // Whether the installation process succeeded. 182 // Whether the installation process succeeded.
155 bool success_; 183 bool success_;
156 184
185 // Whether installing WebAPKs using Google Play is enabled.
186 bool has_google_play_webapk_install_delegate_;
187
157 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerRunner); 188 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerRunner);
158 }; 189 };
159 190
160 // Builds a webapk::WebApkResponse with |download_url| as the WebAPK download 191 // Builds a webapk::WebApkResponse with |download_url| as the WebAPK download
161 // URL. 192 // URL.
162 std::unique_ptr<net::test_server::HttpResponse> BuildValidWebApkResponse( 193 std::unique_ptr<net::test_server::HttpResponse> BuildValidWebApkResponse(
163 const GURL& download_url) { 194 const GURL& download_url) {
164 std::unique_ptr<webapk::WebApkResponse> response_proto( 195 std::unique_ptr<webapk::WebApkResponse> response_proto(
165 new webapk::WebApkResponse); 196 new webapk::WebApkResponse);
166 response_proto->set_package_name(kDownloadedWebApkPackageName); 197 response_proto->set_package_name(kDownloadedWebApkPackageName);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 runner->RunInstallWebApk(); 355 runner->RunInstallWebApk();
325 EXPECT_FALSE(runner->success()); 356 EXPECT_FALSE(runner->success());
326 } 357 }
327 358
328 // Test update succeeding. 359 // Test update succeeding.
329 TEST_F(WebApkInstallerTest, UpdateSuccess) { 360 TEST_F(WebApkInstallerTest, UpdateSuccess) {
330 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); 361 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
331 runner->RunUpdateWebApk(); 362 runner->RunUpdateWebApk();
332 EXPECT_TRUE(runner->success()); 363 EXPECT_TRUE(runner->success());
333 } 364 }
365
366 // Test installation succeeds using Google Play.
367 TEST_F(WebApkInstallerTest, InstallFromGooglePlaySuccess) {
368 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
369 runner->setHasGooglePlayWebApkInstallDelegate(true);
370 runner->RunInstallWebApk();
371 EXPECT_TRUE(runner->success());
372 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698