| Index: components/web_cache/browser/web_cache_manager_unittest.cc
|
| diff --git a/components/web_cache/browser/web_cache_manager_unittest.cc b/components/web_cache/browser/web_cache_manager_unittest.cc
|
| index 826552eb6e14fe4d0106478e185856c97f636ac5..2989021a449b20c46548b47a5d8887404ea7be2d 100644
|
| --- a/components/web_cache/browser/web_cache_manager_unittest.cc
|
| +++ b/components/web_cache/browser/web_cache_manager_unittest.cc
|
| @@ -14,7 +14,6 @@
|
| using base::Time;
|
| using base::TimeDelta;
|
| using content::BrowserThread;
|
| -using blink::WebCache;
|
|
|
| namespace web_cache {
|
|
|
| @@ -26,8 +25,8 @@ class WebCacheManagerTest : public testing::Test {
|
|
|
| static const int kRendererID;
|
| static const int kRendererID2;
|
| - static const WebCache::UsageStats kStats;
|
| - static const WebCache::UsageStats kStats2;
|
| + static const WebCacheManager::RendererInfo kStats;
|
| + static const WebCacheManager::RendererInfo kStats2;
|
|
|
| WebCacheManagerTest()
|
| : ui_thread_(BrowserThread::UI, &message_loop_) {
|
| @@ -53,38 +52,46 @@ class WebCacheManagerTest : public testing::Test {
|
| }
|
| static void GatherStats(WebCacheManager* h,
|
| std::set<int> renderers,
|
| - WebCache::UsageStats* stats) {
|
| - h->GatherStats(renderers, stats);
|
| + WebCacheManager::RendererInfo* stats) {
|
| + memset(stats, 0, sizeof(WebCacheManager::RendererInfo));
|
| + h->GatherStats(renderers, &stats->capacity, &stats->live_size,
|
| + &stats->dead_size);
|
| }
|
| - static size_t GetSize(int tactic,
|
| - const WebCache::UsageStats& stats) {
|
| + static uint64_t GetSize(int tactic,
|
| + const WebCacheManager::RendererInfo& stats) {
|
| return WebCacheManager::GetSize(
|
| - static_cast<WebCacheManager::AllocationTactic>(tactic), stats);
|
| + static_cast<WebCacheManager::AllocationTactic>(tactic), stats.live_size,
|
| + stats.dead_size);
|
| }
|
| static bool AttemptTactic(WebCacheManager* h,
|
| int active_tactic,
|
| - const WebCache::UsageStats& active_stats,
|
| + const WebCacheManager::RendererInfo& active_stats,
|
| int inactive_tactic,
|
| - const WebCache::UsageStats& inactive_stats,
|
| - std::list< std::pair<int,size_t> >* strategy) {
|
| + const WebCacheManager::RendererInfo& inactive_stats,
|
| + std::list<std::pair<int, uint64_t>>* strategy) {
|
| return h->AttemptTactic(
|
| static_cast<WebCacheManager::AllocationTactic>(active_tactic),
|
| - active_stats,
|
| + active_stats.live_size, active_stats.dead_size,
|
| static_cast<WebCacheManager::AllocationTactic>(inactive_tactic),
|
| - inactive_stats,
|
| - strategy);
|
| + inactive_stats.live_size, inactive_stats.dead_size, strategy);
|
| }
|
| static void AddToStrategy(WebCacheManager* h,
|
| std::set<int> renderers,
|
| int tactic,
|
| - size_t extra_bytes_to_allocate,
|
| - std::list< std::pair<int,size_t> >* strategy) {
|
| + uint64_t extra_bytes_to_allocate,
|
| + std::list<std::pair<int, uint64_t>>* strategy) {
|
| h->AddToStrategy(renderers,
|
| static_cast<WebCacheManager::AllocationTactic>(tactic),
|
| extra_bytes_to_allocate,
|
| strategy);
|
| }
|
|
|
| + static bool RendererInfoEqual(const WebCacheManager::RendererInfo& lhs,
|
| + const WebCacheManager::RendererInfo& rhs) {
|
| + return lhs.capacity == rhs.capacity && lhs.live_size == rhs.live_size &&
|
| + lhs.dead_size == rhs.dead_size;
|
| + }
|
| +
|
| enum {
|
| DIVIDE_EVENLY = WebCacheManager::DIVIDE_EVENLY,
|
| KEEP_CURRENT_WITH_HEADROOM = WebCacheManager::KEEP_CURRENT_WITH_HEADROOM,
|
| @@ -108,27 +115,14 @@ const int WebCacheManagerTest::kRendererID = 146;
|
| const int WebCacheManagerTest::kRendererID2 = 245;
|
|
|
| // static
|
| -const WebCache::UsageStats WebCacheManagerTest::kStats = {
|
| - 0,
|
| - 1024 * 1024,
|
| - 1024 * 1024,
|
| - 256 * 1024,
|
| - 512,
|
| - };
|
| +const WebCacheManager::RendererInfo WebCacheManagerTest::kStats = {
|
| + base::Time(), 0, 1024 * 1024, 1024 * 1024, 256 * 1024, 512,
|
| +};
|
|
|
| // static
|
| -const WebCache::UsageStats WebCacheManagerTest::kStats2 = {
|
| - 0,
|
| - 2 * 1024 * 1024,
|
| - 2 * 1024 * 1024,
|
| - 2 * 256 * 1024,
|
| - 2 * 512,
|
| - };
|
| -
|
| -static bool operator==(const WebCache::UsageStats& lhs,
|
| - const WebCache::UsageStats& rhs) {
|
| - return !::memcmp(&lhs, &rhs, sizeof(WebCache::UsageStats));
|
| -}
|
| +const WebCacheManager::RendererInfo WebCacheManagerTest::kStats2 = {
|
| + base::Time(), 0, 2 * 1024 * 1024, 2 * 1024 * 1024, 2 * 256 * 1024, 2 * 512,
|
| +};
|
|
|
| TEST_F(WebCacheManagerTest, AddRemoveRendererTest) {
|
| EXPECT_EQ(0U, active_renderers(manager()).size());
|
| @@ -166,16 +160,18 @@ TEST_F(WebCacheManagerTest, ObserveStatsTest) {
|
|
|
| EXPECT_EQ(1U, stats(manager()).size());
|
|
|
| - manager()->ObserveStats(kRendererID, kStats);
|
| + manager()->ObserveStats(kRendererID, kStats.min_dead_capacity,
|
| + kStats.max_dead_capacity, kStats.capacity,
|
| + kStats.live_size, kStats.dead_size);
|
|
|
| EXPECT_EQ(1U, stats(manager()).size());
|
| - EXPECT_TRUE(kStats == stats(manager())[kRendererID]);
|
| + EXPECT_TRUE(RendererInfoEqual(kStats, stats(manager())[kRendererID]));
|
|
|
| manager()->Remove(kRendererID);
|
| }
|
|
|
| TEST_F(WebCacheManagerTest, SetGlobalSizeLimitTest) {
|
| - size_t limit = manager()->GetDefaultGlobalSizeLimit();
|
| + uint64_t limit = manager()->GetDefaultGlobalSizeLimit();
|
| manager()->SetGlobalSizeLimit(limit);
|
| EXPECT_EQ(limit, manager()->global_size_limit());
|
|
|
| @@ -187,28 +183,32 @@ TEST_F(WebCacheManagerTest, GatherStatsTest) {
|
| manager()->Add(kRendererID);
|
| manager()->Add(kRendererID2);
|
|
|
| - manager()->ObserveStats(kRendererID, kStats);
|
| - manager()->ObserveStats(kRendererID2, kStats2);
|
| + manager()->ObserveStats(kRendererID, kStats.min_dead_capacity,
|
| + kStats.max_dead_capacity, kStats.capacity,
|
| + kStats.live_size, kStats.dead_size);
|
| + manager()->ObserveStats(kRendererID2, kStats2.min_dead_capacity,
|
| + kStats2.max_dead_capacity, kStats2.capacity,
|
| + kStats2.live_size, kStats2.dead_size);
|
|
|
| std::set<int> renderer_set;
|
| renderer_set.insert(kRendererID);
|
|
|
| - WebCache::UsageStats stats;
|
| + WebCacheManager::RendererInfo stats;
|
| GatherStats(manager(), renderer_set, &stats);
|
|
|
| - EXPECT_TRUE(kStats == stats);
|
| + EXPECT_TRUE(RendererInfoEqual(kStats, stats));
|
|
|
| renderer_set.insert(kRendererID2);
|
| GatherStats(manager(), renderer_set, &stats);
|
|
|
| - WebCache::UsageStats expected_stats = kStats;
|
| - expected_stats.minDeadCapacity += kStats2.minDeadCapacity;
|
| - expected_stats.maxDeadCapacity += kStats2.maxDeadCapacity;
|
| + WebCacheManager::RendererInfo expected_stats = kStats;
|
| + expected_stats.min_dead_capacity += kStats2.min_dead_capacity;
|
| + expected_stats.max_dead_capacity += kStats2.max_dead_capacity;
|
| expected_stats.capacity += kStats2.capacity;
|
| - expected_stats.liveSize += kStats2.liveSize;
|
| - expected_stats.deadSize += kStats2.deadSize;
|
| + expected_stats.live_size += kStats2.live_size;
|
| + expected_stats.dead_size += kStats2.dead_size;
|
|
|
| - EXPECT_TRUE(expected_stats == stats);
|
| + EXPECT_TRUE(RendererInfoEqual(expected_stats, stats));
|
|
|
| manager()->Remove(kRendererID);
|
| manager()->Remove(kRendererID2);
|
| @@ -229,11 +229,15 @@ TEST_F(WebCacheManagerTest, AttemptTacticTest) {
|
| manager()->ObserveActivity(kRendererID);
|
| SimulateInactivity(manager(), kRendererID2);
|
|
|
| - manager()->ObserveStats(kRendererID, kStats);
|
| - manager()->ObserveStats(kRendererID2, kStats2);
|
| + manager()->ObserveStats(kRendererID, kStats.min_dead_capacity,
|
| + kStats.max_dead_capacity, kStats.capacity,
|
| + kStats.live_size, kStats.dead_size);
|
| + manager()->ObserveStats(kRendererID2, kStats2.min_dead_capacity,
|
| + kStats2.max_dead_capacity, kStats2.capacity,
|
| + kStats2.live_size, kStats2.dead_size);
|
|
|
| - manager()->SetGlobalSizeLimit(kStats.liveSize + kStats.deadSize +
|
| - kStats2.liveSize + kStats2.deadSize/2);
|
| + manager()->SetGlobalSizeLimit(kStats.live_size + kStats.dead_size +
|
| + kStats2.live_size + kStats2.dead_size / 2);
|
|
|
| AllocationStrategy strategy;
|
|
|
| @@ -256,9 +260,9 @@ TEST_F(WebCacheManagerTest, AttemptTacticTest) {
|
| AllocationStrategy::iterator iter = strategy.begin();
|
| while (iter != strategy.end()) {
|
| if (iter->first == kRendererID)
|
| - EXPECT_LE(kStats.liveSize + kStats.deadSize, iter->second);
|
| + EXPECT_LE(kStats.live_size + kStats.dead_size, iter->second);
|
| else if (iter->first == kRendererID2)
|
| - EXPECT_LE(kStats2.liveSize, iter->second);
|
| + EXPECT_LE(kStats2.live_size, iter->second);
|
| else
|
| ADD_FAILURE(); // Unexpected entry in strategy.
|
| ++iter;
|
| @@ -276,10 +280,14 @@ TEST_F(WebCacheManagerTest, AddToStrategyTest) {
|
| renderer_set.insert(kRendererID);
|
| renderer_set.insert(kRendererID2);
|
|
|
| - manager()->ObserveStats(kRendererID, kStats);
|
| - manager()->ObserveStats(kRendererID2, kStats2);
|
| + manager()->ObserveStats(kRendererID, kStats.min_dead_capacity,
|
| + kStats.max_dead_capacity, kStats.capacity,
|
| + kStats.live_size, kStats.dead_size);
|
| + manager()->ObserveStats(kRendererID2, kStats2.min_dead_capacity,
|
| + kStats2.max_dead_capacity, kStats2.capacity,
|
| + kStats2.live_size, kStats2.dead_size);
|
|
|
| - const size_t kExtraBytesToAllocate = 10 * 1024;
|
| + const uint64_t kExtraBytesToAllocate = 10 * 1024;
|
|
|
| AllocationStrategy strategy;
|
| AddToStrategy(manager(),
|
| @@ -290,23 +298,23 @@ TEST_F(WebCacheManagerTest, AddToStrategyTest) {
|
|
|
| EXPECT_EQ(2U, strategy.size());
|
|
|
| - size_t total_bytes = 0;
|
| + uint64_t total_bytes = 0;
|
| AllocationStrategy::iterator iter = strategy.begin();
|
| while (iter != strategy.end()) {
|
| total_bytes += iter->second;
|
|
|
| if (iter->first == kRendererID)
|
| - EXPECT_LE(kStats.liveSize + kStats.deadSize, iter->second);
|
| + EXPECT_LE(kStats.live_size + kStats.dead_size, iter->second);
|
| else if (iter->first == kRendererID2)
|
| - EXPECT_LE(kStats2.liveSize + kStats2.deadSize, iter->second);
|
| + EXPECT_LE(kStats2.live_size + kStats2.dead_size, iter->second);
|
| else
|
| ADD_FAILURE(); // Unexpected entry in strategy.
|
| ++iter;
|
| }
|
|
|
| - size_t expected_total_bytes = kExtraBytesToAllocate +
|
| - kStats.liveSize + kStats.deadSize +
|
| - kStats2.liveSize + kStats2.deadSize;
|
| + uint64_t expected_total_bytes = kExtraBytesToAllocate + kStats.live_size +
|
| + kStats.dead_size + kStats2.live_size +
|
| + kStats2.dead_size;
|
|
|
| EXPECT_GE(expected_total_bytes, total_bytes);
|
|
|
|
|