Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1173)

Side by Side Diff: chrome/browser/android/webapps/add_to_homescreen_data_fetcher_unittest.cc

Issue 2362813003: Make it clear that AddToHomescreenDataFetcher ignores WebApplicationInfo for WebAPK compatible pages (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/strings/nullable_string16.h" 16 #include "base/strings/nullable_string16.h"
17 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "chrome/common/web_application_info.h" 20 #include "chrome/common/web_application_info.h"
20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
21 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
22 #include "content/browser/service_worker/embedded_worker_test_helper.h" 23 #include "content/browser/service_worker/embedded_worker_test_helper.h"
23 #include "content/browser/service_worker/service_worker_context_core.h" 24 #include "content/browser/service_worker/service_worker_context_core.h"
24 #include "content/common/service_worker/service_worker_status_code.h" 25 #include "content/common/service_worker/service_worker_status_code.h"
25 #include "content/public/browser/site_instance.h" 26 #include "content/public/browser/site_instance.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 263 }
263 264
264 // The value of |check_webapk_compatible| used when building the 265 // The value of |check_webapk_compatible| used when building the
265 // AddToHomescreenDataFetcher. 266 // AddToHomescreenDataFetcher.
266 bool check_webapk_compatibility() { return GetParam(); } 267 bool check_webapk_compatibility() { return GetParam(); }
267 268
268 private: 269 private:
269 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcherTestCommon); 270 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcherTestCommon);
270 }; 271 };
271 272
273 // Test that when the manifest provides Manifest::short_name but not
274 // Manifest::name that Manifest::short_name is used as the name instead of
275 // WebApplicationInfo::title.
276 TEST_P(AddToHomescreenDataFetcherTestCommon,
277 ManifestShortNameClobbersWebApplicationName) {
278 WebApplicationInfo web_application_info;
279 web_application_info.title = base::UTF8ToUTF16("Meta Title");
280
281 content::Manifest manifest(BuildDefaultManifest());
282 manifest.name = base::NullableString16();
283
284 RegisterServiceWorker(GURL(kDefaultStartUrl));
285 SetManifest(GURL(kDefaultManifestUrl), manifest, 0);
286
287 ObserverWaiter waiter;
288 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
289 fetcher->OnDidGetWebApplicationInfo(web_application_info);
Xi Han 2016/09/26 17:48:12 Once when a fetcher is created by BuildFetcher(),
pkotwicz 2016/09/26 20:13:47 Tests with use TestWebContents do not create rende
Xi Han 2016/09/26 20:15:41 Acknowledged.
290 waiter.WaitForDataAvailable();
291
292 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name,
293 kDefaultManifestShortName));
294
295 fetcher->set_weak_observer(nullptr);
296 }
297
298 // Test that when the manifest does not provide either Manifest::short_name nor
299 // Manifest::name that:
300 // - The page is not WebAPK compatible.
301 // - WebApplicationInfo::title is used as the "name".
302 TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestNoNameNoShortName) {
303 const char* kWebApplicationInfoTitle = "Meta Title";
304 WebApplicationInfo web_application_info;
305 web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
306
307 content::Manifest manifest(BuildDefaultManifest());
308 manifest.name = base::NullableString16();
309 manifest.short_name = base::NullableString16();
310
311 RegisterServiceWorker(GURL(kDefaultStartUrl));
312 SetManifest(GURL(kDefaultManifestUrl), manifest, 0);
313
314 ObserverWaiter waiter;
315 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
316 fetcher->OnDidGetWebApplicationInfo(web_application_info);
317 waiter.WaitForDataAvailable();
318
319 EXPECT_FALSE(waiter.is_webapk_compatible);
320 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name,
321 kWebApplicationInfoTitle));
322
323 fetcher->set_weak_observer(nullptr);
324 }
325
272 // Checks that the AddToHomescreenDataFetcher::Observer callbacks are called 326 // Checks that the AddToHomescreenDataFetcher::Observer callbacks are called
273 // when a service worker is registered and the manifest fetch times out. 327 // when a service worker is registered and the manifest fetch times out.
274 TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestFetchTimesOut) { 328 TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestFetchTimesOut) {
275 RegisterServiceWorker(GURL(kDefaultStartUrl)); 329 RegisterServiceWorker(GURL(kDefaultStartUrl));
276 SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest(), 10000); 330 SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest(), 10000);
277 331
278 ObserverWaiter waiter; 332 ObserverWaiter waiter;
279 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); 333 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
280 fetcher->OnDidGetWebApplicationInfo(WebApplicationInfo()); 334 fetcher->OnDidGetWebApplicationInfo(WebApplicationInfo());
281 waiter.WaitForDataAvailable(); 335 waiter.WaitForDataAvailable();
282 336
283 if (check_webapk_compatibility()) { 337 if (check_webapk_compatibility()) {
284 EXPECT_TRUE(waiter.determined_webapk_compatibility); 338 EXPECT_TRUE(waiter.determined_webapk_compatibility);
285 EXPECT_FALSE(waiter.is_webapk_compatible); 339 EXPECT_FALSE(waiter.is_webapk_compatible);
286 } else { 340 } else {
287 EXPECT_FALSE(waiter.determined_webapk_compatibility); 341 EXPECT_FALSE(waiter.determined_webapk_compatibility);
288 } 342 }
289 // This callback enables the text field in the add-to-homescreen dialog. 343 // This callback enables the text field in the add-to-homescreen dialog.
290 EXPECT_TRUE(waiter.title_available); 344 EXPECT_TRUE(waiter.title_available);
291 345
292 fetcher->set_weak_observer(nullptr); 346 fetcher->set_weak_observer(nullptr);
293 } 347 }
294 348
295 INSTANTIATE_TEST_CASE_P(CheckWebApkCompatibility, 349 INSTANTIATE_TEST_CASE_P(CheckWebApkCompatibility,
296 AddToHomescreenDataFetcherTestCommon, 350 AddToHomescreenDataFetcherTestCommon,
297 ::testing::Values(false, true)); 351 ::testing::Values(false, true));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698