Fix CefResourceHandler leak in DownloadTest.Pending*

This commit is contained in:
Marshall Greenblatt
2019-01-23 14:47:52 +01:00
parent e94b3e2478
commit a189c5b937

View File

@@ -323,6 +323,9 @@ class DownloadTestHandler : public TestHandler {
CefRefPtr<CefDownloadItemCallback> callback) override { CefRefPtr<CefDownloadItemCallback> callback) override {
EXPECT_TRUE(CefCurrentlyOn(TID_UI)); EXPECT_TRUE(CefCurrentlyOn(TID_UI));
if (destroyed_)
return;
got_on_download_updated_.yes(); got_on_download_updated_.yes();
EXPECT_TRUE(browser->IsSame(GetBrowser())); EXPECT_TRUE(browser->IsSame(GetBrowser()));
@@ -366,9 +369,11 @@ class DownloadTestHandler : public TestHandler {
EXPECT_LE(0LL, download_item->GetReceivedBytes()); EXPECT_LE(0LL, download_item->GetReceivedBytes());
} }
if (test_mode_ == PENDING) if (test_mode_ == PENDING) {
download_item_callback_ = callback;
ContinuePendingIfReady(); ContinuePendingIfReady();
} }
}
void VerifyResultsOnFileThread() { void VerifyResultsOnFileThread() {
EXPECT_TRUE(CefCurrentlyOn(TID_FILE)); EXPECT_TRUE(CefCurrentlyOn(TID_FILE));
@@ -397,6 +402,14 @@ class DownloadTestHandler : public TestHandler {
return; return;
} }
destroyed_ = true;
if (download_item_callback_) {
// Cancel the pending download to avoid leaking request objects.
download_item_callback_->Cancel();
download_item_callback_ = nullptr;
}
if (request_context_) { if (request_context_) {
request_context_->RegisterSchemeHandlerFactory("http", kTestDomain, request_context_->RegisterSchemeHandlerFactory("http", kTestDomain,
nullptr); nullptr);
@@ -448,13 +461,17 @@ class DownloadTestHandler : public TestHandler {
CefRefPtr<CefRequestContext> request_context_; CefRefPtr<CefRequestContext> request_context_;
// Used with NAVIGATED test mode. // Used with NAVIGATED and PENDING test modes.
CefRefPtr<CefCallback> delay_callback_; CefRefPtr<CefCallback> delay_callback_;
// Used with PENDING test mode.
CefRefPtr<CefDownloadItemCallback> download_item_callback_;
CefScopedTempDir temp_dir_; CefScopedTempDir temp_dir_;
std::string test_path_; std::string test_path_;
uint32 download_id_; uint32 download_id_;
bool verified_results_; bool verified_results_;
bool destroyed_ = false;
TrackCallback got_download_request_; TrackCallback got_download_request_;
TrackCallback got_on_before_download_; TrackCallback got_on_before_download_;