Commit 850aa873 authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

Allow IO in TestCertificateProviderExtension

Move the ScopedAllowBlockingForTesting into the
TestCertificateProviderExtension class where needed, so that its
consumers in tests don't have to worry about it (and also so that the
scoped IO allowance is used in the smallest possible scope).

This is a pure refactoring CL.

Bug: 1067683
Change-Id: I164bd520c3ea9191a58838412628336147029eaf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2280000Reviewed-by: default avatarFabian Sommer <fabiansommer@chromium.org>
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785328}
parent 6971ebbf
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/common/extensions/api/certificate_provider.h" #include "chrome/common/extensions/api/certificate_provider.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
...@@ -108,6 +109,11 @@ void SendReplyToJs(extensions::TestSendMessageFunction* function, ...@@ -108,6 +109,11 @@ void SendReplyToJs(extensions::TestSendMessageFunction* function,
function->Reply(ConvertValueToJson(response)); function->Reply(ConvertValueToJson(response));
} }
bssl::UniquePtr<EVP_PKEY> LoadPrivateKeyFromPem(const base::FilePath& path) {
base::ScopedAllowBlockingForTesting allow_io;
return net::key_util::LoadEVP_PKEYFromPEM(path);
}
} // namespace } // namespace
// static // static
...@@ -134,9 +140,8 @@ TestCertificateProviderExtension::TestCertificateProviderExtension( ...@@ -134,9 +140,8 @@ TestCertificateProviderExtension::TestCertificateProviderExtension(
: browser_context_(browser_context), : browser_context_(browser_context),
extension_id_(extension_id), extension_id_(extension_id),
certificate_(GetCertificate()), certificate_(GetCertificate()),
private_key_(net::key_util::LoadEVP_PKEYFromPEM( private_key_(LoadPrivateKeyFromPem(net::GetTestCertsDirectory().Append(
net::GetTestCertsDirectory().Append( FILE_PATH_LITERAL("client_1.key")))) {
FILE_PATH_LITERAL("client_1.key")))) {
DCHECK(browser_context_); DCHECK(browser_context_);
DCHECK(!extension_id_.empty()); DCHECK(!extension_id_.empty());
CHECK(certificate_); CHECK(certificate_);
......
...@@ -517,14 +517,8 @@ IN_PROC_BROWSER_TEST_F(CertificateProviderApiTest, LazyBackgroundPage) { ...@@ -517,14 +517,8 @@ IN_PROC_BROWSER_TEST_F(CertificateProviderApiTest, LazyBackgroundPage) {
.AppendASCII("test_certificate_provider") .AppendASCII("test_certificate_provider")
.AppendASCII("extension")); .AppendASCII("extension"));
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
std::unique_ptr<TestCertificateProviderExtension> TestCertificateProviderExtension test_certificate_provider_extension(
test_certificate_provider_extension; profile(), extension->id());
{
base::ScopedAllowBlockingForTesting allow_io;
test_certificate_provider_extension =
std::make_unique<TestCertificateProviderExtension>(profile(),
extension->id());
}
extensions::TestBackgroundPageFirstLoadObserver(profile(), extension->id()) extensions::TestBackgroundPageFirstLoadObserver(profile(), extension->id())
.Wait(); .Wait();
...@@ -540,8 +534,7 @@ IN_PROC_BROWSER_TEST_F(CertificateProviderApiTest, LazyBackgroundPage) { ...@@ -540,8 +534,7 @@ IN_PROC_BROWSER_TEST_F(CertificateProviderApiTest, LazyBackgroundPage) {
incognito_browser, client_cert_url, incognito_browser, client_cert_url,
WindowOpenDisposition::NEW_FOREGROUND_TAB, WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP); ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP);
EXPECT_EQ(test_certificate_provider_extension->certificate_request_count(), EXPECT_EQ(test_certificate_provider_extension.certificate_request_count(), 1);
1);
EXPECT_EQ(GetPageTextContent( EXPECT_EQ(GetPageTextContent(
incognito_browser->tab_strip_model()->GetActiveWebContents()), incognito_browser->tab_strip_model()->GetActiveWebContents()),
"got client cert with fingerprint: " + client_cert_fingerprint); "got client cert with fingerprint: " + client_cert_fingerprint);
...@@ -556,8 +549,7 @@ IN_PROC_BROWSER_TEST_F(CertificateProviderApiTest, LazyBackgroundPage) { ...@@ -556,8 +549,7 @@ IN_PROC_BROWSER_TEST_F(CertificateProviderApiTest, LazyBackgroundPage) {
ui_test_utils::NavigateToURLWithDisposition( ui_test_utils::NavigateToURLWithDisposition(
browser(), client_cert_url, WindowOpenDisposition::NEW_FOREGROUND_TAB, browser(), client_cert_url, WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP); ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP);
EXPECT_EQ(test_certificate_provider_extension->certificate_request_count(), EXPECT_EQ(test_certificate_provider_extension.certificate_request_count(), 2);
2);
EXPECT_EQ( EXPECT_EQ(
GetPageTextContent(browser()->tab_strip_model()->GetActiveWebContents()), GetPageTextContent(browser()->tab_strip_model()->GetActiveWebContents()),
"got client cert with fingerprint: " + client_cert_fingerprint); "got client cert with fingerprint: " + client_cert_fingerprint);
......
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