Chromium Code Reviews| Index: chrome/browser/password_manager/password_manager_test_base.cc |
| diff --git a/chrome/browser/password_manager/password_manager_test_base.cc b/chrome/browser/password_manager/password_manager_test_base.cc |
| index c398a218dba7dafb42e6a7d58355860e991cc074..5e991ca08400947ef14ec9fd5a313a0e4d713fd6 100644 |
| --- a/chrome/browser/password_manager/password_manager_test_base.cc |
| +++ b/chrome/browser/password_manager/password_manager_test_base.cc |
| @@ -23,7 +23,10 @@ |
| #include "content/public/browser/render_frame_host.h" |
| #include "content/public/test/browser_test_utils.h" |
| #include "content/public/test/test_utils.h" |
| +#include "net/http/transport_security_state.h" |
| #include "net/test/embedded_test_server/embedded_test_server.h" |
| +#include "net/url_request/url_request_context.h" |
| +#include "net/url_request/url_request_context_getter.h" |
| namespace { |
| @@ -47,6 +50,23 @@ class PasswordStoreResultsObserver |
| DISALLOW_COPY_AND_ASSIGN(PasswordStoreResultsObserver); |
| }; |
| +void AddHSTSHostImpl( |
| + const scoped_refptr<net::URLRequestContextGetter>& request_context, |
| + const std::string& host) { |
| + ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| + net::TransportSecurityState* transport_security_state = |
| + request_context->GetURLRequestContext()->transport_security_state(); |
| + if (!transport_security_state) { |
| + FAIL(); |
|
vasilii
2017/03/08 13:31:16
ADD_FAILURE?
jdoerrie
2017/03/09 18:35:49
Done.
|
| + return; |
| + } |
| + |
| + base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); |
| + bool include_subdomains = false; |
| + transport_security_state->AddHSTS(host, expiry, include_subdomains); |
| + EXPECT_TRUE(transport_security_state->ShouldUpgradeToSSL(host)); |
| +} |
| + |
| } // namespace |
| NavigationObserver::NavigationObserver(content::WebContents* web_contents) |
| @@ -291,3 +311,14 @@ void PasswordManagerBrowserTestBase::CheckElementValue( |
| EXPECT_TRUE(return_value) << "element_id = " << element_id |
| << ", expected_value = " << expected_value; |
| } |
| + |
| +void PasswordManagerBrowserTestBase::AddHSTSHost(const std::string& host) { |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::IO, FROM_HERE, |
| + base::Bind(&AddHSTSHostImpl, |
| + make_scoped_refptr(browser()->profile()->GetRequestContext()), |
| + host)); |
| + |
| + // Wait until posted task is completed. |
| + base::RunLoop().RunUntilIdle(); |
|
vasilii
2017/03/08 13:31:16
I'd avoid it in the browser tests. How about PostT
jdoerrie
2017/03/09 18:35:49
Could you elaborate on what you are thinking of? I
vasilii
2017/03/10 10:21:00
I meant something like this
scoped_refptr<content
jdoerrie
2017/03/10 13:53:10
Done.
|
| +} |