Skip to content

Commit

Permalink
Add test cases for cobalt::loader::FetcherCache (#1832)
Browse files Browse the repository at this point in the history
Test FetcherCache with corner cases, and try to catch crash issue.

b/270993319
  • Loading branch information
borongc authored Apr 14, 2024
1 parent 8b22ec9 commit 89a8945
Show file tree
Hide file tree
Showing 3 changed files with 433 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cobalt/loader/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ target(gtest_target_type, "loader_test") {

sources = [
"blob_fetcher_test.cc",
"fetcher_cache_test.cc",
"fetcher_factory_test.cc",
"fetcher_test.h",
"file_fetcher_test.cc",
Expand All @@ -201,6 +202,7 @@ target(gtest_target_type, "loader_test") {
"//testing/gmock",
"//testing/gtest",
"//third_party/ots:ots",
"//url",
]

data_deps = [ ":copy_loader_test_data" ]
Expand Down
10 changes: 10 additions & 0 deletions cobalt/loader/fetcher_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ class FetcherCache : public base::RefCountedThreadSafe<FetcherCache> {
Loader::FetcherCreator GetFetcherCreator(
const GURL& url, const Loader::FetcherCreator& real_fetcher_creator);
void NotifyResourceRequested(const std::string& url);
size_t size() const {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
CHECK_EQ(thread_id_, SbThreadGetId());
return total_size_;
}
size_t capacity() const {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
CHECK_EQ(thread_id_, SbThreadGetId());
return capacity_;
}

// To signal the imminent destruction of this object. If everything is
// working as expected, there shouldn't be any other reference of this object,
Expand Down
Loading

0 comments on commit 89a8945

Please sign in to comment.