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

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

Issue 2515293004: Chrome talks to Play to install WebAPKs. (Closed)
Patch Set: Upload the missing GooglePlayWebApkInstallDelegate. 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_;
dominickn 2016/12/08 03:31:26 Can you just call this variable "allow_install_fro
Xi Han 2016/12/08 18:03:08 Same here.
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(bool has_delegate) {
dominickn 2016/12/08 03:31:26 Can this be SetAllowInstallFromPlay(bool allow)?
Xi Han 2016/12/08 18:03:08 Same here.
117 has_google_play_webapk_install_delegate_ = has_delegate;
118 }
119
95 void RunInstallWebApk() { 120 void RunInstallWebApk() {
96 WebApkInstaller* installer = CreateWebApkInstaller(); 121 WebApkInstaller* installer = CreateWebApkInstaller();
97 122
98 installer->InstallAsyncWithURLRequestContextGetter( 123 installer->InstallAsyncWithURLRequestContextGetter(
99 url_request_context_getter_.get(), 124 url_request_context_getter_.get(),
100 base::Bind(&WebApkInstallerRunner::OnCompleted, 125 base::Bind(&WebApkInstallerRunner::OnCompleted,
101 base::Unretained(this))); 126 base::Unretained(this)));
102 Run(); 127 Run();
103 } 128 }
104 129
(...skipping 11 matching lines...) Expand all
116 kWebApkVersion); 141 kWebApkVersion);
117 142
118 Run(); 143 Run();
119 } 144 }
120 145
121 WebApkInstaller* CreateWebApkInstaller() { 146 WebApkInstaller* CreateWebApkInstaller() {
122 ShortcutInfo info(GURL::EmptyGURL()); 147 ShortcutInfo info(GURL::EmptyGURL());
123 info.best_icon_url = best_icon_url_; 148 info.best_icon_url = best_icon_url_;
124 149
125 // WebApkInstaller owns itself. 150 // WebApkInstaller owns itself.
126 WebApkInstaller* installer = new TestWebApkInstaller(info, SkBitmap()); 151 WebApkInstaller* installer = new TestWebApkInstaller(
152 info, SkBitmap(), has_google_play_webapk_install_delegate_);
127 installer->SetTimeoutMs(100); 153 installer->SetTimeoutMs(100);
128 return installer; 154 return installer;
129 } 155 }
130 156
131 void Run() { 157 void Run() {
132 base::RunLoop run_loop; 158 base::RunLoop run_loop;
133 on_completed_callback_ = run_loop.QuitClosure(); 159 on_completed_callback_ = run_loop.QuitClosure();
134 run_loop.Run(); 160 run_loop.Run();
135 } 161 }
136 162
(...skipping 10 matching lines...) Expand all
147 173
148 // The Web Manifest's icon URL. 174 // The Web Manifest's icon URL.
149 const GURL best_icon_url_; 175 const GURL best_icon_url_;
150 176
151 // Called after the installation process has succeeded or failed. 177 // Called after the installation process has succeeded or failed.
152 base::Closure on_completed_callback_; 178 base::Closure on_completed_callback_;
153 179
154 // Whether the installation process succeeded. 180 // Whether the installation process succeeded.
155 bool success_; 181 bool success_;
156 182
183 // Whether installing WebAPKs using Google Play is enabled.
184 bool has_google_play_webapk_install_delegate_;
dominickn 2016/12/08 03:31:26 Again, can you call this "allow_install_from_play_
Xi Han 2016/12/08 18:03:08 Updated the description too.
185
157 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerRunner); 186 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerRunner);
158 }; 187 };
159 188
160 // Builds a webapk::WebApkResponse with |download_url| as the WebAPK download 189 // Builds a webapk::WebApkResponse with |download_url| as the WebAPK download
161 // URL. 190 // URL.
162 std::unique_ptr<net::test_server::HttpResponse> BuildValidWebApkResponse( 191 std::unique_ptr<net::test_server::HttpResponse> BuildValidWebApkResponse(
163 const GURL& download_url) { 192 const GURL& download_url) {
164 std::unique_ptr<webapk::WebApkResponse> response_proto( 193 std::unique_ptr<webapk::WebApkResponse> response_proto(
165 new webapk::WebApkResponse); 194 new webapk::WebApkResponse);
166 response_proto->set_package_name(kDownloadedWebApkPackageName); 195 response_proto->set_package_name(kDownloadedWebApkPackageName);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 runner->RunInstallWebApk(); 353 runner->RunInstallWebApk();
325 EXPECT_FALSE(runner->success()); 354 EXPECT_FALSE(runner->success());
326 } 355 }
327 356
328 // Test update succeeding. 357 // Test update succeeding.
329 TEST_F(WebApkInstallerTest, UpdateSuccess) { 358 TEST_F(WebApkInstallerTest, UpdateSuccess) {
330 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); 359 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
331 runner->RunUpdateWebApk(); 360 runner->RunUpdateWebApk();
332 EXPECT_TRUE(runner->success()); 361 EXPECT_TRUE(runner->success());
333 } 362 }
363
364 // Test installation succeeds using Google Play.
365 TEST_F(WebApkInstallerTest, InstallFromGooglePlaySuccess) {
366 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
367 runner->SetHasGooglePlayWebApkInstallDelegate(true);
368 runner->RunInstallWebApk();
369 EXPECT_TRUE(runner->success());
370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698