Commit 05e4b055 authored by David Benjamin's avatar David Benjamin Committed by Commit Bot

Unwind IO thread in SSLClientCertificateSelector tests

The IO thread bits originally set up a URLRequestContext and friends,
but that has been removed as of
https://chromium-review.googlesource.com/c/1355136.

Bug: 908955
Change-Id: I5d2cd6f53352d142d64b7fa1e9fef7ba9f1939a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2314831Reviewed-by: default avatarRyan Sleevi <rsleevi@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: David Benjamin <davidben@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791853}
parent b9e7641f
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "net/base/request_priority.h" #include "net/base/request_priority.h"
...@@ -20,13 +18,12 @@ ...@@ -20,13 +18,12 @@
using ::testing::Mock; using ::testing::Mock;
using ::testing::StrictMock; using ::testing::StrictMock;
SSLClientCertificateSelectorTestBase::SSLClientCertificateSelectorTestBase()
: io_loop_finished_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED) {
}
SSLClientCertificateSelectorTestBase::~SSLClientCertificateSelectorTestBase() { SSLClientCertificateSelectorTestBase::SSLClientCertificateSelectorTestBase() =
} default;
SSLClientCertificateSelectorTestBase::~SSLClientCertificateSelectorTestBase() =
default;
void SSLClientCertificateSelectorTestBase::SetUpInProcessBrowserTestFixture() { void SSLClientCertificateSelectorTestBase::SetUpInProcessBrowserTestFixture() {
cert_request_info_ = base::MakeRefCounted<net::SSLCertRequestInfo>(); cert_request_info_ = base::MakeRefCounted<net::SSLCertRequestInfo>();
...@@ -34,37 +31,15 @@ void SSLClientCertificateSelectorTestBase::SetUpInProcessBrowserTestFixture() { ...@@ -34,37 +31,15 @@ void SSLClientCertificateSelectorTestBase::SetUpInProcessBrowserTestFixture() {
} }
void SSLClientCertificateSelectorTestBase::SetUpOnMainThread() { void SSLClientCertificateSelectorTestBase::SetUpOnMainThread() {
content::GetIOThreadTaskRunner({})->PostTask( auth_requestor_ =
FROM_HERE, new StrictMock<SSLClientAuthRequestorMock>(cert_request_info_.get());
base::BindOnce(&SSLClientCertificateSelectorTestBase::SetUpOnIOThread,
base::Unretained(this)));
io_loop_finished_event_.Wait();
EXPECT_TRUE(content::WaitForLoadStop( EXPECT_TRUE(content::WaitForLoadStop(
browser()->tab_strip_model()->GetActiveWebContents())); browser()->tab_strip_model()->GetActiveWebContents()));
} }
// Have to release our reference to the auth handler during the test to allow // Have to release our reference to the auth handler during the test to allow
// it to be destroyed while the Browser and its IO thread still exist. // it to be destroyed while the Browser still exists.
void SSLClientCertificateSelectorTestBase::TearDownOnMainThread() { void SSLClientCertificateSelectorTestBase::TearDownOnMainThread() {
content::GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&SSLClientCertificateSelectorTestBase::TearDownOnIOThread,
base::Unretained(this)));
io_loop_finished_event_.Wait();
auth_requestor_.reset(); auth_requestor_.reset();
} }
void SSLClientCertificateSelectorTestBase::SetUpOnIOThread() {
auth_requestor_ =
new StrictMock<SSLClientAuthRequestorMock>(cert_request_info_.get());
io_loop_finished_event_.Signal();
}
void SSLClientCertificateSelectorTestBase::TearDownOnIOThread() {
io_loop_finished_event_.Signal();
}
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <memory> #include <memory>
#include "base/synchronization/waitable_event.h"
#include "chrome/browser/ssl/ssl_client_auth_requestor_mock.h" #include "chrome/browser/ssl/ssl_client_auth_requestor_mock.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -22,12 +21,7 @@ class SSLClientCertificateSelectorTestBase : public InProcessBrowserTest { ...@@ -22,12 +21,7 @@ class SSLClientCertificateSelectorTestBase : public InProcessBrowserTest {
void SetUpOnMainThread() override; void SetUpOnMainThread() override;
void TearDownOnMainThread() override; void TearDownOnMainThread() override;
virtual void SetUpOnIOThread();
virtual void TearDownOnIOThread();
protected: protected:
base::WaitableEvent io_loop_finished_event_;
scoped_refptr<net::SSLCertRequestInfo> cert_request_info_; scoped_refptr<net::SSLCertRequestInfo> cert_request_info_;
scoped_refptr<testing::StrictMock<SSLClientAuthRequestorMock> > scoped_refptr<testing::StrictMock<SSLClientAuthRequestorMock> >
auth_requestor_; auth_requestor_;
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -17,8 +16,6 @@ ...@@ -17,8 +16,6 @@
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/client_certificate_delegate.h" #include "content/public/browser/client_certificate_delegate.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
...@@ -42,11 +39,7 @@ using ::testing::StrictMock; ...@@ -42,11 +39,7 @@ using ::testing::StrictMock;
class SSLClientCertificateSelectorTest : public InProcessBrowserTest { class SSLClientCertificateSelectorTest : public InProcessBrowserTest {
public: public:
SSLClientCertificateSelectorTest() SSLClientCertificateSelectorTest() = default;
: io_loop_finished_event_(
base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED),
selector_(nullptr) {}
void SetUpInProcessBrowserTestFixture() override { void SetUpInProcessBrowserTestFixture() override {
base::FilePath certs_dir = net::GetTestCertsDirectory(); base::FilePath certs_dir = net::GetTestCertsDirectory();
...@@ -63,12 +56,8 @@ class SSLClientCertificateSelectorTest : public InProcessBrowserTest { ...@@ -63,12 +56,8 @@ class SSLClientCertificateSelectorTest : public InProcessBrowserTest {
} }
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
content::GetIOThreadTaskRunner({})->PostTask( auth_requestor_ =
FROM_HERE, new StrictMock<SSLClientAuthRequestorMock>(cert_request_info_);
base::BindOnce(&SSLClientCertificateSelectorTest::SetUpOnIOThread,
base::Unretained(this)));
io_loop_finished_event_.Wait();
EXPECT_TRUE(content::WaitForLoadStop( EXPECT_TRUE(content::WaitForLoadStop(
browser()->tab_strip_model()->GetActiveWebContents())); browser()->tab_strip_model()->GetActiveWebContents()));
...@@ -87,39 +76,19 @@ class SSLClientCertificateSelectorTest : public InProcessBrowserTest { ...@@ -87,39 +76,19 @@ class SSLClientCertificateSelectorTest : public InProcessBrowserTest {
selector_->GetSelectedCert()->certificate()); selector_->GetSelectedCert()->certificate());
} }
virtual void SetUpOnIOThread() {
auth_requestor_ = new StrictMock<SSLClientAuthRequestorMock>(
cert_request_info_);
io_loop_finished_event_.Signal();
}
// Have to release our reference to the auth handler during the test to allow // Have to release our reference to the auth handler during the test to allow
// it to be destroyed while the Browser and its IO thread still exist. // it to be destroyed while the Browser still exists.
void TearDownOnMainThread() override { void TearDownOnMainThread() override {
content::GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&SSLClientCertificateSelectorTest::CleanUpOnIOThread,
base::Unretained(this)));
io_loop_finished_event_.Wait();
auth_requestor_.reset(); auth_requestor_.reset();
} }
virtual void CleanUpOnIOThread() {
io_loop_finished_event_.Signal();
}
protected: protected:
base::WaitableEvent io_loop_finished_event_;
std::unique_ptr<net::FakeClientCertIdentity> cert_identity_1_; std::unique_ptr<net::FakeClientCertIdentity> cert_identity_1_;
std::unique_ptr<net::FakeClientCertIdentity> cert_identity_2_; std::unique_ptr<net::FakeClientCertIdentity> cert_identity_2_;
scoped_refptr<net::SSLCertRequestInfo> cert_request_info_; scoped_refptr<net::SSLCertRequestInfo> cert_request_info_;
scoped_refptr<StrictMock<SSLClientAuthRequestorMock> > auth_requestor_; scoped_refptr<StrictMock<SSLClientAuthRequestorMock>> auth_requestor_;
// The selector will be deleted when a cert is selected or the tab is closed. // The selector will be deleted when a cert is selected or the tab is closed.
SSLClientCertificateSelector* selector_; SSLClientCertificateSelector* selector_ = nullptr;
}; };
class SSLClientCertificateSelectorMultiTabTest class SSLClientCertificateSelectorMultiTabTest
...@@ -136,9 +105,13 @@ class SSLClientCertificateSelectorMultiTabTest ...@@ -136,9 +105,13 @@ class SSLClientCertificateSelectorMultiTabTest
} }
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
// Also calls SetUpOnIOThread.
SSLClientCertificateSelectorTest::SetUpOnMainThread(); SSLClientCertificateSelectorTest::SetUpOnMainThread();
auth_requestor_1_ =
new StrictMock<SSLClientAuthRequestorMock>(cert_request_info_1_);
auth_requestor_2_ =
new StrictMock<SSLClientAuthRequestorMock>(cert_request_info_2_);
AddTabAtIndex(1, GURL("about:blank"), ui::PAGE_TRANSITION_LINK); AddTabAtIndex(1, GURL("about:blank"), ui::PAGE_TRANSITION_LINK);
AddTabAtIndex(2, GURL("about:blank"), ui::PAGE_TRANSITION_LINK); AddTabAtIndex(2, GURL("about:blank"), ui::PAGE_TRANSITION_LINK);
ASSERT_TRUE(NULL != browser()->tab_strip_model()->GetWebContentsAt(0)); ASSERT_TRUE(NULL != browser()->tab_strip_model()->GetWebContentsAt(0));
...@@ -178,30 +151,17 @@ class SSLClientCertificateSelectorMultiTabTest ...@@ -178,30 +151,17 @@ class SSLClientCertificateSelectorMultiTabTest
selector_2_->GetSelectedCert()->certificate()); selector_2_->GetSelectedCert()->certificate());
} }
void SetUpOnIOThread() override {
auth_requestor_1_ = new StrictMock<SSLClientAuthRequestorMock>(
cert_request_info_1_);
auth_requestor_2_ = new StrictMock<SSLClientAuthRequestorMock>(
cert_request_info_2_);
SSLClientCertificateSelectorTest::SetUpOnIOThread();
}
void TearDownOnMainThread() override { void TearDownOnMainThread() override {
auth_requestor_2_.reset(); auth_requestor_2_.reset();
auth_requestor_1_.reset(); auth_requestor_1_.reset();
SSLClientCertificateSelectorTest::TearDownOnMainThread(); SSLClientCertificateSelectorTest::TearDownOnMainThread();
} }
void CleanUpOnIOThread() override {
SSLClientCertificateSelectorTest::CleanUpOnIOThread();
}
protected: protected:
scoped_refptr<net::SSLCertRequestInfo> cert_request_info_1_; scoped_refptr<net::SSLCertRequestInfo> cert_request_info_1_;
scoped_refptr<net::SSLCertRequestInfo> cert_request_info_2_; scoped_refptr<net::SSLCertRequestInfo> cert_request_info_2_;
scoped_refptr<StrictMock<SSLClientAuthRequestorMock> > auth_requestor_1_; scoped_refptr<StrictMock<SSLClientAuthRequestorMock>> auth_requestor_1_;
scoped_refptr<StrictMock<SSLClientAuthRequestorMock> > auth_requestor_2_; scoped_refptr<StrictMock<SSLClientAuthRequestorMock>> auth_requestor_2_;
SSLClientCertificateSelector* selector_1_; SSLClientCertificateSelector* selector_1_;
SSLClientCertificateSelector* selector_2_; SSLClientCertificateSelector* selector_2_;
}; };
...@@ -222,9 +182,11 @@ class SSLClientCertificateSelectorMultiProfileTest ...@@ -222,9 +182,11 @@ class SSLClientCertificateSelectorMultiProfileTest
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
browser_1_ = CreateIncognitoBrowser(); browser_1_ = CreateIncognitoBrowser();
// Also calls SetUpOnIOThread.
SSLClientCertificateSelectorTest::SetUpOnMainThread(); SSLClientCertificateSelectorTest::SetUpOnMainThread();
auth_requestor_1_ =
new StrictMock<SSLClientAuthRequestorMock>(cert_request_info_1_);
net::ClientCertIdentityList cert_identity_list; net::ClientCertIdentityList cert_identity_list;
cert_identity_list.push_back(cert_identity_1_->Copy()); cert_identity_list.push_back(cert_identity_1_->Copy());
cert_identity_list.push_back(cert_identity_2_->Copy()); cert_identity_list.push_back(cert_identity_2_->Copy());
...@@ -246,22 +208,11 @@ class SSLClientCertificateSelectorMultiProfileTest ...@@ -246,22 +208,11 @@ class SSLClientCertificateSelectorMultiProfileTest
selector_1_->GetSelectedCert()->certificate()); selector_1_->GetSelectedCert()->certificate());
} }
void SetUpOnIOThread() override {
auth_requestor_1_ = new StrictMock<SSLClientAuthRequestorMock>(
cert_request_info_1_);
SSLClientCertificateSelectorTest::SetUpOnIOThread();
}
void TearDownOnMainThread() override { void TearDownOnMainThread() override {
auth_requestor_1_.reset(); auth_requestor_1_.reset();
SSLClientCertificateSelectorTest::TearDownOnMainThread(); SSLClientCertificateSelectorTest::TearDownOnMainThread();
} }
void CleanUpOnIOThread() override {
SSLClientCertificateSelectorTest::CleanUpOnIOThread();
}
protected: protected:
Browser* browser_1_; Browser* browser_1_;
scoped_refptr<net::SSLCertRequestInfo> cert_request_info_1_; scoped_refptr<net::SSLCertRequestInfo> cert_request_info_1_;
......
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