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

Side by Side Diff: headless/lib/headless_browser_browsertest.cc

Issue 2860323002: net: add IsMethodSafe() method to HttpUtil (Closed)
Patch Set: remove IsMethodSafe() from generic_url_request_job.cc Created 3 years, 7 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 | headless/public/util/generic_url_request_job.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 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 <memory> 5 #include <memory>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_enumerator.h" 8 #include "base/files/file_enumerator.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 13 matching lines...) Expand all
24 #include "headless/public/devtools/domains/tracing.h" 24 #include "headless/public/devtools/domains/tracing.h"
25 #include "headless/public/headless_browser.h" 25 #include "headless/public/headless_browser.h"
26 #include "headless/public/headless_devtools_client.h" 26 #include "headless/public/headless_devtools_client.h"
27 #include "headless/public/headless_devtools_target.h" 27 #include "headless/public/headless_devtools_target.h"
28 #include "headless/public/headless_web_contents.h" 28 #include "headless/public/headless_web_contents.h"
29 #include "headless/test/headless_browser_test.h" 29 #include "headless/test/headless_browser_test.h"
30 #include "headless/test/test_protocol_handler.h" 30 #include "headless/test/test_protocol_handler.h"
31 #include "headless/test/test_url_request_job.h" 31 #include "headless/test/test_url_request_job.h"
32 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 32 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
33 #include "net/cookies/cookie_store.h" 33 #include "net/cookies/cookie_store.h"
34 #include "net/http/http_util.h"
34 #include "net/test/spawned_test_server/spawned_test_server.h" 35 #include "net/test/spawned_test_server/spawned_test_server.h"
35 #include "net/url_request/url_request_context.h" 36 #include "net/url_request/url_request_context.h"
36 #include "testing/gmock/include/gmock/gmock.h" 37 #include "testing/gmock/include/gmock/gmock.h"
37 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
38 #include "ui/base/clipboard/clipboard.h" 39 #include "ui/base/clipboard/clipboard.h"
39 #include "ui/base/clipboard/scoped_clipboard_writer.h" 40 #include "ui/base/clipboard/scoped_clipboard_writer.h"
40 #include "ui/gfx/geometry/size.h" 41 #include "ui/gfx/geometry/size.h"
41 42
42 using testing::UnorderedElementsAre; 43 using testing::UnorderedElementsAre;
43 44
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 // left with the actual screen values. 386 // left with the actual screen values.
386 EXPECT_EQ(kDefaultOptions.window_size.width(), screen_width); 387 EXPECT_EQ(kDefaultOptions.window_size.width(), screen_width);
387 EXPECT_EQ(kDefaultOptions.window_size.height(), screen_height); 388 EXPECT_EQ(kDefaultOptions.window_size.height(), screen_height);
388 #endif // !defined(OS_MACOSX) 389 #endif // !defined(OS_MACOSX)
389 EXPECT_EQ(kDefaultOptions.window_size.width(), window_width); 390 EXPECT_EQ(kDefaultOptions.window_size.width(), window_width);
390 EXPECT_EQ(kDefaultOptions.window_size.height(), window_height); 391 EXPECT_EQ(kDefaultOptions.window_size.height(), window_height);
391 } 392 }
392 393
393 namespace { 394 namespace {
394 395
395 // True if the request method is "safe" (per section 4.2.1 of RFC 7231).
396 bool IsMethodSafe(const std::string& method) {
397 return method == "GET" || method == "HEAD" || method == "OPTIONS" ||
398 method == "TRACE";
399 }
400
401 class ProtocolHandlerWithCookies 396 class ProtocolHandlerWithCookies
402 : public net::URLRequestJobFactory::ProtocolHandler { 397 : public net::URLRequestJobFactory::ProtocolHandler {
403 public: 398 public:
404 ProtocolHandlerWithCookies(net::CookieList* sent_cookies); 399 ProtocolHandlerWithCookies(net::CookieList* sent_cookies);
405 ~ProtocolHandlerWithCookies() override {} 400 ~ProtocolHandlerWithCookies() override {}
406 401
407 net::URLRequestJob* MaybeCreateJob( 402 net::URLRequestJob* MaybeCreateJob(
408 net::URLRequest* request, 403 net::URLRequest* request,
409 net::NetworkDelegate* network_delegate) const override; 404 net::NetworkDelegate* network_delegate) const override;
410 405
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 url::Origin site_for_cookies(request_->first_party_for_cookies()); 456 url::Origin site_for_cookies(request_->first_party_for_cookies());
462 457
463 if (net::registry_controlled_domains::SameDomainOrHost( 458 if (net::registry_controlled_domains::SameDomainOrHost(
464 requested_origin, site_for_cookies, 459 requested_origin, site_for_cookies,
465 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) { 460 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) {
466 if (net::registry_controlled_domains::SameDomainOrHost( 461 if (net::registry_controlled_domains::SameDomainOrHost(
467 requested_origin, request_->initiator(), 462 requested_origin, request_->initiator(),
468 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) { 463 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) {
469 options.set_same_site_cookie_mode( 464 options.set_same_site_cookie_mode(
470 net::CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); 465 net::CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX);
471 } else if (IsMethodSafe(request_->method())) { 466 } else if (net::HttpUtil::IsMethodSafe(request_->method())) {
472 options.set_same_site_cookie_mode( 467 options.set_same_site_cookie_mode(
473 net::CookieOptions::SameSiteCookieMode::INCLUDE_LAX); 468 net::CookieOptions::SameSiteCookieMode::INCLUDE_LAX);
474 } 469 }
475 } 470 }
476 cookie_store->GetCookieListWithOptionsAsync( 471 cookie_store->GetCookieListWithOptionsAsync(
477 request_->url(), options, 472 request_->url(), options,
478 base::Bind(&URLRequestJobWithCookies::SaveCookiesAndStart, 473 base::Bind(&URLRequestJobWithCookies::SaveCookiesAndStart,
479 weak_factory_.GetWeakPtr())); 474 weak_factory_.GetWeakPtr()));
480 } 475 }
481 476
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 891
897 TraceHelper helper(this, target); 892 TraceHelper helper(this, target);
898 RunAsynchronousTest(); 893 RunAsynchronousTest();
899 894
900 std::unique_ptr<base::ListValue> tracing_data = helper.TakeTracingData(); 895 std::unique_ptr<base::ListValue> tracing_data = helper.TakeTracingData();
901 EXPECT_TRUE(tracing_data); 896 EXPECT_TRUE(tracing_data);
902 EXPECT_LT(0u, tracing_data->GetSize()); 897 EXPECT_LT(0u, tracing_data->GetSize());
903 } 898 }
904 899
905 } // namespace headless 900 } // namespace headless
OLDNEW
« no previous file with comments | « no previous file | headless/public/util/generic_url_request_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698