| 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 25 matching lines...) Expand all Loading... |
| 36 FILE_PATH_LITERAL("chrome/test/data"); | 36 FILE_PATH_LITERAL("chrome/test/data"); |
| 37 | 37 |
| 38 // URL of mock WebAPK server. | 38 // URL of mock WebAPK server. |
| 39 const char* kServerUrl = "/webapkserver/"; | 39 const char* kServerUrl = "/webapkserver/"; |
| 40 | 40 |
| 41 // Icon URL from Web Manifest. We use a random file in the test data directory. | 41 // Icon URL from Web Manifest. We use a random file in the test data directory. |
| 42 // Since WebApkInstaller does not try to decode the file as an image it is OK | 42 // Since WebApkInstaller does not try to decode the file as an image it is OK |
| 43 // that the file is not an image. | 43 // that the file is not an image. |
| 44 const char* kIconUrl = "/simple.html"; | 44 const char* kIconUrl = "/simple.html"; |
| 45 | 45 |
| 46 // The response format type expected from the WebAPK server. | |
| 47 const char* kWebApkServerUrlResponseType = "?alt=proto"; | |
| 48 | |
| 49 // 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 |
| 50 // test data directory. | 47 // test data directory. |
| 51 const char* kDownloadUrl = "/simple.html"; | 48 const char* kDownloadUrl = "/simple.html"; |
| 52 | 49 |
| 53 // The package name of the downloaded WebAPK. | 50 // The package name of the downloaded WebAPK. |
| 54 const char* kDownloadedWebApkPackageName = "party.unicode"; | 51 const char* kDownloadedWebApkPackageName = "party.unicode"; |
| 55 | 52 |
| 56 // WebApkInstaller subclass where | 53 // WebApkInstaller subclass where |
| 57 // WebApkInstaller::StartInstallingDownloadedWebApk() and | 54 // WebApkInstaller::StartInstallingDownloadedWebApk() and |
| 58 // WebApkInstaller::StartUpdateUsingDownloadedWebApk() are stubbed out. | 55 // WebApkInstaller::StartUpdateUsingDownloadedWebApk() are stubbed out. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 SetIconUrl(icon_url); | 226 SetIconUrl(icon_url); |
| 230 GURL server_url = test_server_.GetURL(kServerUrl); | 227 GURL server_url = test_server_.GetURL(kServerUrl); |
| 231 SetWebApkServerUrl(server_url); | 228 SetWebApkServerUrl(server_url); |
| 232 GURL download_url = test_server_.GetURL(kDownloadUrl); | 229 GURL download_url = test_server_.GetURL(kDownloadUrl); |
| 233 SetWebApkResponseBuilder( | 230 SetWebApkResponseBuilder( |
| 234 base::Bind(&BuildValidWebApkResponse, download_url)); | 231 base::Bind(&BuildValidWebApkResponse, download_url)); |
| 235 } | 232 } |
| 236 | 233 |
| 237 std::unique_ptr<net::test_server::HttpResponse> HandleWebApkRequest( | 234 std::unique_ptr<net::test_server::HttpResponse> HandleWebApkRequest( |
| 238 const net::test_server::HttpRequest& request) { | 235 const net::test_server::HttpRequest& request) { |
| 239 return (request.relative_url == GetServerUrlForCreateWebApk() || | 236 return (request.relative_url == kServerUrl) |
| 240 request.relative_url == GetServerUrlForUpdateWebApk()) | |
| 241 ? webapk_response_builder_.Run() | 237 ? webapk_response_builder_.Run() |
| 242 : std::unique_ptr<net::test_server::HttpResponse>(); | 238 : std::unique_ptr<net::test_server::HttpResponse>(); |
| 243 } | 239 } |
| 244 | 240 |
| 245 std::string GetServerUrlForCreateWebApk() const { | |
| 246 std::string url(kServerUrl); | |
| 247 return url.append(kWebApkServerUrlResponseType); | |
| 248 } | |
| 249 | |
| 250 std::string GetServerUrlForUpdateWebApk() const { | |
| 251 std::string url(kServerUrl); | |
| 252 url.append(kDownloadedWebApkPackageName); | |
| 253 url.append("/"); | |
| 254 url.append(kWebApkServerUrlResponseType); | |
| 255 return url; | |
| 256 } | |
| 257 | |
| 258 content::TestBrowserThreadBundle thread_bundle_; | 241 content::TestBrowserThreadBundle thread_bundle_; |
| 259 net::EmbeddedTestServer test_server_; | 242 net::EmbeddedTestServer test_server_; |
| 260 | 243 |
| 261 // Web Manifest's icon URL. | 244 // Web Manifest's icon URL. |
| 262 GURL icon_url_; | 245 GURL icon_url_; |
| 263 | 246 |
| 264 // Builds response to the WebAPK creation request. | 247 // Builds response to the WebAPK creation request. |
| 265 WebApkResponseBuilder webapk_response_builder_; | 248 WebApkResponseBuilder webapk_response_builder_; |
| 266 | 249 |
| 267 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerTest); | 250 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerTest); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 runner->RunInstallWebApk(); | 322 runner->RunInstallWebApk(); |
| 340 EXPECT_FALSE(runner->success()); | 323 EXPECT_FALSE(runner->success()); |
| 341 } | 324 } |
| 342 | 325 |
| 343 // Test update succeeding. | 326 // Test update succeeding. |
| 344 TEST_F(WebApkInstallerTest, UpdateSuccess) { | 327 TEST_F(WebApkInstallerTest, UpdateSuccess) { |
| 345 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 328 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
| 346 runner->RunUpdateWebApk(); | 329 runner->RunUpdateWebApk(); |
| 347 EXPECT_TRUE(runner->success()); | 330 EXPECT_TRUE(runner->success()); |
| 348 } | 331 } |
| OLD | NEW |