| OLD | NEW |
| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 void OnReceivedConsoleError() { | 110 void OnReceivedConsoleError() { |
| 111 console_error_count_++; | 111 console_error_count_++; |
| 112 } | 112 } |
| 113 | 113 |
| 114 net::EmbeddedTestServer* cors_embedded_test_server() const { | 114 net::EmbeddedTestServer* cors_embedded_test_server() const { |
| 115 return cors_embedded_test_server_.get(); | 115 return cors_embedded_test_server_.get(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 119 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 120 scoped_ptr<MockWebContentsDelegate> mock_web_contents_delegate_; | 120 std::unique_ptr<MockWebContentsDelegate> mock_web_contents_delegate_; |
| 121 scoped_ptr<net::EmbeddedTestServer> cors_embedded_test_server_; | 121 std::unique_ptr<net::EmbeddedTestServer> cors_embedded_test_server_; |
| 122 Manifest manifest_; | 122 Manifest manifest_; |
| 123 int console_error_count_; | 123 int console_error_count_; |
| 124 bool has_manifest_; | 124 bool has_manifest_; |
| 125 | 125 |
| 126 DISALLOW_COPY_AND_ASSIGN(ManifestBrowserTest); | 126 DISALLOW_COPY_AND_ASSIGN(ManifestBrowserTest); |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 // The implementation of AddMessageToConsole isn't inlined because it needs | 129 // The implementation of AddMessageToConsole isn't inlined because it needs |
| 130 // to know about |test_|. | 130 // to know about |test_|. |
| 131 bool MockWebContentsDelegate::AddMessageToConsole( | 131 bool MockWebContentsDelegate::AddMessageToConsole( |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 EXPECT_FALSE(manifest().IsEmpty()); | 337 EXPECT_FALSE(manifest().IsEmpty()); |
| 338 | 338 |
| 339 HasManifestAndWait(); | 339 HasManifestAndWait(); |
| 340 EXPECT_TRUE(has_manifest()); | 340 EXPECT_TRUE(has_manifest()); |
| 341 EXPECT_EQ(0u, console_error_count()); | 341 EXPECT_EQ(0u, console_error_count()); |
| 342 } | 342 } |
| 343 | 343 |
| 344 // If a page's manifest is in an insecure origin while the page is in a secure | 344 // If a page's manifest is in an insecure origin while the page is in a secure |
| 345 // origin, requesting the manifest should return the empty manifest. | 345 // origin, requesting the manifest should return the empty manifest. |
| 346 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) { | 346 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) { |
| 347 scoped_ptr<net::EmbeddedTestServer> https_server( | 347 std::unique_ptr<net::EmbeddedTestServer> https_server( |
| 348 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 348 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
| 349 https_server->ServeFilesFromSourceDirectory("content/test/data"); | 349 https_server->ServeFilesFromSourceDirectory("content/test/data"); |
| 350 | 350 |
| 351 ASSERT_TRUE(embedded_test_server()->Start()); | 351 ASSERT_TRUE(embedded_test_server()->Start()); |
| 352 ASSERT_TRUE(https_server->Start()); | 352 ASSERT_TRUE(https_server->Start()); |
| 353 | 353 |
| 354 GURL test_url = | 354 GURL test_url = |
| 355 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); | 355 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); |
| 356 | 356 |
| 357 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 357 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 EXPECT_FALSE(manifest().IsEmpty()); | 480 EXPECT_FALSE(manifest().IsEmpty()); |
| 481 EXPECT_EQ(0u, console_error_count()); | 481 EXPECT_EQ(0u, console_error_count()); |
| 482 | 482 |
| 483 HasManifestAndWait(); | 483 HasManifestAndWait(); |
| 484 EXPECT_TRUE(has_manifest()); | 484 EXPECT_TRUE(has_manifest()); |
| 485 EXPECT_EQ(0u, console_error_count()); | 485 EXPECT_EQ(0u, console_error_count()); |
| 486 } | 486 } |
| 487 | 487 |
| 488 namespace { | 488 namespace { |
| 489 | 489 |
| 490 scoped_ptr<net::test_server::HttpResponse> CustomHandleRequestForCookies( | 490 std::unique_ptr<net::test_server::HttpResponse> CustomHandleRequestForCookies( |
| 491 const net::test_server::HttpRequest& request) { | 491 const net::test_server::HttpRequest& request) { |
| 492 if (request.relative_url == "/index.html") { | 492 if (request.relative_url == "/index.html") { |
| 493 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 493 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
| 494 new net::test_server::BasicHttpResponse()); | 494 new net::test_server::BasicHttpResponse()); |
| 495 http_response->set_code(net::HTTP_OK); | 495 http_response->set_code(net::HTTP_OK); |
| 496 http_response->set_content_type("text/html"); | 496 http_response->set_content_type("text/html"); |
| 497 http_response->set_content( | 497 http_response->set_content( |
| 498 "<html><head>" | 498 "<html><head>" |
| 499 "<link rel=manifest crossorigin='use-credentials' href=/manifest.json>" | 499 "<link rel=manifest crossorigin='use-credentials' href=/manifest.json>" |
| 500 "</head></html>"); | 500 "</head></html>"); |
| 501 return std::move(http_response); | 501 return std::move(http_response); |
| 502 } | 502 } |
| 503 | 503 |
| 504 const auto& iter = request.headers.find("Cookie"); | 504 const auto& iter = request.headers.find("Cookie"); |
| 505 if (iter == request.headers.end() || request.relative_url != "/manifest.json") | 505 if (iter == request.headers.end() || request.relative_url != "/manifest.json") |
| 506 return scoped_ptr<net::test_server::HttpResponse>(); | 506 return std::unique_ptr<net::test_server::HttpResponse>(); |
| 507 | 507 |
| 508 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 508 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
| 509 new net::test_server::BasicHttpResponse()); | 509 new net::test_server::BasicHttpResponse()); |
| 510 http_response->set_code(net::HTTP_OK); | 510 http_response->set_code(net::HTTP_OK); |
| 511 http_response->set_content_type("application/json"); | 511 http_response->set_content_type("application/json"); |
| 512 http_response->set_content( | 512 http_response->set_content( |
| 513 base::StringPrintf("{\"name\": \"%s\"}", iter->second.c_str())); | 513 base::StringPrintf("{\"name\": \"%s\"}", iter->second.c_str())); |
| 514 | 514 |
| 515 return std::move(http_response); | 515 return std::move(http_response); |
| 516 } | 516 } |
| 517 | 517 |
| 518 } // anonymous namespace | 518 } // anonymous namespace |
| 519 | 519 |
| 520 // This tests that when fetching a Manifest with 'use-credentials' set, the | 520 // This tests that when fetching a Manifest with 'use-credentials' set, the |
| 521 // cookies associated with it are passed along the request. | 521 // cookies associated with it are passed along the request. |
| 522 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, UseCredentialsSendCookies) { | 522 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, UseCredentialsSendCookies) { |
| 523 scoped_ptr<net::EmbeddedTestServer> custom_embedded_test_server( | 523 std::unique_ptr<net::EmbeddedTestServer> custom_embedded_test_server( |
| 524 new net::EmbeddedTestServer()); | 524 new net::EmbeddedTestServer()); |
| 525 custom_embedded_test_server->RegisterRequestHandler( | 525 custom_embedded_test_server->RegisterRequestHandler( |
| 526 base::Bind(&CustomHandleRequestForCookies)); | 526 base::Bind(&CustomHandleRequestForCookies)); |
| 527 | 527 |
| 528 ASSERT_TRUE(custom_embedded_test_server->Start()); | 528 ASSERT_TRUE(custom_embedded_test_server->Start()); |
| 529 | 529 |
| 530 ASSERT_TRUE(SetCookie(shell()->web_contents()->GetBrowserContext(), | 530 ASSERT_TRUE(SetCookie(shell()->web_contents()->GetBrowserContext(), |
| 531 custom_embedded_test_server->base_url(), | 531 custom_embedded_test_server->base_url(), |
| 532 "foobar")); | 532 "foobar")); |
| 533 | 533 |
| 534 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 534 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 535 shell()->LoadURL(custom_embedded_test_server->GetURL("/index.html")); | 535 shell()->LoadURL(custom_embedded_test_server->GetURL("/index.html")); |
| 536 navigation_observer.Wait(); | 536 navigation_observer.Wait(); |
| 537 | 537 |
| 538 GetManifestAndWait(); | 538 GetManifestAndWait(); |
| 539 EXPECT_FALSE(manifest().IsEmpty()); | 539 EXPECT_FALSE(manifest().IsEmpty()); |
| 540 | 540 |
| 541 HasManifestAndWait(); | 541 HasManifestAndWait(); |
| 542 EXPECT_TRUE(has_manifest()); | 542 EXPECT_TRUE(has_manifest()); |
| 543 EXPECT_EQ(0u, console_error_count()); | 543 EXPECT_EQ(0u, console_error_count()); |
| 544 | 544 |
| 545 // The custom embedded test server will fill the name field with the cookie | 545 // The custom embedded test server will fill the name field with the cookie |
| 546 // content. | 546 // content. |
| 547 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "foobar")); | 547 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "foobar")); |
| 548 } | 548 } |
| 549 | 549 |
| 550 namespace { | 550 namespace { |
| 551 | 551 |
| 552 scoped_ptr<net::test_server::HttpResponse> CustomHandleRequestForNoCookies( | 552 std::unique_ptr<net::test_server::HttpResponse> CustomHandleRequestForNoCookies( |
| 553 const net::test_server::HttpRequest& request) { | 553 const net::test_server::HttpRequest& request) { |
| 554 if (request.relative_url == "/index.html") { | 554 if (request.relative_url == "/index.html") { |
| 555 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 555 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
| 556 new net::test_server::BasicHttpResponse()); | 556 new net::test_server::BasicHttpResponse()); |
| 557 http_response->set_code(net::HTTP_OK); | 557 http_response->set_code(net::HTTP_OK); |
| 558 http_response->set_content_type("text/html"); | 558 http_response->set_content_type("text/html"); |
| 559 http_response->set_content( | 559 http_response->set_content( |
| 560 "<html><head><link rel=manifest href=/manifest.json></head></html>"); | 560 "<html><head><link rel=manifest href=/manifest.json></head></html>"); |
| 561 return std::move(http_response); | 561 return std::move(http_response); |
| 562 } | 562 } |
| 563 | 563 |
| 564 const auto& iter = request.headers.find("Cookie"); | 564 const auto& iter = request.headers.find("Cookie"); |
| 565 if (iter != request.headers.end() || request.relative_url != "/manifest.json") | 565 if (iter != request.headers.end() || request.relative_url != "/manifest.json") |
| 566 return scoped_ptr<net::test_server::HttpResponse>(); | 566 return std::unique_ptr<net::test_server::HttpResponse>(); |
| 567 | 567 |
| 568 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 568 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
| 569 new net::test_server::BasicHttpResponse()); | 569 new net::test_server::BasicHttpResponse()); |
| 570 http_response->set_code(net::HTTP_OK); | 570 http_response->set_code(net::HTTP_OK); |
| 571 http_response->set_content_type("application/json"); | 571 http_response->set_content_type("application/json"); |
| 572 http_response->set_content("{\"name\": \"no cookies\"}"); | 572 http_response->set_content("{\"name\": \"no cookies\"}"); |
| 573 | 573 |
| 574 return std::move(http_response); | 574 return std::move(http_response); |
| 575 } | 575 } |
| 576 | 576 |
| 577 } // anonymous namespace | 577 } // anonymous namespace |
| 578 | 578 |
| 579 // This tests that when fetching a Manifest without 'use-credentials' set, the | 579 // This tests that when fetching a Manifest without 'use-credentials' set, the |
| 580 // cookies associated with it are not passed along the request. | 580 // cookies associated with it are not passed along the request. |
| 581 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, NoUseCredentialsNoCookies) { | 581 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, NoUseCredentialsNoCookies) { |
| 582 scoped_ptr<net::EmbeddedTestServer> custom_embedded_test_server( | 582 std::unique_ptr<net::EmbeddedTestServer> custom_embedded_test_server( |
| 583 new net::EmbeddedTestServer()); | 583 new net::EmbeddedTestServer()); |
| 584 custom_embedded_test_server->RegisterRequestHandler( | 584 custom_embedded_test_server->RegisterRequestHandler( |
| 585 base::Bind(&CustomHandleRequestForNoCookies)); | 585 base::Bind(&CustomHandleRequestForNoCookies)); |
| 586 | 586 |
| 587 ASSERT_TRUE(custom_embedded_test_server->Start()); | 587 ASSERT_TRUE(custom_embedded_test_server->Start()); |
| 588 | 588 |
| 589 ASSERT_TRUE(SetCookie(shell()->web_contents()->GetBrowserContext(), | 589 ASSERT_TRUE(SetCookie(shell()->web_contents()->GetBrowserContext(), |
| 590 custom_embedded_test_server->base_url(), | 590 custom_embedded_test_server->base_url(), |
| 591 "foobar")); | 591 "foobar")); |
| 592 | 592 |
| 593 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 593 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 594 shell()->LoadURL(custom_embedded_test_server->GetURL("/index.html")); | 594 shell()->LoadURL(custom_embedded_test_server->GetURL("/index.html")); |
| 595 navigation_observer.Wait(); | 595 navigation_observer.Wait(); |
| 596 | 596 |
| 597 GetManifestAndWait(); | 597 GetManifestAndWait(); |
| 598 EXPECT_FALSE(manifest().IsEmpty()); | 598 EXPECT_FALSE(manifest().IsEmpty()); |
| 599 | 599 |
| 600 HasManifestAndWait(); | 600 HasManifestAndWait(); |
| 601 EXPECT_TRUE(has_manifest()); | 601 EXPECT_TRUE(has_manifest()); |
| 602 EXPECT_EQ(0u, console_error_count()); | 602 EXPECT_EQ(0u, console_error_count()); |
| 603 | 603 |
| 604 // The custom embedded test server will fill set the name to 'no cookies' if | 604 // The custom embedded test server will fill set the name to 'no cookies' if |
| 605 // it did not find cookies. | 605 // it did not find cookies. |
| 606 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "no cookies")); | 606 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "no cookies")); |
| 607 } | 607 } |
| 608 | 608 |
| 609 } // namespace content | 609 } // namespace content |
| OLD | NEW |