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