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

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

Issue 2324103002: Cleanup EXPECT/ASSERTs in unit tests in core/fetch and core/loader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 TEST(RawResourceTest, DontIgnoreAcceptForCacheReuse) 47 TEST(RawResourceTest, DontIgnoreAcceptForCacheReuse)
48 { 48 {
49 ResourceRequest jpegRequest; 49 ResourceRequest jpegRequest;
50 jpegRequest.setHTTPAccept("image/jpeg"); 50 jpegRequest.setHTTPAccept("image/jpeg");
51 51
52 RawResource* jpegResource(RawResource::create(jpegRequest, Resource::Raw)); 52 RawResource* jpegResource(RawResource::create(jpegRequest, Resource::Raw));
53 53
54 ResourceRequest pngRequest; 54 ResourceRequest pngRequest;
55 pngRequest.setHTTPAccept("image/png"); 55 pngRequest.setHTTPAccept("image/png");
56 56
57 ASSERT_FALSE(jpegResource->canReuse(pngRequest)); 57 EXPECT_FALSE(jpegResource->canReuse(pngRequest));
58 } 58 }
59 59
60 class DummyClient final : public GarbageCollectedFinalized<DummyClient>, public RawResourceClient { 60 class DummyClient final : public GarbageCollectedFinalized<DummyClient>, public RawResourceClient {
61 USING_GARBAGE_COLLECTED_MIXIN(DummyClient); 61 USING_GARBAGE_COLLECTED_MIXIN(DummyClient);
62 public: 62 public:
63 DummyClient() : m_called(false), m_numberOfRedirectsReceived(0) {} 63 DummyClient() : m_called(false), m_numberOfRedirectsReceived(0) {}
64 ~DummyClient() override {} 64 ~DummyClient() override {}
65 65
66 // ResourceClient implementation. 66 // ResourceClient implementation.
67 void notifyFinished(Resource* resource) override 67 void notifyFinished(Resource* resource) override
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 Persistent<DummyClient> client = new DummyClient; 150 Persistent<DummyClient> client = new DummyClient;
151 resource->addClient(client); 151 resource->addClient(client);
152 152
153 ResourceResponse revalidatingResponse; 153 ResourceResponse revalidatingResponse;
154 revalidatingResponse.setHTTPStatusCode(304); 154 revalidatingResponse.setHTTPStatusCode(304);
155 resource->responseReceived(revalidatingResponse, nullptr); 155 resource->responseReceived(revalidatingResponse, nullptr);
156 EXPECT_FALSE(resource->isCacheValidator()); 156 EXPECT_FALSE(resource->isCacheValidator());
157 EXPECT_EQ(200, resource->response().httpStatusCode()); 157 EXPECT_EQ(200, resource->response().httpStatusCode());
158 EXPECT_EQ(4u, resource->resourceBuffer()->size()); 158 EXPECT_EQ(4u, resource->resourceBuffer()->size());
159 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm l,")), resource); 159 EXPECT_EQ(resource, memoryCache()->resourceForURL(KURL(ParsedURLString, "dat a:text/html,")));
160 memoryCache()->remove(resource); 160 memoryCache()->remove(resource);
161 161
162 resource->removeClient(client); 162 resource->removeClient(client);
163 EXPECT_FALSE(resource->isAlive()); 163 EXPECT_FALSE(resource->isAlive());
164 EXPECT_FALSE(client->called()); 164 EXPECT_FALSE(client->called());
165 EXPECT_EQ("abcd", String(client->data().data(), client->data().size())); 165 EXPECT_EQ("abcd", String(client->data().data(), client->data().size()));
166 } 166 }
167 167
168 TEST(RawResourceTest, RevalidationSucceededForResourceWithoutBody) 168 TEST(RawResourceTest, RevalidationSucceededForResourceWithoutBody)
169 { 169 {
170 Resource* resource = RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); 170 Resource* resource = RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw);
171 ResourceResponse response; 171 ResourceResponse response;
172 response.setHTTPStatusCode(200); 172 response.setHTTPStatusCode(200);
173 resource->responseReceived(response, nullptr); 173 resource->responseReceived(response, nullptr);
174 resource->finish(); 174 resource->finish();
175 memoryCache()->add(resource); 175 memoryCache()->add(resource);
176 176
177 // Simulate a successful revalidation. 177 // Simulate a successful revalidation.
178 resource->setRevalidatingRequest(ResourceRequest("data:text/html,")); 178 resource->setRevalidatingRequest(ResourceRequest("data:text/html,"));
179 179
180 Persistent<DummyClient> client = new DummyClient; 180 Persistent<DummyClient> client = new DummyClient;
181 resource->addClient(client); 181 resource->addClient(client);
182 182
183 ResourceResponse revalidatingResponse; 183 ResourceResponse revalidatingResponse;
184 revalidatingResponse.setHTTPStatusCode(304); 184 revalidatingResponse.setHTTPStatusCode(304);
185 resource->responseReceived(revalidatingResponse, nullptr); 185 resource->responseReceived(revalidatingResponse, nullptr);
186 EXPECT_FALSE(resource->isCacheValidator()); 186 EXPECT_FALSE(resource->isCacheValidator());
187 EXPECT_EQ(200, resource->response().httpStatusCode()); 187 EXPECT_EQ(200, resource->response().httpStatusCode());
188 EXPECT_EQ(nullptr, resource->resourceBuffer()); 188 EXPECT_EQ(nullptr, resource->resourceBuffer());
189 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm l,")), resource); 189 EXPECT_EQ(resource, memoryCache()->resourceForURL(KURL(ParsedURLString, "dat a:text/html,")));
190 memoryCache()->remove(resource); 190 memoryCache()->remove(resource);
191 191
192 resource->removeClient(client); 192 resource->removeClient(client);
193 EXPECT_FALSE(resource->isAlive()); 193 EXPECT_FALSE(resource->isAlive());
194 EXPECT_FALSE(client->called()); 194 EXPECT_FALSE(client->called());
195 EXPECT_EQ(0u, client->data().size()); 195 EXPECT_EQ(0u, client->data().size());
196 } 196 }
197 197
198 TEST(RawResourceTest, RevalidationSucceededUpdateHeaders) 198 TEST(RawResourceTest, RevalidationSucceededUpdateHeaders)
199 { 199 {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 resource->responseReceived(revalidatingResponse, nullptr); 301 resource->responseReceived(revalidatingResponse, nullptr);
302 const char data2[4] = "xyz"; 302 const char data2[4] = "xyz";
303 resource->appendData(data2, 3); 303 resource->appendData(data2, 3);
304 resource->finish(); 304 resource->finish();
305 EXPECT_FALSE(resource->isCacheValidator()); 305 EXPECT_FALSE(resource->isCacheValidator());
306 EXPECT_EQ("https://example.com/1", resource->resourceRequest().url().getStri ng()); 306 EXPECT_EQ("https://example.com/1", resource->resourceRequest().url().getStri ng());
307 EXPECT_EQ("https://example.com/2", resource->lastResourceRequest().url().get String()); 307 EXPECT_EQ("https://example.com/2", resource->lastResourceRequest().url().get String());
308 EXPECT_FALSE(resource->isCacheValidator()); 308 EXPECT_FALSE(resource->isCacheValidator());
309 EXPECT_EQ(200, resource->response().httpStatusCode()); 309 EXPECT_EQ(200, resource->response().httpStatusCode());
310 EXPECT_EQ(3u, resource->resourceBuffer()->size()); 310 EXPECT_EQ(3u, resource->resourceBuffer()->size());
311 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "https://examp le.com/1")), resource); 311 EXPECT_EQ(resource, memoryCache()->resourceForURL(KURL(ParsedURLString, "htt ps://example.com/1")));
312 312
313 EXPECT_TRUE(client->called()); 313 EXPECT_TRUE(client->called());
314 EXPECT_EQ(1, client->numberOfRedirectsReceived()); 314 EXPECT_EQ(1, client->numberOfRedirectsReceived());
315 EXPECT_EQ("xyz", String(client->data().data(), client->data().size())); 315 EXPECT_EQ("xyz", String(client->data().data(), client->data().size()));
316 316
317 // Test the case where a client is added after revalidation is completed. 317 // Test the case where a client is added after revalidation is completed.
318 Persistent<DummyClient> client2 = new DummyClient; 318 Persistent<DummyClient> client2 = new DummyClient;
319 resource->addClient(client2); 319 resource->addClient(client2);
320 320
321 // Because RawResourceClient is added asynchronously, 321 // Because RawResourceClient is added asynchronously,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 400
401 TEST(RawResourceTest, CanReuseDevToolsEmulateNetworkConditionsClientIdHeader) 401 TEST(RawResourceTest, CanReuseDevToolsEmulateNetworkConditionsClientIdHeader)
402 { 402 {
403 ResourceRequest request("data:text/html,"); 403 ResourceRequest request("data:text/html,");
404 request.setHTTPHeaderField(HTTPNames::X_DevTools_Emulate_Network_Conditions_ Client_Id, "Foo"); 404 request.setHTTPHeaderField(HTTPNames::X_DevTools_Emulate_Network_Conditions_ Client_Id, "Foo");
405 Resource* raw = RawResource::create(request, Resource::Raw); 405 Resource* raw = RawResource::create(request, Resource::Raw);
406 EXPECT_TRUE(raw->canReuse(ResourceRequest("data:text/html,"))); 406 EXPECT_TRUE(raw->canReuse(ResourceRequest("data:text/html,")));
407 } 407 }
408 408
409 } // namespace blink 409 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698