Chromium Code Reviews| 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 icon URL from Web Manifest. We use a random file in the test data | 42 // The best primary icon URL from Web Manifest. We use a random file in the test |
| 43 // directory. Since WebApkInstaller does not try to decode the file as an image | 43 // data directory. Since WebApkInstaller does not try to decode the file as an |
| 44 // 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* kBestIconUrl = "/simple.html"; | 45 const char* kBestPrimaryIconUrl = "/simple.html"; |
| 46 | 46 |
| 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 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 // available. | 102 // available. |
| 103 bool can_use_google_play_install_service_; | 103 bool can_use_google_play_install_service_; |
| 104 | 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); | 105 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 // Runs the WebApkInstaller installation process/update and blocks till done. | 108 // Runs the WebApkInstaller installation process/update and blocks till done. |
| 109 class WebApkInstallerRunner { | 109 class WebApkInstallerRunner { |
| 110 public: | 110 public: |
| 111 WebApkInstallerRunner(content::BrowserContext* browser_context, | 111 WebApkInstallerRunner(content::BrowserContext* browser_context, |
| 112 const GURL& best_icon_url) | 112 const GURL& best_primary_icon_url) |
| 113 : browser_context_(browser_context), | 113 : browser_context_(browser_context), |
| 114 best_icon_url_(best_icon_url), | 114 best_primary_icon_url_(best_primary_icon_url), |
| 115 can_use_google_play_install_service_(false) {} | 115 can_use_google_play_install_service_(false) {} |
| 116 | 116 |
| 117 ~WebApkInstallerRunner() {} | 117 ~WebApkInstallerRunner() {} |
| 118 | 118 |
| 119 void SetCanUseGooglePlayInstallService( | 119 void SetCanUseGooglePlayInstallService( |
| 120 bool can_use_google_play_install_service) { | 120 bool can_use_google_play_install_service) { |
| 121 can_use_google_play_install_service_ = can_use_google_play_install_service; | 121 can_use_google_play_install_service_ = can_use_google_play_install_service; |
| 122 } | 122 } |
| 123 | 123 |
| 124 void RunInstallWebApk() { | 124 void RunInstallWebApk() { |
| 125 WebApkInstaller::InstallAsyncForTesting( | 125 WebApkInstaller::InstallAsyncForTesting( |
| 126 CreateWebApkInstaller(), | 126 CreateWebApkInstaller(), base::Bind(&WebApkInstallerRunner::OnCompleted, |
| 127 base::Bind(&WebApkInstallerRunner::OnCompleted, | 127 base::Unretained(this))); |
| 128 base::Unretained(this))); | |
| 129 Run(); | 128 Run(); |
| 130 } | 129 } |
| 131 | 130 |
| 132 void RunUpdateWebApk() { | 131 void RunUpdateWebApk() { |
| 133 const int kWebApkVersion = 1; | 132 const int kWebApkVersion = 1; |
| 134 | 133 |
| 135 std::map<std::string, std::string> icon_url_to_murmur2_hash { | 134 std::map<std::string, std::string> icon_url_to_murmur2_hash{ |
| 136 {best_icon_url_.spec(), "0"} }; | 135 {best_primary_icon_url_.spec(), "0"}}; |
| 137 | 136 |
| 138 WebApkInstaller::UpdateAsyncForTesting( | 137 WebApkInstaller::UpdateAsyncForTesting( |
| 139 CreateWebApkInstaller(), | 138 CreateWebApkInstaller(), kDownloadedWebApkPackageName, kWebApkVersion, |
| 140 kDownloadedWebApkPackageName, | 139 icon_url_to_murmur2_hash, false /* is_manifest_stale */, |
| 141 kWebApkVersion, | |
| 142 icon_url_to_murmur2_hash, | |
| 143 false /* is_manifest_stale */, | |
| 144 base::Bind(&WebApkInstallerRunner::OnCompleted, | 140 base::Bind(&WebApkInstallerRunner::OnCompleted, |
| 145 base::Unretained(this))); | 141 base::Unretained(this))); |
| 146 Run(); | 142 Run(); |
| 147 } | 143 } |
| 148 | 144 |
| 149 WebApkInstaller* CreateWebApkInstaller() { | 145 WebApkInstaller* CreateWebApkInstaller() { |
| 150 ShortcutInfo info(GURL::EmptyGURL()); | 146 ShortcutInfo info(GURL::EmptyGURL()); |
| 151 info.best_icon_url = best_icon_url_; | 147 info.best_primary_icon_url = best_primary_icon_url_; |
| 152 | 148 |
| 153 // WebApkInstaller owns itself. | 149 // WebApkInstaller owns itself. |
| 154 WebApkInstaller* installer = | 150 WebApkInstaller* installer = |
| 155 new TestWebApkInstaller(browser_context_, info, SkBitmap(), | 151 new TestWebApkInstaller(browser_context_, info, SkBitmap(), |
| 156 can_use_google_play_install_service_); | 152 can_use_google_play_install_service_); |
| 157 installer->SetTimeoutMs(100); | 153 installer->SetTimeoutMs(100); |
| 158 return installer; | 154 return installer; |
| 159 } | 155 } |
| 160 | 156 |
| 161 void Run() { | 157 void Run() { |
| 162 base::RunLoop run_loop; | 158 base::RunLoop run_loop; |
| 163 on_completed_callback_ = run_loop.QuitClosure(); | 159 on_completed_callback_ = run_loop.QuitClosure(); |
| 164 run_loop.Run(); | 160 run_loop.Run(); |
| 165 } | 161 } |
| 166 | 162 |
| 167 bool success() { return success_; } | 163 bool success() { return success_; } |
| 168 | 164 |
| 169 private: | 165 private: |
| 170 void OnCompleted(bool success, const std::string& webapk_package) { | 166 void OnCompleted(bool success, const std::string& webapk_package) { |
| 171 success_ = success; | 167 success_ = success; |
| 172 on_completed_callback_.Run(); | 168 on_completed_callback_.Run(); |
| 173 } | 169 } |
| 174 | 170 |
| 175 content::BrowserContext* browser_context_; | 171 content::BrowserContext* browser_context_; |
| 176 | 172 |
| 177 // The Web Manifest's icon URL. | 173 // The Web Manifest's icon URL. |
| 178 const GURL best_icon_url_; | 174 const GURL best_primary_icon_url_; |
| 179 | 175 |
| 180 // Called after the installation process has succeeded or failed. | 176 // Called after the installation process has succeeded or failed. |
| 181 base::Closure on_completed_callback_; | 177 base::Closure on_completed_callback_; |
| 182 | 178 |
| 183 // Whether the installation process succeeded. | 179 // Whether the installation process succeeded. |
| 184 bool success_; | 180 bool success_; |
| 185 | 181 |
| 186 // Whether Google Play Service can be used and the install delegate is | 182 // Whether Google Play Service can be used and the install delegate is |
| 187 // available. | 183 // available. |
| 188 bool can_use_google_play_install_service_; | 184 bool can_use_google_play_install_service_; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 210 | 206 |
| 211 // Builds WebApk proto and blocks till done. | 207 // Builds WebApk proto and blocks till done. |
| 212 class BuildProtoRunner { | 208 class BuildProtoRunner { |
| 213 public: | 209 public: |
| 214 explicit BuildProtoRunner(content::BrowserContext* browser_context) | 210 explicit BuildProtoRunner(content::BrowserContext* browser_context) |
| 215 : browser_context_(browser_context) {} | 211 : browser_context_(browser_context) {} |
| 216 | 212 |
| 217 ~BuildProtoRunner() {} | 213 ~BuildProtoRunner() {} |
| 218 | 214 |
| 219 void BuildSync( | 215 void BuildSync( |
| 220 const GURL& best_icon_url, | 216 const GURL& best_primary_icon_url, |
| 221 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 217 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 222 bool is_manifest_stale) { | 218 bool is_manifest_stale) { |
| 223 ShortcutInfo info(GURL::EmptyGURL()); | 219 ShortcutInfo info(GURL::EmptyGURL()); |
| 224 info.best_icon_url = best_icon_url; | 220 info.best_primary_icon_url = best_primary_icon_url; |
| 225 | 221 |
| 226 // WebApkInstaller owns itself. | 222 // WebApkInstaller owns itself. |
| 227 WebApkInstaller* installer = | 223 WebApkInstaller* installer = |
| 228 new TestWebApkInstaller(browser_context_, info, SkBitmap(), false); | 224 new TestWebApkInstaller(browser_context_, info, SkBitmap(), false); |
| 229 installer->BuildWebApkProtoInBackgroundForTesting( | 225 installer->BuildWebApkProtoInBackgroundForTesting( |
| 230 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto, | 226 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto, |
| 231 base::Unretained(this)), | 227 base::Unretained(this)), |
| 232 icon_url_to_murmur2_hash, | 228 icon_url_to_murmur2_hash, is_manifest_stale); |
| 233 is_manifest_stale); | |
| 234 | 229 |
| 235 base::RunLoop run_loop; | 230 base::RunLoop run_loop; |
| 236 on_completed_callback_ = run_loop.QuitClosure(); | 231 on_completed_callback_ = run_loop.QuitClosure(); |
| 237 run_loop.Run(); | 232 run_loop.Run(); |
| 238 } | 233 } |
| 239 | 234 |
| 240 webapk::WebApk* GetWebApkRequest() { return webapk_request_.get(); } | 235 webapk::WebApk* GetWebApkRequest() { return webapk_request_.get(); } |
| 241 | 236 |
| 242 private: | 237 private: |
| 243 // Called when the |webapk_request_| is populated. | 238 // Called when the |webapk_request_| is populated. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 263 public: | 258 public: |
| 264 typedef base::Callback<std::unique_ptr<net::test_server::HttpResponse>(void)> | 259 typedef base::Callback<std::unique_ptr<net::test_server::HttpResponse>(void)> |
| 265 WebApkResponseBuilder; | 260 WebApkResponseBuilder; |
| 266 | 261 |
| 267 WebApkInstallerTest() | 262 WebApkInstallerTest() |
| 268 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} | 263 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 269 ~WebApkInstallerTest() override {} | 264 ~WebApkInstallerTest() override {} |
| 270 | 265 |
| 271 void SetUp() override { | 266 void SetUp() override { |
| 272 test_server_.AddDefaultHandlers(base::FilePath(kTestDataDir)); | 267 test_server_.AddDefaultHandlers(base::FilePath(kTestDataDir)); |
| 273 test_server_.RegisterRequestHandler( | 268 test_server_.RegisterRequestHandler(base::Bind( |
| 274 base::Bind(&WebApkInstallerTest::HandleWebApkRequest, | 269 &WebApkInstallerTest::HandleWebApkRequest, base::Unretained(this))); |
| 275 base::Unretained(this))); | |
| 276 ASSERT_TRUE(test_server_.Start()); | 270 ASSERT_TRUE(test_server_.Start()); |
| 277 | 271 |
| 278 profile_.reset(new TestingProfile()); | 272 profile_.reset(new TestingProfile()); |
| 279 | 273 |
| 280 SetDefaults(); | 274 SetDefaults(); |
| 281 } | 275 } |
| 282 | 276 |
| 283 void TearDown() override { | 277 void TearDown() override { |
| 284 profile_.reset(); | 278 profile_.reset(); |
| 285 base::RunLoop().RunUntilIdle(); | 279 base::RunLoop().RunUntilIdle(); |
| 286 } | 280 } |
| 287 | 281 |
| 288 // Sets the best Web Manifest's icon URL. | 282 // Sets the best Web Manifest's primary icon URL. |
| 289 void SetBestIconUrl(const GURL& best_icon_url) { | 283 void SetBestPrimaryIconUrl(const GURL& best_primary_icon_url) { |
| 290 best_icon_url_ = best_icon_url; | 284 best_primary_icon_url_ = best_primary_icon_url; |
| 291 } | 285 } |
| 292 | 286 |
| 293 // Sets the URL to send the webapk::CreateWebApkRequest to. WebApkInstaller | 287 // Sets the URL to send the webapk::CreateWebApkRequest to. WebApkInstaller |
| 294 // should fail if the URL is not |kServerUrl|. | 288 // should fail if the URL is not |kServerUrl|. |
| 295 void SetWebApkServerUrl(const GURL& server_url) { | 289 void SetWebApkServerUrl(const GURL& server_url) { |
| 296 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 290 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 297 switches::kWebApkServerUrl, server_url.spec()); | 291 switches::kWebApkServerUrl, server_url.spec()); |
| 298 } | 292 } |
| 299 | 293 |
| 300 // Sets the function that should be used to build the response to the | 294 // Sets the function that should be used to build the response to the |
| 301 // WebAPK creation request. | 295 // WebAPK creation request. |
| 302 void SetWebApkResponseBuilder(const WebApkResponseBuilder& builder) { | 296 void SetWebApkResponseBuilder(const WebApkResponseBuilder& builder) { |
| 303 webapk_response_builder_ = builder; | 297 webapk_response_builder_ = builder; |
| 304 } | 298 } |
| 305 | 299 |
| 306 std::unique_ptr<WebApkInstallerRunner> CreateWebApkInstallerRunner() { | 300 std::unique_ptr<WebApkInstallerRunner> CreateWebApkInstallerRunner() { |
| 307 return std::unique_ptr<WebApkInstallerRunner>( | 301 return std::unique_ptr<WebApkInstallerRunner>( |
| 308 new WebApkInstallerRunner(profile_.get(), best_icon_url_)); | 302 new WebApkInstallerRunner(profile_.get(), best_primary_icon_url_)); |
| 309 } | 303 } |
| 310 | 304 |
| 311 std::unique_ptr<BuildProtoRunner> CreateBuildProtoRunner() { | 305 std::unique_ptr<BuildProtoRunner> CreateBuildProtoRunner() { |
| 312 return std::unique_ptr<BuildProtoRunner>( | 306 return std::unique_ptr<BuildProtoRunner>( |
| 313 new BuildProtoRunner(profile_.get())); | 307 new BuildProtoRunner(profile_.get())); |
| 314 } | 308 } |
| 315 | 309 |
| 316 net::test_server::EmbeddedTestServer* test_server() { return &test_server_; } | 310 net::test_server::EmbeddedTestServer* test_server() { return &test_server_; } |
| 317 | 311 |
| 318 private: | 312 private: |
| 319 // Sets default configuration for running WebApkInstaller. | 313 // Sets default configuration for running WebApkInstaller. |
| 320 void SetDefaults() { | 314 void SetDefaults() { |
| 321 GURL best_icon_url = test_server_.GetURL(kBestIconUrl); | 315 GURL best_primary_icon_url = test_server_.GetURL(kBestPrimaryIconUrl); |
| 322 SetBestIconUrl(best_icon_url); | 316 SetBestPrimaryIconUrl(best_primary_icon_url); |
| 323 GURL server_url = test_server_.GetURL(kServerUrl); | 317 GURL server_url = test_server_.GetURL(kServerUrl); |
| 324 SetWebApkServerUrl(server_url); | 318 SetWebApkServerUrl(server_url); |
| 325 GURL download_url = test_server_.GetURL(kDownloadUrl); | 319 GURL download_url = test_server_.GetURL(kDownloadUrl); |
| 326 SetWebApkResponseBuilder( | 320 SetWebApkResponseBuilder( |
| 327 base::Bind(&BuildValidWebApkResponse, download_url)); | 321 base::Bind(&BuildValidWebApkResponse, download_url)); |
| 328 } | 322 } |
| 329 | 323 |
| 330 std::unique_ptr<net::test_server::HttpResponse> HandleWebApkRequest( | 324 std::unique_ptr<net::test_server::HttpResponse> HandleWebApkRequest( |
| 331 const net::test_server::HttpRequest& request) { | 325 const net::test_server::HttpRequest& request) { |
| 332 return (request.relative_url == kServerUrl) | 326 return (request.relative_url == kServerUrl) |
| 333 ? webapk_response_builder_.Run() | 327 ? webapk_response_builder_.Run() |
| 334 : std::unique_ptr<net::test_server::HttpResponse>(); | 328 : std::unique_ptr<net::test_server::HttpResponse>(); |
| 335 } | 329 } |
| 336 | 330 |
| 337 std::unique_ptr<TestingProfile> profile_; | 331 std::unique_ptr<TestingProfile> profile_; |
| 338 content::TestBrowserThreadBundle thread_bundle_; | 332 content::TestBrowserThreadBundle thread_bundle_; |
| 339 net::EmbeddedTestServer test_server_; | 333 net::EmbeddedTestServer test_server_; |
| 340 | 334 |
| 341 // Web Manifest's icon URL. | 335 // Web Manifest's icon URL. |
| 342 GURL best_icon_url_; | 336 GURL best_primary_icon_url_; |
| 343 | 337 |
| 344 // Builds response to the WebAPK creation request. | 338 // Builds response to the WebAPK creation request. |
| 345 WebApkResponseBuilder webapk_response_builder_; | 339 WebApkResponseBuilder webapk_response_builder_; |
| 346 | 340 |
| 347 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerTest); | 341 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerTest); |
| 348 }; | 342 }; |
| 349 | 343 |
| 350 // Test installation succeeding. | 344 // Test installation succeeding. |
| 351 TEST_F(WebApkInstallerTest, Success) { | 345 TEST_F(WebApkInstallerTest, Success) { |
| 352 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 346 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
| 353 runner->RunInstallWebApk(); | 347 runner->RunInstallWebApk(); |
| 354 EXPECT_TRUE(runner->success()); | 348 EXPECT_TRUE(runner->success()); |
| 355 } | 349 } |
| 356 | 350 |
| 357 // Test that installation fails if fetching the bitmap at the best icon URL | 351 // Test that installation fails if fetching the bitmap at the best primary icon |
| 358 // times out. In a perfect world the fetch would never time out because the | 352 // URL times out. In a perfect world the fetch would never time out because the |
| 359 // bitmap at the best icon URL should be in the HTTP cache. | 353 // bitmap at the best primary icon URL should be in the HTTP cache. |
| 360 TEST_F(WebApkInstallerTest, BestIconUrlDownloadTimesOut) { | 354 TEST_F(WebApkInstallerTest, BestPrimaryIconUrlDownloadTimesOut) { |
| 361 GURL best_icon_url = test_server()->GetURL("/slow?1000"); | 355 GURL best_primary_icon_url = test_server()->GetURL("/slow?1000"); |
| 362 SetBestIconUrl(best_icon_url); | 356 SetBestPrimaryIconUrl(best_primary_icon_url); |
| 363 | 357 |
| 364 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 358 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
| 365 runner->RunInstallWebApk(); | 359 runner->RunInstallWebApk(); |
| 366 EXPECT_FALSE(runner->success()); | 360 EXPECT_FALSE(runner->success()); |
| 367 } | 361 } |
| 368 | 362 |
| 369 // Test that installation fails if the WebAPK creation request times out. | 363 // Test that installation fails if the WebAPK creation request times out. |
| 370 TEST_F(WebApkInstallerTest, CreateWebApkRequestTimesOut) { | 364 TEST_F(WebApkInstallerTest, CreateWebApkRequestTimesOut) { |
| 371 GURL server_url = test_server()->GetURL("/slow?1000"); | 365 GURL server_url = test_server()->GetURL("/slow?1000"); |
| 372 SetWebApkServerUrl(server_url); | 366 SetWebApkServerUrl(server_url); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 428 } | 422 } |
| 429 | 423 |
| 430 // Test installation succeeds using Google Play. | 424 // Test installation succeeds using Google Play. |
| 431 TEST_F(WebApkInstallerTest, InstallFromGooglePlaySuccess) { | 425 TEST_F(WebApkInstallerTest, InstallFromGooglePlaySuccess) { |
| 432 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 426 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
| 433 runner->SetCanUseGooglePlayInstallService(true); | 427 runner->SetCanUseGooglePlayInstallService(true); |
| 434 runner->RunInstallWebApk(); | 428 runner->RunInstallWebApk(); |
| 435 EXPECT_TRUE(runner->success()); | 429 EXPECT_TRUE(runner->success()); |
| 436 } | 430 } |
| 437 | 431 |
| 438 // When there is no Web Manifest available for a site, an empty |best_icon_url| | 432 // When there is no Web Manifest available for a site, an empty |
| 433 // |best_primary_icon_url| | |
|
dominickn
2017/02/02 23:34:13
Nit: comment formatting
F
2017/02/03 00:47:15
Done. Thanks!
| |
| 439 // is used to build a WebApk update request. Tests the request can be built | 434 // is used to build a WebApk update request. Tests the request can be built |
| 440 // properly. | 435 // properly. |
| 441 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) { | 436 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) { |
| 442 GURL icon_url_1 = test_server()->GetURL("/icon1.png"); | 437 GURL icon_url_1 = test_server()->GetURL("/icon1.png"); |
| 443 GURL icon_url_2 = test_server()->GetURL("/icon2.png"); | 438 GURL icon_url_2 = test_server()->GetURL("/icon2.png"); |
| 444 std::string icon_murmur2_hash_1 = "1"; | 439 std::string icon_murmur2_hash_1 = "1"; |
| 445 std::string icon_murmur2_hash_2 = "2"; | 440 std::string icon_murmur2_hash_2 = "2"; |
| 446 std::map<std::string, std::string> icon_url_to_murmur2_hash; | 441 std::map<std::string, std::string> icon_url_to_murmur2_hash; |
| 447 icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1; | 442 icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1; |
| 448 icon_url_to_murmur2_hash[icon_url_2.spec()] = icon_murmur2_hash_2; | 443 icon_url_to_murmur2_hash[icon_url_2.spec()] = icon_murmur2_hash_2; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 470 | 465 |
| 471 EXPECT_EQ(icon_url_2.spec(), icons[2].src()); | 466 EXPECT_EQ(icon_url_2.spec(), icons[2].src()); |
| 472 EXPECT_EQ(icon_murmur2_hash_2, icons[2].hash()); | 467 EXPECT_EQ(icon_murmur2_hash_2, icons[2].hash()); |
| 473 EXPECT_FALSE(icons[2].has_image_data()); | 468 EXPECT_FALSE(icons[2].has_image_data()); |
| 474 } | 469 } |
| 475 | 470 |
| 476 // Tests a WebApk install or update request is built properly when the Chrome | 471 // Tests a WebApk install or update request is built properly when the Chrome |
| 477 // knows the best icon URL of a site after fetching its Web Manifest. | 472 // knows the best icon URL of a site after fetching its Web Manifest. |
| 478 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsAvailable) { | 473 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsAvailable) { |
| 479 GURL icon_url_1 = test_server()->GetURL("/icon.png"); | 474 GURL icon_url_1 = test_server()->GetURL("/icon.png"); |
| 480 GURL best_icon_url = test_server()->GetURL(kBestIconUrl); | 475 GURL best_primary_icon_url = test_server()->GetURL(kBestPrimaryIconUrl); |
| 481 std::string icon_murmur2_hash_1 = "1"; | 476 std::string icon_murmur2_hash_1 = "1"; |
| 482 std::string best_icon_murmur2_hash = "0"; | 477 std::string best_primary_icon_murmur2_hash = "0"; |
| 483 std::map<std::string, std::string> icon_url_to_murmur2_hash; | 478 std::map<std::string, std::string> icon_url_to_murmur2_hash; |
| 484 icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1; | 479 icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1; |
| 485 icon_url_to_murmur2_hash[best_icon_url.spec()] = | 480 icon_url_to_murmur2_hash[best_primary_icon_url.spec()] = |
| 486 best_icon_murmur2_hash; | 481 best_primary_icon_murmur2_hash; |
| 487 | 482 |
| 488 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); | 483 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); |
| 489 runner->BuildSync(best_icon_url, icon_url_to_murmur2_hash, | 484 runner->BuildSync(best_primary_icon_url, icon_url_to_murmur2_hash, |
| 490 false /* is_manifest_stale*/); | 485 false /* is_manifest_stale*/); |
| 491 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); | 486 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); |
| 492 ASSERT_NE(nullptr, webapk_request); | 487 ASSERT_NE(nullptr, webapk_request); |
| 493 | 488 |
| 494 webapk::WebAppManifest manifest = webapk_request->manifest(); | 489 webapk::WebAppManifest manifest = webapk_request->manifest(); |
| 495 ASSERT_EQ(2, manifest.icons_size()); | 490 ASSERT_EQ(2, manifest.icons_size()); |
| 496 | 491 |
| 497 webapk::Image icons[2]; | 492 webapk::Image icons[2]; |
| 498 for (int i = 0; i < 2; ++i) | 493 for (int i = 0; i < 2; ++i) |
| 499 icons[i] = manifest.icons(i); | 494 icons[i] = manifest.icons(i); |
| 500 | 495 |
| 501 EXPECT_EQ(best_icon_url.spec(), icons[0].src()); | 496 EXPECT_EQ(best_primary_icon_url.spec(), icons[0].src()); |
| 502 EXPECT_EQ(best_icon_murmur2_hash, icons[0].hash()); | 497 EXPECT_EQ(best_primary_icon_murmur2_hash, icons[0].hash()); |
| 503 EXPECT_TRUE(icons[0].has_image_data()); | 498 EXPECT_TRUE(icons[0].has_image_data()); |
| 504 | 499 |
| 505 EXPECT_EQ(icon_url_1.spec(), icons[1].src()); | 500 EXPECT_EQ(icon_url_1.spec(), icons[1].src()); |
| 506 EXPECT_EQ(icon_murmur2_hash_1, icons[1].hash()); | 501 EXPECT_EQ(icon_murmur2_hash_1, icons[1].hash()); |
| 507 EXPECT_FALSE(icons[1].has_image_data()); | 502 EXPECT_FALSE(icons[1].has_image_data()); |
| 508 } | 503 } |
| OLD | NEW |