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

Side by Side Diff: third_party/WebKit/Source/core/fetch/RawResourceTest.cpp

Issue 1410313002: Revert of Revalidate using the same Resource, attempt #3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 /* 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 ResourcePtr<RawResource> jpegResource(new RawResource(jpegRequest, Resource: :Raw)); 55 ResourcePtr<RawResource> jpegResource(new RawResource(jpegRequest, Resource: :Raw));
56 56
57 ResourceRequest pngRequest; 57 ResourceRequest pngRequest;
58 pngRequest.setHTTPAccept("image/png"); 58 pngRequest.setHTTPAccept("image/png");
59 59
60 ASSERT_FALSE(jpegResource->canReuse(pngRequest)); 60 ASSERT_FALSE(jpegResource->canReuse(pngRequest));
61 } 61 }
62 62
63 TEST(RawResourceTest, RevalidationSucceeded) 63 TEST(RawResourceTest, RevalidationSucceeded)
64 { 64 {
65 ResourcePtr<Resource> resource = new RawResource(ResourceRequest("data:text/ html,"), Resource::Raw); 65 // Create two RawResources and set one to revalidate the other.
66 ResourceResponse response; 66 RawResource* oldResourcePointer = new RawResource(ResourceRequest("data:text /html,"), Resource::Raw);
67 response.setHTTPStatusCode(200); 67 RawResource* newResourcePointer = new RawResource(ResourceRequest("data:text /html,"), Resource::Raw);
68 resource->responseReceived(response, nullptr); 68 newResourcePointer->setResourceToRevalidate(oldResourcePointer);
69 const char data[5] = "abcd"; 69 ResourcePtr<Resource> oldResource = oldResourcePointer;
70 resource->appendData(data, 4); 70 ResourcePtr<Resource> newResource = newResourcePointer;
71 resource->finish(); 71 memoryCache()->add(oldResource.get());
72 memoryCache()->add(resource.get()); 72 memoryCache()->remove(oldResource.get());
73 memoryCache()->add(newResource.get());
73 74
74 // Simulate a successful revalidation. 75 // Simulate a successful revalidation.
75 resource->setRevalidatingRequest(ResourceRequest("data:text/html,")); 76 // The revalidated resource (oldResource) should now be in the cache, newRes ource
76 ResourceResponse revalidatingResponse; 77 // should have been sliently switched to point to the revalidated resource, and
77 revalidatingResponse.setHTTPStatusCode(304); 78 // we shouldn't hit any ASSERTs.
78 resource->responseReceived(revalidatingResponse, nullptr); 79 ResourceResponse response;
79 EXPECT_FALSE(resource->isCacheValidator()); 80 response.setHTTPStatusCode(304);
80 EXPECT_EQ(200, resource->response().httpStatusCode()); 81 newResource->responseReceived(response, nullptr);
81 EXPECT_EQ(4u, resource->resourceBuffer()->size()); 82 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm l,")), oldResource.get());
82 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm l,")), resource.get()); 83 EXPECT_EQ(oldResource.get(), newResource.get());
83 memoryCache()->remove(resource.get()); 84 EXPECT_NE(newResource.get(), newResourcePointer);
85 memoryCache()->remove(newResource.get());
84 } 86 }
85 87
86 class DummyClient : public RawResourceClient { 88 class DummyClient : public RawResourceClient {
87 public: 89 public:
88 DummyClient() : m_called(false) {} 90 DummyClient() : m_called(false) {}
89 ~DummyClient() override {} 91 ~DummyClient() override {}
90 92
91 // ResourceClient implementation. 93 // ResourceClient implementation.
92 virtual void notifyFinished(Resource* resource) 94 virtual void notifyFinished(Resource* resource)
93 { 95 {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 180
179 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); 181 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient());
180 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli ent.get())); 182 OwnPtr<RemovingClient> removingClient = adoptPtr(new RemovingClient(dummyCli ent.get()));
181 raw->addClient(dummyClient.get()); 183 raw->addClient(dummyClient.get());
182 raw->addClient(removingClient.get()); 184 raw->addClient(removingClient.get());
183 testing::runPendingTasks(); 185 testing::runPendingTasks();
184 EXPECT_FALSE(raw->hasClients()); 186 EXPECT_FALSE(raw->hasClients());
185 } 187 }
186 188
187 } // namespace blink 189 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/RawResource.cpp ('k') | third_party/WebKit/Source/core/fetch/Resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698