Skip to content

Commit

Permalink
Cherry pick PR #1832: Add test cases for cobalt::loader::FetcherCache (
Browse files Browse the repository at this point in the history
…#2935)

Refer to the original PR: #1832

Test FetcherCache with corner cases, and try to catch crash issue.

b/270993319

Co-authored-by: Bo-Rong Chen <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and borongc committed Apr 15, 2024
1 parent ca01273 commit 5bda47d
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 @@ -178,6 +178,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 @@ -204,6 +205,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 5bda47d

Please sign in to comment.