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

Side by Side Diff: chrome/browser/installable/installable_manager_browsertest.cc

Issue 2778983005: Allow the app banner installability check to run on page load. (Closed)
Patch Set: Fix enum in test + minor improvements Created 3 years, 8 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/installable/installable_manager.h" 5 #include "chrome/browser/installable/installable_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 content::WebContents* web_contents = 193 content::WebContents* web_contents =
194 browser()->tab_strip_model()->GetActiveWebContents(); 194 browser()->tab_strip_model()->GetActiveWebContents();
195 InstallableManager::CreateForWebContents(web_contents); 195 InstallableManager::CreateForWebContents(web_contents);
196 InstallableManager* manager = 196 InstallableManager* manager =
197 InstallableManager::FromWebContents(web_contents); 197 InstallableManager::FromWebContents(web_contents);
198 CHECK(manager); 198 CHECK(manager);
199 199
200 return manager; 200 return manager;
201 } 201 }
202 202
203 InstallableMetrics::InstallabilityCheckStatus GetStatus() {
204 return GetManager()->page_status_;
205 }
203 }; 206 };
204 207
205 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, 208 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest,
206 ManagerBeginsInEmptyState) { 209 ManagerBeginsInEmptyState) {
207 // Ensure that the InstallableManager starts off with everything null. 210 // Ensure that the InstallableManager starts off with everything null.
208 InstallableManager* manager = GetManager(); 211 InstallableManager* manager = GetManager();
209 212
210 EXPECT_TRUE(manager->manifest().IsEmpty()); 213 EXPECT_TRUE(manager->manifest().IsEmpty());
211 EXPECT_TRUE(manager->manifest_url().is_empty()); 214 EXPECT_TRUE(manager->manifest_url().is_empty());
212 EXPECT_TRUE(manager->icons_.empty()); 215 EXPECT_TRUE(manager->icons_.empty());
(...skipping 17 matching lines...) Expand all
230 233
231 // If there is no manifest, everything should be empty. 234 // If there is no manifest, everything should be empty.
232 EXPECT_TRUE(tester->manifest().IsEmpty()); 235 EXPECT_TRUE(tester->manifest().IsEmpty());
233 EXPECT_TRUE(tester->manifest_url().is_empty()); 236 EXPECT_TRUE(tester->manifest_url().is_empty());
234 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 237 EXPECT_TRUE(tester->primary_icon_url().is_empty());
235 EXPECT_EQ(nullptr, tester->primary_icon()); 238 EXPECT_EQ(nullptr, tester->primary_icon());
236 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 239 EXPECT_TRUE(tester->badge_icon_url().is_empty());
237 EXPECT_EQ(nullptr, tester->badge_icon()); 240 EXPECT_EQ(nullptr, tester->badge_icon());
238 EXPECT_FALSE(tester->is_installable()); 241 EXPECT_FALSE(tester->is_installable());
239 EXPECT_EQ(NO_MANIFEST, tester->error_code()); 242 EXPECT_EQ(NO_MANIFEST, tester->error_code());
243 EXPECT_EQ(GetStatus(), InstallableMetrics::NOT_STARTED);
240 } 244 }
241 245
242 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, CheckManifest404) { 246 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, CheckManifest404) {
243 base::RunLoop run_loop; 247 base::RunLoop run_loop;
244 std::unique_ptr<CallbackTester> tester( 248 std::unique_ptr<CallbackTester> tester(
245 new CallbackTester(run_loop.QuitClosure())); 249 new CallbackTester(run_loop.QuitClosure()));
246 250
247 NavigateAndRunInstallableManager(tester.get(), GetManifestParams(), 251 NavigateAndRunInstallableManager(tester.get(), GetManifestParams(),
248 GetURLOfPageWithServiceWorkerAndManifest( 252 GetURLOfPageWithServiceWorkerAndManifest(
249 "/banners/manifest_missing.json")); 253 "/banners/manifest_missing.json"));
250 run_loop.Run(); 254 run_loop.Run();
251 255
252 // The installable manager should return a manifest URL even if it 404s. 256 // The installable manager should return a manifest URL even if it 404s.
253 // However, the check should fail with a ManifestEmpty error. 257 // However, the check should fail with a ManifestEmpty error.
254 EXPECT_TRUE(tester->manifest().IsEmpty()); 258 EXPECT_TRUE(tester->manifest().IsEmpty());
255 259
256 EXPECT_FALSE(tester->manifest_url().is_empty()); 260 EXPECT_FALSE(tester->manifest_url().is_empty());
257 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 261 EXPECT_TRUE(tester->primary_icon_url().is_empty());
258 EXPECT_EQ(nullptr, tester->primary_icon()); 262 EXPECT_EQ(nullptr, tester->primary_icon());
259 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 263 EXPECT_TRUE(tester->badge_icon_url().is_empty());
260 EXPECT_EQ(nullptr, tester->badge_icon()); 264 EXPECT_EQ(nullptr, tester->badge_icon());
261 EXPECT_FALSE(tester->is_installable()); 265 EXPECT_FALSE(tester->is_installable());
262 EXPECT_EQ(MANIFEST_EMPTY, tester->error_code()); 266 EXPECT_EQ(MANIFEST_EMPTY, tester->error_code());
267 EXPECT_EQ(GetStatus(), InstallableMetrics::NOT_STARTED);
263 } 268 }
264 269
265 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, CheckManifestOnly) { 270 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, CheckManifestOnly) {
266 // Verify that asking for just the manifest works as expected. 271 // Verify that asking for just the manifest works as expected.
267 base::RunLoop run_loop; 272 base::RunLoop run_loop;
268 std::unique_ptr<CallbackTester> tester( 273 std::unique_ptr<CallbackTester> tester(
269 new CallbackTester(run_loop.QuitClosure())); 274 new CallbackTester(run_loop.QuitClosure()));
270 275
271 NavigateAndRunInstallableManager(tester.get(), GetManifestParams(), 276 NavigateAndRunInstallableManager(tester.get(), GetManifestParams(),
272 "/banners/manifest_test_page.html"); 277 "/banners/manifest_test_page.html");
273 run_loop.Run(); 278 run_loop.Run();
274 279
275 EXPECT_FALSE(tester->manifest().IsEmpty()); 280 EXPECT_FALSE(tester->manifest().IsEmpty());
276 EXPECT_FALSE(tester->manifest_url().is_empty()); 281 EXPECT_FALSE(tester->manifest_url().is_empty());
277 282
278 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 283 EXPECT_TRUE(tester->primary_icon_url().is_empty());
279 EXPECT_EQ(nullptr, tester->primary_icon()); 284 EXPECT_EQ(nullptr, tester->primary_icon());
280 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 285 EXPECT_TRUE(tester->badge_icon_url().is_empty());
281 EXPECT_EQ(nullptr, tester->badge_icon()); 286 EXPECT_EQ(nullptr, tester->badge_icon());
282 EXPECT_FALSE(tester->is_installable()); 287 EXPECT_FALSE(tester->is_installable());
283 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code()); 288 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code());
289 EXPECT_EQ(GetStatus(), InstallableMetrics::NOT_STARTED);
284 } 290 }
285 291
286 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, 292 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest,
287 CheckInstallableParamsDefaultConstructor) { 293 CheckInstallableParamsDefaultConstructor) {
288 // Verify that using InstallableParams' default constructor is equivalent to 294 // Verify that using InstallableParams' default constructor is equivalent to
289 // just asking for the manifest alone. 295 // just asking for the manifest alone.
290 base::RunLoop run_loop; 296 base::RunLoop run_loop;
291 std::unique_ptr<CallbackTester> tester( 297 std::unique_ptr<CallbackTester> tester(
292 new CallbackTester(run_loop.QuitClosure())); 298 new CallbackTester(run_loop.QuitClosure()));
293 299
294 InstallableParams params; 300 InstallableParams params;
295 NavigateAndRunInstallableManager(tester.get(), params, 301 NavigateAndRunInstallableManager(tester.get(), params,
296 "/banners/manifest_test_page.html"); 302 "/banners/manifest_test_page.html");
297 run_loop.Run(); 303 run_loop.Run();
298 304
299 EXPECT_FALSE(tester->manifest().IsEmpty()); 305 EXPECT_FALSE(tester->manifest().IsEmpty());
300 EXPECT_FALSE(tester->manifest_url().is_empty()); 306 EXPECT_FALSE(tester->manifest_url().is_empty());
301 307
302 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 308 EXPECT_TRUE(tester->primary_icon_url().is_empty());
303 EXPECT_EQ(nullptr, tester->primary_icon()); 309 EXPECT_EQ(nullptr, tester->primary_icon());
304 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 310 EXPECT_TRUE(tester->badge_icon_url().is_empty());
305 EXPECT_EQ(nullptr, tester->badge_icon()); 311 EXPECT_EQ(nullptr, tester->badge_icon());
306 EXPECT_FALSE(tester->is_installable()); 312 EXPECT_FALSE(tester->is_installable());
307 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code()); 313 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code());
314 EXPECT_EQ(GetStatus(), InstallableMetrics::NOT_STARTED);
308 } 315 }
309 316
310 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, 317 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest,
311 CheckManifestWithOnlyRelatedApplications) { 318 CheckManifestWithOnlyRelatedApplications) {
312 // This page has a manifest with only related applications specified. Asking 319 // This page has a manifest with only related applications specified. Asking
313 // for just the manifest should succeed. 320 // for just the manifest should succeed.
314 { 321 {
315 base::RunLoop run_loop; 322 base::RunLoop run_loop;
316 std::unique_ptr<CallbackTester> tester( 323 std::unique_ptr<CallbackTester> tester(
317 new CallbackTester(run_loop.QuitClosure())); 324 new CallbackTester(run_loop.QuitClosure()));
318 325
319 NavigateAndRunInstallableManager(tester.get(), GetManifestParams(), 326 NavigateAndRunInstallableManager(tester.get(), GetManifestParams(),
320 "/banners/play_app_test_page.html"); 327 "/banners/play_app_test_page.html");
321 run_loop.Run(); 328 run_loop.Run();
322 329
323 EXPECT_FALSE(tester->manifest().IsEmpty()); 330 EXPECT_FALSE(tester->manifest().IsEmpty());
324 EXPECT_FALSE(tester->manifest_url().is_empty()); 331 EXPECT_FALSE(tester->manifest_url().is_empty());
325 EXPECT_TRUE(tester->manifest().prefer_related_applications); 332 EXPECT_TRUE(tester->manifest().prefer_related_applications);
326 333
327 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 334 EXPECT_TRUE(tester->primary_icon_url().is_empty());
328 EXPECT_EQ(nullptr, tester->primary_icon()); 335 EXPECT_EQ(nullptr, tester->primary_icon());
329 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 336 EXPECT_TRUE(tester->badge_icon_url().is_empty());
330 EXPECT_EQ(nullptr, tester->badge_icon()); 337 EXPECT_EQ(nullptr, tester->badge_icon());
331 EXPECT_FALSE(tester->is_installable()); 338 EXPECT_FALSE(tester->is_installable());
332 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code()); 339 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code());
340 EXPECT_EQ(GetStatus(), InstallableMetrics::NOT_STARTED);
333 } 341 }
334 342
335 // Ask for a primary icon (but don't navigate). This should fail with 343 // Ask for a primary icon (but don't navigate). This should fail with
336 // NO_ACCEPTABLE_ICON. 344 // NO_ACCEPTABLE_ICON.
337 { 345 {
338 base::RunLoop run_loop; 346 base::RunLoop run_loop;
339 std::unique_ptr<CallbackTester> tester( 347 std::unique_ptr<CallbackTester> tester(
340 new CallbackTester(run_loop.QuitClosure())); 348 new CallbackTester(run_loop.QuitClosure()));
341 349
342 RunInstallableManager(tester.get(), GetPrimaryIconParams()); 350 RunInstallableManager(tester.get(), GetPrimaryIconParams());
343 run_loop.Run(); 351 run_loop.Run();
344 352
345 EXPECT_FALSE(tester->manifest().IsEmpty()); 353 EXPECT_FALSE(tester->manifest().IsEmpty());
346 EXPECT_FALSE(tester->manifest_url().is_empty()); 354 EXPECT_FALSE(tester->manifest_url().is_empty());
347 EXPECT_TRUE(tester->manifest().prefer_related_applications); 355 EXPECT_TRUE(tester->manifest().prefer_related_applications);
348 356
349 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 357 EXPECT_TRUE(tester->primary_icon_url().is_empty());
350 EXPECT_EQ(nullptr, tester->primary_icon()); 358 EXPECT_EQ(nullptr, tester->primary_icon());
351 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 359 EXPECT_TRUE(tester->badge_icon_url().is_empty());
352 EXPECT_EQ(nullptr, tester->badge_icon()); 360 EXPECT_EQ(nullptr, tester->badge_icon());
353 EXPECT_FALSE(tester->is_installable()); 361 EXPECT_FALSE(tester->is_installable());
354 EXPECT_EQ(NO_ACCEPTABLE_ICON, tester->error_code()); 362 EXPECT_EQ(NO_ACCEPTABLE_ICON, tester->error_code());
363 EXPECT_EQ(GetStatus(), InstallableMetrics::NOT_STARTED);
355 } 364 }
356 365
357 // Ask for everything except badge icon. This should fail with 366 // Ask for everything except badge icon. This should fail with
358 // NO_ACCEPTABLE_ICON - the primary icon fetch has already failed, so that 367 // NO_ACCEPTABLE_ICON - the primary icon fetch has already failed, so that
359 // cached error stops the installable check from being performed. 368 // cached error stops the installable check from being performed.
360 { 369 {
361 base::RunLoop run_loop; 370 base::RunLoop run_loop;
362 std::unique_ptr<CallbackTester> tester( 371 std::unique_ptr<CallbackTester> tester(
363 new CallbackTester(run_loop.QuitClosure())); 372 new CallbackTester(run_loop.QuitClosure()));
364 373
365 RunInstallableManager(tester.get(), GetWebAppParams()); 374 RunInstallableManager(tester.get(), GetWebAppParams());
366 run_loop.Run(); 375 run_loop.Run();
367 376
368 EXPECT_FALSE(tester->manifest().IsEmpty()); 377 EXPECT_FALSE(tester->manifest().IsEmpty());
369 EXPECT_FALSE(tester->manifest_url().is_empty()); 378 EXPECT_FALSE(tester->manifest_url().is_empty());
370 EXPECT_TRUE(tester->manifest().prefer_related_applications); 379 EXPECT_TRUE(tester->manifest().prefer_related_applications);
371 380
372 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 381 EXPECT_TRUE(tester->primary_icon_url().is_empty());
373 EXPECT_EQ(nullptr, tester->primary_icon()); 382 EXPECT_EQ(nullptr, tester->primary_icon());
374 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 383 EXPECT_TRUE(tester->badge_icon_url().is_empty());
375 EXPECT_EQ(nullptr, tester->badge_icon()); 384 EXPECT_EQ(nullptr, tester->badge_icon());
376 EXPECT_FALSE(tester->is_installable()); 385 EXPECT_FALSE(tester->is_installable());
377 EXPECT_EQ(NO_ACCEPTABLE_ICON, tester->error_code()); 386 EXPECT_EQ(NO_ACCEPTABLE_ICON, tester->error_code());
387 EXPECT_EQ(GetStatus(), InstallableMetrics::COMPLETE_NON_PWA);
378 } 388 }
379 389
380 // Ask for a different size primary icon. This should fail with 390 // Ask for a different size primary icon. This should fail with
381 // START_URL_NOT_VALID since we won't have a cached icon error. 391 // START_URL_NOT_VALID since we won't have a cached icon error.
382 { 392 {
383 base::RunLoop run_loop; 393 base::RunLoop run_loop;
384 std::unique_ptr<CallbackTester> tester( 394 std::unique_ptr<CallbackTester> tester(
385 new CallbackTester(run_loop.QuitClosure())); 395 new CallbackTester(run_loop.QuitClosure()));
386 396
387 InstallableParams params = GetWebAppParams(); 397 InstallableParams params = GetWebAppParams();
388 params.ideal_primary_icon_size_in_px = 96; 398 params.ideal_primary_icon_size_in_px = 96;
389 params.minimum_primary_icon_size_in_px = 96; 399 params.minimum_primary_icon_size_in_px = 96;
390 RunInstallableManager(tester.get(), params); 400 RunInstallableManager(tester.get(), params);
391 run_loop.Run(); 401 run_loop.Run();
392 402
393 EXPECT_FALSE(tester->manifest().IsEmpty()); 403 EXPECT_FALSE(tester->manifest().IsEmpty());
394 EXPECT_FALSE(tester->manifest_url().is_empty()); 404 EXPECT_FALSE(tester->manifest_url().is_empty());
395 EXPECT_TRUE(tester->manifest().prefer_related_applications); 405 EXPECT_TRUE(tester->manifest().prefer_related_applications);
396 406
397 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 407 EXPECT_TRUE(tester->primary_icon_url().is_empty());
398 EXPECT_EQ(nullptr, tester->primary_icon()); 408 EXPECT_EQ(nullptr, tester->primary_icon());
399 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 409 EXPECT_TRUE(tester->badge_icon_url().is_empty());
400 EXPECT_EQ(nullptr, tester->badge_icon()); 410 EXPECT_EQ(nullptr, tester->badge_icon());
401 EXPECT_FALSE(tester->is_installable()); 411 EXPECT_FALSE(tester->is_installable());
402 EXPECT_EQ(START_URL_NOT_VALID, tester->error_code()); 412 EXPECT_EQ(START_URL_NOT_VALID, tester->error_code());
413 EXPECT_EQ(GetStatus(), InstallableMetrics::COMPLETE_NON_PWA);
403 } 414 }
404 } 415 }
405 416
406 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, CheckManifestAndIcon) { 417 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, CheckManifestAndIcon) {
407 // Add to homescreen checks for manifest + primary icon. 418 // Add to homescreen checks for manifest + primary icon.
408 { 419 {
409 base::RunLoop run_loop; 420 base::RunLoop run_loop;
410 std::unique_ptr<CallbackTester> tester( 421 std::unique_ptr<CallbackTester> tester(
411 new CallbackTester(run_loop.QuitClosure())); 422 new CallbackTester(run_loop.QuitClosure()));
412 423
413 NavigateAndRunInstallableManager(tester.get(), GetPrimaryIconParams(), 424 NavigateAndRunInstallableManager(tester.get(), GetPrimaryIconParams(),
414 "/banners/manifest_test_page.html"); 425 "/banners/manifest_test_page.html");
415 run_loop.Run(); 426 run_loop.Run();
416 427
417 EXPECT_FALSE(tester->manifest().IsEmpty()); 428 EXPECT_FALSE(tester->manifest().IsEmpty());
418 EXPECT_FALSE(tester->manifest_url().is_empty()); 429 EXPECT_FALSE(tester->manifest_url().is_empty());
419 430
420 EXPECT_FALSE(tester->primary_icon_url().is_empty()); 431 EXPECT_FALSE(tester->primary_icon_url().is_empty());
421 EXPECT_NE(nullptr, tester->primary_icon()); 432 EXPECT_NE(nullptr, tester->primary_icon());
422 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 433 EXPECT_TRUE(tester->badge_icon_url().is_empty());
423 EXPECT_EQ(nullptr, tester->badge_icon()); 434 EXPECT_EQ(nullptr, tester->badge_icon());
424 EXPECT_FALSE(tester->is_installable()); 435 EXPECT_FALSE(tester->is_installable());
425 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code()); 436 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code());
437 EXPECT_EQ(GetStatus(), InstallableMetrics::NOT_STARTED);
426 } 438 }
427 439
428 // Add to homescreen checks for manifest + primary icon + badge icon. 440 // Add to homescreen checks for manifest + primary icon + badge icon.
429 { 441 {
430 base::RunLoop run_loop; 442 base::RunLoop run_loop;
431 std::unique_ptr<CallbackTester> tester( 443 std::unique_ptr<CallbackTester> tester(
432 new CallbackTester(run_loop.QuitClosure())); 444 new CallbackTester(run_loop.QuitClosure()));
433 445
434 RunInstallableManager(tester.get(), GetPrimaryIconAndBadgeIconParams()); 446 RunInstallableManager(tester.get(), GetPrimaryIconAndBadgeIconParams());
435 run_loop.Run(); 447 run_loop.Run();
436 448
437 EXPECT_FALSE(tester->manifest().IsEmpty()); 449 EXPECT_FALSE(tester->manifest().IsEmpty());
438 EXPECT_FALSE(tester->manifest_url().is_empty()); 450 EXPECT_FALSE(tester->manifest_url().is_empty());
439 451
440 EXPECT_FALSE(tester->primary_icon_url().is_empty()); 452 EXPECT_FALSE(tester->primary_icon_url().is_empty());
441 EXPECT_NE(nullptr, tester->primary_icon()); 453 EXPECT_NE(nullptr, tester->primary_icon());
442 EXPECT_FALSE(tester->badge_icon_url().is_empty()); 454 EXPECT_FALSE(tester->badge_icon_url().is_empty());
443 EXPECT_NE(nullptr, tester->badge_icon()); 455 EXPECT_NE(nullptr, tester->badge_icon());
444 EXPECT_FALSE(tester->is_installable()); 456 EXPECT_FALSE(tester->is_installable());
445 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code()); 457 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code());
458 EXPECT_EQ(GetStatus(), InstallableMetrics::NOT_STARTED);
446 } 459 }
447 460
448 // Request an oversized badge icon. This should fetch only the manifest and 461 // Request an oversized badge icon. This should fetch only the manifest and
449 // the primary icon, and return no errors. 462 // the primary icon, and return no errors.
450 { 463 {
451 base::RunLoop run_loop; 464 base::RunLoop run_loop;
452 std::unique_ptr<CallbackTester> tester( 465 std::unique_ptr<CallbackTester> tester(
453 new CallbackTester(run_loop.QuitClosure())); 466 new CallbackTester(run_loop.QuitClosure()));
454 467
455 InstallableParams params = GetPrimaryIconAndBadgeIconParams(); 468 InstallableParams params = GetPrimaryIconAndBadgeIconParams();
456 params.ideal_badge_icon_size_in_px = 2000; 469 params.ideal_badge_icon_size_in_px = 2000;
457 params.minimum_badge_icon_size_in_px = 2000; 470 params.minimum_badge_icon_size_in_px = 2000;
458 RunInstallableManager(tester.get(), params); 471 RunInstallableManager(tester.get(), params);
459 run_loop.Run(); 472 run_loop.Run();
460 473
461 EXPECT_FALSE(tester->manifest().IsEmpty()); 474 EXPECT_FALSE(tester->manifest().IsEmpty());
462 EXPECT_FALSE(tester->manifest_url().is_empty()); 475 EXPECT_FALSE(tester->manifest_url().is_empty());
463 476
464 EXPECT_FALSE(tester->primary_icon_url().is_empty()); 477 EXPECT_FALSE(tester->primary_icon_url().is_empty());
465 EXPECT_NE(nullptr, tester->primary_icon()); 478 EXPECT_NE(nullptr, tester->primary_icon());
466 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 479 EXPECT_TRUE(tester->badge_icon_url().is_empty());
467 EXPECT_EQ(nullptr, tester->badge_icon()); 480 EXPECT_EQ(nullptr, tester->badge_icon());
468 EXPECT_FALSE(tester->is_installable()); 481 EXPECT_FALSE(tester->is_installable());
469 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code()); 482 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code());
483 EXPECT_EQ(GetStatus(), InstallableMetrics::NOT_STARTED);
470 } 484 }
471 } 485 }
472 486
473 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, CheckWebapp) { 487 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, CheckWebapp) {
474 // Request everything except badge icon. 488 // Request everything except badge icon.
475 { 489 {
476 base::RunLoop run_loop; 490 base::RunLoop run_loop;
477 std::unique_ptr<CallbackTester> tester( 491 std::unique_ptr<CallbackTester> tester(
478 new CallbackTester(run_loop.QuitClosure())); 492 new CallbackTester(run_loop.QuitClosure()));
479 493
480 NavigateAndRunInstallableManager(tester.get(), GetWebAppParams(), 494 NavigateAndRunInstallableManager(tester.get(), GetWebAppParams(),
481 "/banners/manifest_test_page.html"); 495 "/banners/manifest_test_page.html");
482 run_loop.Run(); 496 run_loop.Run();
483 497
484 EXPECT_FALSE(tester->manifest().IsEmpty()); 498 EXPECT_FALSE(tester->manifest().IsEmpty());
485 EXPECT_FALSE(tester->manifest_url().is_empty()); 499 EXPECT_FALSE(tester->manifest_url().is_empty());
486 EXPECT_TRUE(tester->is_installable()); 500 EXPECT_TRUE(tester->is_installable());
487 EXPECT_FALSE(tester->primary_icon_url().is_empty()); 501 EXPECT_FALSE(tester->primary_icon_url().is_empty());
488 EXPECT_NE(nullptr, tester->primary_icon()); 502 EXPECT_NE(nullptr, tester->primary_icon());
489 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 503 EXPECT_TRUE(tester->badge_icon_url().is_empty());
490 EXPECT_EQ(nullptr, tester->badge_icon()); 504 EXPECT_EQ(nullptr, tester->badge_icon());
491 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code()); 505 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code());
506 EXPECT_EQ(GetStatus(), InstallableMetrics::COMPLETE_PWA);
492 507
493 // Verify that the returned state matches manager internal state. 508 // Verify that the returned state matches manager internal state.
494 InstallableManager* manager = GetManager(); 509 InstallableManager* manager = GetManager();
495 510
496 EXPECT_FALSE(manager->manifest().IsEmpty()); 511 EXPECT_FALSE(manager->manifest().IsEmpty());
497 EXPECT_FALSE(manager->manifest_url().is_empty()); 512 EXPECT_FALSE(manager->manifest_url().is_empty());
498 EXPECT_TRUE(manager->is_installable()); 513 EXPECT_TRUE(manager->is_installable());
499 EXPECT_EQ(1u, manager->icons_.size()); 514 EXPECT_EQ(1u, manager->icons_.size());
500 EXPECT_FALSE((manager->icon_url(kPrimaryIconParams).is_empty())); 515 EXPECT_FALSE((manager->icon_url(kPrimaryIconParams).is_empty()));
501 EXPECT_NE(nullptr, (manager->icon(kPrimaryIconParams))); 516 EXPECT_NE(nullptr, (manager->icon(kPrimaryIconParams)));
(...skipping 14 matching lines...) Expand all
516 run_loop.Run(); 531 run_loop.Run();
517 532
518 EXPECT_FALSE(tester->manifest().IsEmpty()); 533 EXPECT_FALSE(tester->manifest().IsEmpty());
519 EXPECT_FALSE(tester->manifest_url().is_empty()); 534 EXPECT_FALSE(tester->manifest_url().is_empty());
520 EXPECT_TRUE(tester->is_installable()); 535 EXPECT_TRUE(tester->is_installable());
521 EXPECT_FALSE(tester->primary_icon_url().is_empty()); 536 EXPECT_FALSE(tester->primary_icon_url().is_empty());
522 EXPECT_NE(nullptr, tester->primary_icon()); 537 EXPECT_NE(nullptr, tester->primary_icon());
523 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 538 EXPECT_TRUE(tester->badge_icon_url().is_empty());
524 EXPECT_EQ(nullptr, tester->badge_icon()); 539 EXPECT_EQ(nullptr, tester->badge_icon());
525 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code()); 540 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code());
541 EXPECT_EQ(GetStatus(), InstallableMetrics::COMPLETE_PWA);
526 542
527 // Verify that the returned state matches manager internal state. 543 // Verify that the returned state matches manager internal state.
528 InstallableManager* manager = GetManager(); 544 InstallableManager* manager = GetManager();
529 545
530 EXPECT_FALSE(manager->manifest().IsEmpty()); 546 EXPECT_FALSE(manager->manifest().IsEmpty());
531 EXPECT_FALSE(manager->manifest_url().is_empty()); 547 EXPECT_FALSE(manager->manifest_url().is_empty());
532 EXPECT_TRUE(manager->is_installable()); 548 EXPECT_TRUE(manager->is_installable());
533 EXPECT_EQ(1u, manager->icons_.size()); 549 EXPECT_EQ(1u, manager->icons_.size());
534 EXPECT_FALSE((manager->icon_url(kPrimaryIconParams).is_empty())); 550 EXPECT_FALSE((manager->icon_url(kPrimaryIconParams).is_empty()));
535 EXPECT_NE(nullptr, (manager->icon(kPrimaryIconParams))); 551 EXPECT_NE(nullptr, (manager->icon(kPrimaryIconParams)));
(...skipping 30 matching lines...) Expand all
566 // The installable manager should only retrieve items in the main frame; 582 // The installable manager should only retrieve items in the main frame;
567 // everything should be empty here. 583 // everything should be empty here.
568 EXPECT_TRUE(tester->manifest().IsEmpty()); 584 EXPECT_TRUE(tester->manifest().IsEmpty());
569 EXPECT_TRUE(tester->manifest_url().is_empty()); 585 EXPECT_TRUE(tester->manifest_url().is_empty());
570 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 586 EXPECT_TRUE(tester->primary_icon_url().is_empty());
571 EXPECT_EQ(nullptr, tester->primary_icon()); 587 EXPECT_EQ(nullptr, tester->primary_icon());
572 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 588 EXPECT_TRUE(tester->badge_icon_url().is_empty());
573 EXPECT_EQ(nullptr, tester->badge_icon()); 589 EXPECT_EQ(nullptr, tester->badge_icon());
574 EXPECT_FALSE(tester->is_installable()); 590 EXPECT_FALSE(tester->is_installable());
575 EXPECT_EQ(NO_MANIFEST, tester->error_code()); 591 EXPECT_EQ(NO_MANIFEST, tester->error_code());
592 EXPECT_EQ(GetStatus(), InstallableMetrics::COMPLETE_NON_PWA);
576 } 593 }
577 594
578 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, 595 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest,
579 CheckPageWithManifestAndNoServiceWorker) { 596 CheckPageWithManifestAndNoServiceWorker) {
580 // Just fetch the manifest. This should have no error. 597 // Just fetch the manifest. This should have no error.
581 { 598 {
582 base::RunLoop run_loop; 599 base::RunLoop run_loop;
583 std::unique_ptr<CallbackTester> tester( 600 std::unique_ptr<CallbackTester> tester(
584 new CallbackTester(run_loop.QuitClosure())); 601 new CallbackTester(run_loop.QuitClosure()));
585 602
586 NavigateAndRunInstallableManager( 603 NavigateAndRunInstallableManager(
587 tester.get(), GetManifestParams(), 604 tester.get(), GetManifestParams(),
588 "/banners/manifest_no_service_worker.html"); 605 "/banners/manifest_no_service_worker.html");
589 run_loop.Run(); 606 run_loop.Run();
590 607
591 EXPECT_FALSE(tester->manifest().IsEmpty()); 608 EXPECT_FALSE(tester->manifest().IsEmpty());
592 EXPECT_FALSE(tester->manifest_url().is_empty()); 609 EXPECT_FALSE(tester->manifest_url().is_empty());
593 610
594 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 611 EXPECT_TRUE(tester->primary_icon_url().is_empty());
595 EXPECT_EQ(nullptr, tester->primary_icon()); 612 EXPECT_EQ(nullptr, tester->primary_icon());
596 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 613 EXPECT_TRUE(tester->badge_icon_url().is_empty());
597 EXPECT_EQ(nullptr, tester->badge_icon()); 614 EXPECT_EQ(nullptr, tester->badge_icon());
598 EXPECT_FALSE(tester->is_installable()); 615 EXPECT_FALSE(tester->is_installable());
599 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code()); 616 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code());
617 EXPECT_EQ(GetStatus(), InstallableMetrics::NOT_STARTED);
600 } 618 }
601 619
602 // Fetch the full criteria should fail. 620 // Fetch the full criteria should fail.
603 { 621 {
604 base::RunLoop run_loop; 622 base::RunLoop run_loop;
605 std::unique_ptr<CallbackTester> tester( 623 std::unique_ptr<CallbackTester> tester(
606 new CallbackTester(run_loop.QuitClosure())); 624 new CallbackTester(run_loop.QuitClosure()));
607 625
608 RunInstallableManager(tester.get(), GetWebAppParams()); 626 RunInstallableManager(tester.get(), GetWebAppParams());
609 run_loop.Run(); 627 run_loop.Run();
610 628
611 EXPECT_FALSE(tester->manifest().IsEmpty()); 629 EXPECT_FALSE(tester->manifest().IsEmpty());
612 EXPECT_FALSE(tester->manifest_url().is_empty()); 630 EXPECT_FALSE(tester->manifest_url().is_empty());
613 631
614 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 632 EXPECT_TRUE(tester->primary_icon_url().is_empty());
615 EXPECT_EQ(nullptr, tester->primary_icon()); 633 EXPECT_EQ(nullptr, tester->primary_icon());
616 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 634 EXPECT_TRUE(tester->badge_icon_url().is_empty());
617 EXPECT_EQ(nullptr, tester->badge_icon()); 635 EXPECT_EQ(nullptr, tester->badge_icon());
618 EXPECT_FALSE(tester->is_installable()); 636 EXPECT_FALSE(tester->is_installable());
619 EXPECT_EQ(NO_MATCHING_SERVICE_WORKER, tester->error_code()); 637 EXPECT_EQ(NO_MATCHING_SERVICE_WORKER, tester->error_code());
638 EXPECT_EQ(GetStatus(), InstallableMetrics::COMPLETE_NON_PWA);
620 } 639 }
621 } 640 }
622 641
623 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, 642 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest,
624 CheckPageWithNoServiceWorkerFetchHandler) { 643 CheckPageWithNoServiceWorkerFetchHandler) {
625 base::RunLoop run_loop; 644 base::RunLoop run_loop;
626 std::unique_ptr<CallbackTester> tester( 645 std::unique_ptr<CallbackTester> tester(
627 new CallbackTester(run_loop.QuitClosure())); 646 new CallbackTester(run_loop.QuitClosure()));
628 647
629 NavigateAndRunInstallableManager( 648 NavigateAndRunInstallableManager(
630 tester.get(), GetWebAppParams(), 649 tester.get(), GetWebAppParams(),
631 "/banners/no_sw_fetch_handler_test_page.html"); 650 "/banners/no_sw_fetch_handler_test_page.html");
632 651
633 RunInstallableManager(tester.get(), GetWebAppParams()); 652 RunInstallableManager(tester.get(), GetWebAppParams());
634 run_loop.Run(); 653 run_loop.Run();
635 654
636 EXPECT_FALSE(tester->manifest().IsEmpty()); 655 EXPECT_FALSE(tester->manifest().IsEmpty());
637 EXPECT_FALSE(tester->manifest_url().is_empty()); 656 EXPECT_FALSE(tester->manifest_url().is_empty());
638 657
639 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 658 EXPECT_TRUE(tester->primary_icon_url().is_empty());
640 EXPECT_EQ(nullptr, tester->primary_icon()); 659 EXPECT_EQ(nullptr, tester->primary_icon());
641 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 660 EXPECT_TRUE(tester->badge_icon_url().is_empty());
642 EXPECT_EQ(nullptr, tester->badge_icon()); 661 EXPECT_EQ(nullptr, tester->badge_icon());
643 EXPECT_FALSE(tester->is_installable()); 662 EXPECT_FALSE(tester->is_installable());
644 EXPECT_EQ(NOT_OFFLINE_CAPABLE, tester->error_code()); 663 EXPECT_EQ(NOT_OFFLINE_CAPABLE, tester->error_code());
664 EXPECT_EQ(GetStatus(), InstallableMetrics::COMPLETE_NON_PWA);
645 } 665 }
646 666
647 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, CheckDataUrlIcon) { 667 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, CheckDataUrlIcon) {
648 // Verify that InstallableManager can handle data URL icons. 668 // Verify that InstallableManager can handle data URL icons.
649 base::RunLoop run_loop; 669 base::RunLoop run_loop;
650 std::unique_ptr<CallbackTester> tester( 670 std::unique_ptr<CallbackTester> tester(
651 new CallbackTester(run_loop.QuitClosure())); 671 new CallbackTester(run_loop.QuitClosure()));
652 672
653 NavigateAndRunInstallableManager(tester.get(), GetWebAppParams(), 673 NavigateAndRunInstallableManager(tester.get(), GetWebAppParams(),
654 GetURLOfPageWithServiceWorkerAndManifest( 674 GetURLOfPageWithServiceWorkerAndManifest(
655 "/banners/manifest_data_url_icon.json")); 675 "/banners/manifest_data_url_icon.json"));
656 run_loop.Run(); 676 run_loop.Run();
657 677
658 EXPECT_FALSE(tester->manifest().IsEmpty()); 678 EXPECT_FALSE(tester->manifest().IsEmpty());
659 EXPECT_FALSE(tester->manifest_url().is_empty()); 679 EXPECT_FALSE(tester->manifest_url().is_empty());
660 680
661 EXPECT_FALSE(tester->primary_icon_url().is_empty()); 681 EXPECT_FALSE(tester->primary_icon_url().is_empty());
662 EXPECT_NE(nullptr, tester->primary_icon()); 682 EXPECT_NE(nullptr, tester->primary_icon());
663 EXPECT_EQ(144, tester->primary_icon()->width()); 683 EXPECT_EQ(144, tester->primary_icon()->width());
664 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 684 EXPECT_TRUE(tester->badge_icon_url().is_empty());
665 EXPECT_EQ(nullptr, tester->badge_icon()); 685 EXPECT_EQ(nullptr, tester->badge_icon());
666 EXPECT_TRUE(tester->is_installable()); 686 EXPECT_TRUE(tester->is_installable());
667 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code()); 687 EXPECT_EQ(NO_ERROR_DETECTED, tester->error_code());
688 EXPECT_EQ(GetStatus(), InstallableMetrics::COMPLETE_PWA);
668 } 689 }
669 690
670 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, 691 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest,
671 CheckManifestCorruptedIcon) { 692 CheckManifestCorruptedIcon) {
672 // Verify that the returned InstallableData::primary_icon is null if the web 693 // Verify that the returned InstallableData::primary_icon is null if the web
673 // manifest points to a corrupt primary icon. 694 // manifest points to a corrupt primary icon.
674 base::RunLoop run_loop; 695 base::RunLoop run_loop;
675 std::unique_ptr<CallbackTester> tester( 696 std::unique_ptr<CallbackTester> tester(
676 new CallbackTester(run_loop.QuitClosure())); 697 new CallbackTester(run_loop.QuitClosure()));
677 698
678 NavigateAndRunInstallableManager(tester.get(), GetPrimaryIconParams(), 699 NavigateAndRunInstallableManager(tester.get(), GetPrimaryIconParams(),
679 GetURLOfPageWithServiceWorkerAndManifest( 700 GetURLOfPageWithServiceWorkerAndManifest(
680 "/banners/manifest_bad_icon.json")); 701 "/banners/manifest_bad_icon.json"));
681 run_loop.Run(); 702 run_loop.Run();
682 703
683 EXPECT_FALSE(tester->manifest().IsEmpty()); 704 EXPECT_FALSE(tester->manifest().IsEmpty());
684 EXPECT_FALSE(tester->manifest_url().is_empty()); 705 EXPECT_FALSE(tester->manifest_url().is_empty());
685 EXPECT_TRUE(tester->primary_icon_url().is_empty()); 706 EXPECT_TRUE(tester->primary_icon_url().is_empty());
686 EXPECT_EQ(nullptr, tester->primary_icon()); 707 EXPECT_EQ(nullptr, tester->primary_icon());
687 EXPECT_TRUE(tester->badge_icon_url().is_empty()); 708 EXPECT_TRUE(tester->badge_icon_url().is_empty());
688 EXPECT_EQ(nullptr, tester->badge_icon()); 709 EXPECT_EQ(nullptr, tester->badge_icon());
689 EXPECT_FALSE(tester->is_installable()); 710 EXPECT_FALSE(tester->is_installable());
690 EXPECT_EQ(NO_ICON_AVAILABLE, tester->error_code()); 711 EXPECT_EQ(NO_ICON_AVAILABLE, tester->error_code());
712 EXPECT_EQ(GetStatus(), InstallableMetrics::NOT_STARTED);
691 } 713 }
692 714
693 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, 715 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest,
694 CheckChangeInIconDimensions) { 716 CheckChangeInIconDimensions) {
695 // Verify that a follow-up request for a primary icon with a different size 717 // Verify that a follow-up request for a primary icon with a different size
696 // works. 718 // works.
697 { 719 {
698 base::RunLoop run_loop; 720 base::RunLoop run_loop;
699 std::unique_ptr<CallbackTester> tester( 721 std::unique_ptr<CallbackTester> tester(
700 new CallbackTester(run_loop.QuitClosure())); 722 new CallbackTester(run_loop.QuitClosure()));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 CheckNestedCallsToGetData) { 807 CheckNestedCallsToGetData) {
786 // Verify that we can call GetData while in a callback from GetData. 808 // Verify that we can call GetData while in a callback from GetData.
787 base::RunLoop run_loop; 809 base::RunLoop run_loop;
788 InstallableParams params = GetWebAppParams(); 810 InstallableParams params = GetWebAppParams();
789 std::unique_ptr<NestedCallbackTester> tester( 811 std::unique_ptr<NestedCallbackTester> tester(
790 new NestedCallbackTester(GetManager(), params, run_loop.QuitClosure())); 812 new NestedCallbackTester(GetManager(), params, run_loop.QuitClosure()));
791 813
792 tester->Run(); 814 tester->Run();
793 run_loop.Run(); 815 run_loop.Run();
794 } 816 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698