| 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/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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2)); | 453 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2)); |
| 454 | 454 |
| 455 sdch_manager().ClearData(); | 455 sdch_manager().ClearData(); |
| 456 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d1)); | 456 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d1)); |
| 457 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2)); | 457 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2)); |
| 458 | 458 |
| 459 // Addition should now succeed. | 459 // Addition should now succeed. |
| 460 EXPECT_TRUE(CreateAndAddDictionary(kMaxSizeForTesting, nullptr)); | 460 EXPECT_TRUE(CreateAndAddDictionary(kMaxSizeForTesting, nullptr)); |
| 461 } | 461 } |
| 462 | 462 |
| 463 #if 0 |
| 464 // Remove memory_pressure_listener_ to investigate http://crbug.com/447208 |
| 463 // Confirm memory pressure gets all the space back. | 465 // Confirm memory pressure gets all the space back. |
| 464 TEST_F(SdchOwnerTest, MemoryPressureReturnsSpace) { | 466 TEST_F(SdchOwnerTest, MemoryPressureReturnsSpace) { |
| 465 std::string server_hash_d1; | 467 std::string server_hash_d1; |
| 466 std::string server_hash_d2; | 468 std::string server_hash_d2; |
| 467 | 469 |
| 468 // Take up all the space. | 470 // Take up all the space. |
| 469 EXPECT_TRUE(CreateAndAddDictionary(kMaxSizeForTesting, &server_hash_d1)); | 471 EXPECT_TRUE(CreateAndAddDictionary(kMaxSizeForTesting, &server_hash_d1)); |
| 470 | 472 |
| 471 // Addition should fail. | 473 // Addition should fail. |
| 472 EXPECT_FALSE(CreateAndAddDictionary(kMaxSizeForTesting, &server_hash_d2)); | 474 EXPECT_FALSE(CreateAndAddDictionary(kMaxSizeForTesting, &server_hash_d2)); |
| 473 | 475 |
| 474 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1)); | 476 EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1)); |
| 475 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2)); | 477 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2)); |
| 476 | 478 |
| 477 base::MemoryPressureListener::NotifyMemoryPressure( | 479 base::MemoryPressureListener::NotifyMemoryPressure( |
| 478 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); | 480 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 479 // The notification may have (implementation note: does :-}) use a PostTask, | 481 // The notification may have (implementation note: does :-}) use a PostTask, |
| 480 // so we drain the local message queue. This should be safe (i.e. not have | 482 // so we drain the local message queue. This should be safe (i.e. not have |
| 481 // an inifinite number of messages) in a unit test. | 483 // an inifinite number of messages) in a unit test. |
| 482 base::RunLoop().RunUntilIdle(); | 484 base::RunLoop().RunUntilIdle(); |
| 483 | 485 |
| 484 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d1)); | 486 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d1)); |
| 485 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2)); | 487 EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2)); |
| 486 | 488 |
| 487 // Addition should now succeed. | 489 // Addition should now succeed. |
| 488 EXPECT_TRUE(CreateAndAddDictionary(kMaxSizeForTesting, nullptr)); | 490 EXPECT_TRUE(CreateAndAddDictionary(kMaxSizeForTesting, nullptr)); |
| 489 } | 491 } |
| 492 #endif |
| 490 | 493 |
| 491 } // namespace net | 494 } // namespace net |
| OLD | NEW |