OLD | NEW |
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 "config.h" | 5 #include "config.h" |
6 #include "modules/fetch/FetchResponseData.h" | 6 #include "modules/fetch/FetchResponseData.h" |
7 | 7 |
8 #include "core/dom/DOMArrayBuffer.h" | 8 #include "core/dom/DOMArrayBuffer.h" |
9 #include "modules/fetch/FetchHeaderList.h" | 9 #include "modules/fetch/FetchHeaderList.h" |
10 #include "platform/blob/BlobData.h" | 10 #include "platform/blob/BlobData.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 void CheckHeaders(const WebServiceWorkerResponse& webResponse) | 29 void CheckHeaders(const WebServiceWorkerResponse& webResponse) |
30 { | 30 { |
31 EXPECT_STREQ("foo", webResponse.getHeader("set-cookie").utf8().c_str()); | 31 EXPECT_STREQ("foo", webResponse.getHeader("set-cookie").utf8().c_str()); |
32 EXPECT_STREQ("bar", webResponse.getHeader("bar").utf8().c_str()); | 32 EXPECT_STREQ("bar", webResponse.getHeader("bar").utf8().c_str()); |
33 EXPECT_STREQ("no-cache", webResponse.getHeader("cache-control").utf8().c
_str()); | 33 EXPECT_STREQ("no-cache", webResponse.getHeader("cache-control").utf8().c
_str()); |
34 } | 34 } |
35 }; | 35 }; |
36 | 36 |
| 37 TEST_F(FetchResponseDataTest, HeaderList) |
| 38 { |
| 39 FetchResponseData* responseData = createInternalResponse(); |
| 40 |
| 41 Vector<String> setCookieValues; |
| 42 responseData->headerList()->getAll("set-cookie", setCookieValues); |
| 43 ASSERT_EQ(1U, setCookieValues.size()); |
| 44 EXPECT_EQ("foo", setCookieValues[0]); |
| 45 |
| 46 Vector<String> barValues; |
| 47 responseData->headerList()->getAll("bar", barValues); |
| 48 ASSERT_EQ(1U, barValues.size()); |
| 49 EXPECT_EQ("bar", barValues[0]); |
| 50 |
| 51 Vector<String> cacheControlValues; |
| 52 responseData->headerList()->getAll("cache-control", cacheControlValues); |
| 53 ASSERT_EQ(1U, cacheControlValues.size()); |
| 54 EXPECT_EQ("no-cache", cacheControlValues[0]); |
| 55 } |
| 56 |
37 TEST_F(FetchResponseDataTest, ToWebServiceWorkerDefaultType) | 57 TEST_F(FetchResponseDataTest, ToWebServiceWorkerDefaultType) |
38 { | 58 { |
39 WebServiceWorkerResponse webResponse; | 59 WebServiceWorkerResponse webResponse; |
40 FetchResponseData* internalResponse = createInternalResponse(); | 60 FetchResponseData* internalResponse = createInternalResponse(); |
41 | 61 |
42 internalResponse->populateWebServiceWorkerResponse(webResponse); | 62 internalResponse->populateWebServiceWorkerResponse(webResponse); |
43 EXPECT_EQ(WebServiceWorkerResponseTypeDefault, webResponse.responseType()); | 63 EXPECT_EQ(WebServiceWorkerResponseTypeDefault, webResponse.responseType()); |
44 CheckHeaders(webResponse); | 64 CheckHeaders(webResponse); |
45 } | 65 } |
46 | 66 |
| 67 TEST_F(FetchResponseDataTest, BasicFilter) |
| 68 { |
| 69 FetchResponseData* internalResponse = createInternalResponse(); |
| 70 FetchResponseData* basicResponseData = internalResponse->createBasicFiltered
Response(); |
| 71 |
| 72 EXPECT_FALSE(basicResponseData->headerList()->has("set-cookie")); |
| 73 |
| 74 Vector<String> barValues; |
| 75 basicResponseData->headerList()->getAll("bar", barValues); |
| 76 ASSERT_EQ(1U, barValues.size()); |
| 77 EXPECT_EQ("bar", barValues[0]); |
| 78 |
| 79 Vector<String> cacheControlValues; |
| 80 basicResponseData->headerList()->getAll("cache-control", cacheControlValues)
; |
| 81 ASSERT_EQ(1U, cacheControlValues.size()); |
| 82 EXPECT_EQ("no-cache", cacheControlValues[0]); |
| 83 } |
| 84 |
47 TEST_F(FetchResponseDataTest, ToWebServiceWorkerBasicType) | 85 TEST_F(FetchResponseDataTest, ToWebServiceWorkerBasicType) |
48 { | 86 { |
49 WebServiceWorkerResponse webResponse; | 87 WebServiceWorkerResponse webResponse; |
50 FetchResponseData* internalResponse = createInternalResponse(); | 88 FetchResponseData* internalResponse = createInternalResponse(); |
51 FetchResponseData* basicResponseData = internalResponse->createBasicFiltered
Response(); | 89 FetchResponseData* basicResponseData = internalResponse->createBasicFiltered
Response(); |
52 | 90 |
53 basicResponseData->populateWebServiceWorkerResponse(webResponse); | 91 basicResponseData->populateWebServiceWorkerResponse(webResponse); |
54 EXPECT_EQ(WebServiceWorkerResponseTypeBasic, webResponse.responseType()); | 92 EXPECT_EQ(WebServiceWorkerResponseTypeBasic, webResponse.responseType()); |
55 CheckHeaders(webResponse); | 93 CheckHeaders(webResponse); |
56 } | 94 } |
57 | 95 |
| 96 TEST_F(FetchResponseDataTest, CORSFilter) |
| 97 { |
| 98 FetchResponseData* internalResponse = createInternalResponse(); |
| 99 FetchResponseData* corsResponseData = internalResponse->createCORSFilteredRe
sponse(); |
| 100 |
| 101 EXPECT_FALSE(corsResponseData->headerList()->has("set-cookie")); |
| 102 |
| 103 EXPECT_FALSE(corsResponseData->headerList()->has("bar")); |
| 104 |
| 105 Vector<String> cacheControlValues; |
| 106 corsResponseData->headerList()->getAll("cache-control", cacheControlValues); |
| 107 ASSERT_EQ(1U, cacheControlValues.size()); |
| 108 EXPECT_EQ("no-cache", cacheControlValues[0]); |
| 109 } |
| 110 |
| 111 TEST_F(FetchResponseDataTest, CORSFilterOnResponseWithAccessControlExposeHeaders
) |
| 112 { |
| 113 FetchResponseData* internalResponse = createInternalResponse(); |
| 114 internalResponse->headerList()->append("access-control-expose-headers", "set
-cookie, bar"); |
| 115 |
| 116 FetchResponseData* corsResponseData = internalResponse->createCORSFilteredRe
sponse(); |
| 117 |
| 118 EXPECT_FALSE(corsResponseData->headerList()->has("set-cookie")); |
| 119 |
| 120 Vector<String> barValues; |
| 121 corsResponseData->headerList()->getAll("bar", barValues); |
| 122 ASSERT_EQ(1U, barValues.size()); |
| 123 EXPECT_EQ("bar", barValues[0]); |
| 124 } |
| 125 |
58 TEST_F(FetchResponseDataTest, ToWebServiceWorkerCORSType) | 126 TEST_F(FetchResponseDataTest, ToWebServiceWorkerCORSType) |
59 { | 127 { |
60 WebServiceWorkerResponse webResponse; | 128 WebServiceWorkerResponse webResponse; |
61 FetchResponseData* internalResponse = createInternalResponse(); | 129 FetchResponseData* internalResponse = createInternalResponse(); |
62 FetchResponseData* corsResponseData = internalResponse->createCORSFilteredRe
sponse(); | 130 FetchResponseData* corsResponseData = internalResponse->createCORSFilteredRe
sponse(); |
63 | 131 |
64 corsResponseData->populateWebServiceWorkerResponse(webResponse); | 132 corsResponseData->populateWebServiceWorkerResponse(webResponse); |
65 EXPECT_EQ(WebServiceWorkerResponseTypeCORS, webResponse.responseType()); | 133 EXPECT_EQ(WebServiceWorkerResponseTypeCORS, webResponse.responseType()); |
66 CheckHeaders(webResponse); | 134 CheckHeaders(webResponse); |
67 } | 135 } |
68 | 136 |
| 137 TEST_F(FetchResponseDataTest, OpaqueFilter) |
| 138 { |
| 139 FetchResponseData* internalResponse = createInternalResponse(); |
| 140 FetchResponseData* opaqueResponseData = internalResponse->createOpaqueFilter
edResponse(); |
| 141 |
| 142 EXPECT_FALSE(opaqueResponseData->headerList()->has("set-cookie")); |
| 143 EXPECT_FALSE(opaqueResponseData->headerList()->has("bar")); |
| 144 EXPECT_FALSE(opaqueResponseData->headerList()->has("cache-control")); |
| 145 } |
| 146 |
| 147 TEST_F(FetchResponseDataTest, OpaqueFilterOnResponseWithAccessControlExposeHeade
rs) |
| 148 { |
| 149 FetchResponseData* internalResponse = createInternalResponse(); |
| 150 internalResponse->headerList()->append("access-control-expose-headers", "set
-cookie, bar"); |
| 151 |
| 152 FetchResponseData* opaqueResponseData = internalResponse->createOpaqueFilter
edResponse(); |
| 153 |
| 154 EXPECT_FALSE(opaqueResponseData->headerList()->has("set-cookie")); |
| 155 EXPECT_FALSE(opaqueResponseData->headerList()->has("bar")); |
| 156 EXPECT_FALSE(opaqueResponseData->headerList()->has("cache-control")); |
| 157 } |
| 158 |
69 TEST_F(FetchResponseDataTest, ToWebServiceWorkerOpaqueType) | 159 TEST_F(FetchResponseDataTest, ToWebServiceWorkerOpaqueType) |
70 { | 160 { |
71 WebServiceWorkerResponse webResponse; | 161 WebServiceWorkerResponse webResponse; |
72 FetchResponseData* internalResponse = createInternalResponse(); | 162 FetchResponseData* internalResponse = createInternalResponse(); |
73 FetchResponseData* opaqueResponseData = internalResponse->createOpaqueFilter
edResponse(); | 163 FetchResponseData* opaqueResponseData = internalResponse->createOpaqueFilter
edResponse(); |
74 | 164 |
75 opaqueResponseData->populateWebServiceWorkerResponse(webResponse); | 165 opaqueResponseData->populateWebServiceWorkerResponse(webResponse); |
76 EXPECT_EQ(WebServiceWorkerResponseTypeOpaque, webResponse.responseType()); | 166 EXPECT_EQ(WebServiceWorkerResponseTypeOpaque, webResponse.responseType()); |
77 CheckHeaders(webResponse); | 167 CheckHeaders(webResponse); |
78 } | 168 } |
79 | 169 |
80 TEST_F(FetchResponseDataTest, ToWebServiceWorkerOpaqueRedirectType) | 170 TEST_F(FetchResponseDataTest, ToWebServiceWorkerOpaqueRedirectType) |
81 { | 171 { |
82 WebServiceWorkerResponse webResponse; | 172 WebServiceWorkerResponse webResponse; |
83 FetchResponseData* internalResponse = createInternalResponse(); | 173 FetchResponseData* internalResponse = createInternalResponse(); |
84 FetchResponseData* opaqueRedirectResponseData = internalResponse->createOpaq
ueRedirectFilteredResponse(); | 174 FetchResponseData* opaqueRedirectResponseData = internalResponse->createOpaq
ueRedirectFilteredResponse(); |
85 | 175 |
86 opaqueRedirectResponseData->populateWebServiceWorkerResponse(webResponse); | 176 opaqueRedirectResponseData->populateWebServiceWorkerResponse(webResponse); |
87 EXPECT_EQ(WebServiceWorkerResponseTypeOpaqueRedirect, webResponse.responseTy
pe()); | 177 EXPECT_EQ(WebServiceWorkerResponseTypeOpaqueRedirect, webResponse.responseTy
pe()); |
88 CheckHeaders(webResponse); | 178 CheckHeaders(webResponse); |
89 } | 179 } |
90 | 180 |
91 } // namespace WebCore | 181 } // namespace WebCore |
OLD | NEW |