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

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

Issue 2385843002: Revert of Make it clear that AddToHomescreenDataFetcher ignores WebApplicationInfo for WebAPK (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
« no previous file with comments | « chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
18 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
19 #include "base/time/time.h" 18 #include "base/time/time.h"
20 #include "chrome/common/web_application_info.h" 19 #include "chrome/common/web_application_info.h"
21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
22 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
23 #include "content/browser/service_worker/embedded_worker_test_helper.h" 22 #include "content/browser/service_worker/embedded_worker_test_helper.h"
24 #include "content/browser/service_worker/service_worker_context_core.h" 23 #include "content/browser/service_worker/service_worker_context_core.h"
25 #include "content/common/service_worker/service_worker_status_code.h" 24 #include "content/common/service_worker/service_worker_status_code.h"
26 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/site_instance.h" 26 #include "content/public/browser/site_instance.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 content::Manifest manifest_; 89 content::Manifest manifest_;
91 int manifest_fetch_delay_ms_; 90 int manifest_fetch_delay_ms_;
92 91
93 DISALLOW_COPY_AND_ASSIGN(MockWebContents); 92 DISALLOW_COPY_AND_ASSIGN(MockWebContents);
94 }; 93 };
95 94
96 // Tracks which of the AddToHomescreenDataFetcher::Observer callbacks have been 95 // Tracks which of the AddToHomescreenDataFetcher::Observer callbacks have been
97 // called. 96 // called.
98 class ObserverWaiter : public AddToHomescreenDataFetcher::Observer { 97 class ObserverWaiter : public AddToHomescreenDataFetcher::Observer {
99 public: 98 public:
100 ObserverWaiter() 99 ObserverWaiter() {}
101 : is_webapk_compatible_(false),
102 determined_webapk_compatibility_(false),
103 title_available_(false),
104 data_available_(false) {}
105 ~ObserverWaiter() override {} 100 ~ObserverWaiter() override {}
106 101
107 // Waits till the OnDataAvailable() callback is called. 102 // Waits till the OnDataAvailable() callback is called.
108 void WaitForDataAvailable() { 103 void WaitForDataAvailable() {
109 if (data_available_) 104 if (data_available_)
110 return; 105 return;
111 106
112 base::RunLoop run_loop; 107 base::RunLoop run_loop;
113 quit_closure_ = run_loop.QuitClosure(); 108 quit_closure_ = run_loop.QuitClosure();
114 run_loop.Run(); 109 run_loop.Run();
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 268 }
274 269
275 // The value of |check_webapk_compatible| used when building the 270 // The value of |check_webapk_compatible| used when building the
276 // AddToHomescreenDataFetcher. 271 // AddToHomescreenDataFetcher.
277 bool check_webapk_compatibility() { return GetParam(); } 272 bool check_webapk_compatibility() { return GetParam(); }
278 273
279 private: 274 private:
280 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcherTestCommon); 275 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcherTestCommon);
281 }; 276 };
282 277
283 // Test that when the manifest provides Manifest::short_name but not
284 // Manifest::name that Manifest::short_name is used as the name instead of
285 // WebApplicationInfo::title.
286 TEST_P(AddToHomescreenDataFetcherTestCommon,
287 ManifestShortNameClobbersWebApplicationName) {
288 WebApplicationInfo web_application_info;
289 web_application_info.title = base::UTF8ToUTF16("Meta Title");
290
291 content::Manifest manifest(BuildDefaultManifest());
292 manifest.name = base::NullableString16();
293
294 RegisterServiceWorker(GURL(kDefaultStartUrl));
295 SetManifest(GURL(kDefaultManifestUrl), manifest, 0);
296
297 ObserverWaiter waiter;
298 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
299 fetcher->OnDidGetWebApplicationInfo(web_application_info);
300 waiter.WaitForDataAvailable();
301
302 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name,
303 kDefaultManifestShortName));
304
305 fetcher->set_weak_observer(nullptr);
306 }
307
308 // Test that when the manifest does not provide either Manifest::short_name nor
309 // Manifest::name that:
310 // - The page is not WebAPK compatible.
311 // - WebApplicationInfo::title is used as the "name".
312 TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestNoNameNoShortName) {
313 const char* kWebApplicationInfoTitle = "Meta Title";
314 WebApplicationInfo web_application_info;
315 web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
316
317 content::Manifest manifest(BuildDefaultManifest());
318 manifest.name = base::NullableString16();
319 manifest.short_name = base::NullableString16();
320
321 RegisterServiceWorker(GURL(kDefaultStartUrl));
322 SetManifest(GURL(kDefaultManifestUrl), manifest, 0);
323
324 ObserverWaiter waiter;
325 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
326 fetcher->OnDidGetWebApplicationInfo(web_application_info);
327 waiter.WaitForDataAvailable();
328
329 EXPECT_FALSE(waiter.is_webapk_compatible());
330 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name,
331 kWebApplicationInfoTitle));
332
333 fetcher->set_weak_observer(nullptr);
334 }
335
336 // Checks that the AddToHomescreenDataFetcher::Observer callbacks are called 278 // Checks that the AddToHomescreenDataFetcher::Observer callbacks are called
337 // when a service worker is registered and the manifest fetch times out. 279 // when a service worker is registered and the manifest fetch times out.
338 TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestFetchTimesOut) { 280 TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestFetchTimesOut) {
339 RegisterServiceWorker(GURL(kDefaultStartUrl)); 281 RegisterServiceWorker(GURL(kDefaultStartUrl));
340 SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest(), 10000); 282 SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest(), 10000);
341 283
342 ObserverWaiter waiter; 284 ObserverWaiter waiter;
343 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); 285 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
344 fetcher->OnDidGetWebApplicationInfo(WebApplicationInfo()); 286 fetcher->OnDidGetWebApplicationInfo(WebApplicationInfo());
345 waiter.WaitForDataAvailable(); 287 waiter.WaitForDataAvailable();
346 288
347 if (check_webapk_compatibility()) { 289 if (check_webapk_compatibility()) {
348 EXPECT_TRUE(waiter.determined_webapk_compatibility()); 290 EXPECT_TRUE(waiter.determined_webapk_compatibility());
349 EXPECT_FALSE(waiter.is_webapk_compatible()); 291 EXPECT_FALSE(waiter.is_webapk_compatible());
350 } else { 292 } else {
351 EXPECT_FALSE(waiter.determined_webapk_compatibility()); 293 EXPECT_FALSE(waiter.determined_webapk_compatibility());
352 } 294 }
353 // This callback enables the text field in the add-to-homescreen dialog. 295 // This callback enables the text field in the add-to-homescreen dialog.
354 EXPECT_TRUE(waiter.title_available()); 296 EXPECT_TRUE(waiter.title_available());
355 297
356 fetcher->set_weak_observer(nullptr); 298 fetcher->set_weak_observer(nullptr);
357 } 299 }
358 300
359 INSTANTIATE_TEST_CASE_P(CheckWebApkCompatibility, 301 INSTANTIATE_TEST_CASE_P(CheckWebApkCompatibility,
360 AddToHomescreenDataFetcherTestCommon, 302 AddToHomescreenDataFetcherTestCommon,
361 ::testing::Values(false, true)); 303 ::testing::Values(false, true));
OLDNEW
« no previous file with comments | « chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698