| OLD | NEW |
| 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/process/process_info.h" |
| 7 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 8 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/test/histogram_tester.h" |
| 9 #include "base/test/simple_test_clock.h" | 11 #include "base/test/simple_test_clock.h" |
| 10 #include "base/values.h" | 12 #include "base/values.h" |
| 11 #include "net/base/net_log.h" | 13 #include "net/base/net_log.h" |
| 12 #include "net/base/sdch_manager.h" | 14 #include "net/base/sdch_manager.h" |
| 13 #include "net/sdch/sdch_owner.h" | 15 #include "net/sdch/sdch_owner.h" |
| 14 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
| 15 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
| 16 #include "net/url_request/url_request_error_job.h" | 18 #include "net/url_request/url_request_error_job.h" |
| 17 #include "net/url_request/url_request_job.h" | 19 #include "net/url_request/url_request_job.h" |
| 18 #include "net/url_request/url_request_job_factory.h" | 20 #include "net/url_request/url_request_job_factory.h" |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 dictionary_last_used_time)); | 400 dictionary_last_used_time)); |
| 399 EXPECT_EQ(0, JobsRecentlyCreated()); | 401 EXPECT_EQ(0, JobsRecentlyCreated()); |
| 400 } | 402 } |
| 401 | 403 |
| 402 // Confirm auto-eviction happens if space is needed. | 404 // Confirm auto-eviction happens if space is needed. |
| 403 TEST_F(SdchOwnerTest, ConfirmAutoEviction) { | 405 TEST_F(SdchOwnerTest, ConfirmAutoEviction) { |
| 404 std::string server_hash_d1; | 406 std::string server_hash_d1; |
| 405 std::string server_hash_d2; | 407 std::string server_hash_d2; |
| 406 std::string server_hash_d3; | 408 std::string server_hash_d3; |
| 407 | 409 |
| 410 base::SimpleTestClock* test_clock = new base::SimpleTestClock(); |
| 411 sdch_owner().SetClockForTesting(make_scoped_ptr(test_clock)); |
| 412 test_clock->SetNow(base::Time::Now()); |
| 413 |
| 408 // Add two dictionaries, one recent, one more than a day in the past. | 414 // Add two dictionaries, one recent, one more than a day in the past. |
| 409 base::Time fresh(base::Time::Now() - base::TimeDelta::FromHours(23)); | 415 base::Time fresh(base::Time::Now() - base::TimeDelta::FromHours(23)); |
| 410 base::Time stale(base::Time::Now() - base::TimeDelta::FromHours(25)); | 416 base::Time stale(base::Time::Now() - base::TimeDelta::FromHours(25)); |
| 411 | 417 |
| 412 EXPECT_TRUE( | 418 EXPECT_TRUE( |
| 413 CreateAndAddDictionary(kMaxSizeForTesting / 2, &server_hash_d1, fresh)); | 419 CreateAndAddDictionary(kMaxSizeForTesting / 2, &server_hash_d1, fresh)); |
| 414 EXPECT_TRUE( | 420 EXPECT_TRUE( |
| 415 CreateAndAddDictionary(kMaxSizeForTesting / 2, &server_hash_d2, stale)); | 421 CreateAndAddDictionary(kMaxSizeForTesting / 2, &server_hash_d2, stale)); |
| 416 | 422 |
| 417 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1)); | 423 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1)); |
| 418 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d2)); | 424 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d2)); |
| 419 | 425 |
| 426 base::HistogramTester tester; |
| 427 const base::TimeDelta synthetic_delta = base::TimeDelta::FromSeconds(5); |
| 428 |
| 429 test_clock->Advance(synthetic_delta); |
| 430 |
| 420 EXPECT_TRUE( | 431 EXPECT_TRUE( |
| 421 CreateAndAddDictionary(kMaxSizeForTesting / 2, &server_hash_d3, fresh)); | 432 CreateAndAddDictionary(kMaxSizeForTesting / 2, &server_hash_d3, fresh)); |
| 422 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1)); | 433 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1)); |
| 423 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2)); | 434 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2)); |
| 424 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d3)); | 435 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d3)); |
| 436 |
| 437 base::TimeDelta expected_dict_lifetime = synthetic_delta; |
| 438 base::TimeDelta expected_proc_lifetime = synthetic_delta + |
| 439 base::Time::Now() - base::CurrentProcessInfo::CreationTime(); |
| 440 size_t expected_value = ((kMaxSizeForTesting / 2) * |
| 441 expected_dict_lifetime.InMilliseconds()) / |
| 442 expected_proc_lifetime.InMilliseconds(); |
| 443 |
| 444 tester.ExpectTotalCount("Sdch3.TimeWeightedMemoryUse", 1); |
| 445 tester.ExpectUniqueSample("Sdch3.TimeWeightedMemoryUse", expected_value, 1); |
| 425 } | 446 } |
| 426 | 447 |
| 427 // Confirm auto-eviction happens if space is needed, with a more complicated | 448 // Confirm auto-eviction happens if space is needed, with a more complicated |
| 428 // situation | 449 // situation |
| 429 TEST_F(SdchOwnerTest, ConfirmAutoEviction_2) { | 450 TEST_F(SdchOwnerTest, ConfirmAutoEviction_2) { |
| 430 std::string server_hash_d1; | 451 std::string server_hash_d1; |
| 431 std::string server_hash_d2; | 452 std::string server_hash_d2; |
| 432 std::string server_hash_d3; | 453 std::string server_hash_d3; |
| 433 | 454 |
| 434 // Add dictionaries, one recent, two more than a day in the past that | 455 // Add dictionaries, one recent, two more than a day in the past that |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 | 868 |
| 848 ResetOwner(true); | 869 ResetOwner(true); |
| 849 InsertDictionaryForURL(url0, "0"); | 870 InsertDictionaryForURL(url0, "0"); |
| 850 EXPECT_EQ(1, owner_->GetDictionaryCountForTesting()); | 871 EXPECT_EQ(1, owner_->GetDictionaryCountForTesting()); |
| 851 owner_->EnablePersistentStorage(pref_store_.get()); | 872 owner_->EnablePersistentStorage(pref_store_.get()); |
| 852 ASSERT_TRUE(CompleteLoadFromURL(url1, "1")); | 873 ASSERT_TRUE(CompleteLoadFromURL(url1, "1")); |
| 853 EXPECT_EQ(2, owner_->GetDictionaryCountForTesting()); | 874 EXPECT_EQ(2, owner_->GetDictionaryCountForTesting()); |
| 854 } | 875 } |
| 855 | 876 |
| 856 } // namespace net | 877 } // namespace net |
| OLD | NEW |