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

Side by Side Diff: net/http/http_cache_lookup_manager_unittest.cc

Issue 2519473002: Fixes the cache lock issue. (Closed)
Patch Set: Initial patch Created 4 years 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 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 <string> 5 #include <string>
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 #include "net/base/test_completion_callback.h" 9 #include "net/base/test_completion_callback.h"
10 #include "net/http/http_cache_lookup_manager.h" 10 #include "net/http/http_cache_lookup_manager.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 void PopulateCacheEntry(HttpCache* cache, const GURL& request_url) { 46 void PopulateCacheEntry(HttpCache* cache, const GURL& request_url) {
47 TestCompletionCallback callback; 47 TestCompletionCallback callback;
48 48
49 std::unique_ptr<MockTransaction> mock_trans = 49 std::unique_ptr<MockTransaction> mock_trans =
50 CreateMockTransaction(request_url); 50 CreateMockTransaction(request_url);
51 AddMockTransaction(mock_trans.get()); 51 AddMockTransaction(mock_trans.get());
52 52
53 MockHttpRequest request(*(mock_trans.get())); 53 MockHttpRequest request(*(mock_trans.get()));
54 54
55 std::unique_ptr<HttpTransaction> trans; 55 Context* c = new Context();
56 int rv = cache->CreateTransaction(DEFAULT_PRIORITY, &trans); 56 int rv = cache->CreateTransaction(DEFAULT_PRIORITY, &c->trans);
57 EXPECT_THAT(rv, IsOk()); 57 EXPECT_THAT(rv, IsOk());
58 ASSERT_TRUE(trans.get()); 58 ASSERT_TRUE(c->trans.get());
59 59
60 rv = trans->Start(&request, callback.callback(), NetLogWithSource()); 60 rv = c->trans->Start(&request, callback.callback(), NetLogWithSource());
61 base::RunLoop().RunUntilIdle(); 61 base::RunLoop().RunUntilIdle();
62 62
63 if (rv == ERR_IO_PENDING) 63 if (rv == ERR_IO_PENDING)
64 rv = callback.WaitForResult(); 64 rv = callback.WaitForResult();
65 65
66 ASSERT_EQ(mock_trans->return_code, rv); 66 ASSERT_EQ(mock_trans->return_code, rv);
67 if (OK != rv) 67 if (OK != rv)
68 return; 68 return;
69 69
70 const HttpResponseInfo* response = trans->GetResponseInfo(); 70 const HttpResponseInfo* response = c->trans->GetResponseInfo();
71 ASSERT_TRUE(response); 71 ASSERT_TRUE(response);
72 72
73 std::string content; 73 std::string content;
74 rv = ReadTransaction(trans.get(), &content); 74 rv = ReadTransaction(c->trans.get(), &content);
75 75
76 EXPECT_THAT(rv, IsOk()); 76 EXPECT_THAT(rv, IsOk());
77 std::string expected(mock_trans->data); 77 std::string expected(mock_trans->data);
78 EXPECT_EQ(expected, content); 78 EXPECT_EQ(expected, content);
79 RemoveMockTransaction(mock_trans.get()); 79 RemoveMockTransaction(mock_trans.get());
80
81 delete c;
80 } 82 }
81 83
82 } // namespace 84 } // namespace
83 85
84 TEST(HttpCacheLookupManagerTest, ServerPushMissCache) { 86 TEST(HttpCacheLookupManagerTest, ServerPushMissCache) {
85 MockHttpCache mock_cache; 87 MockHttpCache mock_cache;
86 HttpCacheLookupManager push_delegate(mock_cache.http_cache(), 88 HttpCacheLookupManager push_delegate(mock_cache.http_cache(),
87 NetLogWithSource()); 89 NetLogWithSource());
88 GURL request_url("http://www.example.com/pushed.jpg"); 90 GURL request_url("http://www.example.com/pushed.jpg");
89 91
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 280
279 base::RunLoop().RunUntilIdle(); 281 base::RunLoop().RunUntilIdle();
280 // Make sure no new net layer transaction is created. 282 // Make sure no new net layer transaction is created.
281 EXPECT_EQ(1, mock_cache.network_layer()->transaction_count()); 283 EXPECT_EQ(1, mock_cache.network_layer()->transaction_count());
282 EXPECT_EQ(2, mock_cache.disk_cache()->open_count()); 284 EXPECT_EQ(2, mock_cache.disk_cache()->open_count());
283 EXPECT_EQ(1, mock_cache.disk_cache()->create_count()); 285 EXPECT_EQ(1, mock_cache.disk_cache()->create_count());
284 RemoveMockTransaction(mock_trans3.get()); 286 RemoveMockTransaction(mock_trans3.get());
285 } 287 }
286 288
287 } // namespace net 289 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698