Commit 1c455525 authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

Fix leaks in BackgroundFetchDataManagerTest tests.

These tests must allow tasks on the cache thread and the main loop to
run to allow for proper cleanup. Without this, files in the profile dir
may be held open beyond the lifetime of the test function, inhibiting
ScopedTempDir's ability to clean them up during TestBrowserContext
destruction.

BUG=546640,1016662

Change-Id: I1f9b50cb91a7fd287a103a4528ffe393720aeec9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1882319
Commit-Queue: Greg Thompson <grt@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Reviewed-by: default avatarRayan Kanso <rayankans@chromium.org>
Auto-Submit: Greg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709877}
parent 87367777
......@@ -17,6 +17,7 @@
#include "base/guid.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/metrics/histogram_tester.h"
#include "content/browser/background_fetch/background_fetch.pb.h"
#include "content/browser/background_fetch/background_fetch_data_manager_observer.h"
......@@ -198,6 +199,14 @@ class BackgroundFetchDataManagerTest
background_fetch_data_manager_->RemoveObserver(this);
}
void TearDown() override {
// Allow remaining tasks on the cache thread and main thread to run to clean
// up all dangling file handles.
base::ThreadPoolInstance::Get()->FlushForTesting();
base::RunLoop().RunUntilIdle();
BackgroundFetchTestBase::TearDown();
}
// Re-creates the data manager. Useful for testing that data was persisted.
void RestartDataManagerFromPersistentStorage() {
background_fetch_data_manager_ =
......@@ -478,16 +487,12 @@ class BackgroundFetchDataManagerTest
origin(), CacheStorageOwner::kBackgroundFetch);
auto match_options = blink::mojom::CacheQueryOptions::New();
match_options->ignore_search = true;
// Note: QuitWhenIdleClosure is used rather than QuitClosure to allow
// destruction of the fetch response given to DidMatchCache to post a
// series of tasks that ultimately tear down the connection and allow
// resources to be freed (including an open file in the cache).
cache_storage.value()->MatchCache(
kExampleUniqueId, BackgroundFetchSettledFetch::CloneRequest(request),
std::move(match_options),
/* trace_id= */ 0,
base::BindOnce(&BackgroundFetchDataManagerTest::DidMatchCache,
base::Unretained(this), run_loop.QuitWhenIdleClosure(),
base::Unretained(this), run_loop.QuitClosure(),
&result));
run_loop.Run();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment