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

Side by Side Diff: third_party/WebKit/Source/platform/network/ResourceRequestTest.cpp

Issue 2254693002: Delay generation of User-Agent header to URLRequestHttpJob and accept custom User-Agent from XHR/Fe… Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed Android test Created 4 years, 3 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
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 "platform/network/ResourceRequest.h" 5 #include "platform/network/ResourceRequest.h"
6 6
7 #include "platform/network/EncodedFormData.h" 7 #include "platform/network/EncodedFormData.h"
8 #include "platform/weborigin/KURL.h" 8 #include "platform/weborigin/KURL.h"
9 #include "platform/weborigin/Referrer.h" 9 #include "platform/weborigin/Referrer.h"
10 #include "public/platform/WebCachePolicy.h" 10 #include "public/platform/WebCachePolicy.h"
(...skipping 15 matching lines...) Expand all
26 { 26 {
27 ResourceRequest original; 27 ResourceRequest original;
28 original.setURL(KURL(ParsedURLString, "http://www.example.com/test.htm")); 28 original.setURL(KURL(ParsedURLString, "http://www.example.com/test.htm"));
29 original.setCachePolicy(WebCachePolicy::UseProtocolCachePolicy); 29 original.setCachePolicy(WebCachePolicy::UseProtocolCachePolicy);
30 original.setTimeoutInterval(10); 30 original.setTimeoutInterval(10);
31 original.setFirstPartyForCookies(KURL(ParsedURLString, "http://www.example.c om/first_party.htm")); 31 original.setFirstPartyForCookies(KURL(ParsedURLString, "http://www.example.c om/first_party.htm"));
32 original.setRequestorOrigin(SecurityOrigin::create(KURL(ParsedURLString, "ht tp://www.example.com/first_party.htm"))); 32 original.setRequestorOrigin(SecurityOrigin::create(KURL(ParsedURLString, "ht tp://www.example.com/first_party.htm")));
33 original.setHTTPMethod(HTTPNames::GET); 33 original.setHTTPMethod(HTTPNames::GET);
34 original.setHTTPHeaderField(AtomicString("Foo"), AtomicString("Bar")); 34 original.setHTTPHeaderField(AtomicString("Foo"), AtomicString("Bar"));
35 original.setHTTPHeaderField(AtomicString("Piyo"), AtomicString("Fuga")); 35 original.setHTTPHeaderField(AtomicString("Piyo"), AtomicString("Fuga"));
36 original.setDefaultHTTPUserAgent("Human");
36 original.setPriority(ResourceLoadPriorityLow, 20); 37 original.setPriority(ResourceLoadPriorityLow, 20);
37 38
38 RefPtr<EncodedFormData> originalBody(EncodedFormData::create("Test Body")); 39 RefPtr<EncodedFormData> originalBody(EncodedFormData::create("Test Body"));
39 original.setHTTPBody(originalBody); 40 original.setHTTPBody(originalBody);
40 original.setAllowStoredCredentials(false); 41 original.setAllowStoredCredentials(false);
41 original.setReportUploadProgress(false); 42 original.setReportUploadProgress(false);
42 original.setHasUserGesture(false); 43 original.setHasUserGesture(false);
43 original.setDownloadToFile(false); 44 original.setDownloadToFile(false);
44 original.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::None); 45 original.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::None);
45 original.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS); 46 original.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS);
46 original.setFetchCredentialsMode(WebURLRequest::FetchCredentialsModeSameOrig in); 47 original.setFetchCredentialsMode(WebURLRequest::FetchCredentialsModeSameOrig in);
47 original.setRequestorID(30); 48 original.setRequestorID(30);
48 original.setRequestorProcessID(40); 49 original.setRequestorProcessID(40);
49 original.setAppCacheHostID(50); 50 original.setAppCacheHostID(50);
50 original.setRequestContext(WebURLRequest::RequestContextAudio); 51 original.setRequestContext(WebURLRequest::RequestContextAudio);
51 original.setFrameType(WebURLRequest::FrameTypeNested); 52 original.setFrameType(WebURLRequest::FrameTypeNested);
52 original.setHTTPReferrer(Referrer("http://www.example.com/referrer.htm", Ref errerPolicyDefault)); 53 original.setHTTPReferrer(Referrer("http://www.example.com/referrer.htm", Ref errerPolicyDefault));
53 54
54 EXPECT_STREQ("http://www.example.com/test.htm", original.url().getString().u tf8().data()); 55 EXPECT_STREQ("http://www.example.com/test.htm", original.url().getString().u tf8().data());
55 EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, original.getCachePolicy()) ; 56 EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, original.getCachePolicy()) ;
56 EXPECT_EQ(10, original.timeoutInterval()); 57 EXPECT_EQ(10, original.timeoutInterval());
57 EXPECT_STREQ("http://www.example.com/first_party.htm", original.firstPartyFo rCookies().getString().utf8().data()); 58 EXPECT_STREQ("http://www.example.com/first_party.htm", original.firstPartyFo rCookies().getString().utf8().data());
58 EXPECT_STREQ("www.example.com", original.requestorOrigin()->host().utf8().da ta()); 59 EXPECT_STREQ("www.example.com", original.requestorOrigin()->host().utf8().da ta());
59 EXPECT_STREQ("GET", original.httpMethod().utf8().data()); 60 EXPECT_STREQ("GET", original.httpMethod().utf8().data());
60 EXPECT_STREQ("Bar", original.httpHeaderFields().get("Foo").utf8().data()); 61 EXPECT_STREQ("Bar", original.httpHeaderFields().get("Foo").utf8().data());
61 EXPECT_STREQ("Fuga", original.httpHeaderFields().get("Piyo").utf8().data()); 62 EXPECT_STREQ("Fuga", original.httpHeaderFields().get("Piyo").utf8().data());
63 EXPECT_STREQ("Human", original.defaultHTTPUserAgent().utf8().data());
62 EXPECT_EQ(ResourceLoadPriorityLow, original.priority()); 64 EXPECT_EQ(ResourceLoadPriorityLow, original.priority());
63 EXPECT_STREQ("Test Body", original.httpBody()->flattenToString().utf8().data ()); 65 EXPECT_STREQ("Test Body", original.httpBody()->flattenToString().utf8().data ());
64 EXPECT_FALSE(original.allowStoredCredentials()); 66 EXPECT_FALSE(original.allowStoredCredentials());
65 EXPECT_FALSE(original.reportUploadProgress()); 67 EXPECT_FALSE(original.reportUploadProgress());
66 EXPECT_FALSE(original.hasUserGesture()); 68 EXPECT_FALSE(original.hasUserGesture());
67 EXPECT_FALSE(original.downloadToFile()); 69 EXPECT_FALSE(original.downloadToFile());
68 EXPECT_EQ(WebURLRequest::SkipServiceWorker::None, original.skipServiceWorker ()); 70 EXPECT_EQ(WebURLRequest::SkipServiceWorker::None, original.skipServiceWorker ());
69 EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, original.fetchRequestMode()); 71 EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, original.fetchRequestMode());
70 EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin, original.fetchCrede ntialsMode()); 72 EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin, original.fetchCrede ntialsMode());
71 EXPECT_EQ(30, original.requestorID()); 73 EXPECT_EQ(30, original.requestorID());
72 EXPECT_EQ(40, original.requestorProcessID()); 74 EXPECT_EQ(40, original.requestorProcessID());
73 EXPECT_EQ(50, original.appCacheHostID()); 75 EXPECT_EQ(50, original.appCacheHostID());
74 EXPECT_EQ(WebURLRequest::RequestContextAudio, original.requestContext()); 76 EXPECT_EQ(WebURLRequest::RequestContextAudio, original.requestContext());
75 EXPECT_EQ(WebURLRequest::FrameTypeNested, original.frameType()); 77 EXPECT_EQ(WebURLRequest::FrameTypeNested, original.frameType());
76 EXPECT_STREQ("http://www.example.com/referrer.htm", original.httpReferrer(). utf8().data()); 78 EXPECT_STREQ("http://www.example.com/referrer.htm", original.httpReferrer(). utf8().data());
77 EXPECT_EQ(ReferrerPolicyDefault, original.getReferrerPolicy()); 79 EXPECT_EQ(ReferrerPolicyDefault, original.getReferrerPolicy());
78 80
79 std::unique_ptr<CrossThreadResourceRequestData> data1(original.copyData()); 81 std::unique_ptr<CrossThreadResourceRequestData> data1(original.copyData());
80 ResourceRequest copy1(data1.get()); 82 ResourceRequest copy1(data1.get());
81 83
82 EXPECT_STREQ("http://www.example.com/test.htm", copy1.url().getString().utf8 ().data()); 84 EXPECT_STREQ("http://www.example.com/test.htm", copy1.url().getString().utf8 ().data());
83 EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, copy1.getCachePolicy()); 85 EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, copy1.getCachePolicy());
84 EXPECT_EQ(10, copy1.timeoutInterval()); 86 EXPECT_EQ(10, copy1.timeoutInterval());
85 EXPECT_STREQ("http://www.example.com/first_party.htm", copy1.firstPartyForCo okies().getString().utf8().data()); 87 EXPECT_STREQ("http://www.example.com/first_party.htm", copy1.firstPartyForCo okies().getString().utf8().data());
86 EXPECT_STREQ("www.example.com", copy1.requestorOrigin()->host().utf8().data( )); 88 EXPECT_STREQ("www.example.com", copy1.requestorOrigin()->host().utf8().data( ));
87 EXPECT_STREQ("GET", copy1.httpMethod().utf8().data()); 89 EXPECT_STREQ("GET", copy1.httpMethod().utf8().data());
88 EXPECT_STREQ("Bar", copy1.httpHeaderFields().get("Foo").utf8().data()); 90 EXPECT_STREQ("Bar", copy1.httpHeaderFields().get("Foo").utf8().data());
91 EXPECT_STREQ("Human", copy1.defaultHTTPUserAgent().utf8().data());
89 EXPECT_EQ(ResourceLoadPriorityLow, copy1.priority()); 92 EXPECT_EQ(ResourceLoadPriorityLow, copy1.priority());
90 EXPECT_STREQ("Test Body", copy1.httpBody()->flattenToString().utf8().data()) ; 93 EXPECT_STREQ("Test Body", copy1.httpBody()->flattenToString().utf8().data()) ;
91 EXPECT_FALSE(copy1.allowStoredCredentials()); 94 EXPECT_FALSE(copy1.allowStoredCredentials());
92 EXPECT_FALSE(copy1.reportUploadProgress()); 95 EXPECT_FALSE(copy1.reportUploadProgress());
93 EXPECT_FALSE(copy1.hasUserGesture()); 96 EXPECT_FALSE(copy1.hasUserGesture());
94 EXPECT_FALSE(copy1.downloadToFile()); 97 EXPECT_FALSE(copy1.downloadToFile());
95 EXPECT_EQ(WebURLRequest::SkipServiceWorker::None, copy1.skipServiceWorker()) ; 98 EXPECT_EQ(WebURLRequest::SkipServiceWorker::None, copy1.skipServiceWorker()) ;
96 EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, copy1.fetchRequestMode()); 99 EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, copy1.fetchRequestMode());
97 EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin, copy1.fetchCredenti alsMode()); 100 EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin, copy1.fetchCredenti alsMode());
98 EXPECT_EQ(30, copy1.requestorID()); 101 EXPECT_EQ(30, copy1.requestorID());
(...skipping 27 matching lines...) Expand all
126 { 129 {
127 ResourceRequest original; 130 ResourceRequest original;
128 EXPECT_FALSE(original.hasUserGesture()); 131 EXPECT_FALSE(original.hasUserGesture());
129 original.setHasUserGesture(true); 132 original.setHasUserGesture(true);
130 EXPECT_TRUE(original.hasUserGesture()); 133 EXPECT_TRUE(original.hasUserGesture());
131 original.setHasUserGesture(false); 134 original.setHasUserGesture(false);
132 EXPECT_TRUE(original.hasUserGesture()); 135 EXPECT_TRUE(original.hasUserGesture());
133 } 136 }
134 137
135 } // namespace blink 138 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698