| 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/webapps/add_to_homescreen_data_fetcher.h" | 5 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 BuildFetcher(false, &waiter)); | 260 BuildFetcher(false, &waiter)); |
| 261 fetcher->OnDidGetWebApplicationInfo(WebApplicationInfo()); | 261 fetcher->OnDidGetWebApplicationInfo(WebApplicationInfo()); |
| 262 waiter.WaitForDataAvailable(); | 262 waiter.WaitForDataAvailable(); |
| 263 | 263 |
| 264 EXPECT_FALSE(waiter.determined_webapk_compatibility()); | 264 EXPECT_FALSE(waiter.determined_webapk_compatibility()); |
| 265 EXPECT_TRUE(waiter.title_available()); | 265 EXPECT_TRUE(waiter.title_available()); |
| 266 | 266 |
| 267 fetcher->set_weak_observer(nullptr); | 267 fetcher->set_weak_observer(nullptr); |
| 268 } | 268 } |
| 269 | 269 |
| 270 // Test that a page with WebApplicationInfo but no Web Manifest is not WebAPK |
| 271 // capable. |
| 272 TEST_F(AddToHomescreenDataFetcherTest, WebApplicationInfoNotWebApkCompatible) { |
| 273 const char* kWebApplicationInfoTitle = "Meta Title"; |
| 274 WebApplicationInfo web_application_info; |
| 275 web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); |
| 276 web_application_info.mobile_capable = WebApplicationInfo::MOBILE_CAPABLE; |
| 277 |
| 278 RegisterServiceWorker(GURL(kDefaultStartUrl)); |
| 279 SetManifest(GURL(), content::Manifest(), 0); |
| 280 |
| 281 ObserverWaiter waiter; |
| 282 scoped_refptr<AddToHomescreenDataFetcher> fetcher( |
| 283 BuildFetcher(true, &waiter)); |
| 284 fetcher->OnDidGetWebApplicationInfo(web_application_info); |
| 285 waiter.WaitForDataAvailable(); |
| 286 |
| 287 EXPECT_TRUE(waiter.determined_webapk_compatibility()); |
| 288 EXPECT_FALSE(waiter.is_webapk_compatible()); |
| 289 |
| 290 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name, |
| 291 kWebApplicationInfoTitle)); |
| 292 EXPECT_EQ(blink::kWebDisplayModeStandalone, fetcher->shortcut_info().display); |
| 293 |
| 294 fetcher->set_weak_observer(nullptr); |
| 295 } |
| 296 |
| 270 // Class for tests which should be run with AddToHomescreenDataFetcher built | 297 // Class for tests which should be run with AddToHomescreenDataFetcher built |
| 271 // with both true and false values of |check_webapk_compatible|. | 298 // with both true and false values of |check_webapk_compatible|. |
| 272 class AddToHomescreenDataFetcherTestCommon | 299 class AddToHomescreenDataFetcherTestCommon |
| 273 : public AddToHomescreenDataFetcherTest, | 300 : public AddToHomescreenDataFetcherTest, |
| 274 public testing::WithParamInterface<bool> { | 301 public testing::WithParamInterface<bool> { |
| 275 public: | 302 public: |
| 276 AddToHomescreenDataFetcherTestCommon() {} | 303 AddToHomescreenDataFetcherTestCommon() {} |
| 277 ~AddToHomescreenDataFetcherTestCommon() override {} | 304 ~AddToHomescreenDataFetcherTestCommon() override {} |
| 278 | 305 |
| 279 scoped_refptr<AddToHomescreenDataFetcher> BuildFetcher( | 306 scoped_refptr<AddToHomescreenDataFetcher> BuildFetcher( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 308 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); | 335 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); |
| 309 fetcher->OnDidGetWebApplicationInfo(web_application_info); | 336 fetcher->OnDidGetWebApplicationInfo(web_application_info); |
| 310 waiter.WaitForDataAvailable(); | 337 waiter.WaitForDataAvailable(); |
| 311 | 338 |
| 312 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name, | 339 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name, |
| 313 kDefaultManifestShortName)); | 340 kDefaultManifestShortName)); |
| 314 | 341 |
| 315 fetcher->set_weak_observer(nullptr); | 342 fetcher->set_weak_observer(nullptr); |
| 316 } | 343 } |
| 317 | 344 |
| 318 // Test that when the manifest does not provide either Manifest::short_name nor | 345 // Test that when a manifest is provided that it overwrites the |
| 319 // Manifest::name that: | 346 // WebapplicationInfo. |
| 320 // - The page is not WebAPK compatible. | 347 TEST_P(AddToHomescreenDataFetcherTestCommon, |
| 321 // - WebApplicationInfo::title is used as the "name". | 348 ManifestOverwritesWebApplicationInfo) { |
| 322 TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestNoNameNoShortName) { | 349 const char* kWebApplicationInfoTitle = "Meta Title"; |
| 323 const char* kWebApplicationInfoTitle = "Meta Title"; | 350 WebApplicationInfo web_application_info; |
| 324 WebApplicationInfo web_application_info; | 351 web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); |
| 325 web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); | |
| 326 | 352 |
| 327 content::Manifest manifest(BuildDefaultManifest()); | 353 content::Manifest manifest(BuildDefaultManifest()); |
| 328 manifest.name = base::NullableString16(); | 354 manifest.name = base::NullableString16(); |
| 329 manifest.short_name = base::NullableString16(); | 355 manifest.short_name = base::NullableString16(); |
| 330 | 356 |
| 331 RegisterServiceWorker(GURL(kDefaultStartUrl)); | 357 RegisterServiceWorker(GURL(kDefaultStartUrl)); |
| 332 SetManifest(GURL(kDefaultManifestUrl), manifest, 0); | 358 SetManifest(GURL(kDefaultManifestUrl), manifest, 0); |
| 333 | 359 |
| 334 ObserverWaiter waiter; | 360 ObserverWaiter waiter; |
| 335 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); | 361 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); |
| 336 fetcher->OnDidGetWebApplicationInfo(web_application_info); | 362 fetcher->OnDidGetWebApplicationInfo(web_application_info); |
| 337 waiter.WaitForDataAvailable(); | 363 waiter.WaitForDataAvailable(); |
| 338 | 364 |
| 339 EXPECT_FALSE(waiter.is_webapk_compatible()); | 365 // The name should be empty (even though one is provided in |
| 340 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name, | 366 // WebApplicationInfo) because the name was not provided in the Web |
| 341 kWebApplicationInfoTitle)); | 367 // Manifest. |
| 368 EXPECT_TRUE(fetcher->shortcut_info().name.empty()); |
| 369 EXPECT_EQ(blink::kWebDisplayModeUndefined, fetcher->shortcut_info().display); |
| 342 | 370 |
| 343 fetcher->set_weak_observer(nullptr); | 371 fetcher->set_weak_observer(nullptr); |
| 344 } | 372 } |
| 345 | 373 |
| 346 // Checks that the AddToHomescreenDataFetcher::Observer callbacks are called | 374 // Checks that the AddToHomescreenDataFetcher::Observer callbacks are called |
| 347 // when a service worker is registered and the manifest fetch times out. | 375 // when a service worker is registered and the manifest fetch times out. |
| 348 TEST_P(AddToHomescreenDataFetcherTestCommon, DISABLED_ManifestFetchTimesOut) { | 376 TEST_P(AddToHomescreenDataFetcherTestCommon, DISABLED_ManifestFetchTimesOut) { |
| 349 RegisterServiceWorker(GURL(kDefaultStartUrl)); | 377 RegisterServiceWorker(GURL(kDefaultStartUrl)); |
| 350 SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest(), 10000); | 378 SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest(), 10000); |
| 351 | 379 |
| 352 ObserverWaiter waiter; | 380 ObserverWaiter waiter; |
| 353 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); | 381 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); |
| 354 fetcher->OnDidGetWebApplicationInfo(WebApplicationInfo()); | 382 fetcher->OnDidGetWebApplicationInfo(WebApplicationInfo()); |
| 355 waiter.WaitForDataAvailable(); | 383 waiter.WaitForDataAvailable(); |
| 356 | 384 |
| 357 if (check_webapk_compatibility()) { | 385 if (check_webapk_compatibility()) { |
| 358 EXPECT_TRUE(waiter.determined_webapk_compatibility()); | 386 EXPECT_TRUE(waiter.determined_webapk_compatibility()); |
| 359 EXPECT_FALSE(waiter.is_webapk_compatible()); | 387 EXPECT_FALSE(waiter.is_webapk_compatible()); |
| 360 } else { | 388 } else { |
| 361 EXPECT_FALSE(waiter.determined_webapk_compatibility()); | 389 EXPECT_FALSE(waiter.determined_webapk_compatibility()); |
| 362 } | 390 } |
| 363 // This callback enables the text field in the add-to-homescreen dialog. | 391 // This callback enables the text field in the add-to-homescreen dialog. |
| 364 EXPECT_TRUE(waiter.title_available()); | 392 EXPECT_TRUE(waiter.title_available()); |
| 365 | 393 |
| 366 fetcher->set_weak_observer(nullptr); | 394 fetcher->set_weak_observer(nullptr); |
| 367 } | 395 } |
| 368 | 396 |
| 369 INSTANTIATE_TEST_CASE_P(CheckWebApkCompatibility, | 397 INSTANTIATE_TEST_CASE_P(CheckWebApkCompatibility, |
| 370 AddToHomescreenDataFetcherTestCommon, | 398 AddToHomescreenDataFetcherTestCommon, |
| 371 ::testing::Values(false, true)); | 399 ::testing::Values(false, true)); |
| OLD | NEW |