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

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

Issue 2960103002: Improve add to homescreen data fetcher unit tests. (Closed)
Patch Set: Consolidation, testing calling GetData callback after time out Created 3 years, 5 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 | « no previous file | chrome/browser/installable/installable_manager.h » ('j') | 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 #include <utility>
9 10
10 #include "base/callback_forward.h" 11 #include "base/bind.h"
11 #include "base/files/file_path.h" 12 #include "base/callback.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.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/string_util.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/time/time.h"
20 #include "chrome/browser/installable/installable_manager.h" 19 #include "chrome/browser/installable/installable_manager.h"
21 #include "chrome/common/web_application_info.h" 20 #include "chrome/common/web_application_info.h"
22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
23 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
24 #include "content/browser/service_worker/embedded_worker_test_helper.h"
25 #include "content/browser/service_worker/service_worker_context_core.h"
26 #include "content/common/service_worker/service_worker_status_code.h"
27 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/site_instance.h"
29 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
30 #include "content/public/common/manifest.h" 24 #include "content/public/common/manifest.h"
31 #include "content/test/test_web_contents.h"
32 #include "net/http/http_status_code.h"
33 #include "third_party/WebKit/public/platform/WebDisplayMode.h" 25 #include "third_party/WebKit/public/platform/WebDisplayMode.h"
34 #include "ui/gfx/image/image_unittest_util.h" 26 #include "ui/gfx/image/image_unittest_util.h"
35 #include "url/gurl.h" 27 #include "url/gurl.h"
36 28
37 namespace { 29 namespace {
38 30
39 const char* kWebApplicationInfoTitle = "Meta Title"; 31 const char* kWebApplicationInfoTitle = "Meta Title";
40 const char* kDefaultManifestUrl = "https://www.example.com/manifest.json"; 32 const char* kDefaultManifestUrl = "https://www.example.com/manifest.json";
33 const char* kDefaultIconUrl = "https://www.example.com/icon.png";
41 const char* kDefaultManifestName = "Default Name"; 34 const char* kDefaultManifestName = "Default Name";
42 const char* kDefaultManifestShortName = "Default Short Name"; 35 const char* kDefaultManifestShortName = "Default Short Name";
43 const char* kDefaultStartUrl = "https://www.example.com/index.html"; 36 const char* kDefaultStartUrl = "https://www.example.com/index.html";
44 const blink::WebDisplayMode kDefaultManifestDisplayMode = 37 const blink::WebDisplayMode kDefaultManifestDisplayMode =
45 blink::kWebDisplayModeStandalone; 38 blink::kWebDisplayModeStandalone;
39 const int kIconSizePx = 144;
46 40
47 // WebContents subclass which mocks out image and manifest fetching. 41 // Tracks which of the AddToHomescreenDataFetcher::Observer methods have been
48 class MockWebContents : public content::TestWebContents {
49 public:
50 explicit MockWebContents(content::BrowserContext* browser_context)
51 : content::TestWebContents(browser_context),
52 should_image_time_out_(false),
53 should_manifest_time_out_(false) {}
54
55 ~MockWebContents() override {}
56
57 void SetManifest(const GURL& manifest_url,
58 const content::Manifest& manifest) {
59 manifest_url_ = manifest_url;
60 manifest_ = manifest;
61 }
62
63 int DownloadImage(const GURL& url,
64 bool is_favicon,
65 uint32_t max_bitmap_size,
66 bool bypass_cache,
67 const ImageDownloadCallback& callback) override {
68 if (should_image_time_out_)
69 return 0;
70
71 const int kIconSizePx = 144;
72 SkBitmap icon = gfx::test::CreateBitmap(kIconSizePx, kIconSizePx);
73 std::vector<SkBitmap> icons(1u, icon);
74 std::vector<gfx::Size> pixel_sizes(1u, gfx::Size(kIconSizePx, kIconSizePx));
75 content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::UI)
76 ->PostTask(FROM_HERE, base::Bind(callback, 0, net::HTTP_OK, url, icons,
77 pixel_sizes));
78 return 0;
79 }
80
81 void GetManifest(const GetManifestCallback& callback) override {
82 if (should_manifest_time_out_)
83 return;
84
85 content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::UI)
86 ->PostTask(FROM_HERE, base::Bind(callback, manifest_url_, manifest_));
87 }
88
89 void SetShouldImageTimeOut(bool should_time_out) {
90 should_image_time_out_ = should_time_out;
91 }
92
93 void SetShouldManifestTimeOut(bool should_time_out) {
94 should_manifest_time_out_ = should_time_out;
95 }
96
97 private:
98 GURL manifest_url_;
99 content::Manifest manifest_;
100 bool should_image_time_out_;
101 bool should_manifest_time_out_;
102
103 DISALLOW_COPY_AND_ASSIGN(MockWebContents);
104 };
105
106 // Tracks which of the AddToHomescreenDataFetcher::Observer callbacks have been
107 // called. 42 // called.
108 class ObserverWaiter : public AddToHomescreenDataFetcher::Observer { 43 class ObserverWaiter : public AddToHomescreenDataFetcher::Observer {
109 public: 44 public:
110 ObserverWaiter() 45 ObserverWaiter()
111 : is_webapk_compatible_(false), 46 : is_webapk_compatible_(false),
112 determined_webapk_compatibility_(false), 47 determined_webapk_compatibility_(false),
113 title_available_(false), 48 title_available_(false),
114 data_available_(false) {} 49 data_available_(false) {}
115 ~ObserverWaiter() override {} 50 ~ObserverWaiter() override {}
116 51
117 // Waits till the OnDataAvailable() callback is called. 52 // Waits till the OnDataAvailable() callback is called.
118 void WaitForDataAvailable() { 53 void WaitForDataAvailable() {
119 if (data_available_) 54 if (data_available_)
120 return; 55 return;
121 56
122 base::RunLoop run_loop; 57 base::RunLoop run_loop;
123 quit_closure_ = run_loop.QuitClosure(); 58 quit_closure_ = run_loop.QuitClosure();
124 run_loop.Run(); 59 run_loop.Run();
125 } 60 }
126 61
127 void OnDidDetermineWebApkCompatibility(bool is_webapk_compatible) override { 62 void OnDidDetermineWebApkCompatibility(bool is_webapk_compatible) override {
63 // This should only be called once.
64 EXPECT_FALSE(determined_webapk_compatibility_);
128 EXPECT_FALSE(title_available_); 65 EXPECT_FALSE(title_available_);
129 determined_webapk_compatibility_ = true; 66 determined_webapk_compatibility_ = true;
130 is_webapk_compatible_ = is_webapk_compatible; 67 is_webapk_compatible_ = is_webapk_compatible;
131 } 68 }
132 69
133 void OnUserTitleAvailable(const base::string16& title) override { 70 void OnUserTitleAvailable(const base::string16& title) override {
71 // This should only be called once.
72 EXPECT_FALSE(title_available_);
134 EXPECT_FALSE(data_available_); 73 EXPECT_FALSE(data_available_);
135 title_available_ = true; 74 title_available_ = true;
136 title_ = title; 75 title_ = title;
137 } 76 }
138 77
139 SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon, 78 SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon,
140 const GURL& url, 79 const GURL& url,
141 bool* is_generated) override { 80 bool* is_generated) override {
142 *is_generated = false; 81 *is_generated = false;
143 return icon; 82 return icon;
144 } 83 }
145 84
146 void OnDataAvailable(const ShortcutInfo& info, 85 void OnDataAvailable(const ShortcutInfo& info,
147 const SkBitmap& primary_icon, 86 const SkBitmap& primary_icon,
148 const SkBitmap& badge_icon) override { 87 const SkBitmap& badge_icon) override {
88 // This should only be called once.
89 EXPECT_FALSE(data_available_);
149 EXPECT_TRUE(title_available_); 90 EXPECT_TRUE(title_available_);
150 data_available_ = true; 91 data_available_ = true;
151 if (!quit_closure_.is_null()) 92 if (!quit_closure_.is_null())
152 quit_closure_.Run(); 93 quit_closure_.Run();
153 } 94 }
154 95
155 base::string16 title() const { return title_; } 96 base::string16 title() const { return title_; }
156 bool is_webapk_compatible() const { return is_webapk_compatible_; } 97 bool is_webapk_compatible() const { return is_webapk_compatible_; }
157 bool determined_webapk_compatibility() const { 98 bool determined_webapk_compatibility() const {
158 return determined_webapk_compatibility_; 99 return determined_webapk_compatibility_;
159 } 100 }
160 bool title_available() const { return title_available_; } 101 bool title_available() const { return title_available_; }
161 102
162 private: 103 private:
163 base::string16 title_; 104 base::string16 title_;
164 bool is_webapk_compatible_; 105 bool is_webapk_compatible_;
165 bool determined_webapk_compatibility_; 106 bool determined_webapk_compatibility_;
166 bool title_available_; 107 bool title_available_;
167 bool data_available_; 108 bool data_available_;
168 base::Closure quit_closure_; 109 base::Closure quit_closure_;
169 110
170 DISALLOW_COPY_AND_ASSIGN(ObserverWaiter); 111 DISALLOW_COPY_AND_ASSIGN(ObserverWaiter);
171 }; 112 };
172 113
173 // Builds non-null base::NullableString16 from a UTF8 string. 114 // Builds non-null base::NullableString16 from a UTF8 string.
174 base::NullableString16 NullableStringFromUTF8(const std::string& value) { 115 base::NullableString16 NullableStringFromUTF8(const std::string& value) {
175 return base::NullableString16(base::UTF8ToUTF16(value), false); 116 return base::NullableString16(base::UTF8ToUTF16(value), false);
176 } 117 }
177 118
178 content::Manifest BuildEmptyManifest() { 119 content::Manifest BuildNoIconManifest() {
179 return content::Manifest();
180 }
181
182 // Builds WebAPK compatible content::Manifest.
183 content::Manifest BuildDefaultManifest() {
184 content::Manifest manifest; 120 content::Manifest manifest;
185 manifest.name = NullableStringFromUTF8(kDefaultManifestName); 121 manifest.name = NullableStringFromUTF8(kDefaultManifestName);
186 manifest.short_name = NullableStringFromUTF8(kDefaultManifestShortName); 122 manifest.short_name = NullableStringFromUTF8(kDefaultManifestShortName);
187 manifest.start_url = GURL(kDefaultStartUrl); 123 manifest.start_url = GURL(kDefaultStartUrl);
188 manifest.display = kDefaultManifestDisplayMode; 124 manifest.display = kDefaultManifestDisplayMode;
189 125
126 return manifest;
127 }
128
129 // Builds WebAPK compatible content::Manifest.
130 content::Manifest BuildDefaultManifest() {
131 content::Manifest manifest = BuildNoIconManifest();
132
190 content::Manifest::Icon primary_icon; 133 content::Manifest::Icon primary_icon;
191 primary_icon.type = base::ASCIIToUTF16("image/png"); 134 primary_icon.type = base::ASCIIToUTF16("image/png");
192 primary_icon.sizes.push_back(gfx::Size(144, 144)); 135 primary_icon.sizes.push_back(gfx::Size(144, 144));
193 primary_icon.purpose.push_back(content::Manifest::Icon::IconPurpose::ANY); 136 primary_icon.purpose.push_back(content::Manifest::Icon::IconPurpose::ANY);
194 primary_icon.src = GURL("https://www.google.com/image.png"); 137 primary_icon.src = GURL("https://www.google.com/image.png");
195 manifest.icons.push_back(primary_icon); 138 manifest.icons.push_back(primary_icon);
196 139
197 return manifest; 140 return manifest;
198 } 141 }
199 142
200 } // anonymous namespace 143 } // anonymous namespace
201 144
145 class TestInstallableManager : public InstallableManager {
146 public:
147 explicit TestInstallableManager(content::WebContents* web_contents)
148 : InstallableManager(web_contents) {}
149
150 void GetData(const InstallableParams& params,
151 const InstallableCallback& callback) override {
152 InstallableStatusCode code = code_;
153 if (params.check_installable) {
154 if (!IsManifestValidForWebApp(manifest_))
pkotwicz 2017/06/29 19:22:05 Can you make IsManifestValidForWebApp() a static m
dominickn 2017/06/30 02:42:31 I'll do that in a follow up because it will mean c
pkotwicz 2017/06/30 23:54:52 Fair enough
155 code = valid_manifest_->error;
156 else if (!is_installable_)
157 code = NO_MATCHING_SERVICE_WORKER;
158 }
159
160 // Store the callback so it can be redispatched later.
161 InstallableData data{
162 code, manifest_url_,
163 manifest_, primary_icon_url_,
164 &primary_icon_, badge_icon_url_,
165 &badge_icon_, params.check_installable ? is_installable_ : false};
pkotwicz 2017/06/29 19:22:06 For the sake of clarity, you should only return a
dominickn 2017/06/30 02:42:31 Good suggestion, done
166 callback_ = base::BindOnce(callback, data);
167
168 if (should_manifest_time_out_ ||
169 (params.check_installable && should_installable_time_out_)) {
pkotwicz 2017/06/29 19:22:05 Can this be simplified to: if (should_manifest_ti
dominickn 2017/06/30 02:42:31 Not really, because we want to test the first GetD
pkotwicz 2017/06/30 23:54:52 You are right, my suggestion has problems. We sho
dominickn 2017/07/05 07:03:26 The initial manifest fetch is always made, and it
pkotwicz 2017/07/05 21:37:42 Because SetShouldInstallableTimeOut() takes preced
pkotwicz 2017/07/06 02:03:16 Ping on this comment
dominickn 2017/07/06 02:53:39 SetInstallable defaults to false and is explicitly
170 return;
171 }
172
173 std::move(callback_).Run();
174 }
175
176 bool IsDeferredCallbackNull() { return callback_.is_null(); }
177
178 void RunCallback() {
179 EXPECT_FALSE(IsDeferredCallbackNull());
180 std::move(callback_).Run();
181 }
182
183 void SetStatus(InstallableStatusCode code, bool is_installable) {
184 code_ = code;
185 is_installable_ = is_installable;
186 }
187
188 void SetManifest(const GURL& url, const content::Manifest& manifest) {
189 manifest_url_ = url;
190 manifest_ = manifest;
191 }
192
193 void SetPrimaryIcon(const GURL& url, const SkBitmap& icon) {
194 primary_icon_url_ = url;
195 primary_icon_ = icon;
196 }
197
198 void SetBadgeIcon(const GURL& url, const SkBitmap& icon) {
199 badge_icon_url_ = url;
200 badge_icon_ = icon;
201 }
202
203 void SetShouldManifestTimeOut(bool should_time_out) {
204 should_manifest_time_out_ = should_time_out;
205 }
206
207 void SetShouldInstallableTimeOut(bool should_time_out) {
208 should_installable_time_out_ = should_time_out;
209 }
210
211 private:
212 base::OnceClosure callback_;
213 InstallableStatusCode code_;
214 content::Manifest manifest_;
215 GURL manifest_url_;
pkotwicz 2017/06/29 19:22:05 It seems like this is always kDefaultManifestUrl.
dominickn 2017/06/30 02:42:32 Done.
216 GURL primary_icon_url_;
217 GURL badge_icon_url_;
218 SkBitmap primary_icon_;
219 SkBitmap badge_icon_;
220
221 bool is_installable_ = false;
pkotwicz 2017/06/29 19:22:05 Should this variable be renamed to |has_service_wo
dominickn 2017/06/30 02:42:31 I want to keep it is_installable_ to match the nam
222
223 bool should_manifest_time_out_ = false;
224 bool should_installable_time_out_ = false;
225 };
226
202 // Tests AddToHomescreenDataFetcher. These tests should be browser tests but 227 // Tests AddToHomescreenDataFetcher. These tests should be browser tests but
203 // Android does not support browser tests yet (crbug.com/611756). 228 // Android does not support browser tests yet (crbug.com/611756).
204 class AddToHomescreenDataFetcherTest : public ChromeRenderViewHostTestHarness { 229 class AddToHomescreenDataFetcherTest : public ChromeRenderViewHostTestHarness {
205 public: 230 public:
206 AddToHomescreenDataFetcherTest() {} 231 AddToHomescreenDataFetcherTest() {}
207 ~AddToHomescreenDataFetcherTest() override {} 232 ~AddToHomescreenDataFetcherTest() override {}
208 233
209 void SetUp() override { 234 void SetUp() override {
210 ChromeRenderViewHostTestHarness::SetUp(); 235 ChromeRenderViewHostTestHarness::SetUp();
211 236
212 ASSERT_TRUE(profile()->CreateHistoryService(false, true)); 237 ASSERT_TRUE(profile()->CreateHistoryService(false, true));
213 profile()->CreateFaviconService(); 238 profile()->CreateFaviconService();
214 239
215 embedded_worker_test_helper_.reset( 240 // Manually inject the TestInstallableManager as a "InstallableManager"
216 new content::EmbeddedWorkerTestHelper(base::FilePath())); 241 // WebContentsUserData. We can't directly call ::CreateForWebContents due to
217 242 // typing issues since TestInstallableManager doesn't directly inherit from
218 scoped_refptr<content::SiteInstance> site_instance = 243 // WebContentsUserData.
219 content::SiteInstance::Create(browser_context()); 244 web_contents()->SetUserData(
220 site_instance->GetProcess()->Init(); 245 TestInstallableManager::UserDataKey(),
221 MockWebContents* mock_web_contents = new MockWebContents(browser_context()); 246 base::WrapUnique(new TestInstallableManager(web_contents())));
222 mock_web_contents->Init(content::WebContents::CreateParams( 247 installable_manager_ = static_cast<TestInstallableManager*>(
223 browser_context(), std::move(site_instance))); 248 web_contents()->GetUserData(TestInstallableManager::UserDataKey()));
224 InstallableManager::CreateForWebContents(mock_web_contents);
225 SetContents(mock_web_contents);
226 NavigateAndCommit(GURL(kDefaultStartUrl));
227 }
228
229 void TearDown() override {
230 embedded_worker_test_helper_.reset();
231 ChromeRenderViewHostTestHarness::TearDown();
232 } 249 }
233 250
234 scoped_refptr<AddToHomescreenDataFetcher> BuildFetcher( 251 scoped_refptr<AddToHomescreenDataFetcher> BuildFetcher(
235 bool check_webapk_compatible, 252 bool check_webapk_compatible,
236 AddToHomescreenDataFetcher::Observer* observer) { 253 AddToHomescreenDataFetcher::Observer* observer) {
237 return new AddToHomescreenDataFetcher(web_contents(), 1, 1, 1, 1, 1, 500, 254 return new AddToHomescreenDataFetcher(web_contents(), 1, 1, 1, 1, 1, 500,
238 check_webapk_compatible, observer); 255 check_webapk_compatible, observer);
239 } 256 }
240 257
241 // Set the manifest to be returned as a result of WebContents::GetManifest(). 258 void RunFetcher(scoped_refptr<AddToHomescreenDataFetcher> fetcher,
242 void SetManifest(const GURL& manifest_url, 259 ObserverWaiter& waiter,
243 const content::Manifest& manifest) { 260 const char* expected_title,
244 MockWebContents* mock_web_contents = 261 blink::WebDisplayMode display_mode,
245 static_cast<MockWebContents*>(web_contents()); 262 bool is_webapk_compatible) {
246 mock_web_contents->SetManifest(manifest_url, manifest); 263 WebApplicationInfo web_application_info;
264 web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
265
266 fetcher->OnDidGetWebApplicationInfo(web_application_info);
267 waiter.WaitForDataAvailable();
268
269 EXPECT_EQ(check_webapk_compatibility(),
270 waiter.determined_webapk_compatibility());
271 EXPECT_EQ(is_webapk_compatible, waiter.is_webapk_compatible());
272 EXPECT_TRUE(waiter.title_available());
273 EXPECT_TRUE(base::EqualsASCII(waiter.title(), expected_title));
274 EXPECT_TRUE(
275 base::EqualsASCII(fetcher->shortcut_info().user_title, expected_title));
276 EXPECT_EQ(display_mode, fetcher->shortcut_info().display);
247 } 277 }
pkotwicz 2017/06/29 19:22:05 Maybe we can make RunFetcher() call a helper funct
dominickn 2017/06/30 02:42:31 I don't see a strong enough benefit here - just us
248 278
249 void SetShouldImageTimeOut(bool should_time_out) { 279 void SetManifest(const content::Manifest& manifest) {
250 MockWebContents* mock_web_contents = 280 installable_manager_->SetManifest(GURL(kDefaultManifestUrl), manifest);
251 static_cast<MockWebContents*>(web_contents()); 281 installable_manager_->SetStatus(NO_ACCEPTABLE_ICON, false);
252 mock_web_contents->SetShouldImageTimeOut(should_time_out); 282 }
283
284 void SetManifestAndIcons(const content::Manifest& manifest) {
285 SetManifest(manifest);
286 installable_manager_->SetPrimaryIcon(
287 GURL(kDefaultIconUrl),
288 gfx::test::CreateBitmap(kIconSizePx, kIconSizePx));
289 installable_manager_->SetStatus(NO_ERROR_DETECTED, false);
290 }
291
292 void SetInstallable(const content::Manifest& manifest) {
293 SetManifestAndIcons(manifest);
294 installable_manager_->SetStatus(NO_ERROR_DETECTED, true);
295 }
296
297 void SetInstallableAndBadgeIcon(const content::Manifest& manifest) {
298 SetInstallable(manifest);
299 installable_manager_->SetBadgeIcon(
300 GURL(kDefaultIconUrl),
301 gfx::test::CreateBitmap(kIconSizePx, kIconSizePx));
253 } 302 }
254 303
255 void SetShouldManifestTimeOut(bool should_time_out) { 304 void SetShouldManifestTimeOut(bool should_time_out) {
256 MockWebContents* mock_web_contents = 305 installable_manager_->SetShouldManifestTimeOut(should_time_out);
257 static_cast<MockWebContents*>(web_contents());
258 mock_web_contents->SetShouldManifestTimeOut(should_time_out);
259 } 306 }
260 307
261 // Registers service worker at |url|. Blocks till the service worker is 308 void SetShouldInstallableTimeOut(bool should_time_out) {
262 // registered. 309 installable_manager_->SetShouldInstallableTimeOut(should_time_out);
263 void RegisterServiceWorker(const GURL& url) {
264 base::RunLoop run_loop;
265 embedded_worker_test_helper_->context()->RegisterServiceWorker(
266 url, GURL(url.spec() + "/service_worker.js"), nullptr,
267 base::Bind(&AddToHomescreenDataFetcherTest::OnServiceWorkerRegistered,
268 base::Unretained(this), run_loop.QuitClosure()));
269 } 310 }
270 311
271 private: 312 void RunDeferredCallback() { installable_manager_->RunCallback(); }
pkotwicz 2017/06/29 19:22:06 We should call base::RunLoop().RunUntilIdle() afte
dominickn 2017/06/30 02:42:31 Done.
272 // Callback for RegisterServiceWorker() for when service worker registration 313
273 // has completed. 314 bool IsDeferredCallbackNull() {
274 void OnServiceWorkerRegistered(const base::Closure& callback, 315 return installable_manager_->IsDeferredCallbackNull();
275 content::ServiceWorkerStatusCode status,
276 const std::string& status_message,
277 int64_t registration_id) {
278 ASSERT_EQ(content::SERVICE_WORKER_OK, status)
279 << content::ServiceWorkerStatusToString(status);
280 callback.Run();
281 } 316 }
282 317
283 std::unique_ptr<content::EmbeddedWorkerTestHelper> 318 virtual bool check_webapk_compatibility() { return true; }
284 embedded_worker_test_helper_; 319
320 private:
321 TestInstallableManager* installable_manager_;
285 322
286 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcherTest); 323 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcherTest);
287 }; 324 };
288 325
289 // Class for tests which should be run with AddToHomescreenDataFetcher built 326 // Class for tests which should be run with AddToHomescreenDataFetcher built
290 // with both true and false values of |check_webapk_compatible|. 327 // with both true and false values of |check_webapk_compatible|.
291 class AddToHomescreenDataFetcherTestCommon 328 class AddToHomescreenDataFetcherTestCommon
292 : public AddToHomescreenDataFetcherTest, 329 : public AddToHomescreenDataFetcherTest,
293 public testing::WithParamInterface<bool> { 330 public testing::WithParamInterface<bool> {
294 public: 331 public:
295 AddToHomescreenDataFetcherTestCommon() {} 332 AddToHomescreenDataFetcherTestCommon() {}
296 ~AddToHomescreenDataFetcherTestCommon() override {} 333 ~AddToHomescreenDataFetcherTestCommon() override {}
297 334
298 scoped_refptr<AddToHomescreenDataFetcher> BuildFetcher( 335 scoped_refptr<AddToHomescreenDataFetcher> BuildFetcher(
299 AddToHomescreenDataFetcher::Observer* observer) { 336 AddToHomescreenDataFetcher::Observer* observer) {
300 return AddToHomescreenDataFetcherTest::BuildFetcher( 337 return AddToHomescreenDataFetcherTest::BuildFetcher(
301 check_webapk_compatibility(), observer); 338 check_webapk_compatibility(), observer);
302 } 339 }
303 340
304 // The value of |check_webapk_compatible| used when building the 341 // The value of |check_webapk_compatible| used when building the
305 // AddToHomescreenDataFetcher. 342 // AddToHomescreenDataFetcher.
306 bool check_webapk_compatibility() { return GetParam(); } 343 bool check_webapk_compatibility() override { return GetParam(); }
307 344
308 private: 345 private:
309 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcherTestCommon); 346 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcherTestCommon);
310 }; 347 };
311 348
312 // Checks that AddToHomescreenDataFetcher::Observer::OnUserTitleAvailable() is
313 // called when the web manifest returned is empty. The add-to-homescreen dialog
314 // makes the dialog's text field editable once OnUserTitleAvailable() is called.
315 TEST_P(AddToHomescreenDataFetcherTestCommon, EmptyManifest) { 349 TEST_P(AddToHomescreenDataFetcherTestCommon, EmptyManifest) {
316 WebApplicationInfo web_application_info; 350 // Check that an empty manifest has the appropriate methods run.
317 web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
318
319 SetManifest(GURL(kDefaultManifestUrl), BuildEmptyManifest());
320
321 ObserverWaiter waiter; 351 ObserverWaiter waiter;
322 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); 352 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
323 fetcher->OnDidGetWebApplicationInfo(web_application_info); 353 RunFetcher(fetcher, waiter, kWebApplicationInfoTitle,
324 waiter.WaitForDataAvailable(); 354 blink::kWebDisplayModeBrowser, false);
325 355 EXPECT_TRUE(IsDeferredCallbackNull());
326 EXPECT_EQ(check_webapk_compatibility(),
327 waiter.determined_webapk_compatibility());
328 EXPECT_FALSE(waiter.is_webapk_compatible());
329 EXPECT_TRUE(waiter.title_available());
330 EXPECT_TRUE(base::EqualsASCII(waiter.title(), kWebApplicationInfoTitle));
331
332 fetcher->set_weak_observer(nullptr); 356 fetcher->set_weak_observer(nullptr);
333 } 357 }
334 358
335 // Test that when the manifest provides Manifest::short_name but not 359 TEST_P(AddToHomescreenDataFetcherTestCommon, NoIconManifest) {
336 // Manifest::name that Manifest::short_name is used as the name instead of 360 // Test a manifest with no icons. This should only use the metadata title and
pkotwicz 2017/06/29 19:22:06 Nit: "only use" -> "use"
dominickn 2017/06/30 02:42:31 Done.
337 // WebApplicationInfo::title. 361 // have an empty icon in this test runner (in production the empty icon would
362 // be replaced by a favicon or a generated icon).
pkotwicz 2017/06/29 19:22:06 Thank you for the awesome explanatory comment! Thi
dominickn 2017/06/30 02:42:31 :)
363 SetManifest(BuildNoIconManifest());
364 ObserverWaiter waiter;
365 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
366 RunFetcher(fetcher, waiter, kDefaultManifestShortName,
367 blink::kWebDisplayModeStandalone, false);
368 EXPECT_TRUE(IsDeferredCallbackNull());
369
370 EXPECT_TRUE(fetcher->primary_icon().drawsNothing());
371 EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty());
372 EXPECT_TRUE(fetcher->badge_icon().drawsNothing());
373 EXPECT_TRUE(fetcher->shortcut_info().best_badge_icon_url.is_empty());
374
375 fetcher->set_weak_observer(nullptr);
376 }
377
378 TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestFetchTimesOut) {
379 // Check that the AddToHomescreenDataFetcher::Observer methods are called
380 // if the first call to InstallableManager::GetData times out. This should
381 // fall back to the metadata title and have an empty icon.
382 SetShouldManifestTimeOut(true);
383
384 {
385 // Check with a site that has a manifest and icons, but no service worker.
pkotwicz 2017/06/29 19:22:05 If the manifest-fetch times out, I don't think tha
dominickn 2017/06/30 02:42:32 Done.
386 SetManifestAndIcons(BuildDefaultManifest());
387 ObserverWaiter waiter;
388 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
389 RunFetcher(fetcher, waiter, kWebApplicationInfoTitle,
390 blink::kWebDisplayModeBrowser, false);
391
392 EXPECT_TRUE(fetcher->primary_icon().drawsNothing());
393 EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty());
394
395 // Ensure GetData can call the data fetcher callback after the time out.
pkotwicz 2017/06/29 19:22:06 Nit: "GetData" -> "GetData()" Maybe add: "Test th
dominickn 2017/06/30 02:42:31 Done.
396 RunDeferredCallback();
397 fetcher->set_weak_observer(nullptr);
398 }
399
400 {
401 // Check with a service worker present.
402 SetInstallable(BuildDefaultManifest());
403 ObserverWaiter waiter;
404 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
405 RunFetcher(fetcher, waiter, kWebApplicationInfoTitle,
406 blink::kWebDisplayModeBrowser, false);
407
408 EXPECT_TRUE(fetcher->primary_icon().drawsNothing());
409 EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty());
410
411 // Ensure GetData can call the data fetcher callback after the time out.
412 RunDeferredCallback();
413 fetcher->set_weak_observer(nullptr);
414 }
415 }
416
417 TEST_F(AddToHomescreenDataFetcherTest, ServiceWorkerCheckTimesOut) {
pkotwicz 2017/06/29 19:22:05 Because this is the only TEST_F() test, you can pr
dominickn 2017/06/30 02:42:31 That leaves a do-nothing test, which is a bit misl
pkotwicz 2017/06/30 23:54:52 Fair enough
418 // Check that the AddToHomescreenDataFetcher::Observer methods are called
419 // if the service worker check times out (e.g. because we are waiting
420 // to detect a worker). This should use the short_name and icon from the
421 // manifest, but not be WebAPK-compatible. Only relevant when checking WebAPK
422 // compatibility.
pkotwicz 2017/06/29 19:22:06 Can you make it clear that this test tests the cas
dominickn 2017/06/30 02:42:31 Very subtle difference. Added a new test for it.
423 SetInstallable(BuildDefaultManifest());
424 SetShouldInstallableTimeOut(true);
425
426 ObserverWaiter waiter;
427 scoped_refptr<AddToHomescreenDataFetcher> fetcher(
428 BuildFetcher(true, &waiter));
429 RunFetcher(fetcher, waiter, kDefaultManifestShortName,
430 blink::kWebDisplayModeStandalone, false);
431
432 EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
433 EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
434 GURL(kDefaultIconUrl));
435
436 // Ensure GetData can call the data fetcher callback after the time out.
437 RunDeferredCallback();
438 fetcher->set_weak_observer(nullptr);
439 }
440
441 TEST_P(AddToHomescreenDataFetcherTestCommon, InstallableManifest) {
442 content::Manifest manifest(BuildDefaultManifest());
443
444 {
445 // Test an installable manifest for a site that has a service worker.
446 SetInstallable(manifest);
447 ObserverWaiter waiter;
448 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
449 RunFetcher(fetcher, waiter, kDefaultManifestShortName,
450 blink::kWebDisplayModeStandalone, check_webapk_compatibility());
451 EXPECT_TRUE(IsDeferredCallbackNull());
452
453 EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
454 EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
455 GURL(kDefaultIconUrl));
456 EXPECT_TRUE(fetcher->badge_icon().drawsNothing());
457 EXPECT_TRUE(fetcher->shortcut_info().best_badge_icon_url.is_empty());
458 fetcher->set_weak_observer(nullptr);
459 }
460
461 {
462 // Test that the provided badge icon is used when checking for WebAPK
463 // compatibility.
pkotwicz 2017/06/29 19:22:06 Maybe change the comment to: "Check that the badge
dominickn 2017/06/30 02:42:31 Done.
464 SetInstallableAndBadgeIcon(BuildDefaultManifest());
465 ObserverWaiter waiter;
466 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
467 RunFetcher(fetcher, waiter, kDefaultManifestShortName,
468 blink::kWebDisplayModeStandalone, check_webapk_compatibility());
469 EXPECT_TRUE(IsDeferredCallbackNull());
470
471 EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
472 EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
473 GURL(kDefaultIconUrl));
474 if (check_webapk_compatibility()) {
475 EXPECT_FALSE(fetcher->badge_icon().drawsNothing());
476 EXPECT_EQ(fetcher->shortcut_info().best_badge_icon_url,
477 GURL(kDefaultIconUrl));
478 }
479 fetcher->set_weak_observer(nullptr);
480 }
481 }
482
338 TEST_P(AddToHomescreenDataFetcherTestCommon, 483 TEST_P(AddToHomescreenDataFetcherTestCommon,
339 ManifestShortNameClobbersWebApplicationName) { 484 ManifestShortNameClobbersWebApplicationName) {
340 WebApplicationInfo web_application_info; 485 // Test that when the manifest provides Manifest::short_name but not
341 web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); 486 // Manifest::name that Manifest::short_name is used as the name.
342 487 {
343 content::Manifest manifest(BuildDefaultManifest()); 488 // Check the case where we have no icons.
344 manifest.name = base::NullableString16(); 489 content::Manifest manifest(BuildNoIconManifest());
345 490 manifest.name = base::NullableString16();
346 RegisterServiceWorker(GURL(kDefaultStartUrl)); 491 SetManifest(manifest);
347 SetManifest(GURL(kDefaultManifestUrl), manifest); 492
348 493 ObserverWaiter waiter;
349 ObserverWaiter waiter; 494 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
350 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); 495 RunFetcher(fetcher, waiter, kDefaultManifestShortName,
351 fetcher->OnDidGetWebApplicationInfo(web_application_info); 496 blink::kWebDisplayModeStandalone, false);
352 waiter.WaitForDataAvailable(); 497 EXPECT_TRUE(IsDeferredCallbackNull());
353 498
354 EXPECT_TRUE(base::EqualsASCII(waiter.title(), kDefaultManifestShortName)); 499 EXPECT_TRUE(fetcher->primary_icon().drawsNothing());
355 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name, 500 EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty());
356 kDefaultManifestShortName)); 501 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name,
357 502 kDefaultManifestShortName));
358 fetcher->set_weak_observer(nullptr); 503
359 } 504 fetcher->set_weak_observer(nullptr);
360 505 }
361 // Test that when the manifest does not provide either Manifest::short_name nor 506
362 // Manifest::name that: 507 {
363 // - The page is not WebAPK compatible. 508 // Check the case where the service worker check times out if we are
364 // - WebApplicationInfo::title is used as the "name". 509 // checking WebAPK compatibility.
pkotwicz 2017/06/29 19:22:05 Maybe change the comment to: "Check page with no s
dominickn 2017/06/30 02:42:30 Done.
510 content::Manifest manifest(BuildDefaultManifest());
511 manifest.name = base::NullableString16();
512 SetInstallable(manifest);
513 SetShouldInstallableTimeOut(true);
514
515 ObserverWaiter waiter;
516 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
517 RunFetcher(fetcher, waiter, kDefaultManifestShortName,
518 blink::kWebDisplayModeStandalone, false);
519
520 EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
521 EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
522 GURL(kDefaultIconUrl));
523 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name,
524 kDefaultManifestShortName));
525
526 // Ensure GetData can call the data fetcher callback after the time out.
527 if (check_webapk_compatibility())
528 RunDeferredCallback();
pkotwicz 2017/06/29 19:22:06 Maybe change the comment to: if (check_webapk_comp
dominickn 2017/06/30 02:42:31 Done.
529
530 EXPECT_TRUE(IsDeferredCallbackNull());
531 fetcher->set_weak_observer(nullptr);
532 }
533
534 {
535 // Check the case where the service worker check doesn't time out.
pkotwicz 2017/06/29 19:22:06 Maybe change the comment to: "Check page with serv
dominickn 2017/06/30 02:42:31 Done.
536 SetShouldInstallableTimeOut(false);
537 ObserverWaiter waiter;
538 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
539 RunFetcher(fetcher, waiter, kDefaultManifestShortName,
540 blink::kWebDisplayModeStandalone, check_webapk_compatibility());
541 EXPECT_TRUE(IsDeferredCallbackNull());
542
543 EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
544 EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
545 GURL(kDefaultIconUrl));
546 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name,
547 kDefaultManifestShortName));
548
549 fetcher->set_weak_observer(nullptr);
550 }
551 }
552
365 TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestNoNameNoShortName) { 553 TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestNoNameNoShortName) {
366 WebApplicationInfo web_application_info; 554 // Test that when the manifest does not provide either Manifest::short_name
367 web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); 555 // nor Manifest::name that: - The page is not WebAPK compatible. -
368 556 // WebApplicationInfo::title is used as the "name". - We still use the icons
557 // from the manifest.
pkotwicz 2017/06/29 19:22:05 Nit: Please put each '-' on a separate line
dominickn 2017/06/30 02:42:31 Ugh that was a clang-format fail.
369 content::Manifest manifest(BuildDefaultManifest()); 558 content::Manifest manifest(BuildDefaultManifest());
370 manifest.name = base::NullableString16(); 559 manifest.name = base::NullableString16();
371 manifest.short_name = base::NullableString16(); 560 manifest.short_name = base::NullableString16();
372 561
373 RegisterServiceWorker(GURL(kDefaultStartUrl)); 562 {
374 SetManifest(GURL(kDefaultManifestUrl), manifest); 563 // Check the case where waiting for the service worker times out if we check
375 564 // WebAPK compatibility.
376 ObserverWaiter waiter; 565 SetManifestAndIcons(manifest);
377 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); 566 SetShouldInstallableTimeOut(true);
pkotwicz 2017/06/29 19:22:06 This case cannot occur in practice because IsManif
dominickn 2017/06/30 02:42:30 Done.
378 fetcher->OnDidGetWebApplicationInfo(web_application_info); 567 ObserverWaiter waiter;
379 waiter.WaitForDataAvailable(); 568 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
380 569 RunFetcher(fetcher, waiter, kWebApplicationInfoTitle,
381 EXPECT_EQ(check_webapk_compatibility(), 570 blink::kWebDisplayModeStandalone, false);
382 waiter.determined_webapk_compatibility()); 571
383 EXPECT_FALSE(waiter.is_webapk_compatible()); 572 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name,
384 EXPECT_TRUE(base::EqualsASCII(waiter.title(), kWebApplicationInfoTitle)); 573 kWebApplicationInfoTitle));
385 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name, 574 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().short_name,
386 kWebApplicationInfoTitle)); 575 kWebApplicationInfoTitle));
387 576 EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
388 fetcher->set_weak_observer(nullptr); 577 EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
389 } 578 GURL(kDefaultIconUrl));
390 579
391 // Checks that the AddToHomescreenDataFetcher::Observer callbacks are called 580 // Ensure GetData can call the data fetcher callback after the time out.
392 // when the manifest fetch times out. 581 if (check_webapk_compatibility())
393 TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestFetchTimesOut) { 582 RunDeferredCallback();
394 WebApplicationInfo web_application_info; 583
395 web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); 584 EXPECT_TRUE(IsDeferredCallbackNull());
396 585 fetcher->set_weak_observer(nullptr);
397 RegisterServiceWorker(GURL(kDefaultStartUrl)); 586 }
398 SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest()); 587
399 SetShouldManifestTimeOut(true); 588 {
400 SetShouldImageTimeOut(false); 589 // Check the case where we don't time out waiting for the service worker.
401 590 SetInstallable(manifest);
402 ObserverWaiter waiter; 591 SetShouldInstallableTimeOut(false);
403 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); 592 ObserverWaiter waiter;
404 fetcher->OnDidGetWebApplicationInfo(web_application_info); 593 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
405 waiter.WaitForDataAvailable(); 594 RunFetcher(fetcher, waiter, kWebApplicationInfoTitle,
406 595 blink::kWebDisplayModeStandalone, false);
407 EXPECT_EQ(check_webapk_compatibility(), 596 EXPECT_TRUE(IsDeferredCallbackNull());
408 waiter.determined_webapk_compatibility()); 597
409 EXPECT_FALSE(waiter.is_webapk_compatible()); 598 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name,
410 EXPECT_TRUE(base::EqualsASCII(waiter.title(), kWebApplicationInfoTitle)); 599 kWebApplicationInfoTitle));
411 EXPECT_TRUE(waiter.title_available()); 600 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().short_name,
412 601 kWebApplicationInfoTitle));
413 fetcher->set_weak_observer(nullptr); 602 EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
414 } 603 EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
415 604 GURL(kDefaultIconUrl));
416 // Checks that the AddToHomescreenDataFetcher::Observer callbacks are called 605
417 // when the image fetch times out. 606 fetcher->set_weak_observer(nullptr);
418 TEST_P(AddToHomescreenDataFetcherTestCommon, ImageFetchTimesOut) { 607 }
419 WebApplicationInfo web_application_info;
420 web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
421
422 RegisterServiceWorker(GURL(kDefaultStartUrl));
423 SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest());
424 SetShouldManifestTimeOut(false);
425 SetShouldImageTimeOut(true);
426
427 ObserverWaiter waiter;
428 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
429 fetcher->OnDidGetWebApplicationInfo(web_application_info);
430 waiter.WaitForDataAvailable();
431
432 EXPECT_EQ(check_webapk_compatibility(),
433 waiter.determined_webapk_compatibility());
434 EXPECT_FALSE(waiter.is_webapk_compatible());
435 EXPECT_TRUE(waiter.title_available());
436 EXPECT_TRUE(base::EqualsASCII(waiter.title(), kWebApplicationInfoTitle));
437
438 fetcher->set_weak_observer(nullptr);
439 }
440
441 // Checks that the AddToHomescreenDataFetcher::Observer callbacks are called
442 // when the service worker check times out.
443 TEST_P(AddToHomescreenDataFetcherTestCommon, ServiceWorkerCheckTimesOut) {
444 WebApplicationInfo web_application_info;
445 web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
446
447 // Not registering a service worker means we'll wait and time out for the
448 // worker.
449 SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest());
450 SetShouldManifestTimeOut(false);
451 SetShouldImageTimeOut(false);
452
453 ObserverWaiter waiter;
454 scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
455 fetcher->OnDidGetWebApplicationInfo(web_application_info);
456 waiter.WaitForDataAvailable();
457
458 EXPECT_EQ(check_webapk_compatibility(),
459 waiter.determined_webapk_compatibility());
460 EXPECT_FALSE(waiter.is_webapk_compatible());
461 EXPECT_TRUE(waiter.title_available());
462 EXPECT_TRUE(base::EqualsASCII(waiter.title(), kDefaultManifestShortName));
463 EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().user_title,
464 kDefaultManifestShortName));
465
466 fetcher->set_weak_observer(nullptr);
467 } 608 }
468 609
469 INSTANTIATE_TEST_CASE_P(CheckWebApkCompatibility, 610 INSTANTIATE_TEST_CASE_P(CheckWebApkCompatibility,
470 AddToHomescreenDataFetcherTestCommon, 611 AddToHomescreenDataFetcherTestCommon,
471 ::testing::Values(false, true)); 612 ::testing::Values(false, true));
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/installable/installable_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698