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

Side by Side Diff: net/url_request/url_request_http_job_unittest.cc

Issue 1563163002: Don't pass SDCH GetDictionary event for cached responses (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test added Created 4 years, 10 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 | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "net/url_request/url_request_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <cstddef> 9 #include <cstddef>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
16 #include "net/base/auth.h" 16 #include "net/base/auth.h"
17 #include "net/base/request_priority.h" 17 #include "net/base/request_priority.h"
18 #include "net/base/sdch_observer.h"
18 #include "net/base/test_data_directory.h" 19 #include "net/base/test_data_directory.h"
19 #include "net/cookies/cookie_store_test_helpers.h" 20 #include "net/cookies/cookie_store_test_helpers.h"
20 #include "net/http/http_transaction_factory.h" 21 #include "net/http/http_transaction_factory.h"
21 #include "net/http/http_transaction_test_util.h" 22 #include "net/http/http_transaction_test_util.h"
22 #include "net/socket/socket_test_util.h" 23 #include "net/socket/socket_test_util.h"
23 #include "net/test/cert_test_util.h" 24 #include "net/test/cert_test_util.h"
24 #include "net/url_request/url_request.h" 25 #include "net/url_request/url_request.h"
25 #include "net/url_request/url_request_status.h" 26 #include "net/url_request/url_request_status.h"
26 #include "net/url_request/url_request_test_util.h" 27 #include "net/url_request/url_request_test_util.h"
27 #include "net/websockets/websocket_handshake_stream_base.h" 28 #include "net/websockets/websocket_handshake_stream_base.h"
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 600
600 // Confirm we don't advertise SDCH encoding in the case of a POST. 601 // Confirm we don't advertise SDCH encoding in the case of a POST.
601 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) { 602 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) {
602 EnableSdch(); 603 EnableSdch();
603 req_->set_method("POST"); 604 req_->set_method("POST");
604 scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get())); 605 scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get()));
605 job->Start(); 606 job->Start();
606 EXPECT_FALSE(TransactionAcceptsSdchEncoding()); 607 EXPECT_FALSE(TransactionAcceptsSdchEncoding());
607 } 608 }
608 609
610 class MockSdchObserver : public SdchObserver {
611 public:
612 MockSdchObserver() {}
613 MOCK_METHOD2(OnDictionaryAdded,
614 void(const GURL& request_url, const std::string& server_hash));
615 MOCK_METHOD1(OnDictionaryRemoved, void(const std::string& server_hash));
616 MOCK_METHOD1(OnDictionaryUsed, void(const std::string& server_hash));
617 MOCK_METHOD2(OnGetDictionary,
618 void(const GURL& request_url, const GURL& dictionary_url));
619 MOCK_METHOD0(OnClearDictionaries, void());
620 };
621
622 class URLRequestHttpJobWithSdchSupportTest : public ::testing::Test {
623 protected:
624 URLRequestHttpJobWithSdchSupportTest() : context_(true) {
625 scoped_ptr<HttpNetworkSession::Params> params(
626 new HttpNetworkSession::Params);
627 context_.set_http_network_session_params(std::move(params));
628 context_.set_client_socket_factory(&socket_factory_);
629 context_.Init();
630 }
631
632 MockClientSocketFactory socket_factory_;
633 TestURLRequestContext context_;
634 };
635
636 TEST_F(URLRequestHttpJobWithSdchSupportTest, GetDictionary) {
637 MockWrite writes[] = {
638 MockWrite("GET / HTTP/1.1\r\n"
639 "Host: example.com\r\n"
640 "Connection: keep-alive\r\n"
641 "User-Agent:\r\n"
642 "Accept-Encoding: gzip, deflate, sdch\r\n"
643 "Accept-Language: en-us,fr\r\n\r\n")};
644
645 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
646 "Get-Dictionary: /sdch.dict\r\n"
647 "Cache-Control: max-age=120\r\n"
648 "Content-Length: 12\r\n\r\n"),
649 MockRead("Test Content")};
650 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
651 arraysize(writes));
652 socket_factory_.AddSocketDataProvider(&socket_data);
653
654 MockSdchObserver sdch_observer;
655 SdchManager sdch_manager;
656 sdch_manager.AddObserver(&sdch_observer);
657 context_.set_sdch_manager(&sdch_manager);
658
659 // First response will be "from network" and we should have OnGetDictionary
660 // invoked.
661 GURL url("http://example.com");
662 EXPECT_CALL(sdch_observer,
663 OnGetDictionary(url, GURL("http://example.com/sdch.dict")));
664 TestDelegate delegate;
665 scoped_ptr<URLRequest> request =
666 context_.CreateRequest(url, DEFAULT_PRIORITY, &delegate);
667 request->Start();
668 base::RunLoop().RunUntilIdle();
669
670 EXPECT_TRUE(request->status().is_success());
671
672 // Second response should be from cache without notification of SdchObserver
673 TestDelegate delegate2;
674 scoped_ptr<URLRequest> request2 =
675 context_.CreateRequest(url, DEFAULT_PRIORITY, &delegate2);
676 request2->Start();
677 base::RunLoop().RunUntilIdle();
678
679 EXPECT_TRUE(request->status().is_success());
680
681 // Cleanup manager.
682 sdch_manager.RemoveObserver(&sdch_observer);
683 }
684
609 class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test { 685 class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test {
610 protected: 686 protected:
611 URLRequestHttpJobWithBrotliSupportTest() 687 URLRequestHttpJobWithBrotliSupportTest()
612 : context_(new TestURLRequestContext(true)) { 688 : context_(new TestURLRequestContext(true)) {
613 scoped_ptr<HttpNetworkSession::Params> params( 689 scoped_ptr<HttpNetworkSession::Params> params(
614 new HttpNetworkSession::Params); 690 new HttpNetworkSession::Params);
615 params->enable_brotli = true; 691 params->enable_brotli = true;
616 context_->set_http_network_session_params(std::move(params)); 692 context_->set_http_network_session_params(std::move(params));
617 context_->set_client_socket_factory(&socket_factory_); 693 context_->set_client_socket_factory(&socket_factory_);
618 context_->Init(); 694 context_->Init();
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 req_->SetLoadFlags(LOAD_DISABLE_CACHE); 916 req_->SetLoadFlags(LOAD_DISABLE_CACHE);
841 job->Start(); 917 job->Start();
842 base::RunLoop().RunUntilIdle(); 918 base::RunLoop().RunUntilIdle();
843 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); 919 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status());
844 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); 920 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called());
845 } 921 }
846 922
847 } // namespace 923 } // namespace
848 924
849 } // namespace net 925 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698