| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 EXPECT_EQ(nullptr, resource->resourceBuffer()); | 164 EXPECT_EQ(nullptr, resource->resourceBuffer()); |
| 165 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm
l,")), resource.get()); | 165 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm
l,")), resource.get()); |
| 166 memoryCache()->remove(resource.get()); | 166 memoryCache()->remove(resource.get()); |
| 167 | 167 |
| 168 resource->removeClient(client.get()); | 168 resource->removeClient(client.get()); |
| 169 EXPECT_FALSE(resource->hasClientsOrObservers()); | 169 EXPECT_FALSE(resource->hasClientsOrObservers()); |
| 170 EXPECT_FALSE(client->called()); | 170 EXPECT_FALSE(client->called()); |
| 171 EXPECT_EQ(0u, client->data().size()); | 171 EXPECT_EQ(0u, client->data().size()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 TEST(RawResourceTest, RevalidationSucceededUpdateHeaders) |
| 175 { |
| 176 RefPtrWillBeRawPtr<Resource> resource = RawResource::create(ResourceRequest(
"data:text/html,"), Resource::Raw); |
| 177 ResourceResponse response; |
| 178 response.setHTTPStatusCode(200); |
| 179 response.addHTTPHeaderField("keep-alive", "keep-alive value"); |
| 180 response.addHTTPHeaderField("expires", "expires value"); |
| 181 response.addHTTPHeaderField("last-modified", "last-modified value"); |
| 182 response.addHTTPHeaderField("proxy-authenticate", "proxy-authenticate value"
); |
| 183 response.addHTTPHeaderField("proxy-connection", "proxy-connection value"); |
| 184 response.addHTTPHeaderField("x-custom", "custom value"); |
| 185 resource->responseReceived(response, nullptr); |
| 186 resource->finish(); |
| 187 memoryCache()->add(resource.get()); |
| 188 |
| 189 // Simulate a successful revalidation. |
| 190 resource->setRevalidatingRequest(ResourceRequest("data:text/html,")); |
| 191 |
| 192 // Validate that these headers pre-update. |
| 193 EXPECT_EQ("keep-alive value", resource->response().httpHeaderField("keep-ali
ve")); |
| 194 EXPECT_EQ("expires value", resource->response().httpHeaderField("expires")); |
| 195 EXPECT_EQ("last-modified value", resource->response().httpHeaderField("last-
modified")); |
| 196 EXPECT_EQ("proxy-authenticate value", resource->response().httpHeaderField("
proxy-authenticate")); |
| 197 EXPECT_EQ("proxy-authenticate value", resource->response().httpHeaderField("
proxy-authenticate")); |
| 198 EXPECT_EQ("proxy-connection value", resource->response().httpHeaderField("pr
oxy-connection")); |
| 199 EXPECT_EQ("custom value", resource->response().httpHeaderField("x-custom")); |
| 200 |
| 201 OwnPtr<DummyClient> client = adoptPtr(new DummyClient); |
| 202 resource->addClient(client.get()); |
| 203 |
| 204 // Perform a revalidation step. |
| 205 ResourceResponse revalidatingResponse; |
| 206 revalidatingResponse.setHTTPStatusCode(304); |
| 207 // Headers that aren't copied with an 304 code. |
| 208 revalidatingResponse.addHTTPHeaderField("keep-alive", "garbage"); |
| 209 revalidatingResponse.addHTTPHeaderField("expires", "garbage"); |
| 210 revalidatingResponse.addHTTPHeaderField("last-modified", "garbage"); |
| 211 revalidatingResponse.addHTTPHeaderField("proxy-authenticate", "garbage"); |
| 212 revalidatingResponse.addHTTPHeaderField("proxy-connection", "garbage"); |
| 213 // Header that is updated with 304 code. |
| 214 revalidatingResponse.addHTTPHeaderField("x-custom", "updated"); |
| 215 resource->responseReceived(revalidatingResponse, nullptr); |
| 216 |
| 217 // Validate the original response. |
| 218 EXPECT_EQ(200, resource->response().httpStatusCode()); |
| 219 |
| 220 // Validate that these headers are not updated. |
| 221 EXPECT_EQ("keep-alive value", resource->response().httpHeaderField("keep-ali
ve")); |
| 222 EXPECT_EQ("expires value", resource->response().httpHeaderField("expires")); |
| 223 EXPECT_EQ("last-modified value", resource->response().httpHeaderField("last-
modified")); |
| 224 EXPECT_EQ("proxy-authenticate value", resource->response().httpHeaderField("
proxy-authenticate")); |
| 225 EXPECT_EQ("proxy-authenticate value", resource->response().httpHeaderField("
proxy-authenticate")); |
| 226 EXPECT_EQ("proxy-connection value", resource->response().httpHeaderField("pr
oxy-connection")); |
| 227 EXPECT_EQ("updated", resource->response().httpHeaderField("x-custom")); |
| 228 |
| 229 memoryCache()->remove(resource.get()); |
| 230 |
| 231 resource->removeClient(client.get()); |
| 232 EXPECT_FALSE(resource->hasClientsOrObservers()); |
| 233 EXPECT_FALSE(client->called()); |
| 234 EXPECT_EQ(0u, client->data().size()); |
| 235 } |
| 236 |
| 174 TEST(RawResourceTest, AddClientDuringCallback) | 237 TEST(RawResourceTest, AddClientDuringCallback) |
| 175 { | 238 { |
| 176 RefPtrWillBeRawPtr<Resource> raw = RawResource::create(ResourceRequest("data
:text/html,"), Resource::Raw); | 239 RefPtrWillBeRawPtr<Resource> raw = RawResource::create(ResourceRequest("data
:text/html,"), Resource::Raw); |
| 177 | 240 |
| 178 // Create a non-null response. | 241 // Create a non-null response. |
| 179 ResourceResponse response = raw->response(); | 242 ResourceResponse response = raw->response(); |
| 180 response.setURL(KURL(ParsedURLString, "http://600.613/")); | 243 response.setURL(KURL(ParsedURLString, "http://600.613/")); |
| 181 raw->setResponse(response); | 244 raw->setResponse(response); |
| 182 raw->finish(); | 245 raw->finish(); |
| 183 EXPECT_FALSE(raw->response().isNull()); | 246 EXPECT_FALSE(raw->response().isNull()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 286 |
| 224 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); | 287 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); |
| 225 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli
ent.get())); | 288 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli
ent.get())); |
| 226 raw->addClient(dummyClient.get()); | 289 raw->addClient(dummyClient.get()); |
| 227 raw->addClient(removingClient.get()); | 290 raw->addClient(removingClient.get()); |
| 228 testing::runPendingTasks(); | 291 testing::runPendingTasks(); |
| 229 EXPECT_FALSE(raw->hasClientsOrObservers()); | 292 EXPECT_FALSE(raw->hasClientsOrObservers()); |
| 230 } | 293 } |
| 231 | 294 |
| 232 } // namespace blink | 295 } // namespace blink |
| OLD | NEW |