Chromium Code Reviews| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 EXPECT_EQ(nullptr, resource->resourceBuffer()); | 167 EXPECT_EQ(nullptr, resource->resourceBuffer()); |
| 168 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm l,")), resource.get()); | 168 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm l,")), resource.get()); |
| 169 memoryCache()->remove(resource.get()); | 169 memoryCache()->remove(resource.get()); |
| 170 | 170 |
| 171 resource->removeClient(client.get()); | 171 resource->removeClient(client.get()); |
| 172 EXPECT_FALSE(resource->hasClients()); | 172 EXPECT_FALSE(resource->hasClients()); |
| 173 EXPECT_FALSE(client->called()); | 173 EXPECT_FALSE(client->called()); |
| 174 EXPECT_EQ(0u, client->data().size()); | 174 EXPECT_EQ(0u, client->data().size()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 TEST(RawResourceTest, RevalidationSucceededUpdateHeaders) | |
| 178 { | |
| 179 ResourcePtr<Resource> resource = new RawResource(ResourceRequest("data:text/ html,"), Resource::Raw); | |
|
grt (UTC plus 2)
2016/03/31 15:14:25
new RawResource -> RawResource::create
ResourcePtr
etienneb
2016/03/31 20:49:42
Done.
| |
| 180 ResourceResponse response; | |
| 181 response.setHTTPStatusCode(200); | |
| 182 response.addHTTPHeaderField("keep-alive", "keep-alive value"); | |
| 183 response.addHTTPHeaderField("expires", "expires value"); | |
| 184 response.addHTTPHeaderField("last-modified", "last-modified value"); | |
| 185 response.addHTTPHeaderField("proxy-authenticate", "proxy-authenticate value" ); | |
| 186 response.addHTTPHeaderField("proxy-connection", "proxy-connection value"); | |
| 187 response.addHTTPHeaderField("x-custom", "custom value"); | |
| 188 resource->responseReceived(response, nullptr); | |
| 189 resource->finish(); | |
| 190 memoryCache()->add(resource.get()); | |
| 191 | |
| 192 // Simulate a successful revalidation. | |
| 193 resource->setRevalidatingRequest(ResourceRequest("data:text/html,")); | |
| 194 | |
| 195 // Validate that these headers pre-update. | |
| 196 EXPECT_EQ("keep-alive value", resource->response().httpHeaderField("keep-ali ve")); | |
| 197 EXPECT_EQ("expires value", resource->response().httpHeaderField("expires")); | |
| 198 EXPECT_EQ("last-modified value", resource->response().httpHeaderField("last- modified")); | |
| 199 EXPECT_EQ("proxy-authenticate value", resource->response().httpHeaderField(" proxy-authenticate")); | |
| 200 EXPECT_EQ("proxy-authenticate value", resource->response().httpHeaderField(" proxy-authenticate")); | |
| 201 EXPECT_EQ("proxy-connection value", resource->response().httpHeaderField("pr oxy-connection")); | |
| 202 EXPECT_EQ("custom value", resource->response().httpHeaderField("x-custom")); | |
| 203 | |
| 204 OwnPtr<DummyClient> client = adoptPtr(new DummyClient); | |
| 205 resource->addClient(client.get()); | |
| 206 | |
| 207 // Perform a revalidation step. | |
| 208 ResourceResponse revalidatingResponse; | |
| 209 revalidatingResponse.setHTTPStatusCode(304); | |
| 210 // Headers that aren't copied with an 304 code. | |
| 211 revalidatingResponse.addHTTPHeaderField("keep-alive", "garbage"); | |
| 212 revalidatingResponse.addHTTPHeaderField("expires", "garbage"); | |
| 213 revalidatingResponse.addHTTPHeaderField("last-modified", "garbage"); | |
| 214 revalidatingResponse.addHTTPHeaderField("proxy-authenticate", "garbage"); | |
| 215 revalidatingResponse.addHTTPHeaderField("proxy-connection", "garbage"); | |
| 216 // Header that is updated with 304 code. | |
| 217 revalidatingResponse.addHTTPHeaderField("x-custom", "updated"); | |
| 218 resource->responseReceived(revalidatingResponse, nullptr); | |
| 219 | |
| 220 // Validate the original response. | |
| 221 EXPECT_EQ(200, resource->response().httpStatusCode()); | |
| 222 | |
| 223 // Validate that these headers are not updated. | |
| 224 EXPECT_EQ("keep-alive value", resource->response().httpHeaderField("keep-ali ve")); | |
| 225 EXPECT_EQ("expires value", resource->response().httpHeaderField("expires")); | |
| 226 EXPECT_EQ("last-modified value", resource->response().httpHeaderField("last- modified")); | |
| 227 EXPECT_EQ("proxy-authenticate value", resource->response().httpHeaderField(" proxy-authenticate")); | |
| 228 EXPECT_EQ("proxy-authenticate value", resource->response().httpHeaderField(" proxy-authenticate")); | |
| 229 EXPECT_EQ("proxy-connection value", resource->response().httpHeaderField("pr oxy-connection")); | |
| 230 EXPECT_EQ("updated", resource->response().httpHeaderField("x-custom")); | |
| 231 | |
| 232 memoryCache()->remove(resource.get()); | |
| 233 | |
| 234 resource->removeClient(client.get()); | |
| 235 EXPECT_FALSE(resource->hasClients()); | |
|
grt (UTC plus 2)
2016/03/31 15:14:25
hasClients -> hasClientsOrObservers
(http://crrev.
etienneb
2016/03/31 20:49:42
Done.
| |
| 236 EXPECT_FALSE(client->called()); | |
| 237 EXPECT_EQ(0u, client->data().size()); | |
| 238 } | |
| 239 | |
| 177 TEST(RawResourceTest, AddClientDuringCallback) | 240 TEST(RawResourceTest, AddClientDuringCallback) |
| 178 { | 241 { |
| 179 ResourcePtr<Resource> raw = new RawResource(ResourceRequest("data:text/html, "), Resource::Raw); | 242 ResourcePtr<Resource> raw = new RawResource(ResourceRequest("data:text/html, "), Resource::Raw); |
| 180 raw->setLoading(false); | 243 raw->setLoading(false); |
| 181 | 244 |
| 182 // Create a non-null response. | 245 // Create a non-null response. |
| 183 ResourceResponse response = raw->response(); | 246 ResourceResponse response = raw->response(); |
| 184 response.setURL(KURL(ParsedURLString, "http://600.613/")); | 247 response.setURL(KURL(ParsedURLString, "http://600.613/")); |
| 185 raw->setResponse(response); | 248 raw->setResponse(response); |
| 186 EXPECT_FALSE(raw->response().isNull()); | 249 EXPECT_FALSE(raw->response().isNull()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 | 289 |
| 227 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); | 290 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); |
| 228 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli ent.get())); | 291 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli ent.get())); |
| 229 raw->addClient(dummyClient.get()); | 292 raw->addClient(dummyClient.get()); |
| 230 raw->addClient(removingClient.get()); | 293 raw->addClient(removingClient.get()); |
| 231 testing::runPendingTasks(); | 294 testing::runPendingTasks(); |
| 232 EXPECT_FALSE(raw->hasClients()); | 295 EXPECT_FALSE(raw->hasClients()); |
| 233 } | 296 } |
| 234 | 297 |
| 235 } // namespace blink | 298 } // namespace blink |
| OLD | NEW |