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 29 matching lines...) Expand all Loading... | |
| 40 #include "core/testing/DummyPageHolder.h" | 40 #include "core/testing/DummyPageHolder.h" |
| 41 #include "core/testing/UnitTestHelpers.h" | 41 #include "core/testing/UnitTestHelpers.h" |
| 42 #include "platform/SharedBuffer.h" | 42 #include "platform/SharedBuffer.h" |
| 43 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
| 44 #include "public/platform/WebURL.h" | 44 #include "public/platform/WebURL.h" |
| 45 #include "public/platform/WebURLResponse.h" | 45 #include "public/platform/WebURLResponse.h" |
| 46 #include "public/platform/WebUnitTestSupport.h" | 46 #include "public/platform/WebUnitTestSupport.h" |
| 47 | 47 |
| 48 using namespace WebCore; | 48 using namespace WebCore; |
| 49 | 49 |
| 50 namespace { | 50 namespace WebCore { |
| 51 | 51 |
| 52 TEST(RawResourceTest, DontIgnoreAcceptForCacheReuse) | 52 TEST(RawResourceTest, DontIgnoreAcceptForCacheReuse) |
| 53 { | 53 { |
| 54 ResourceRequest jpegRequest; | 54 ResourceRequest jpegRequest; |
| 55 jpegRequest.setHTTPAccept("image/jpeg"); | 55 jpegRequest.setHTTPAccept("image/jpeg"); |
| 56 | 56 |
| 57 RawResource jpegResource(jpegRequest, Resource::Raw); | 57 RawResource jpegResource(jpegRequest, Resource::Raw); |
| 58 | 58 |
| 59 ResourceRequest pngRequest; | 59 ResourceRequest pngRequest; |
| 60 pngRequest.setHTTPAccept("image/png"); | 60 pngRequest.setHTTPAccept("image/png"); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 79 // should have been sliently switched to point to the revalidated resource, and | 79 // should have been sliently switched to point to the revalidated resource, and |
| 80 // we shouldn't hit any ASSERTs. | 80 // we shouldn't hit any ASSERTs. |
| 81 ResourceResponse response; | 81 ResourceResponse response; |
| 82 response.setHTTPStatusCode(304); | 82 response.setHTTPStatusCode(304); |
| 83 newResource->responseReceived(response); | 83 newResource->responseReceived(response); |
| 84 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm l,")), oldResource.get()); | 84 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm l,")), oldResource.get()); |
| 85 EXPECT_EQ(oldResource.get(), newResource.get()); | 85 EXPECT_EQ(oldResource.get(), newResource.get()); |
| 86 EXPECT_NE(newResource.get(), newResourcePointer); | 86 EXPECT_NE(newResource.get(), newResourcePointer); |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace | 89 class DummyClient : public RawResourceClient { |
| 90 public: | |
| 91 DummyClient() : m_called(false) { } | |
| 92 virtual ~DummyClient() { } | |
| 93 | |
| 94 // ResourceClient implementation. | |
| 95 virtual void notifyFinished(Resource* resource) | |
| 96 { | |
| 97 m_called = true; | |
| 98 } | |
| 99 | |
| 100 bool called() { return m_called; } | |
| 101 private: | |
| 102 bool m_called; | |
| 103 }; | |
| 104 | |
| 105 // This client adds another client when notified. | |
| 106 class TrickyClient : public RawResourceClient { | |
| 107 public: | |
| 108 TrickyClient(DummyClient* client, Resource* resource) | |
| 109 : m_dummyClient(client) | |
|
Nate Chapin
2014/04/10 17:36:10
Nit: indent intializers.
Alpha Left Google
2014/04/10 18:26:23
Done.
| |
| 110 , m_resource(resource) | |
| 111 , m_removeClientTimer(this, &TrickyClient::removeClient) { } | |
| 112 | |
| 113 virtual ~TrickyClient() { } | |
| 114 | |
| 115 // ResourceClient implementation. | |
| 116 virtual void notifyFinished(Resource* resource) | |
| 117 { | |
| 118 // First schedule an asynchronous task to remove the client and delete t he resource. | |
| 119 // We do not expect the client to be called. | |
| 120 m_removeClientTimer.startOneShot(0, FROM_HERE); | |
| 121 resource->addClient(m_dummyClient); | |
| 122 } | |
| 123 void removeClient(Timer<TrickyClient>* timer) | |
| 124 { | |
| 125 m_resource->removeClient(m_dummyClient); | |
| 126 } | |
| 127 private: | |
| 128 DummyClient* m_dummyClient; | |
| 129 Resource* m_resource; | |
| 130 Timer<TrickyClient> m_removeClientTimer; | |
| 131 }; | |
| 132 | |
| 133 TEST(RawResourceTest, AddClientDuringCallback) | |
| 134 { | |
| 135 RawResource* raw = new RawResource(ResourceRequest("data:text/html,"), Resou rce::Raw); | |
| 136 ResourcePtr<Resource> rawOwner = raw; | |
|
Nate Chapin
2014/04/10 17:36:10
Nit: You should be able to merge these two lines a
Alpha Left Google
2014/04/10 18:26:23
Done.
| |
| 137 raw->setLoading(false); | |
| 138 | |
| 139 // Create a non-null response. | |
| 140 ResourceResponse response = raw->response(); | |
| 141 response.setURL(KURL(ParsedURLString, "http://600.613/")); | |
| 142 raw->setResponse(response); | |
| 143 EXPECT_FALSE(raw->response().isNull()); | |
| 144 | |
| 145 OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); | |
| 146 OwnPtr<TrickyClient> trickClient = adoptPtr(new TrickyClient(dummyClient.get (), rawOwner.get())); | |
| 147 raw->addClient(trickClient.get()); | |
| 148 testing::runPendingTasks(); | |
| 149 EXPECT_FALSE(dummyClient->called()); | |
| 150 } | |
| 151 | |
| 152 } // namespace WebCore | |
| OLD | NEW |