OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "core/fetch/Resource.h" | 5 #include "core/fetch/Resource.h" |
6 | 6 |
7 #include "core/fetch/MemoryCache.h" | 7 #include "core/fetch/MemoryCache.h" |
8 #include "platform/SharedBuffer.h" | 8 #include "platform/SharedBuffer.h" |
9 #include "platform/network/ResourceRequest.h" | 9 #include "platform/network/ResourceRequest.h" |
10 #include "platform/network/ResourceResponse.h" | 10 #include "platform/network/ResourceResponse.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 void createTestResourceAndSetCachedMetadata(const ResourceResponse& response) { | 44 void createTestResourceAndSetCachedMetadata(const ResourceResponse& response) { |
45 const char testData[] = "test data"; | 45 const char testData[] = "test data"; |
46 Resource* resource = | 46 Resource* resource = |
47 Resource::create(ResourceRequest(response.url()), Resource::Raw); | 47 Resource::create(ResourceRequest(response.url()), Resource::Raw); |
48 resource->setResponse(response); | 48 resource->setResponse(response); |
49 resource->cacheHandler()->setCachedMetadata( | 49 resource->cacheHandler()->setCachedMetadata( |
50 100, testData, sizeof(testData), CachedMetadataHandler::SendToPlatform); | 50 100, testData, sizeof(testData), CachedMetadataHandler::SendToPlatform); |
51 return; | 51 return; |
52 } | 52 } |
53 | 53 |
54 class TestProhibitAddRemoveClientResource : public Resource { | |
hiroshige
2016/10/05 08:37:25
optional: I'd like to avoid creating new test-only
hiroshige
2016/10/05 08:37:25
Add "final".
Shao-Chuan Lee
2016/10/05 09:04:53
Done.
| |
55 public: | |
56 static TestProhibitAddRemoveClientResource* create() { | |
57 return new TestProhibitAddRemoveClientResource( | |
58 ResourceRequest(), Resource::Raw, ResourceLoaderOptions()); | |
kouhei (in TOK)
2016/10/05 08:29:42
We can just pass these to Resource ctor in line 70
Shao-Chuan Lee
2016/10/05 09:04:53
Done.
| |
59 } | |
60 void test() { | |
kouhei (in TOK)
2016/10/05 08:29:42
We should have this logic in line 112 func.
Shao-Chuan Lee
2016/10/05 09:04:53
Moving EXPECT_DEATH()s to test function.
| |
61 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this); | |
62 EXPECT_DEATH(addClient(nullptr), "!m_isAddRemoveClientProhibited"); | |
hiroshige
2016/10/05 08:37:25
addClient(nullptr) is invalid even outside Prohibi
Shao-Chuan Lee
2016/10/05 08:51:20
Since MockResourceClient calls addClient in ctor,
Shao-Chuan Lee
2016/10/05 09:04:53
Done.
| |
63 EXPECT_DEATH(removeClient(nullptr), "!m_isAddRemoveClientProhibited"); | |
hiroshige
2016/10/05 08:37:26
ditto.
Shao-Chuan Lee
2016/10/05 09:04:53
Done.
| |
64 } | |
65 | |
66 private: | |
67 TestProhibitAddRemoveClientResource(const ResourceRequest& request, | |
hiroshige
2016/10/05 08:37:25
We can remove these parameters as they receive onl
Shao-Chuan Lee
2016/10/05 09:04:53
Done.
| |
68 Type type, | |
69 const ResourceLoaderOptions& options) | |
70 : Resource(request, type, options) {} | |
71 }; | |
72 | |
54 } // anonymous namespace | 73 } // anonymous namespace |
55 | 74 |
56 TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform) { | 75 TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform) { |
57 MockPlatform mock; | 76 MockPlatform mock; |
58 ResourceResponse response(createTestResourceResponse()); | 77 ResourceResponse response(createTestResourceResponse()); |
59 createTestResourceAndSetCachedMetadata(response); | 78 createTestResourceAndSetCachedMetadata(response); |
60 EXPECT_EQ(1u, mock.cachedURLs().size()); | 79 EXPECT_EQ(1u, mock.cachedURLs().size()); |
61 } | 80 } |
62 | 81 |
63 TEST( | 82 TEST( |
(...skipping 18 matching lines...) Expand all Loading... | |
82 // Revalidating with a url that differs by only the fragment | 101 // Revalidating with a url that differs by only the fragment |
83 // shouldn't trigger a securiy check. | 102 // shouldn't trigger a securiy check. |
84 url.setFragmentIdentifier("bar"); | 103 url.setFragmentIdentifier("bar"); |
85 resource->setRevalidatingRequest(ResourceRequest(url)); | 104 resource->setRevalidatingRequest(ResourceRequest(url)); |
86 ResourceResponse revalidatingResponse; | 105 ResourceResponse revalidatingResponse; |
87 revalidatingResponse.setURL(url); | 106 revalidatingResponse.setURL(url); |
88 revalidatingResponse.setHTTPStatusCode(304); | 107 revalidatingResponse.setHTTPStatusCode(304); |
89 resource->responseReceived(revalidatingResponse, nullptr); | 108 resource->responseReceived(revalidatingResponse, nullptr); |
90 } | 109 } |
91 | 110 |
111 TEST(ResourceTest, ProhibitAddRemoveClientInScope) { | |
112 TestProhibitAddRemoveClientResource::create()->test(); | |
113 } | |
114 | |
92 } // namespace blink | 115 } // namespace blink |
OLD | NEW |