Commit 0bbefb9f authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: fix crash in AwBrowserContextTest

No change to production logic.

This fixes a crash in AwBrowserContextTest. The issue was the second
test in the suite (regardless of what that test did) would crash as soon
as the setup constructs a TestContentClientInitializer. This is because
a posted task created a NetworkConnectionTracker, running after
TestContentClientInitializer's destructor nulled it out. It's invalid to
re-set a NetworkConnectionTracker without first clearing it, triggering
a DCHECK.

We avoid this by pumping through the UI thread looper during the test
teardown, so we're sure the background task has executed prior to
destroying TestContentClientInitializer.

This also fixes a memory leak in the test setup/teardown (we need to
clean up the AwBrowserProcess instance), although this was unrelated
to the bug.

Bug: 990547
Test: run_android_webview_unittests --num_retries=0 --gtest_filter=AwBrowserContextTest.*
Change-Id: I16d03a1cf6d813b7052b8205d2936864397fc21e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1849174
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704282}
parent 62c45474
......@@ -5,6 +5,7 @@
#include "android_webview/browser/aw_browser_context.h"
#include "android_webview/browser/aw_browser_process.h"
#include "android_webview/browser/aw_feature_list_creator.h"
#include "base/run_loop.h"
#include "content/public/browser/browser_context.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_content_client_initializer.h"
......@@ -25,7 +26,15 @@ class AwBrowserContextTest : public testing::Test {
browser_process_ = new AwBrowserProcess(aw_feature_list_creator);
}
void TearDown() override { delete test_content_client_initializer_; }
void TearDown() override {
// Drain the message queue before destroying
// |test_content_client_initializer_|, otherwise a posted task may call
// content::GetNetworkConnectionTracker() after
// TestContentClientInitializer's destructor sets it to null.
base::RunLoop().RunUntilIdle();
delete test_content_client_initializer_;
delete browser_process_;
}
// Create the TestBrowserThreads.
content::BrowserTaskEnvironment task_environment_;
......
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