Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: chrome/browser/password_manager/password_manager_test_base.cc

Issue 2721663002: Move Credentials when migrating to HSTS page (Closed)
Patch Set: Code Deduplication Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/password_manager/password_manager_test_base.h" 5 #include "chrome/browser/password_manager/password_manager_test_base.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/password_manager/password_store_factory.h" 12 #include "chrome/browser/password_manager/password_store_factory.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 15 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "components/autofill/core/browser/autofill_test_utils.h" 18 #include "components/autofill/core/browser/autofill_test_utils.h"
19 #include "components/password_manager/core/browser/password_manager_test_utils.h " 19 #include "components/password_manager/core/browser/password_manager_test_utils.h "
20 #include "components/password_manager/core/browser/test_password_store.h" 20 #include "components/password_manager/core/browser/test_password_store.h"
21 #include "content/public/browser/navigation_details.h" 21 #include "content/public/browser/navigation_details.h"
22 #include "content/public/browser/navigation_handle.h" 22 #include "content/public/browser/navigation_handle.h"
23 #include "content/public/browser/render_frame_host.h" 23 #include "content/public/browser/render_frame_host.h"
24 #include "content/public/test/browser_test_utils.h" 24 #include "content/public/test/browser_test_utils.h"
25 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
26 #include "net/http/transport_security_state.h"
26 #include "net/test/embedded_test_server/embedded_test_server.h" 27 #include "net/test/embedded_test_server/embedded_test_server.h"
28 #include "net/url_request/url_request_context.h"
29 #include "net/url_request/url_request_context_getter.h"
27 30
28 namespace { 31 namespace {
29 32
30 // A helper class that synchronously waits until the password store handles a 33 // A helper class that synchronously waits until the password store handles a
31 // GetLogins() request. 34 // GetLogins() request.
32 class PasswordStoreResultsObserver 35 class PasswordStoreResultsObserver
33 : public password_manager::PasswordStoreConsumer { 36 : public password_manager::PasswordStoreConsumer {
34 public: 37 public:
35 PasswordStoreResultsObserver() = default; 38 PasswordStoreResultsObserver() = default;
36 39
37 void OnGetPasswordStoreResults( 40 void OnGetPasswordStoreResults(
38 std::vector<std::unique_ptr<autofill::PasswordForm>> results) override { 41 std::vector<std::unique_ptr<autofill::PasswordForm>> results) override {
39 run_loop_.Quit(); 42 run_loop_.Quit();
40 } 43 }
41 44
42 void Wait() { run_loop_.Run(); } 45 void Wait() { run_loop_.Run(); }
43 46
44 private: 47 private:
45 base::RunLoop run_loop_; 48 base::RunLoop run_loop_;
46 49
47 DISALLOW_COPY_AND_ASSIGN(PasswordStoreResultsObserver); 50 DISALLOW_COPY_AND_ASSIGN(PasswordStoreResultsObserver);
48 }; 51 };
49 52
53 void AddHSTSHostImpl(
54 const scoped_refptr<net::URLRequestContextGetter>& request_context,
55 const std::string& host) {
56 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
57 net::TransportSecurityState* transport_security_state =
58 request_context->GetURLRequestContext()->transport_security_state();
59 if (!transport_security_state) {
60 FAIL();
vasilii 2017/03/08 13:31:16 ADD_FAILURE?
jdoerrie 2017/03/09 18:35:49 Done.
61 return;
62 }
63
64 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000);
65 bool include_subdomains = false;
66 transport_security_state->AddHSTS(host, expiry, include_subdomains);
67 EXPECT_TRUE(transport_security_state->ShouldUpgradeToSSL(host));
68 }
69
50 } // namespace 70 } // namespace
51 71
52 NavigationObserver::NavigationObserver(content::WebContents* web_contents) 72 NavigationObserver::NavigationObserver(content::WebContents* web_contents)
53 : content::WebContentsObserver(web_contents), 73 : content::WebContentsObserver(web_contents),
54 quit_on_entry_committed_(false), 74 quit_on_entry_committed_(false),
55 message_loop_runner_(new content::MessageLoopRunner) { 75 message_loop_runner_(new content::MessageLoopRunner) {
56 } 76 }
57 NavigationObserver::~NavigationObserver() { 77 NavigationObserver::~NavigationObserver() {
58 } 78 }
59 79
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 " var element = document.getElementById('%s');" 304 " var element = document.getElementById('%s');"
285 "window.domAutomationController.send(element && element.value == '%s');", 305 "window.domAutomationController.send(element && element.value == '%s');",
286 iframe_id.c_str(), iframe_id.c_str(), element_id.c_str(), 306 iframe_id.c_str(), iframe_id.c_str(), element_id.c_str(),
287 element_id.c_str(), expected_value.c_str()); 307 element_id.c_str(), expected_value.c_str());
288 bool return_value = false; 308 bool return_value = false;
289 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 309 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
290 RenderViewHost(), value_check_script, &return_value)); 310 RenderViewHost(), value_check_script, &return_value));
291 EXPECT_TRUE(return_value) << "element_id = " << element_id 311 EXPECT_TRUE(return_value) << "element_id = " << element_id
292 << ", expected_value = " << expected_value; 312 << ", expected_value = " << expected_value;
293 } 313 }
314
315 void PasswordManagerBrowserTestBase::AddHSTSHost(const std::string& host) {
316 content::BrowserThread::PostTask(
317 content::BrowserThread::IO, FROM_HERE,
318 base::Bind(&AddHSTSHostImpl,
319 make_scoped_refptr(browser()->profile()->GetRequestContext()),
320 host));
321
322 // Wait until posted task is completed.
323 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.
324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698