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

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 126112: Add a regression test for 14056. This verifies that HttpNetworkTransaction se... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync to resolve changes to MockSocket Created 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <math.h> // ceil 5 #include <math.h> // ceil
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "net/base/client_socket_factory.h" 8 #include "net/base/client_socket_factory.h"
9 #include "net/base/completion_callback.h" 9 #include "net/base/completion_callback.h"
10 #include "net/base/host_resolver_unittest.h" 10 #include "net/base/host_resolver_unittest.h"
(...skipping 3013 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 3024
3025 TestCompletionCallback callback; 3025 TestCompletionCallback callback;
3026 3026
3027 int rv = trans->Start(&request, &callback); 3027 int rv = trans->Start(&request, &callback);
3028 EXPECT_EQ(ERR_IO_PENDING, rv); 3028 EXPECT_EQ(ERR_IO_PENDING, rv);
3029 3029
3030 rv = callback.WaitForResult(); 3030 rv = callback.WaitForResult();
3031 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); 3031 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv);
3032 } 3032 }
3033 3033
3034 // Host resolution observer used by
3035 // HttpNetworkTransactionTest.ResolveMadeWithReferrer to check that host
3036 // resovle requests are issued with a referrer of |expected_referrer|.
3037 class ResolutionReferrerObserver : public HostResolver::Observer {
3038 public:
3039 explicit ResolutionReferrerObserver(const GURL& expected_referrer)
3040 : expected_referrer_(expected_referrer),
3041 called_start_with_referrer_(false),
3042 called_finish_with_referrer_(false) {
3043 }
3044
3045 virtual void OnStartResolution(int id,
3046 const HostResolver::RequestInfo& info) {
3047 if (info.referrer() == expected_referrer_)
3048 called_start_with_referrer_ = true;
3049 }
3050
3051 virtual void OnFinishResolutionWithStatus(
3052 int id, bool was_resolved, const HostResolver::RequestInfo& info ) {
3053 if (info.referrer() == expected_referrer_)
3054 called_finish_with_referrer_ = true;
3055 }
3056
3057 bool did_complete_with_expected_referrer() const {
3058 return called_start_with_referrer_ && called_finish_with_referrer_;
3059 }
3060
3061 private:
3062 GURL expected_referrer_;
3063 bool called_start_with_referrer_;
3064 bool called_finish_with_referrer_;
3065
3066 DISALLOW_COPY_AND_ASSIGN(ResolutionReferrerObserver);
3067 };
3068
3069 // Make sure that when HostResolver::Resolve() is invoked, it passes through
3070 // the "referrer". This is depended on by the DNS prefetch observer.
3071 TEST_F(HttpNetworkTransactionTest, ResolveMadeWithReferrer) {
3072 GURL referrer = GURL("http://expected-referrer/");
3073 EXPECT_TRUE(referrer.is_valid());
3074 ResolutionReferrerObserver resolution_observer(referrer);
3075
3076 SessionDependencies session_deps;
3077 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(
3078 CreateSession(&session_deps), &session_deps.socket_factory));
3079
3080 // Attach an observer to watch the host resolutions being made.
3081 session_deps.host_resolver.AddObserver(&resolution_observer);
3082
3083 // Connect up a mock socket which will fail when reading.
3084 MockRead data_reads[] = {
3085 MockRead(false, ERR_FAILED),
3086 };
3087 StaticMockSocket data(data_reads, NULL);
3088 session_deps.socket_factory.AddMockSocket(&data);
3089
3090 // Issue a request, containing an HTTP referrer.
3091 HttpRequestInfo request;
3092 request.method = "GET";
3093 request.referrer = referrer;
3094 request.url = GURL("http://www.google.com/");
3095
3096 // Run the request until it fails reading from the socket.
3097 TestCompletionCallback callback;
3098 int rv = trans->Start(&request, &callback);
3099 EXPECT_EQ(ERR_IO_PENDING, rv);
3100 rv = callback.WaitForResult();
3101 EXPECT_EQ(ERR_FAILED, rv);
3102
3103 // Check that the host resolution observer saw |referrer|.
3104 EXPECT_TRUE(resolution_observer.did_complete_with_expected_referrer());
3105 }
3106
3034 } // namespace net 3107 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698