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

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

Issue 2634173002: Fall back to legacy add to homescreen behavior on non-GMS device or GMS isn't availabe. (Closed)
Patch Set: Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/android/webapk/webapk_installer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // URL of file to download from the WebAPK server. We use a random file in the 47 // URL of file to download from the WebAPK server. We use a random file in the
48 // test data directory. 48 // test data directory.
49 const char* kDownloadUrl = "/simple.html"; 49 const char* kDownloadUrl = "/simple.html";
50 50
51 // The package name of the downloaded WebAPK. 51 // The package name of the downloaded WebAPK.
52 const char* kDownloadedWebApkPackageName = "party.unicode"; 52 const char* kDownloadedWebApkPackageName = "party.unicode";
53 53
54 // WebApkInstaller subclass where 54 // WebApkInstaller subclass where
55 // WebApkInstaller::StartInstallingDownloadedWebApk() and 55 // WebApkInstaller::StartInstallingDownloadedWebApk() and
56 // WebApkInstaller::StartUpdateUsingDownloadedWebApk() and 56 // WebApkInstaller::StartUpdateUsingDownloadedWebApk() and
57 // WebApkInstaller::HasGooglePlayWebApkInstallDelegate() and 57 // WebApkInstaller::CanUseGooglePlayInstallService() and
58 // WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay() are stubbed out. 58 // WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay() are stubbed out.
59 class TestWebApkInstaller : public WebApkInstaller { 59 class TestWebApkInstaller : public WebApkInstaller {
60 public: 60 public:
61 TestWebApkInstaller(content::BrowserContext* browser_context, 61 TestWebApkInstaller(content::BrowserContext* browser_context,
62 const ShortcutInfo& shortcut_info, 62 const ShortcutInfo& shortcut_info,
63 const SkBitmap& shortcut_icon, 63 const SkBitmap& shortcut_icon,
64 bool has_google_play_webapk_install_delegate) 64 bool can_use_google_play_install_service)
65 : WebApkInstaller(browser_context, shortcut_info, shortcut_icon), 65 : WebApkInstaller(browser_context, shortcut_info, shortcut_icon),
66 has_google_play_webapk_install_delegate_( 66 can_use_google_play_install_service_(
67 has_google_play_webapk_install_delegate) {} 67 can_use_google_play_install_service) {}
68 68
69 bool StartInstallingDownloadedWebApk( 69 bool StartInstallingDownloadedWebApk(
70 JNIEnv* env, 70 JNIEnv* env,
71 const base::android::ScopedJavaLocalRef<jstring>& file_path, 71 const base::android::ScopedJavaLocalRef<jstring>& file_path,
72 const base::android::ScopedJavaLocalRef<jstring>& package_name) override { 72 const base::android::ScopedJavaLocalRef<jstring>& package_name) override {
73 PostTaskToRunSuccessCallback(); 73 PostTaskToRunSuccessCallback();
74 return true; 74 return true;
75 } 75 }
76 76
77 bool StartUpdateUsingDownloadedWebApk( 77 bool StartUpdateUsingDownloadedWebApk(
78 JNIEnv* env, 78 JNIEnv* env,
79 const base::android::ScopedJavaLocalRef<jstring>& file_path) override { 79 const base::android::ScopedJavaLocalRef<jstring>& file_path) override {
80 return true; 80 return true;
81 } 81 }
82 82
83 bool HasGooglePlayWebApkInstallDelegate() override { 83 bool CanUseGooglePlayInstallService() override {
84 return has_google_play_webapk_install_delegate_; 84 return can_use_google_play_install_service_;
85 } 85 }
86 86
87 bool InstallOrUpdateWebApkFromGooglePlay(const std::string& package_name, 87 bool InstallOrUpdateWebApkFromGooglePlay(const std::string& package_name,
88 int version, 88 int version,
89 const std::string& token) override { 89 const std::string& token) override {
90 PostTaskToRunSuccessCallback(); 90 PostTaskToRunSuccessCallback();
91 return true; 91 return true;
92 } 92 }
93 93
94 void PostTaskToRunSuccessCallback() { 94 void PostTaskToRunSuccessCallback() {
95 base::ThreadTaskRunnerHandle::Get()->PostTask( 95 base::ThreadTaskRunnerHandle::Get()->PostTask(
96 FROM_HERE, 96 FROM_HERE,
97 base::Bind(&TestWebApkInstaller::OnSuccess, base::Unretained(this))); 97 base::Bind(&TestWebApkInstaller::OnSuccess, base::Unretained(this)));
98 } 98 }
99 99
100 private: 100 private:
101 // Whether the Google Play install delegate is available. 101 // Whether the Google Play Service can be used and the install delegate is
102 bool has_google_play_webapk_install_delegate_; 102 // available.
103 bool can_use_google_play_install_service_;
103 104
104 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); 105 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller);
105 }; 106 };
106 107
107 // Runs the WebApkInstaller installation process/update and blocks till done. 108 // Runs the WebApkInstaller installation process/update and blocks till done.
108 class WebApkInstallerRunner { 109 class WebApkInstallerRunner {
109 public: 110 public:
110 WebApkInstallerRunner(content::BrowserContext* browser_context, 111 WebApkInstallerRunner(content::BrowserContext* browser_context,
111 const GURL& best_icon_url) 112 const GURL& best_icon_url)
112 : browser_context_(browser_context), 113 : browser_context_(browser_context),
113 best_icon_url_(best_icon_url), 114 best_icon_url_(best_icon_url),
114 has_google_play_webapk_install_delegate_(false) {} 115 can_use_google_play_install_service_(false) {}
115 116
116 ~WebApkInstallerRunner() {} 117 ~WebApkInstallerRunner() {}
117 118
118 void SetHasGooglePlayWebApkInstallDelegate(bool has_delegate) { 119 void SetCanUseGooglePlayInstallService(
119 has_google_play_webapk_install_delegate_ = has_delegate; 120 bool can_use_google_play_install_service) {
121 can_use_google_play_install_service_ = can_use_google_play_install_service;
120 } 122 }
121 123
122 void RunInstallWebApk() { 124 void RunInstallWebApk() {
123 WebApkInstaller::InstallAsyncForTesting( 125 WebApkInstaller::InstallAsyncForTesting(
124 CreateWebApkInstaller(), 126 CreateWebApkInstaller(),
125 base::Bind(&WebApkInstallerRunner::OnCompleted, 127 base::Bind(&WebApkInstallerRunner::OnCompleted,
126 base::Unretained(this))); 128 base::Unretained(this)));
127 Run(); 129 Run();
128 } 130 }
129 131
(...skipping 14 matching lines...) Expand all
144 Run(); 146 Run();
145 } 147 }
146 148
147 WebApkInstaller* CreateWebApkInstaller() { 149 WebApkInstaller* CreateWebApkInstaller() {
148 ShortcutInfo info(GURL::EmptyGURL()); 150 ShortcutInfo info(GURL::EmptyGURL());
149 info.best_icon_url = best_icon_url_; 151 info.best_icon_url = best_icon_url_;
150 152
151 // WebApkInstaller owns itself. 153 // WebApkInstaller owns itself.
152 WebApkInstaller* installer = 154 WebApkInstaller* installer =
153 new TestWebApkInstaller(browser_context_, info, SkBitmap(), 155 new TestWebApkInstaller(browser_context_, info, SkBitmap(),
154 has_google_play_webapk_install_delegate_); 156 can_use_google_play_install_service_);
155 installer->SetTimeoutMs(100); 157 installer->SetTimeoutMs(100);
156 return installer; 158 return installer;
157 } 159 }
158 160
159 void Run() { 161 void Run() {
160 base::RunLoop run_loop; 162 base::RunLoop run_loop;
161 on_completed_callback_ = run_loop.QuitClosure(); 163 on_completed_callback_ = run_loop.QuitClosure();
162 run_loop.Run(); 164 run_loop.Run();
163 } 165 }
164 166
165 bool success() { return success_; } 167 bool success() { return success_; }
166 168
167 private: 169 private:
168 void OnCompleted(bool success, const std::string& webapk_package) { 170 void OnCompleted(bool success, const std::string& webapk_package) {
169 success_ = success; 171 success_ = success;
170 on_completed_callback_.Run(); 172 on_completed_callback_.Run();
171 } 173 }
172 174
173 content::BrowserContext* browser_context_; 175 content::BrowserContext* browser_context_;
174 176
175 // The Web Manifest's icon URL. 177 // The Web Manifest's icon URL.
176 const GURL best_icon_url_; 178 const GURL best_icon_url_;
177 179
178 // Called after the installation process has succeeded or failed. 180 // Called after the installation process has succeeded or failed.
179 base::Closure on_completed_callback_; 181 base::Closure on_completed_callback_;
180 182
181 // Whether the installation process succeeded. 183 // Whether the installation process succeeded.
182 bool success_; 184 bool success_;
183 185
184 // Whether the Google Play install delegate is available. 186 // Whether Google Play Service can be used and the install delegate are
pkotwicz 2017/01/17 02:20:41 Nit: are -> is
Xi Han 2017/01/17 14:36:07 Done.
185 bool has_google_play_webapk_install_delegate_; 187 // available.
188 bool can_use_google_play_install_service_;
186 189
187 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerRunner); 190 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerRunner);
188 }; 191 };
189 192
190 // Builds a webapk::WebApkResponse with |download_url| as the WebAPK download 193 // Builds a webapk::WebApkResponse with |download_url| as the WebAPK download
191 // URL. 194 // URL.
192 std::unique_ptr<net::test_server::HttpResponse> BuildValidWebApkResponse( 195 std::unique_ptr<net::test_server::HttpResponse> BuildValidWebApkResponse(
193 const GURL& download_url) { 196 const GURL& download_url) {
194 std::unique_ptr<webapk::WebApkResponse> response_proto( 197 std::unique_ptr<webapk::WebApkResponse> response_proto(
195 new webapk::WebApkResponse); 198 new webapk::WebApkResponse);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // Test update succeeding. 423 // Test update succeeding.
421 TEST_F(WebApkInstallerTest, UpdateSuccess) { 424 TEST_F(WebApkInstallerTest, UpdateSuccess) {
422 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); 425 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
423 runner->RunUpdateWebApk(); 426 runner->RunUpdateWebApk();
424 EXPECT_TRUE(runner->success()); 427 EXPECT_TRUE(runner->success());
425 } 428 }
426 429
427 // Test installation succeeds using Google Play. 430 // Test installation succeeds using Google Play.
428 TEST_F(WebApkInstallerTest, InstallFromGooglePlaySuccess) { 431 TEST_F(WebApkInstallerTest, InstallFromGooglePlaySuccess) {
429 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); 432 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
430 runner->SetHasGooglePlayWebApkInstallDelegate(true); 433 runner->SetCanUseGooglePlayInstallService(true);
431 runner->RunInstallWebApk(); 434 runner->RunInstallWebApk();
432 EXPECT_TRUE(runner->success()); 435 EXPECT_TRUE(runner->success());
433 } 436 }
434 437
435 // When there is no Web Manifest available for a site, an empty |best_icon_url| 438 // When there is no Web Manifest available for a site, an empty |best_icon_url|
436 // is used to build a WebApk update request. Tests the request can be built 439 // is used to build a WebApk update request. Tests the request can be built
437 // properly. 440 // properly.
438 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) { 441 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) {
439 GURL icon_url_1 = test_server()->GetURL("/icon1.png"); 442 GURL icon_url_1 = test_server()->GetURL("/icon1.png");
440 GURL icon_url_2 = test_server()->GetURL("/icon2.png"); 443 GURL icon_url_2 = test_server()->GetURL("/icon2.png");
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 icons[i] = manifest.icons(i); 499 icons[i] = manifest.icons(i);
497 500
498 EXPECT_EQ(best_icon_url.spec(), icons[0].src()); 501 EXPECT_EQ(best_icon_url.spec(), icons[0].src());
499 EXPECT_EQ(best_icon_murmur2_hash, icons[0].hash()); 502 EXPECT_EQ(best_icon_murmur2_hash, icons[0].hash());
500 EXPECT_TRUE(icons[0].has_image_data()); 503 EXPECT_TRUE(icons[0].has_image_data());
501 504
502 EXPECT_EQ(icon_url_1.spec(), icons[1].src()); 505 EXPECT_EQ(icon_url_1.spec(), icons[1].src());
503 EXPECT_EQ(icon_murmur2_hash_1, icons[1].hash()); 506 EXPECT_EQ(icon_murmur2_hash_1, icons[1].hash());
504 EXPECT_FALSE(icons[1].has_image_data()); 507 EXPECT_FALSE(icons[1].has_image_data());
505 } 508 }
OLDNEW
« no previous file with comments | « chrome/browser/android/webapk/webapk_installer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698