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

Side by Side Diff: net/sdch/sdch_owner_unittest.cc

Issue 881413003: Make SDCH dictionaries persistent across browser restart. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/memory/memory_pressure_listener.h" 5 #include "base/memory/memory_pressure_listener.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/test/simple_test_clock.h" 8 #include "base/test/simple_test_clock.h"
9 #include "net/base/net_log.h" 9 #include "net/base/net_log.h"
10 #include "net/base/sdch_manager.h" 10 #include "net/base/sdch_manager.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 base::StringPrintf("%s/d%d", generic_url, dictionary_creation_index_)); 177 base::StringPrintf("%s/d%d", generic_url, dictionary_creation_index_));
178 std::string dictionary_text(NewSdchDictionary(size - 4)); 178 std::string dictionary_text(NewSdchDictionary(size - 4));
179 dictionary_text += base::StringPrintf("%04d", dictionary_creation_index_); 179 dictionary_text += base::StringPrintf("%04d", dictionary_creation_index_);
180 ++dictionary_creation_index_; 180 ++dictionary_creation_index_;
181 std::string client_hash; 181 std::string client_hash;
182 std::string server_hash; 182 std::string server_hash;
183 SdchManager::GenerateHash(dictionary_text, &client_hash, &server_hash); 183 SdchManager::GenerateHash(dictionary_text, &client_hash, &server_hash);
184 184
185 if (DictionaryPresentInManager(server_hash)) 185 if (DictionaryPresentInManager(server_hash))
186 return false; 186 return false;
187 sdch_owner().OnDictionaryFetched(dictionary_text, dictionary_url, net_log_); 187 sdch_owner().OnDictionaryFetched(dictionary_text, dictionary_url,
188 scoped_ptr<SdchDictionaryFetcher::Data>(),
189 net_log_);
188 if (server_hash_p) 190 if (server_hash_p)
189 *server_hash_p = server_hash; 191 *server_hash_p = server_hash;
190 return DictionaryPresentInManager(server_hash); 192 return DictionaryPresentInManager(server_hash);
191 } 193 }
192 194
193 private: 195 private:
194 int last_jobs_created_; 196 int last_jobs_created_;
195 BoundNetLog net_log_; 197 BoundNetLog net_log_;
196 int dictionary_creation_index_; 198 int dictionary_creation_index_;
197 199
(...skipping 15 matching lines...) Expand all
213 215
214 // Fetch generated when empty. 216 // Fetch generated when empty.
215 GURL dict_url1(std::string(generic_url) + "/d1"); 217 GURL dict_url1(std::string(generic_url) + "/d1");
216 EXPECT_EQ(0, JobsRecentlyCreated()); 218 EXPECT_EQ(0, JobsRecentlyCreated());
217 SignalGetDictionaryAndClearJobs(request_url, dict_url1); 219 SignalGetDictionaryAndClearJobs(request_url, dict_url1);
218 EXPECT_EQ(1, JobsRecentlyCreated()); 220 EXPECT_EQ(1, JobsRecentlyCreated());
219 221
220 // Fetch generated when half full. 222 // Fetch generated when half full.
221 GURL dict_url2(std::string(generic_url) + "/d2"); 223 GURL dict_url2(std::string(generic_url) + "/d2");
222 std::string dictionary1(NewSdchDictionary(kMaxSizeForTesting / 2)); 224 std::string dictionary1(NewSdchDictionary(kMaxSizeForTesting / 2));
223 sdch_owner().OnDictionaryFetched(dictionary1, dict_url1, bound_net_log()); 225 sdch_owner().OnDictionaryFetched(dictionary1, dict_url1,
226 scoped_ptr<SdchDictionaryFetcher::Data>(),
227 bound_net_log());
224 EXPECT_EQ(0, JobsRecentlyCreated()); 228 EXPECT_EQ(0, JobsRecentlyCreated());
225 SignalGetDictionaryAndClearJobs(request_url, dict_url2); 229 SignalGetDictionaryAndClearJobs(request_url, dict_url2);
226 EXPECT_EQ(1, JobsRecentlyCreated()); 230 EXPECT_EQ(1, JobsRecentlyCreated());
227 231
228 // Fetch not generated when close to completely full. 232 // Fetch not generated when close to completely full.
229 GURL dict_url3(std::string(generic_url) + "/d3"); 233 GURL dict_url3(std::string(generic_url) + "/d3");
230 std::string dictionary2(NewSdchDictionary( 234 std::string dictionary2(NewSdchDictionary(
231 (kMaxSizeForTesting / 2 - kMinFetchSpaceForTesting / 2))); 235 (kMaxSizeForTesting / 2 - kMinFetchSpaceForTesting / 2)));
232 sdch_owner().OnDictionaryFetched(dictionary2, dict_url2, bound_net_log()); 236 sdch_owner().OnDictionaryFetched(dictionary2, dict_url2,
237 scoped_ptr<SdchDictionaryFetcher::Data>(),
238 bound_net_log());
233 EXPECT_EQ(0, JobsRecentlyCreated()); 239 EXPECT_EQ(0, JobsRecentlyCreated());
234 SignalGetDictionaryAndClearJobs(request_url, dict_url3); 240 SignalGetDictionaryAndClearJobs(request_url, dict_url3);
235 EXPECT_EQ(0, JobsRecentlyCreated()); 241 EXPECT_EQ(0, JobsRecentlyCreated());
236 } 242 }
237 243
238 // Make sure attempts to add dictionaries do what they should. 244 // Make sure attempts to add dictionaries do what they should.
239 TEST_F(SdchOwnerTest, OnDictionaryFetched_Fetching) { 245 TEST_F(SdchOwnerTest, OnDictionaryFetched_Fetching) {
240 GURL request_url(std::string(generic_url) + "/r1"); 246 GURL request_url(std::string(generic_url) + "/r1");
241 std::string client_hash; 247 std::string client_hash;
242 std::string server_hash; 248 std::string server_hash;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 base::RunLoop().RunUntilIdle(); 488 base::RunLoop().RunUntilIdle();
483 489
484 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d1)); 490 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d1));
485 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2)); 491 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2));
486 492
487 // Addition should now succeed. 493 // Addition should now succeed.
488 EXPECT_TRUE(CreateAndAddDictionary(kMaxSizeForTesting, nullptr)); 494 EXPECT_TRUE(CreateAndAddDictionary(kMaxSizeForTesting, nullptr));
489 } 495 }
490 496
491 } // namespace net 497 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698