File: ResourceRequestTest.cpp

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (149 lines) | stat: -rw-r--r-- 6,968 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "platform/network/ResourceRequest.h"

#include "platform/network/EncodedFormData.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/Referrer.h"
#include "public/platform/WebCachePolicy.h"
#include "public/platform/WebURLRequest.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/text/AtomicString.h"
#include <memory>

namespace blink {

TEST(ResourceRequestTest, RequestorOriginNonNull) {
  ResourceRequest req;
  EXPECT_NE(nullptr, req.requestorOrigin().get());
  EXPECT_TRUE(req.requestorOrigin()->isUnique());
}

TEST(ResourceRequestTest, CrossThreadResourceRequestData) {
  ResourceRequest original;
  original.setURL(KURL(ParsedURLString, "http://www.example.com/test.htm"));
  original.setCachePolicy(WebCachePolicy::UseProtocolCachePolicy);
  original.setTimeoutInterval(10);
  original.setFirstPartyForCookies(
      KURL(ParsedURLString, "http://www.example.com/first_party.htm"));
  original.setRequestorOrigin(SecurityOrigin::create(
      KURL(ParsedURLString, "http://www.example.com/first_party.htm")));
  original.setHTTPMethod(HTTPNames::GET);
  original.setHTTPHeaderField(AtomicString("Foo"), AtomicString("Bar"));
  original.setHTTPHeaderField(AtomicString("Piyo"), AtomicString("Fuga"));
  original.setPriority(ResourceLoadPriorityLow, 20);

  RefPtr<EncodedFormData> originalBody(EncodedFormData::create("Test Body"));
  original.setHTTPBody(originalBody);
  original.setAllowStoredCredentials(false);
  original.setReportUploadProgress(false);
  original.setHasUserGesture(false);
  original.setDownloadToFile(false);
  original.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::None);
  original.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS);
  original.setFetchCredentialsMode(
      WebURLRequest::FetchCredentialsModeSameOrigin);
  original.setRequestorID(30);
  original.setRequestorProcessID(40);
  original.setAppCacheHostID(50);
  original.setRequestContext(WebURLRequest::RequestContextAudio);
  original.setFrameType(WebURLRequest::FrameTypeNested);
  original.setHTTPReferrer(
      Referrer("http://www.example.com/referrer.htm", ReferrerPolicyDefault));

  EXPECT_STREQ("http://www.example.com/test.htm",
               original.url().getString().utf8().data());
  EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, original.getCachePolicy());
  EXPECT_EQ(10, original.timeoutInterval());
  EXPECT_STREQ("http://www.example.com/first_party.htm",
               original.firstPartyForCookies().getString().utf8().data());
  EXPECT_STREQ("www.example.com",
               original.requestorOrigin()->host().utf8().data());
  EXPECT_STREQ("GET", original.httpMethod().utf8().data());
  EXPECT_STREQ("Bar", original.httpHeaderFields().get("Foo").utf8().data());
  EXPECT_STREQ("Fuga", original.httpHeaderFields().get("Piyo").utf8().data());
  EXPECT_EQ(ResourceLoadPriorityLow, original.priority());
  EXPECT_STREQ("Test Body",
               original.httpBody()->flattenToString().utf8().data());
  EXPECT_FALSE(original.allowStoredCredentials());
  EXPECT_FALSE(original.reportUploadProgress());
  EXPECT_FALSE(original.hasUserGesture());
  EXPECT_FALSE(original.downloadToFile());
  EXPECT_EQ(WebURLRequest::SkipServiceWorker::None,
            original.skipServiceWorker());
  EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, original.fetchRequestMode());
  EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin,
            original.fetchCredentialsMode());
  EXPECT_EQ(30, original.requestorID());
  EXPECT_EQ(40, original.requestorProcessID());
  EXPECT_EQ(50, original.appCacheHostID());
  EXPECT_EQ(WebURLRequest::RequestContextAudio, original.requestContext());
  EXPECT_EQ(WebURLRequest::FrameTypeNested, original.frameType());
  EXPECT_STREQ("http://www.example.com/referrer.htm",
               original.httpReferrer().utf8().data());
  EXPECT_EQ(ReferrerPolicyDefault, original.getReferrerPolicy());

  std::unique_ptr<CrossThreadResourceRequestData> data1(original.copyData());
  ResourceRequest copy1(data1.get());

  EXPECT_STREQ("http://www.example.com/test.htm",
               copy1.url().getString().utf8().data());
  EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, copy1.getCachePolicy());
  EXPECT_EQ(10, copy1.timeoutInterval());
  EXPECT_STREQ("http://www.example.com/first_party.htm",
               copy1.firstPartyForCookies().getString().utf8().data());
  EXPECT_STREQ("www.example.com",
               copy1.requestorOrigin()->host().utf8().data());
  EXPECT_STREQ("GET", copy1.httpMethod().utf8().data());
  EXPECT_STREQ("Bar", copy1.httpHeaderFields().get("Foo").utf8().data());
  EXPECT_EQ(ResourceLoadPriorityLow, copy1.priority());
  EXPECT_STREQ("Test Body", copy1.httpBody()->flattenToString().utf8().data());
  EXPECT_FALSE(copy1.allowStoredCredentials());
  EXPECT_FALSE(copy1.reportUploadProgress());
  EXPECT_FALSE(copy1.hasUserGesture());
  EXPECT_FALSE(copy1.downloadToFile());
  EXPECT_EQ(WebURLRequest::SkipServiceWorker::None, copy1.skipServiceWorker());
  EXPECT_EQ(WebURLRequest::FetchRequestModeCORS, copy1.fetchRequestMode());
  EXPECT_EQ(WebURLRequest::FetchCredentialsModeSameOrigin,
            copy1.fetchCredentialsMode());
  EXPECT_EQ(30, copy1.requestorID());
  EXPECT_EQ(40, copy1.requestorProcessID());
  EXPECT_EQ(50, copy1.appCacheHostID());
  EXPECT_EQ(WebURLRequest::RequestContextAudio, copy1.requestContext());
  EXPECT_EQ(WebURLRequest::FrameTypeNested, copy1.frameType());
  EXPECT_STREQ("http://www.example.com/referrer.htm",
               copy1.httpReferrer().utf8().data());
  EXPECT_EQ(ReferrerPolicyDefault, copy1.getReferrerPolicy());

  copy1.setAllowStoredCredentials(true);
  copy1.setReportUploadProgress(true);
  copy1.setHasUserGesture(true);
  copy1.setDownloadToFile(true);
  copy1.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All);
  copy1.setFetchRequestMode(WebURLRequest::FetchRequestModeNoCORS);
  copy1.setFetchCredentialsMode(WebURLRequest::FetchCredentialsModeInclude);

  std::unique_ptr<CrossThreadResourceRequestData> data2(copy1.copyData());
  ResourceRequest copy2(data2.get());
  EXPECT_TRUE(copy2.allowStoredCredentials());
  EXPECT_TRUE(copy2.reportUploadProgress());
  EXPECT_TRUE(copy2.hasUserGesture());
  EXPECT_TRUE(copy2.downloadToFile());
  EXPECT_EQ(WebURLRequest::SkipServiceWorker::All, copy2.skipServiceWorker());
  EXPECT_EQ(WebURLRequest::FetchRequestModeNoCORS, copy1.fetchRequestMode());
  EXPECT_EQ(WebURLRequest::FetchCredentialsModeInclude,
            copy1.fetchCredentialsMode());
}

TEST(ResourceRequestTest, SetHasUserGesture) {
  ResourceRequest original;
  EXPECT_FALSE(original.hasUserGesture());
  original.setHasUserGesture(true);
  EXPECT_TRUE(original.hasUserGesture());
  original.setHasUserGesture(false);
  EXPECT_TRUE(original.hasUserGesture());
}

}  // namespace blink