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

Side by Side Diff: content/browser/manifest/manifest_browsertest.cc

Issue 2933743002: Move chrome/browser/manifest to content/browser. (Closed)
Patch Set: rebased Created 3 years, 6 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 | « content/browser/manifest/OWNERS ('k') | content/browser/manifest/manifest_icon_downloader.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 { 260 {
261 GetManifestAndWait(); 261 GetManifestAndWait();
262 EXPECT_TRUE(manifest().IsEmpty()); 262 EXPECT_TRUE(manifest().IsEmpty());
263 EXPECT_TRUE(manifest_url().is_empty()); 263 EXPECT_TRUE(manifest_url().is_empty());
264 EXPECT_TRUE(reported_manifest_urls().empty()); 264 EXPECT_TRUE(reported_manifest_urls().empty());
265 } 265 }
266 266
267 { 267 {
268 std::string manifest_link = 268 std::string manifest_link =
269 embedded_test_server()->GetURL("/manifest/dummy-manifest.json").spec(); 269 embedded_test_server()->GetURL("/manifest/dummy-manifest.json").spec();
270 ASSERT_TRUE(content::ExecuteScript( 270 ASSERT_TRUE(
271 shell(), "setManifestTo('" + manifest_link + "')")); 271 ExecuteScript(shell(), "setManifestTo('" + manifest_link + "')"));
272 272
273 GetManifestAndWait(); 273 GetManifestAndWait();
274 EXPECT_FALSE(manifest().IsEmpty()); 274 EXPECT_FALSE(manifest().IsEmpty());
275 EXPECT_FALSE(manifest_url().is_empty()); 275 EXPECT_FALSE(manifest_url().is_empty());
276 expected_manifest_urls.push_back(manifest_url()); 276 expected_manifest_urls.push_back(manifest_url());
277 EXPECT_EQ(expected_manifest_urls, reported_manifest_urls()); 277 EXPECT_EQ(expected_manifest_urls, reported_manifest_urls());
278 } 278 }
279 { 279 {
280 std::string manifest_link = 280 std::string manifest_link =
281 embedded_test_server()->GetURL("/manifest/empty-manifest.json").spec(); 281 embedded_test_server()->GetURL("/manifest/empty-manifest.json").spec();
282 ASSERT_TRUE(content::ExecuteScript( 282 ASSERT_TRUE(
283 shell(), "setManifestTo('" + manifest_link + "')")); 283 ExecuteScript(shell(), "setManifestTo('" + manifest_link + "')"));
284 284
285 GetManifestAndWait(); 285 GetManifestAndWait();
286 EXPECT_TRUE(manifest().IsEmpty()); 286 EXPECT_TRUE(manifest().IsEmpty());
287 EXPECT_FALSE(manifest_url().is_empty()); 287 EXPECT_FALSE(manifest_url().is_empty());
288 expected_manifest_urls.push_back(manifest_url()); 288 expected_manifest_urls.push_back(manifest_url());
289 EXPECT_EQ(expected_manifest_urls, reported_manifest_urls()); 289 EXPECT_EQ(expected_manifest_urls, reported_manifest_urls());
290 } 290 }
291 291
292 { 292 {
293 ASSERT_TRUE(content::ExecuteScript(shell(), "clearManifest()")); 293 ASSERT_TRUE(ExecuteScript(shell(), "clearManifest()"));
294 294
295 GetManifestAndWait(); 295 GetManifestAndWait();
296 EXPECT_TRUE(manifest().IsEmpty()); 296 EXPECT_TRUE(manifest().IsEmpty());
297 EXPECT_TRUE(manifest_url().is_empty()); 297 EXPECT_TRUE(manifest_url().is_empty());
298 expected_manifest_urls.push_back(manifest_url()); 298 expected_manifest_urls.push_back(manifest_url());
299 EXPECT_EQ(expected_manifest_urls, reported_manifest_urls()); 299 EXPECT_EQ(expected_manifest_urls, reported_manifest_urls());
300 ASSERT_EQ(1u, manifests_reported_when_favicon_url_updated().size()); 300 ASSERT_EQ(1u, manifests_reported_when_favicon_url_updated().size());
301 EXPECT_EQ(0u, manifests_reported_when_favicon_url_updated()[0]); 301 EXPECT_EQ(0u, manifests_reported_when_favicon_url_updated()[0]);
302 } 302 }
303 303
304 EXPECT_EQ(0u, console_error_count()); 304 EXPECT_EQ(0u, console_error_count());
305 } 305 }
306 306
307 // If a page's manifest lives in a different origin, it should follow the CORS 307 // If a page's manifest lives in a different origin, it should follow the CORS
308 // rules and requesting the manifest should return an empty manifest (unless the 308 // rules and requesting the manifest should return an empty manifest (unless the
309 // response contains CORS headers). 309 // response contains CORS headers).
310 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) { 310 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) {
311 ASSERT_TRUE(cors_embedded_test_server()->Start()); 311 ASSERT_TRUE(cors_embedded_test_server()->Start());
312 ASSERT_NE(embedded_test_server()->port(), 312 ASSERT_NE(embedded_test_server()->port(),
313 cors_embedded_test_server()->port()); 313 cors_embedded_test_server()->port());
314 314
315 GURL test_url = 315 GURL test_url =
316 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); 316 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html");
317 std::vector<GURL> expected_manifest_urls; 317 std::vector<GURL> expected_manifest_urls;
318 318
319 ASSERT_TRUE(NavigateToURL(shell(), test_url)); 319 ASSERT_TRUE(NavigateToURL(shell(), test_url));
320 320
321 std::string manifest_link = cors_embedded_test_server()->GetURL( 321 std::string manifest_link = cors_embedded_test_server()->GetURL(
322 "/manifest/dummy-manifest.json").spec(); 322 "/manifest/dummy-manifest.json").spec();
323 ASSERT_TRUE(content::ExecuteScript(shell(), 323 ASSERT_TRUE(ExecuteScript(shell(), "setManifestTo('" + manifest_link + "')"));
324 "setManifestTo('" + manifest_link + "')"));
325 324
326 GetManifestAndWait(); 325 GetManifestAndWait();
327 EXPECT_TRUE(manifest().IsEmpty()); 326 EXPECT_TRUE(manifest().IsEmpty());
328 EXPECT_FALSE(manifest_url().is_empty()); 327 EXPECT_FALSE(manifest_url().is_empty());
329 EXPECT_EQ(0u, console_error_count()); 328 EXPECT_EQ(0u, console_error_count());
330 expected_manifest_urls.push_back(manifest_url()); 329 expected_manifest_urls.push_back(manifest_url());
331 EXPECT_EQ(expected_manifest_urls, reported_manifest_urls()); 330 EXPECT_EQ(expected_manifest_urls, reported_manifest_urls());
332 331
333 // The purpose of this second load is to make sure the first load is fully 332 // The purpose of this second load is to make sure the first load is fully
334 // finished. The first load will fail because of Access Control error but the 333 // finished. The first load will fail because of Access Control error but the
335 // underlying Blink loader will continue fetching the file. There is no 334 // underlying Blink loader will continue fetching the file. There is no
336 // reliable way to know when the fetch is finished from the browser test 335 // reliable way to know when the fetch is finished from the browser test
337 // except by fetching the same file from same origin, making it succeed when 336 // except by fetching the same file from same origin, making it succeed when
338 // it is actually fully loaded. 337 // it is actually fully loaded.
339 manifest_link = 338 manifest_link =
340 embedded_test_server()->GetURL("/manifest/dummy-manifest.json").spec(); 339 embedded_test_server()->GetURL("/manifest/dummy-manifest.json").spec();
341 ASSERT_TRUE(content::ExecuteScript(shell(), 340 ASSERT_TRUE(ExecuteScript(shell(), "setManifestTo('" + manifest_link + "')"));
342 "setManifestTo('" + manifest_link + "')"));
343 GetManifestAndWait(); 341 GetManifestAndWait();
344 expected_manifest_urls.push_back(manifest_url()); 342 expected_manifest_urls.push_back(manifest_url());
345 EXPECT_EQ(expected_manifest_urls, reported_manifest_urls()); 343 EXPECT_EQ(expected_manifest_urls, reported_manifest_urls());
346 ASSERT_EQ(1u, manifests_reported_when_favicon_url_updated().size()); 344 ASSERT_EQ(1u, manifests_reported_when_favicon_url_updated().size());
347 EXPECT_EQ(0u, manifests_reported_when_favicon_url_updated()[0]); 345 EXPECT_EQ(0u, manifests_reported_when_favicon_url_updated()[0]);
348 } 346 }
349 347
350 // If a page's manifest lives in a different origin, it should be accessible if 348 // If a page's manifest lives in a different origin, it should be accessible if
351 // it has valid access controls headers. 349 // it has valid access controls headers.
352 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifestWithAcessControls) { 350 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifestWithAcessControls) {
353 ASSERT_TRUE(cors_embedded_test_server()->Start()); 351 ASSERT_TRUE(cors_embedded_test_server()->Start());
354 ASSERT_NE(embedded_test_server()->port(), 352 ASSERT_NE(embedded_test_server()->port(),
355 cors_embedded_test_server()->port()); 353 cors_embedded_test_server()->port());
356 354
357 GURL test_url = 355 GURL test_url =
358 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); 356 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html");
359 357
360 ASSERT_TRUE(NavigateToURL(shell(), test_url)); 358 ASSERT_TRUE(NavigateToURL(shell(), test_url));
361 359
362 std::string manifest_link = cors_embedded_test_server()->GetURL( 360 std::string manifest_link = cors_embedded_test_server()->GetURL(
363 "/manifest/manifest-cors.json").spec(); 361 "/manifest/manifest-cors.json").spec();
364 ASSERT_TRUE(content::ExecuteScript(shell(), 362 ASSERT_TRUE(ExecuteScript(shell(), "setManifestTo('" + manifest_link + "')"));
365 "setManifestTo('" + manifest_link + "')"));
366 363
367 GetManifestAndWait(); 364 GetManifestAndWait();
368 EXPECT_FALSE(manifest().IsEmpty()); 365 EXPECT_FALSE(manifest().IsEmpty());
369 EXPECT_FALSE(manifest_url().is_empty()); 366 EXPECT_FALSE(manifest_url().is_empty());
370 EXPECT_EQ(0u, console_error_count()); 367 EXPECT_EQ(0u, console_error_count());
371 ASSERT_EQ(1u, reported_manifest_urls().size()); 368 ASSERT_EQ(1u, reported_manifest_urls().size());
372 EXPECT_EQ(manifest_url(), reported_manifest_urls()[0]); 369 EXPECT_EQ(manifest_url(), reported_manifest_urls()[0]);
373 ASSERT_EQ(1u, manifests_reported_when_favicon_url_updated().size()); 370 ASSERT_EQ(1u, manifests_reported_when_favicon_url_updated().size());
374 EXPECT_EQ(0u, manifests_reported_when_favicon_url_updated()[0]); 371 EXPECT_EQ(0u, manifests_reported_when_favicon_url_updated()[0]);
375 } 372 }
376 373
377 // If a page's manifest is in an insecure origin while the page is in a secure 374 // If a page's manifest is in an insecure origin while the page is in a secure
378 // origin, requesting the manifest should return the empty manifest. 375 // origin, requesting the manifest should return the empty manifest.
379 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) { 376 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) {
380 std::unique_ptr<net::EmbeddedTestServer> https_server( 377 std::unique_ptr<net::EmbeddedTestServer> https_server(
381 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); 378 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS));
382 https_server->ServeFilesFromSourceDirectory("content/test/data"); 379 https_server->ServeFilesFromSourceDirectory("content/test/data");
383 380
384 ASSERT_TRUE(https_server->Start()); 381 ASSERT_TRUE(https_server->Start());
385 382
386 GURL test_url = 383 GURL test_url =
387 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); 384 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html");
388 385
389 ASSERT_TRUE(NavigateToURL(shell(), test_url)); 386 ASSERT_TRUE(NavigateToURL(shell(), test_url));
390 387
391 std::string manifest_link = 388 std::string manifest_link =
392 https_server->GetURL("/manifest/dummy-manifest.json").spec(); 389 https_server->GetURL("/manifest/dummy-manifest.json").spec();
393 ASSERT_TRUE(content::ExecuteScript(shell(), 390 ASSERT_TRUE(ExecuteScript(shell(), "setManifestTo('" + manifest_link + "')"));
394 "setManifestTo('" + manifest_link + "')"));
395 391
396 GetManifestAndWait(); 392 GetManifestAndWait();
397 EXPECT_TRUE(manifest().IsEmpty()); 393 EXPECT_TRUE(manifest().IsEmpty());
398 EXPECT_FALSE(manifest_url().is_empty()); 394 EXPECT_FALSE(manifest_url().is_empty());
399 EXPECT_EQ(0u, console_error_count()); 395 EXPECT_EQ(0u, console_error_count());
400 ASSERT_EQ(1u, reported_manifest_urls().size()); 396 ASSERT_EQ(1u, reported_manifest_urls().size());
401 EXPECT_EQ(manifest_url(), reported_manifest_urls()[0]); 397 EXPECT_EQ(manifest_url(), reported_manifest_urls()[0]);
402 ASSERT_EQ(1u, manifests_reported_when_favicon_url_updated().size()); 398 ASSERT_EQ(1u, manifests_reported_when_favicon_url_updated().size());
403 EXPECT_EQ(0u, manifests_reported_when_favicon_url_updated()[0]); 399 EXPECT_EQ(0u, manifests_reported_when_favicon_url_updated()[0]);
404 } 400 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // If a page has a manifest and the page is navigated using pushState (ie. same 472 // If a page has a manifest and the page is navigated using pushState (ie. same
477 // page), it should keep its manifest state. 473 // page), it should keep its manifest state.
478 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, PushStateNavigation) { 474 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, PushStateNavigation) {
479 GURL test_url = 475 GURL test_url =
480 embedded_test_server()->GetURL("/manifest/dummy-manifest.html"); 476 embedded_test_server()->GetURL("/manifest/dummy-manifest.html");
481 477
482 ASSERT_TRUE(NavigateToURL(shell(), test_url)); 478 ASSERT_TRUE(NavigateToURL(shell(), test_url));
483 479
484 { 480 {
485 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 481 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
486 ASSERT_TRUE(content::ExecuteScript( 482 ASSERT_TRUE(ExecuteScript(
487 shell(), "history.pushState({foo: \"bar\"}, 'page', 'page.html');")); 483 shell(), "history.pushState({foo: \"bar\"}, 'page', 'page.html');"));
488 navigation_observer.Wait(); 484 navigation_observer.Wait();
489 } 485 }
490 486
491 GetManifestAndWait(); 487 GetManifestAndWait();
492 EXPECT_FALSE(manifest().IsEmpty()); 488 EXPECT_FALSE(manifest().IsEmpty());
493 EXPECT_FALSE(manifest_url().is_empty()); 489 EXPECT_FALSE(manifest_url().is_empty());
494 EXPECT_EQ(0u, console_error_count()); 490 EXPECT_EQ(0u, console_error_count());
495 ASSERT_EQ(1u, reported_manifest_urls().size()); 491 ASSERT_EQ(1u, reported_manifest_urls().size());
496 EXPECT_EQ(manifest_url(), reported_manifest_urls()[0]); 492 EXPECT_EQ(manifest_url(), reported_manifest_urls()[0]);
497 ASSERT_EQ(2u, manifests_reported_when_favicon_url_updated().size()); 493 ASSERT_EQ(2u, manifests_reported_when_favicon_url_updated().size());
498 EXPECT_EQ(1u, manifests_reported_when_favicon_url_updated()[0]); 494 EXPECT_EQ(1u, manifests_reported_when_favicon_url_updated()[0]);
499 EXPECT_EQ(1u, manifests_reported_when_favicon_url_updated()[1]); 495 EXPECT_EQ(1u, manifests_reported_when_favicon_url_updated()[1]);
500 } 496 }
501 497
502 // If a page has a manifest and is navigated using an anchor (ie. same page), it 498 // If a page has a manifest and is navigated using an anchor (ie. same page), it
503 // should keep its manifest state. 499 // should keep its manifest state.
504 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, AnchorNavigation) { 500 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, AnchorNavigation) {
505 GURL test_url = 501 GURL test_url =
506 embedded_test_server()->GetURL("/manifest/dummy-manifest.html"); 502 embedded_test_server()->GetURL("/manifest/dummy-manifest.html");
507 503
508 ASSERT_TRUE(NavigateToURL(shell(), test_url)); 504 ASSERT_TRUE(NavigateToURL(shell(), test_url));
509 { 505 {
510 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 506 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
511 ASSERT_TRUE(content::ExecuteScript( 507 ASSERT_TRUE(
512 shell(), 508 ExecuteScript(shell(),
513 "var a = document.createElement('a'); a.href='#foo';" 509 "var a = document.createElement('a'); a.href='#foo';"
514 "document.body.appendChild(a); a.click();")); 510 "document.body.appendChild(a); a.click();"));
515 navigation_observer.Wait(); 511 navigation_observer.Wait();
516 } 512 }
517 513
518 GetManifestAndWait(); 514 GetManifestAndWait();
519 EXPECT_FALSE(manifest().IsEmpty()); 515 EXPECT_FALSE(manifest().IsEmpty());
520 EXPECT_FALSE(manifest_url().is_empty()); 516 EXPECT_FALSE(manifest_url().is_empty());
521 EXPECT_EQ(0u, console_error_count()); 517 EXPECT_EQ(0u, console_error_count());
522 ASSERT_EQ(1u, reported_manifest_urls().size()); 518 ASSERT_EQ(1u, reported_manifest_urls().size());
523 EXPECT_EQ(manifest_url(), reported_manifest_urls()[0]); 519 EXPECT_EQ(manifest_url(), reported_manifest_urls()[0]);
524 ASSERT_EQ(2u, manifests_reported_when_favicon_url_updated().size()); 520 ASSERT_EQ(2u, manifests_reported_when_favicon_url_updated().size());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 EXPECT_EQ(manifest_url(), reported_manifest_urls()[0]); 639 EXPECT_EQ(manifest_url(), reported_manifest_urls()[0]);
644 ASSERT_EQ(1u, manifests_reported_when_favicon_url_updated().size()); 640 ASSERT_EQ(1u, manifests_reported_when_favicon_url_updated().size());
645 EXPECT_EQ(1u, manifests_reported_when_favicon_url_updated()[0]); 641 EXPECT_EQ(1u, manifests_reported_when_favicon_url_updated()[0]);
646 642
647 // The custom embedded test server will fill set the name to 'no cookies' if 643 // The custom embedded test server will fill set the name to 'no cookies' if
648 // it did not find cookies. 644 // it did not find cookies.
649 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "no cookies")); 645 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "no cookies"));
650 } 646 }
651 647
652 } // namespace content 648 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/manifest/OWNERS ('k') | content/browser/manifest/manifest_icon_downloader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698