OLD | NEW |
---|---|
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 22 matching lines...) Expand all Loading... | |
33 #include "url/gurl.h" | 33 #include "url/gurl.h" |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 const base::FilePath::CharType kTestDataDir[] = | 37 const base::FilePath::CharType kTestDataDir[] = |
38 FILE_PATH_LITERAL("chrome/test/data"); | 38 FILE_PATH_LITERAL("chrome/test/data"); |
39 | 39 |
40 // URL of mock WebAPK server. | 40 // URL of mock WebAPK server. |
41 const char* kServerUrl = "/webapkserver/"; | 41 const char* kServerUrl = "/webapkserver/"; |
42 | 42 |
43 // The best primary icon URL from Web Manifest. We use a random file in the test | 43 // The URLs of best icons from Web Manifest. We use a random file in the test |
44 // data directory. Since WebApkInstaller does not try to decode the file as an | 44 // data directory. Since WebApkInstaller does not try to decode the file as an |
45 // image it is OK that the file is not an image. | 45 // image it is OK that the file is not an image. |
46 const char* kBestPrimaryIconUrl = "/simple.html"; | 46 const char* kBestPrimaryIconUrl = "/simple.html"; |
dominickn
2017/04/04 05:25:33
If these two have the same value, can you use have
F
2017/04/04 15:21:26
Done.
| |
47 const char* kBestBadgeIconUrl = "/simple.html"; | |
47 | 48 |
48 // URL of file to download from the WebAPK server. We use a random file in the | 49 // URL of file to download from the WebAPK server. We use a random file in the |
49 // test data directory. | 50 // test data directory. |
50 const char* kDownloadUrl = "/simple.html"; | 51 const char* kDownloadUrl = "/simple.html"; |
51 | 52 |
52 // The package name of the downloaded WebAPK. | 53 // The package name of the downloaded WebAPK. |
53 const char* kDownloadedWebApkPackageName = "party.unicode"; | 54 const char* kDownloadedWebApkPackageName = "party.unicode"; |
54 | 55 |
55 // WebApkInstaller subclass where | 56 // WebApkInstaller subclass where |
56 // WebApkInstaller::StartInstallingDownloadedWebApk() and | 57 // WebApkInstaller::StartInstallingDownloadedWebApk() and |
57 // WebApkInstaller::StartUpdateUsingDownloadedWebApk() and | 58 // WebApkInstaller::StartUpdateUsingDownloadedWebApk() and |
58 // WebApkInstaller::CanUseGooglePlayInstallService() and | 59 // WebApkInstaller::CanUseGooglePlayInstallService() and |
59 // WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay() are stubbed out. | 60 // WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay() are stubbed out. |
60 class TestWebApkInstaller : public WebApkInstaller { | 61 class TestWebApkInstaller : public WebApkInstaller { |
61 public: | 62 public: |
62 TestWebApkInstaller(content::BrowserContext* browser_context, | 63 TestWebApkInstaller(content::BrowserContext* browser_context, |
63 const ShortcutInfo& shortcut_info, | 64 const ShortcutInfo& shortcut_info, |
64 const SkBitmap& shortcut_icon, | 65 const SkBitmap& primary_icon, |
66 const SkBitmap& badge_icon, | |
65 bool can_use_google_play_install_service) | 67 bool can_use_google_play_install_service) |
66 : WebApkInstaller(browser_context, shortcut_info, shortcut_icon), | 68 : WebApkInstaller(browser_context, |
69 shortcut_info, | |
70 primary_icon, | |
71 badge_icon), | |
67 can_use_google_play_install_service_( | 72 can_use_google_play_install_service_( |
68 can_use_google_play_install_service) {} | 73 can_use_google_play_install_service) {} |
69 | 74 |
70 void InstallDownloadedWebApk( | 75 void InstallDownloadedWebApk( |
71 JNIEnv* env, | 76 JNIEnv* env, |
72 const base::android::ScopedJavaLocalRef<jstring>& file_path, | 77 const base::android::ScopedJavaLocalRef<jstring>& file_path, |
73 const base::android::ScopedJavaLocalRef<jstring>& package_name) override { | 78 const base::android::ScopedJavaLocalRef<jstring>& package_name) override { |
74 PostTaskToRunSuccessCallback(); | 79 PostTaskToRunSuccessCallback(); |
75 } | 80 } |
76 | 81 |
(...skipping 25 matching lines...) Expand all Loading... | |
102 // available. | 107 // available. |
103 bool can_use_google_play_install_service_; | 108 bool can_use_google_play_install_service_; |
104 | 109 |
105 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); | 110 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); |
106 }; | 111 }; |
107 | 112 |
108 // Runs the WebApkInstaller installation process/update and blocks till done. | 113 // Runs the WebApkInstaller installation process/update and blocks till done. |
109 class WebApkInstallerRunner { | 114 class WebApkInstallerRunner { |
110 public: | 115 public: |
111 WebApkInstallerRunner(content::BrowserContext* browser_context, | 116 WebApkInstallerRunner(content::BrowserContext* browser_context, |
112 const GURL& best_primary_icon_url) | 117 const GURL& best_primary_icon_url, |
118 const GURL& best_badge_icon_url) | |
113 : browser_context_(browser_context), | 119 : browser_context_(browser_context), |
114 best_primary_icon_url_(best_primary_icon_url), | 120 best_primary_icon_url_(best_primary_icon_url), |
121 best_badge_icon_url_(best_badge_icon_url), | |
115 can_use_google_play_install_service_(false) {} | 122 can_use_google_play_install_service_(false) {} |
116 | 123 |
117 ~WebApkInstallerRunner() {} | 124 ~WebApkInstallerRunner() {} |
118 | 125 |
119 void SetCanUseGooglePlayInstallService( | 126 void SetCanUseGooglePlayInstallService( |
120 bool can_use_google_play_install_service) { | 127 bool can_use_google_play_install_service) { |
121 can_use_google_play_install_service_ = can_use_google_play_install_service; | 128 can_use_google_play_install_service_ = can_use_google_play_install_service; |
122 } | 129 } |
123 | 130 |
124 void RunInstallWebApk() { | 131 void RunInstallWebApk() { |
125 WebApkInstaller::InstallAsyncForTesting( | 132 WebApkInstaller::InstallAsyncForTesting( |
126 CreateWebApkInstaller(), base::Bind(&WebApkInstallerRunner::OnCompleted, | 133 CreateWebApkInstaller(), base::Bind(&WebApkInstallerRunner::OnCompleted, |
127 base::Unretained(this))); | 134 base::Unretained(this))); |
128 Run(); | 135 Run(); |
129 } | 136 } |
130 | 137 |
131 void RunUpdateWebApk() { | 138 void RunUpdateWebApk() { |
132 const int kWebApkVersion = 1; | 139 const int kWebApkVersion = 1; |
133 | 140 |
134 std::map<std::string, std::string> icon_url_to_murmur2_hash{ | 141 std::map<std::string, std::string> icon_url_to_murmur2_hash{ |
135 {best_primary_icon_url_.spec(), "0"}}; | 142 {best_primary_icon_url_.spec(), "0"}, |
143 {best_badge_icon_url_.spec(), "0"}}; | |
136 | 144 |
137 WebApkInstaller::UpdateAsyncForTesting( | 145 WebApkInstaller::UpdateAsyncForTesting( |
138 CreateWebApkInstaller(), kDownloadedWebApkPackageName, kWebApkVersion, | 146 CreateWebApkInstaller(), kDownloadedWebApkPackageName, kWebApkVersion, |
139 icon_url_to_murmur2_hash, false /* is_manifest_stale */, | 147 icon_url_to_murmur2_hash, false /* is_manifest_stale */, |
140 base::Bind(&WebApkInstallerRunner::OnCompleted, | 148 base::Bind(&WebApkInstallerRunner::OnCompleted, |
141 base::Unretained(this))); | 149 base::Unretained(this))); |
142 Run(); | 150 Run(); |
143 } | 151 } |
144 | 152 |
145 WebApkInstaller* CreateWebApkInstaller() { | 153 WebApkInstaller* CreateWebApkInstaller() { |
146 ShortcutInfo info(GURL::EmptyGURL()); | 154 ShortcutInfo info(GURL::EmptyGURL()); |
147 info.best_primary_icon_url = best_primary_icon_url_; | 155 info.best_primary_icon_url = best_primary_icon_url_; |
156 info.best_badge_icon_url = best_badge_icon_url_; | |
148 | 157 |
149 // WebApkInstaller owns itself. | 158 // WebApkInstaller owns itself. |
150 WebApkInstaller* installer = | 159 WebApkInstaller* installer = |
151 new TestWebApkInstaller(browser_context_, info, SkBitmap(), | 160 new TestWebApkInstaller(browser_context_, info, SkBitmap(), SkBitmap(), |
152 can_use_google_play_install_service_); | 161 can_use_google_play_install_service_); |
153 installer->SetTimeoutMs(100); | 162 installer->SetTimeoutMs(100); |
154 return installer; | 163 return installer; |
155 } | 164 } |
156 | 165 |
157 void Run() { | 166 void Run() { |
158 base::RunLoop run_loop; | 167 base::RunLoop run_loop; |
159 on_completed_callback_ = run_loop.QuitClosure(); | 168 on_completed_callback_ = run_loop.QuitClosure(); |
160 run_loop.Run(); | 169 run_loop.Run(); |
161 } | 170 } |
162 | 171 |
163 WebApkInstallResult result() { return result_; } | 172 WebApkInstallResult result() { return result_; } |
164 | 173 |
165 private: | 174 private: |
166 void OnCompleted(WebApkInstallResult result, | 175 void OnCompleted(WebApkInstallResult result, |
167 bool relax_updates, | 176 bool relax_updates, |
168 const std::string& webapk_package) { | 177 const std::string& webapk_package) { |
169 result_ = result; | 178 result_ = result; |
170 on_completed_callback_.Run(); | 179 on_completed_callback_.Run(); |
171 } | 180 } |
172 | 181 |
173 content::BrowserContext* browser_context_; | 182 content::BrowserContext* browser_context_; |
174 | 183 |
175 // The Web Manifest's icon URL. | 184 // The Web Manifest's icon URLs. |
176 const GURL best_primary_icon_url_; | 185 const GURL best_primary_icon_url_; |
186 const GURL best_badge_icon_url_; | |
177 | 187 |
178 // Called after the installation process has succeeded or failed. | 188 // Called after the installation process has succeeded or failed. |
179 base::Closure on_completed_callback_; | 189 base::Closure on_completed_callback_; |
180 | 190 |
181 // The result of the installation process. | 191 // The result of the installation process. |
182 WebApkInstallResult result_; | 192 WebApkInstallResult result_; |
183 | 193 |
184 // Whether Google Play Service can be used and the install delegate is | 194 // Whether Google Play Service can be used and the install delegate is |
185 // available. | 195 // available. |
186 bool can_use_google_play_install_service_; | 196 bool can_use_google_play_install_service_; |
(...skipping 22 matching lines...) Expand all Loading... | |
209 // Builds WebApk proto and blocks till done. | 219 // Builds WebApk proto and blocks till done. |
210 class BuildProtoRunner { | 220 class BuildProtoRunner { |
211 public: | 221 public: |
212 explicit BuildProtoRunner(content::BrowserContext* browser_context) | 222 explicit BuildProtoRunner(content::BrowserContext* browser_context) |
213 : browser_context_(browser_context) {} | 223 : browser_context_(browser_context) {} |
214 | 224 |
215 ~BuildProtoRunner() {} | 225 ~BuildProtoRunner() {} |
216 | 226 |
217 void BuildSync( | 227 void BuildSync( |
218 const GURL& best_primary_icon_url, | 228 const GURL& best_primary_icon_url, |
229 const GURL& best_badge_icon_url, | |
219 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 230 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
220 bool is_manifest_stale) { | 231 bool is_manifest_stale) { |
221 ShortcutInfo info(GURL::EmptyGURL()); | 232 ShortcutInfo info(GURL::EmptyGURL()); |
222 info.best_primary_icon_url = best_primary_icon_url; | 233 info.best_primary_icon_url = best_primary_icon_url; |
234 info.best_badge_icon_url = best_badge_icon_url; | |
223 | 235 |
224 // WebApkInstaller owns itself. | 236 // WebApkInstaller owns itself. |
225 WebApkInstaller* installer = | 237 WebApkInstaller* installer = new TestWebApkInstaller( |
226 new TestWebApkInstaller(browser_context_, info, SkBitmap(), false); | 238 browser_context_, info, SkBitmap(), SkBitmap(), false); |
227 installer->BuildWebApkProtoInBackgroundForTesting( | 239 installer->BuildWebApkProtoInBackgroundForTesting( |
228 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto, | 240 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto, |
229 base::Unretained(this)), | 241 base::Unretained(this)), |
230 icon_url_to_murmur2_hash, is_manifest_stale); | 242 icon_url_to_murmur2_hash, is_manifest_stale); |
231 | 243 |
232 base::RunLoop run_loop; | 244 base::RunLoop run_loop; |
233 on_completed_callback_ = run_loop.QuitClosure(); | 245 on_completed_callback_ = run_loop.QuitClosure(); |
234 run_loop.Run(); | 246 run_loop.Run(); |
235 } | 247 } |
236 | 248 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 void TearDown() override { | 291 void TearDown() override { |
280 profile_.reset(); | 292 profile_.reset(); |
281 base::RunLoop().RunUntilIdle(); | 293 base::RunLoop().RunUntilIdle(); |
282 } | 294 } |
283 | 295 |
284 // Sets the best Web Manifest's primary icon URL. | 296 // Sets the best Web Manifest's primary icon URL. |
285 void SetBestPrimaryIconUrl(const GURL& best_primary_icon_url) { | 297 void SetBestPrimaryIconUrl(const GURL& best_primary_icon_url) { |
286 best_primary_icon_url_ = best_primary_icon_url; | 298 best_primary_icon_url_ = best_primary_icon_url; |
287 } | 299 } |
288 | 300 |
301 // Sets the best Web Manifest's badge icon URL. | |
302 void SetBestBadgeIconUrl(const GURL& best_badge_icon_url) { | |
303 best_badge_icon_url_ = best_badge_icon_url; | |
304 } | |
305 | |
289 // Sets the URL to send the webapk::CreateWebApkRequest to. WebApkInstaller | 306 // Sets the URL to send the webapk::CreateWebApkRequest to. WebApkInstaller |
290 // should fail if the URL is not |kServerUrl|. | 307 // should fail if the URL is not |kServerUrl|. |
291 void SetWebApkServerUrl(const GURL& server_url) { | 308 void SetWebApkServerUrl(const GURL& server_url) { |
292 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 309 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
293 switches::kWebApkServerUrl, server_url.spec()); | 310 switches::kWebApkServerUrl, server_url.spec()); |
294 } | 311 } |
295 | 312 |
296 // Sets the function that should be used to build the response to the | 313 // Sets the function that should be used to build the response to the |
297 // WebAPK creation request. | 314 // WebAPK creation request. |
298 void SetWebApkResponseBuilder(const WebApkResponseBuilder& builder) { | 315 void SetWebApkResponseBuilder(const WebApkResponseBuilder& builder) { |
299 webapk_response_builder_ = builder; | 316 webapk_response_builder_ = builder; |
300 } | 317 } |
301 | 318 |
302 std::unique_ptr<WebApkInstallerRunner> CreateWebApkInstallerRunner() { | 319 std::unique_ptr<WebApkInstallerRunner> CreateWebApkInstallerRunner() { |
303 return std::unique_ptr<WebApkInstallerRunner>( | 320 return std::unique_ptr<WebApkInstallerRunner>(new WebApkInstallerRunner( |
304 new WebApkInstallerRunner(profile_.get(), best_primary_icon_url_)); | 321 profile_.get(), best_primary_icon_url_, best_badge_icon_url_)); |
305 } | 322 } |
306 | 323 |
307 std::unique_ptr<BuildProtoRunner> CreateBuildProtoRunner() { | 324 std::unique_ptr<BuildProtoRunner> CreateBuildProtoRunner() { |
308 return std::unique_ptr<BuildProtoRunner>( | 325 return std::unique_ptr<BuildProtoRunner>( |
309 new BuildProtoRunner(profile_.get())); | 326 new BuildProtoRunner(profile_.get())); |
310 } | 327 } |
311 | 328 |
312 net::test_server::EmbeddedTestServer* test_server() { return &test_server_; } | 329 net::test_server::EmbeddedTestServer* test_server() { return &test_server_; } |
313 | 330 |
314 private: | 331 private: |
315 // Sets default configuration for running WebApkInstaller. | 332 // Sets default configuration for running WebApkInstaller. |
316 void SetDefaults() { | 333 void SetDefaults() { |
317 GURL best_primary_icon_url = test_server_.GetURL(kBestPrimaryIconUrl); | 334 SetBestPrimaryIconUrl(test_server_.GetURL(kBestPrimaryIconUrl)); |
318 SetBestPrimaryIconUrl(best_primary_icon_url); | 335 SetBestBadgeIconUrl(test_server_.GetURL(kBestBadgeIconUrl)); |
319 GURL server_url = test_server_.GetURL(kServerUrl); | 336 SetWebApkServerUrl(test_server_.GetURL(kServerUrl)); |
320 SetWebApkServerUrl(server_url); | 337 SetWebApkResponseBuilder(base::Bind(&BuildValidWebApkResponse, |
321 GURL download_url = test_server_.GetURL(kDownloadUrl); | 338 test_server_.GetURL(kDownloadUrl))); |
322 SetWebApkResponseBuilder( | |
323 base::Bind(&BuildValidWebApkResponse, download_url)); | |
324 } | 339 } |
325 | 340 |
326 std::unique_ptr<net::test_server::HttpResponse> HandleWebApkRequest( | 341 std::unique_ptr<net::test_server::HttpResponse> HandleWebApkRequest( |
327 const net::test_server::HttpRequest& request) { | 342 const net::test_server::HttpRequest& request) { |
328 return (request.relative_url == kServerUrl) | 343 return (request.relative_url == kServerUrl) |
329 ? webapk_response_builder_.Run() | 344 ? webapk_response_builder_.Run() |
330 : std::unique_ptr<net::test_server::HttpResponse>(); | 345 : std::unique_ptr<net::test_server::HttpResponse>(); |
331 } | 346 } |
332 | 347 |
333 std::unique_ptr<TestingProfile> profile_; | 348 std::unique_ptr<TestingProfile> profile_; |
334 content::TestBrowserThreadBundle thread_bundle_; | 349 content::TestBrowserThreadBundle thread_bundle_; |
335 net::EmbeddedTestServer test_server_; | 350 net::EmbeddedTestServer test_server_; |
336 | 351 |
337 // Web Manifest's icon URL. | 352 // Web Manifest's icon URLs. |
338 GURL best_primary_icon_url_; | 353 GURL best_primary_icon_url_; |
354 GURL best_badge_icon_url_; | |
339 | 355 |
340 // Builds response to the WebAPK creation request. | 356 // Builds response to the WebAPK creation request. |
341 WebApkResponseBuilder webapk_response_builder_; | 357 WebApkResponseBuilder webapk_response_builder_; |
342 | 358 |
343 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerTest); | 359 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerTest); |
344 }; | 360 }; |
345 | 361 |
346 // Test installation succeeding. | 362 // Test installation succeeding. |
347 TEST_F(WebApkInstallerTest, Success) { | 363 TEST_F(WebApkInstallerTest, Success) { |
348 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 364 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
349 runner->RunInstallWebApk(); | 365 runner->RunInstallWebApk(); |
350 EXPECT_EQ(WebApkInstallResult::SUCCESS, runner->result()); | 366 EXPECT_EQ(WebApkInstallResult::SUCCESS, runner->result()); |
351 } | 367 } |
352 | 368 |
353 // Test that installation fails if fetching the bitmap at the best primary icon | 369 // Test that installation fails if fetching the bitmap at the best primary icon |
354 // URL times out. In a perfect world the fetch would never time out because the | 370 // URL times out. In a perfect world the fetch would never time out because the |
355 // bitmap at the best primary icon URL should be in the HTTP cache. | 371 // bitmap at the best primary icon URL should be in the HTTP cache. |
356 TEST_F(WebApkInstallerTest, BestPrimaryIconUrlDownloadTimesOut) { | 372 TEST_F(WebApkInstallerTest, BestPrimaryIconUrlDownloadTimesOut) { |
357 GURL best_primary_icon_url = test_server()->GetURL("/slow?1000"); | 373 SetBestPrimaryIconUrl(test_server()->GetURL("/slow?1000")); |
358 SetBestPrimaryIconUrl(best_primary_icon_url); | |
359 | 374 |
360 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 375 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
361 runner->RunInstallWebApk(); | 376 runner->RunInstallWebApk(); |
377 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); | |
378 } | |
379 | |
380 // Test that installation fails if fetching the bitmap at the best badge icon | |
381 // URL times out. In a perfect world the fetch would never time out because the | |
382 // bitmap at the best badge icon URL should be in the HTTP cache. | |
383 TEST_F(WebApkInstallerTest, BestBadgeIconUrlDownloadTimesOut) { | |
384 SetBestBadgeIconUrl(test_server()->GetURL("/slow?1000")); | |
385 | |
386 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | |
387 runner->RunInstallWebApk(); | |
362 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); | 388 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); |
363 } | 389 } |
364 | 390 |
365 // Test that installation fails if the WebAPK creation request times out. | 391 // Test that installation fails if the WebAPK creation request times out. |
366 TEST_F(WebApkInstallerTest, CreateWebApkRequestTimesOut) { | 392 TEST_F(WebApkInstallerTest, CreateWebApkRequestTimesOut) { |
367 GURL server_url = test_server()->GetURL("/slow?1000"); | 393 SetWebApkServerUrl(test_server()->GetURL("/slow?1000")); |
368 SetWebApkServerUrl(server_url); | |
369 | 394 |
370 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 395 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
371 runner->RunInstallWebApk(); | 396 runner->RunInstallWebApk(); |
372 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); | 397 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); |
373 } | 398 } |
374 | 399 |
375 // Test that installation fails if the WebAPK download times out. | 400 // Test that installation fails if the WebAPK download times out. |
376 TEST_F(WebApkInstallerTest, WebApkDownloadTimesOut) { | 401 TEST_F(WebApkInstallerTest, WebApkDownloadTimesOut) { |
377 GURL download_url = test_server()->GetURL("/slow?1000"); | 402 SetWebApkResponseBuilder(base::Bind(&BuildValidWebApkResponse, |
378 SetWebApkResponseBuilder(base::Bind(&BuildValidWebApkResponse, download_url)); | 403 test_server()->GetURL("/slow?1000"))); |
379 | 404 |
380 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 405 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
381 runner->RunInstallWebApk(); | 406 runner->RunInstallWebApk(); |
382 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); | 407 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); |
383 } | 408 } |
384 | 409 |
385 // Test that installation fails if the WebAPK download fails. | 410 // Test that installation fails if the WebAPK download fails. |
386 TEST_F(WebApkInstallerTest, WebApkDownloadFails) { | 411 TEST_F(WebApkInstallerTest, WebApkDownloadFails) { |
387 GURL download_url = test_server()->GetURL("/nocontent"); | 412 SetWebApkResponseBuilder(base::Bind(&BuildValidWebApkResponse, |
388 SetWebApkResponseBuilder(base::Bind(&BuildValidWebApkResponse, download_url)); | 413 test_server()->GetURL("/nocontent"))); |
389 | 414 |
390 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 415 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
391 runner->RunInstallWebApk(); | 416 runner->RunInstallWebApk(); |
392 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); | 417 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); |
393 } | 418 } |
394 | 419 |
395 namespace { | 420 namespace { |
396 | 421 |
397 // Returns an HttpResponse which cannot be parsed as a webapk::WebApkResponse. | 422 // Returns an HttpResponse which cannot be parsed as a webapk::WebApkResponse. |
398 std::unique_ptr<net::test_server::HttpResponse> | 423 std::unique_ptr<net::test_server::HttpResponse> |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) { | 477 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) { |
453 GURL icon_url_1 = test_server()->GetURL("/icon1.png"); | 478 GURL icon_url_1 = test_server()->GetURL("/icon1.png"); |
454 GURL icon_url_2 = test_server()->GetURL("/icon2.png"); | 479 GURL icon_url_2 = test_server()->GetURL("/icon2.png"); |
455 std::string icon_murmur2_hash_1 = "1"; | 480 std::string icon_murmur2_hash_1 = "1"; |
456 std::string icon_murmur2_hash_2 = "2"; | 481 std::string icon_murmur2_hash_2 = "2"; |
457 std::map<std::string, std::string> icon_url_to_murmur2_hash; | 482 std::map<std::string, std::string> icon_url_to_murmur2_hash; |
458 icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1; | 483 icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1; |
459 icon_url_to_murmur2_hash[icon_url_2.spec()] = icon_murmur2_hash_2; | 484 icon_url_to_murmur2_hash[icon_url_2.spec()] = icon_murmur2_hash_2; |
460 | 485 |
461 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); | 486 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); |
462 runner->BuildSync(GURL(""), icon_url_to_murmur2_hash, | 487 runner->BuildSync(GURL(), GURL(), icon_url_to_murmur2_hash, |
463 true /* is_manifest_stale*/); | 488 true /* is_manifest_stale*/); |
464 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); | 489 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); |
465 ASSERT_NE(nullptr, webapk_request); | 490 ASSERT_NE(nullptr, webapk_request); |
466 | 491 |
467 webapk::WebAppManifest manifest = webapk_request->manifest(); | 492 webapk::WebAppManifest manifest = webapk_request->manifest(); |
468 ASSERT_EQ(3, manifest.icons_size()); | 493 ASSERT_EQ(3, manifest.icons_size()); |
469 | 494 |
470 webapk::Image icons[3]; | 495 webapk::Image icons[3]; |
471 for (int i = 0; i < 3; ++i) | 496 for (int i = 0; i < 3; ++i) |
472 icons[i] = manifest.icons(i); | 497 icons[i] = manifest.icons(i); |
473 | 498 |
474 EXPECT_EQ("", icons[0].src()); | 499 EXPECT_EQ("", icons[0].src()); |
475 EXPECT_FALSE(icons[0].has_hash()); | 500 EXPECT_FALSE(icons[0].has_hash()); |
476 EXPECT_TRUE(icons[0].has_image_data()); | 501 EXPECT_TRUE(icons[0].has_image_data()); |
477 | 502 |
478 EXPECT_EQ(icon_url_1.spec(), icons[1].src()); | 503 EXPECT_EQ(icon_url_1.spec(), icons[1].src()); |
479 EXPECT_EQ(icon_murmur2_hash_1, icons[1].hash()); | 504 EXPECT_EQ(icon_murmur2_hash_1, icons[1].hash()); |
480 EXPECT_FALSE(icons[1].has_image_data()); | 505 EXPECT_FALSE(icons[1].has_image_data()); |
481 | 506 |
482 EXPECT_EQ(icon_url_2.spec(), icons[2].src()); | 507 EXPECT_EQ(icon_url_2.spec(), icons[2].src()); |
483 EXPECT_EQ(icon_murmur2_hash_2, icons[2].hash()); | 508 EXPECT_EQ(icon_murmur2_hash_2, icons[2].hash()); |
484 EXPECT_FALSE(icons[2].has_image_data()); | 509 EXPECT_FALSE(icons[2].has_image_data()); |
485 } | 510 } |
486 | 511 |
487 // Tests a WebApk install or update request is built properly when the Chrome | 512 // Tests a WebApk install or update request is built properly when the Chrome |
488 // knows the best icon URL of a site after fetching its Web Manifest. | 513 // knows the best icon URL of a site after fetching its Web Manifest. |
489 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsAvailable) { | 514 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsAvailable) { |
490 GURL icon_url_1 = test_server()->GetURL("/icon.png"); | 515 GURL icon_url_1 = test_server()->GetURL("/icon.png"); |
491 GURL best_primary_icon_url = test_server()->GetURL(kBestPrimaryIconUrl); | 516 GURL best_primary_icon_url = test_server()->GetURL(kBestPrimaryIconUrl); |
517 GURL best_badge_icon_url = test_server()->GetURL(kBestBadgeIconUrl); | |
492 std::string icon_murmur2_hash_1 = "1"; | 518 std::string icon_murmur2_hash_1 = "1"; |
493 std::string best_primary_icon_murmur2_hash = "0"; | 519 std::string best_primary_icon_murmur2_hash = "0"; |
520 std::string best_badge_icon_murmur2_hash = "0"; | |
494 std::map<std::string, std::string> icon_url_to_murmur2_hash; | 521 std::map<std::string, std::string> icon_url_to_murmur2_hash; |
495 icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1; | 522 icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1; |
496 icon_url_to_murmur2_hash[best_primary_icon_url.spec()] = | 523 icon_url_to_murmur2_hash[best_primary_icon_url.spec()] = |
497 best_primary_icon_murmur2_hash; | 524 best_primary_icon_murmur2_hash; |
525 icon_url_to_murmur2_hash[best_badge_icon_url.spec()] = | |
526 best_badge_icon_murmur2_hash; | |
498 | 527 |
499 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); | 528 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); |
500 runner->BuildSync(best_primary_icon_url, icon_url_to_murmur2_hash, | 529 runner->BuildSync(best_primary_icon_url, best_badge_icon_url, |
501 false /* is_manifest_stale*/); | 530 icon_url_to_murmur2_hash, false /* is_manifest_stale*/); |
502 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); | 531 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); |
503 ASSERT_NE(nullptr, webapk_request); | 532 ASSERT_NE(nullptr, webapk_request); |
504 | 533 |
505 webapk::WebAppManifest manifest = webapk_request->manifest(); | 534 webapk::WebAppManifest manifest = webapk_request->manifest(); |
506 ASSERT_EQ(2, manifest.icons_size()); | 535 ASSERT_EQ(2, manifest.icons_size()); |
507 | 536 |
508 webapk::Image icons[2]; | 537 webapk::Image icons[2]; |
509 for (int i = 0; i < 2; ++i) | 538 for (int i = 0; i < 2; ++i) |
510 icons[i] = manifest.icons(i); | 539 icons[i] = manifest.icons(i); |
511 | 540 |
512 EXPECT_EQ(best_primary_icon_url.spec(), icons[0].src()); | 541 // /icon.png |
dominickn
2017/04/04 05:25:33
This comment is a bit lonely. Can you expand it or
F
2017/04/04 15:21:26
Done.
| |
513 EXPECT_EQ(best_primary_icon_murmur2_hash, icons[0].hash()); | 542 EXPECT_EQ(icon_url_1.spec(), icons[0].src()); |
514 EXPECT_TRUE(icons[0].has_image_data()); | 543 EXPECT_EQ(icon_murmur2_hash_1, icons[0].hash()); |
544 EXPECT_FALSE(icons[0].has_image_data()); | |
515 | 545 |
516 EXPECT_EQ(icon_url_1.spec(), icons[1].src()); | 546 // /simple.html |
517 EXPECT_EQ(icon_murmur2_hash_1, icons[1].hash()); | 547 EXPECT_EQ(best_primary_icon_url.spec(), icons[1].src()); |
518 EXPECT_FALSE(icons[1].has_image_data()); | 548 EXPECT_EQ(best_primary_icon_murmur2_hash, icons[1].hash()); |
549 EXPECT_EQ(best_badge_icon_url.spec(), icons[1].src()); | |
550 EXPECT_EQ(best_badge_icon_murmur2_hash, icons[1].hash()); | |
551 ASSERT_EQ(2, icons[1].usages_size()); | |
552 EXPECT_EQ(webapk::Image::PRIMARY_ICON, icons[1].usages(0)); | |
553 EXPECT_EQ(webapk::Image::BADGE_ICON, icons[1].usages(1)); | |
554 EXPECT_TRUE(icons[1].has_image_data()); | |
519 } | 555 } |
OLD | NEW |