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

Side by Side Diff: net/disk_cache/backend_unittest.cc

Issue 2661333002: Track SimpleCache memory usage in net/ MemoryDumpProvider (Closed)
Patch Set: address comments Created 3 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/test/mock_entropy_provider.h" 16 #include "base/test/mock_entropy_provider.h"
17 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 17 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
18 #include "base/threading/platform_thread.h" 18 #include "base/threading/platform_thread.h"
19 #include "base/threading/thread_restrictions.h" 19 #include "base/threading/thread_restrictions.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/trace_event/memory_usage_estimator.h"
21 #include "net/base/cache_type.h" 22 #include "net/base/cache_type.h"
22 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
23 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
24 #include "net/base/test_completion_callback.h" 25 #include "net/base/test_completion_callback.h"
25 #include "net/disk_cache/blockfile/backend_impl.h" 26 #include "net/disk_cache/blockfile/backend_impl.h"
26 #include "net/disk_cache/blockfile/entry_impl.h" 27 #include "net/disk_cache/blockfile/entry_impl.h"
27 #include "net/disk_cache/blockfile/experiments.h" 28 #include "net/disk_cache/blockfile/experiments.h"
28 #include "net/disk_cache/blockfile/histogram_macros.h" 29 #include "net/disk_cache/blockfile/histogram_macros.h"
29 #include "net/disk_cache/blockfile/mapped_file.h" 30 #include "net/disk_cache/blockfile/mapped_file.h"
30 #include "net/disk_cache/cache_util.h" 31 #include "net/disk_cache/cache_util.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 317 }
317 318
318 void DiskCacheBackendTest::BackendBasics() { 319 void DiskCacheBackendTest::BackendBasics() {
319 InitCache(); 320 InitCache();
320 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; 321 disk_cache::Entry *entry1 = NULL, *entry2 = NULL;
321 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); 322 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1));
322 ASSERT_THAT(CreateEntry("the first key", &entry1), IsOk()); 323 ASSERT_THAT(CreateEntry("the first key", &entry1), IsOk());
323 ASSERT_TRUE(NULL != entry1); 324 ASSERT_TRUE(NULL != entry1);
324 entry1->Close(); 325 entry1->Close();
325 entry1 = NULL; 326 entry1 = NULL;
327 // base::trace_event::EstimateMemoryUsage(cache_) is added to make sure
328 // tracking memory doesn't introduce crashes.
329 EXPECT_LT(0u, base::trace_event::EstimateMemoryUsage(cache_));
326 330
327 ASSERT_THAT(OpenEntry("the first key", &entry1), IsOk()); 331 ASSERT_THAT(OpenEntry("the first key", &entry1), IsOk());
328 ASSERT_TRUE(NULL != entry1); 332 ASSERT_TRUE(NULL != entry1);
329 entry1->Close(); 333 entry1->Close();
330 entry1 = NULL; 334 entry1 = NULL;
331 335
332 EXPECT_NE(net::OK, CreateEntry("the first key", &entry1)); 336 EXPECT_NE(net::OK, CreateEntry("the first key", &entry1));
333 ASSERT_THAT(OpenEntry("the first key", &entry1), IsOk()); 337 ASSERT_THAT(OpenEntry("the first key", &entry1), IsOk());
334 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); 338 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
335 ASSERT_THAT(CreateEntry("some other key", &entry2), IsOk()); 339 ASSERT_THAT(CreateEntry("some other key", &entry2), IsOk());
336 ASSERT_TRUE(NULL != entry1); 340 ASSERT_TRUE(NULL != entry1);
337 ASSERT_TRUE(NULL != entry2); 341 ASSERT_TRUE(NULL != entry2);
338 EXPECT_EQ(2, cache_->GetEntryCount()); 342 EXPECT_EQ(2, cache_->GetEntryCount());
343 EXPECT_LT(0u, base::trace_event::EstimateMemoryUsage(cache_));
339 344
340 disk_cache::Entry* entry3 = NULL; 345 disk_cache::Entry* entry3 = NULL;
341 ASSERT_THAT(OpenEntry("some other key", &entry3), IsOk()); 346 ASSERT_THAT(OpenEntry("some other key", &entry3), IsOk());
342 ASSERT_TRUE(NULL != entry3); 347 ASSERT_TRUE(NULL != entry3);
343 EXPECT_TRUE(entry2 == entry3); 348 EXPECT_TRUE(entry2 == entry3);
344 EXPECT_EQ(2, cache_->GetEntryCount()); 349 EXPECT_LT(0u, base::trace_event::EstimateMemoryUsage(cache_));
345 350
346 EXPECT_THAT(DoomEntry("some other key"), IsOk()); 351 EXPECT_THAT(DoomEntry("some other key"), IsOk());
347 EXPECT_EQ(1, cache_->GetEntryCount()); 352 EXPECT_EQ(1, cache_->GetEntryCount());
348 entry1->Close(); 353 entry1->Close();
349 entry2->Close(); 354 entry2->Close();
350 entry3->Close(); 355 entry3->Close();
356 EXPECT_LT(0u, base::trace_event::EstimateMemoryUsage(cache_));
351 357
352 EXPECT_THAT(DoomEntry("the first key"), IsOk()); 358 EXPECT_THAT(DoomEntry("the first key"), IsOk());
353 EXPECT_EQ(0, cache_->GetEntryCount()); 359 EXPECT_EQ(0, cache_->GetEntryCount());
354 360
355 ASSERT_THAT(CreateEntry("the first key", &entry1), IsOk()); 361 ASSERT_THAT(CreateEntry("the first key", &entry1), IsOk());
356 ASSERT_THAT(CreateEntry("some other key", &entry2), IsOk()); 362 ASSERT_THAT(CreateEntry("some other key", &entry2), IsOk());
357 entry1->Doom(); 363 entry1->Doom();
358 entry1->Close(); 364 entry1->Close();
359 EXPECT_THAT(DoomEntry("some other key"), IsOk()); 365 EXPECT_THAT(DoomEntry("some other key"), IsOk());
360 EXPECT_EQ(0, cache_->GetEntryCount()); 366 EXPECT_EQ(0, cache_->GetEntryCount());
361 entry2->Close(); 367 entry2->Close();
368 EXPECT_LT(0u, base::trace_event::EstimateMemoryUsage(cache_));
362 } 369 }
363 370
364 TEST_F(DiskCacheBackendTest, Basics) { 371 TEST_F(DiskCacheBackendTest, Basics) {
365 BackendBasics(); 372 BackendBasics();
366 } 373 }
367 374
368 TEST_F(DiskCacheBackendTest, NewEvictionBasics) { 375 TEST_F(DiskCacheBackendTest, NewEvictionBasics) {
369 SetNewEviction(); 376 SetNewEviction();
370 BackendBasics(); 377 BackendBasics();
371 } 378 }
(...skipping 3549 matching lines...) Expand 10 before | Expand all | Expand 10 after
3921 // because that would advance the cache directory mtime and invalidate the 3928 // because that would advance the cache directory mtime and invalidate the
3922 // index. 3929 // index.
3923 entry2->Doom(); 3930 entry2->Doom();
3924 entry2->Close(); 3931 entry2->Close();
3925 3932
3926 DisableFirstCleanup(); 3933 DisableFirstCleanup();
3927 InitCache(); 3934 InitCache();
3928 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, 3935 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED,
3929 simple_cache_impl_->index()->init_method()); 3936 simple_cache_impl_->index()->init_method());
3930 } 3937 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698