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

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

Issue 1133763003: SdchObserver: add OnDictionary{Added,Removed} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove manager parameter from SdchObserver Created 5 years, 7 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/prefs/testing_pref_store.h" 6 #include "base/prefs/testing_pref_store.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
10 #include "base/test/simple_test_clock.h" 10 #include "base/test/simple_test_clock.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return; 292 return;
293 293
294 base::RunLoop run_loop; 294 base::RunLoop run_loop;
295 base::Closure quit_closure(run_loop.QuitClosure()); 295 base::Closure quit_closure(run_loop.QuitClosure());
296 empty_url_request_jobs_callback = &quit_closure; 296 empty_url_request_jobs_callback = &quit_closure;
297 run_loop.Run(); 297 run_loop.Run();
298 empty_url_request_jobs_callback = NULL; 298 empty_url_request_jobs_callback = NULL;
299 } 299 }
300 300
301 void SignalGetDictionaryAndClearJobs(GURL request_url, GURL dictionary_url) { 301 void SignalGetDictionaryAndClearJobs(GURL request_url, GURL dictionary_url) {
302 sdch_owner().OnGetDictionary(&sdch_manager_, request_url, dictionary_url); 302 sdch_owner().OnGetDictionary(request_url, dictionary_url);
303 WaitForNoJobs(); 303 WaitForNoJobs();
304 } 304 }
305 305
306 // Create a unique (by hash) dictionary of the given size, 306 // Create a unique (by hash) dictionary of the given size,
307 // associate it with a unique URL, add it to the manager through 307 // associate it with a unique URL, add it to the manager through
308 // SdchOwner::OnDictionaryFetched(), and return whether that 308 // SdchOwner::OnDictionaryFetched(), and return whether that
309 // addition was successful or not. 309 // addition was successful or not.
310 bool CreateAndAddDictionary(size_t size, 310 bool CreateAndAddDictionary(size_t size,
311 std::string* server_hash_p, 311 std::string* server_hash_p,
312 base::Time last_used_time) { 312 base::Time last_used_time) {
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 stale_newer)); 554 stale_newer));
555 555
556 EXPECT_TRUE(CreateAndAddDictionary(kMaxSizeForTesting / 4, &server_hash_d3, 556 EXPECT_TRUE(CreateAndAddDictionary(kMaxSizeForTesting / 4, &server_hash_d3,
557 stale_older)); 557 stale_older));
558 558
559 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1)); 559 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1));
560 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d2)); 560 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d2));
561 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d3)); 561 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d3));
562 562
563 // Use the oldest dictionary. 563 // Use the oldest dictionary.
564 sdch_owner().OnDictionaryUsed(&sdch_manager(), server_hash_d3); 564 sdch_owner().OnDictionaryUsed(server_hash_d3);
565 565
566 // The addition of a new dictionary should succeed, evicting only the 566 // The addition of a new dictionary should succeed, evicting only the
567 // newer stale one. 567 // newer stale one.
568 std::string server_hash_d4; 568 std::string server_hash_d4;
569 EXPECT_TRUE( 569 EXPECT_TRUE(
570 CreateAndAddDictionary(kMaxSizeForTesting / 2, &server_hash_d4, fresh)); 570 CreateAndAddDictionary(kMaxSizeForTesting / 2, &server_hash_d4, fresh));
571 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1)); 571 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1));
572 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2)); 572 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2));
573 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d3)); 573 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d3));
574 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d4)); 574 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d4));
(...skipping 18 matching lines...) Expand all
593 stale_newer)); 593 stale_newer));
594 594
595 EXPECT_TRUE(CreateAndAddDictionary(kMaxSizeForTesting / 4, &server_hash_d3, 595 EXPECT_TRUE(CreateAndAddDictionary(kMaxSizeForTesting / 4, &server_hash_d3,
596 stale_older)); 596 stale_older));
597 597
598 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1)); 598 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1));
599 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d2)); 599 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d2));
600 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d3)); 600 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d3));
601 601
602 // Use the older dictionaries. 602 // Use the older dictionaries.
603 sdch_owner().OnDictionaryUsed(&sdch_manager(), server_hash_d2); 603 sdch_owner().OnDictionaryUsed(server_hash_d2);
604 sdch_owner().OnDictionaryUsed(&sdch_manager(), server_hash_d3); 604 sdch_owner().OnDictionaryUsed(server_hash_d3);
605 605
606 // The addition of a new dictionary should fail, not evicting anything. 606 // The addition of a new dictionary should fail, not evicting anything.
607 std::string server_hash_d4; 607 std::string server_hash_d4;
608 EXPECT_FALSE( 608 EXPECT_FALSE(
609 CreateAndAddDictionary(kMaxSizeForTesting / 2, &server_hash_d4, fresh)); 609 CreateAndAddDictionary(kMaxSizeForTesting / 2, &server_hash_d4, fresh));
610 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1)); 610 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1));
611 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d2)); 611 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d2));
612 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d3)); 612 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d3));
613 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d4)); 613 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d4));
614 } 614 }
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 int old_count; 864 int old_count;
865 { 865 {
866 ClearOwner(); 866 ClearOwner();
867 base::DictionaryValue* dict = nullptr; 867 base::DictionaryValue* dict = nullptr;
868 ASSERT_TRUE(GetDictionaryForURL(pref_store_.get(), url, &hash, &dict)); 868 ASSERT_TRUE(GetDictionaryForURL(pref_store_.get(), url, &hash, &dict));
869 ASSERT_TRUE(dict->GetInteger("use_count", &old_count)); 869 ASSERT_TRUE(dict->GetInteger("use_count", &old_count));
870 } 870 }
871 871
872 ResetOwner(false); 872 ResetOwner(false);
873 ASSERT_TRUE(CompleteLoadFromURL(url, "0", true)); 873 ASSERT_TRUE(CompleteLoadFromURL(url, "0", true));
874 owner_->OnDictionaryUsed(manager_.get(), hash); 874 owner_->OnDictionaryUsed(hash);
875 875
876 int new_count; 876 int new_count;
877 { 877 {
878 ClearOwner(); 878 ClearOwner();
879 base::DictionaryValue* dict = nullptr; 879 base::DictionaryValue* dict = nullptr;
880 ASSERT_TRUE(GetDictionaryForURL(pref_store_.get(), url, nullptr, &dict)); 880 ASSERT_TRUE(GetDictionaryForURL(pref_store_.get(), url, nullptr, &dict));
881 ASSERT_TRUE(dict->GetInteger("use_count", &new_count)); 881 ASSERT_TRUE(dict->GetInteger("use_count", &new_count));
882 } 882 }
883 883
884 EXPECT_EQ(old_count + 1, new_count); 884 EXPECT_EQ(old_count + 1, new_count);
(...skipping 28 matching lines...) Expand all
913 913
914 EXPECT_TRUE(CompleteLoadFromURL(url0, "0", true)); 914 EXPECT_TRUE(CompleteLoadFromURL(url0, "0", true));
915 EXPECT_TRUE(CompleteLoadFromURL(url1, "1", false)); 915 EXPECT_TRUE(CompleteLoadFromURL(url1, "1", false));
916 916
917 tester.ExpectTotalCount("Sdch3.NetworkBytesSpent", 1); 917 tester.ExpectTotalCount("Sdch3.NetworkBytesSpent", 1);
918 tester.ExpectUniqueSample("Sdch3.NetworkBytesSpent", 918 tester.ExpectUniqueSample("Sdch3.NetworkBytesSpent",
919 CreateDictionary(url1, "1").size(), 1); 919 CreateDictionary(url1, "1").size(), 1);
920 } 920 }
921 921
922 } // namespace net 922 } // namespace net
OLDNEW
« chrome/browser/net/sdch_browsertest.cc ('K') | « net/sdch/sdch_owner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698