Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
| 9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 #include "ui/events/keycodes/keyboard_codes.h" | 48 #include "ui/events/keycodes/keyboard_codes.h" |
| 49 #include "ui/gfx/geometry/point.h" | 49 #include "ui/gfx/geometry/point.h" |
| 50 | 50 |
| 51 | 51 |
| 52 // NavigationObserver --------------------------------------------------------- | 52 // NavigationObserver --------------------------------------------------------- |
| 53 | 53 |
| 54 namespace { | 54 namespace { |
| 55 | 55 |
| 56 // Observer that waits for navigation to complete and for the password infobar | 56 // Observer that waits for navigation to complete and for the password infobar |
| 57 // to be shown. | 57 // to be shown. |
| 58 class NavigationObserver : public content::WebContentsObserver, | 58 class NavigationObserver : public content::WebContentsObserver { |
| 59 public infobars::InfoBarManager::Observer { | |
| 60 public: | 59 public: |
| 61 explicit NavigationObserver(content::WebContents* web_contents) | 60 explicit NavigationObserver(content::WebContents* web_contents) |
| 62 : content::WebContentsObserver(web_contents), | 61 : content::WebContentsObserver(web_contents), |
| 63 message_loop_runner_(new content::MessageLoopRunner), | 62 message_loop_runner_(new content::MessageLoopRunner) {} |
| 64 infobar_shown_(false), | |
| 65 infobar_removed_(false), | |
| 66 should_automatically_accept_infobar_(true), | |
| 67 infobar_service_(InfoBarService::FromWebContents(web_contents)) { | |
| 68 infobar_service_->AddObserver(this); | |
| 69 } | |
| 70 | 63 |
| 71 virtual ~NavigationObserver() { | 64 virtual ~NavigationObserver() {} |
| 72 if (infobar_service_) | |
| 73 infobar_service_->RemoveObserver(this); | |
| 74 } | |
| 75 | 65 |
| 76 // Normally Wait() will not return until a main frame navigation occurs. | 66 // Normally Wait() will not return until a main frame navigation occurs. |
| 77 // If a path is set, Wait() will return after this path has been seen, | 67 // If a path is set, Wait() will return after this path has been seen, |
| 78 // regardless of the frame that navigated. Useful for multi-frame pages. | 68 // regardless of the frame that navigated. Useful for multi-frame pages. |
| 79 void SetPathToWaitFor(const std::string& path) { | 69 void SetPathToWaitFor(const std::string& path) { |
| 80 wait_for_path_ = path; | 70 wait_for_path_ = path; |
| 81 } | 71 } |
| 82 | 72 |
| 83 // content::WebContentsObserver: | 73 // content::WebContentsObserver: |
| 84 virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host, | 74 virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| 85 const GURL& validated_url) OVERRIDE { | 75 const GURL& validated_url) OVERRIDE { |
| 86 if (!wait_for_path_.empty()) { | 76 if (!wait_for_path_.empty()) { |
| 87 if (validated_url.path() == wait_for_path_) | 77 if (validated_url.path() == wait_for_path_) |
| 88 message_loop_runner_->Quit(); | 78 message_loop_runner_->Quit(); |
| 89 } else if (!render_frame_host->GetParent()) { | 79 } else if (!render_frame_host->GetParent()) { |
| 90 message_loop_runner_->Quit(); | 80 message_loop_runner_->Quit(); |
| 91 } | 81 } |
| 92 } | 82 } |
| 93 | 83 |
| 94 bool infobar_shown() const { return infobar_shown_; } | |
| 95 bool infobar_removed() const { return infobar_removed_; } | |
| 96 | |
| 97 void disable_should_automatically_accept_infobar() { | |
| 98 should_automatically_accept_infobar_ = false; | |
| 99 } | |
| 100 | |
| 101 void Wait() { | 84 void Wait() { |
| 102 message_loop_runner_->Run(); | 85 message_loop_runner_->Run(); |
| 103 } | 86 } |
| 104 | 87 |
| 105 private: | 88 private: |
| 89 | |
| 90 std::string wait_for_path_; | |
| 91 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(NavigationObserver); | |
| 94 }; | |
| 95 | |
| 96 // Observes save password prompt (bubble or infobar) for a specified | |
|
engedy
2014/07/11 18:07:26
nits: Observes *the* save password prompt (bubble
vabr (Chromium)
2014/07/11 18:48:01
Done.
| |
| 97 // WebContents, keeps track if it is currently shown, and allows accepting | |
| 98 // passwords through it. | |
| 99 class PromptObserver { | |
| 100 public: | |
| 101 virtual ~PromptObserver() {} | |
| 102 | |
| 103 // Check if the prompt is being currently shown. | |
|
engedy
2014/07/11 18:07:27
nits: Please use third person in comments. (3 verb
vabr (Chromium)
2014/07/11 18:48:02
Done.
| |
| 104 virtual bool IsPromptShown() const = 0; | |
|
engedy
2014/07/11 18:07:26
nit: IsShowingPrompt
vabr (Chromium)
2014/07/11 18:48:02
Done.
| |
| 105 | |
| 106 // Expecting that the prompt is shown, save the password. Check that the | |
| 107 // prompt is no more visible. | |
|
engedy
2014/07/11 18:07:27
nit: no longer visible afterwards.
vabr (Chromium)
2014/07/11 18:48:02
Done.
| |
| 108 void Accept() const { | |
| 109 EXPECT_TRUE(IsPromptShown()); | |
| 110 AcceptImpl(); | |
| 111 } | |
| 112 | |
| 113 // Chooses the right implementation of PromptObserver and creates an instance | |
| 114 // of it. | |
| 115 static scoped_ptr<PromptObserver> Create(content::WebContents* web_contents); | |
|
engedy
2014/07/11 18:07:26
Nice!
vabr (Chromium)
2014/07/11 18:48:02
Acknowledged.
(And thanks! :))
| |
| 116 | |
| 117 protected: | |
| 118 PromptObserver() {} | |
| 119 | |
| 120 // Accepts the password. Can assume that the prompt is currently shown, makes | |
|
engedy
2014/07/11 18:07:26
Nit: the implementation can assume ... but is requ
vabr (Chromium)
2014/07/11 18:48:02
Done.
| |
| 121 // sure that the prompt is eventually closed. | |
| 122 virtual void AcceptImpl() const = 0; | |
| 123 | |
| 124 private: | |
| 125 DISALLOW_COPY_AND_ASSIGN(PromptObserver); | |
| 126 }; | |
| 127 | |
| 128 class InfoBarObserver : public PromptObserver, | |
| 129 public infobars::InfoBarManager::Observer { | |
| 130 public: | |
| 131 explicit InfoBarObserver(content::WebContents* web_contents) | |
| 132 : infobar_is_shown_(false), | |
|
engedy
2014/07/11 18:07:27
nit: infobar_is_showing_ or is_infobar_showing_.
vabr (Chromium)
2014/07/11 18:48:01
Done, with a change to infobar_is_being_shown_, wh
| |
| 133 infobar_service_(InfoBarService::FromWebContents(web_contents)) { | |
| 134 infobar_service_->AddObserver(this); | |
| 135 } | |
| 136 | |
| 137 virtual ~InfoBarObserver() { | |
| 138 if (infobar_service_) | |
| 139 infobar_service_->RemoveObserver(this); | |
| 140 } | |
| 141 | |
| 142 private: | |
| 143 // PromptObserver: | |
| 144 virtual bool IsPromptShown() const OVERRIDE { return infobar_is_shown_; } | |
| 145 | |
| 146 virtual void AcceptImpl() const OVERRIDE { | |
| 147 EXPECT_EQ(1u, infobar_service_->infobar_count()); | |
|
engedy
2014/07/11 18:07:26
I would assert here instead. (Or your if-solution,
vabr (Chromium)
2014/07/11 18:48:01
Done.
I don't think it would hang because of this.
| |
| 148 // ConfirmInfoBarDelegate::Accept returning true means the infobar is | |
| 149 // immediately closed. Checking the return value is preferred to testing | |
| 150 // IsPromptShown() here, for it avoids the delay until the closing | |
| 151 // notification is received. | |
| 152 EXPECT_TRUE(infobar_service_->infobar_at(0) | |
| 153 ->delegate() | |
| 154 ->AsConfirmInfoBarDelegate() | |
| 155 ->Accept()); | |
| 156 } | |
| 157 | |
| 106 // infobars::InfoBarManager::Observer: | 158 // infobars::InfoBarManager::Observer: |
| 107 virtual void OnInfoBarAdded(infobars::InfoBar* infobar) OVERRIDE { | 159 virtual void OnInfoBarAdded(infobars::InfoBar* infobar) OVERRIDE { |
| 108 if (should_automatically_accept_infobar_) { | 160 infobar_is_shown_ = true; |
| 109 infobar_service_->infobar_at(0)->delegate()-> | |
| 110 AsConfirmInfoBarDelegate()->Accept(); | |
| 111 } | |
| 112 infobar_shown_ = true; | |
| 113 } | 161 } |
| 114 | 162 |
| 115 virtual void OnInfoBarRemoved(infobars::InfoBar* infobar, | 163 virtual void OnInfoBarRemoved(infobars::InfoBar* infobar, |
| 116 bool animate) OVERRIDE { | 164 bool animate) OVERRIDE { |
| 117 infobar_removed_ = true; | 165 infobar_is_shown_ = false; |
| 118 } | 166 } |
| 119 | 167 |
| 120 virtual void OnManagerShuttingDown( | 168 virtual void OnManagerShuttingDown( |
| 121 infobars::InfoBarManager* manager) OVERRIDE { | 169 infobars::InfoBarManager* manager) OVERRIDE { |
| 122 ASSERT_EQ(infobar_service_, manager); | 170 ASSERT_EQ(infobar_service_, manager); |
| 123 infobar_service_->RemoveObserver(this); | 171 infobar_service_->RemoveObserver(this); |
| 124 infobar_service_ = NULL; | 172 infobar_service_ = NULL; |
| 125 } | 173 } |
| 126 | 174 |
| 127 std::string wait_for_path_; | 175 bool infobar_is_shown_; |
| 128 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 129 bool infobar_shown_; | |
| 130 bool infobar_removed_; | |
| 131 // If |should_automatically_accept_infobar_| is true, then whenever the test | |
| 132 // sees an infobar added, it will click its accepting button. Default = true. | |
| 133 bool should_automatically_accept_infobar_; | |
| 134 InfoBarService* infobar_service_; | 176 InfoBarService* infobar_service_; |
| 135 | 177 |
| 136 DISALLOW_COPY_AND_ASSIGN(NavigationObserver); | 178 DISALLOW_COPY_AND_ASSIGN(InfoBarObserver); |
| 137 }; | 179 }; |
| 138 | 180 |
| 181 class BubbleObserver : public PromptObserver { | |
| 182 public: | |
| 183 explicit BubbleObserver(content::WebContents* web_contents) | |
| 184 : ui_controller_( | |
| 185 ManagePasswordsUIController::FromWebContents(web_contents)) {} | |
| 186 | |
| 187 virtual ~BubbleObserver() {} | |
| 188 | |
| 189 private: | |
| 190 // PromptObserver: | |
| 191 virtual bool IsPromptShown() const OVERRIDE { | |
| 192 return ui_controller_->PasswordPendingUserDecision(); | |
| 193 } | |
| 194 | |
| 195 virtual void AcceptImpl() const OVERRIDE { | |
| 196 ui_controller_->SavePassword(); | |
| 197 EXPECT_FALSE(IsPromptShown()); | |
| 198 } | |
| 199 | |
| 200 ManagePasswordsUIController* const ui_controller_; | |
| 201 | |
| 202 DISALLOW_COPY_AND_ASSIGN(BubbleObserver); | |
| 203 }; | |
| 204 | |
| 205 // static | |
| 206 scoped_ptr<PromptObserver> PromptObserver::Create( | |
| 207 content::WebContents* web_contents) { | |
| 208 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | |
| 209 return scoped_ptr<PromptObserver>(new BubbleObserver(web_contents)); | |
| 210 } else { | |
| 211 return scoped_ptr<PromptObserver>(new InfoBarObserver(web_contents)); | |
| 212 } | |
| 213 } | |
| 214 | |
| 139 // Handles |request| to "/basic_auth". If "Authorization" header is present, | 215 // Handles |request| to "/basic_auth". If "Authorization" header is present, |
| 140 // responds with a non-empty HTTP 200 page (regardless of its value). Otherwise | 216 // responds with a non-empty HTTP 200 page (regardless of its value). Otherwise |
| 141 // serves a Basic Auth challenge. | 217 // serves a Basic Auth challenge. |
| 142 scoped_ptr<net::test_server::HttpResponse> HandleTestAuthRequest( | 218 scoped_ptr<net::test_server::HttpResponse> HandleTestAuthRequest( |
| 143 const net::test_server::HttpRequest& request) { | 219 const net::test_server::HttpRequest& request) { |
| 144 if (!StartsWithASCII(request.relative_url, "/basic_auth", true)) | 220 if (!StartsWithASCII(request.relative_url, "/basic_auth", true)) |
| 145 return scoped_ptr<net::test_server::HttpResponse>(); | 221 return scoped_ptr<net::test_server::HttpResponse>(); |
| 146 | 222 |
| 147 if (ContainsKey(request.headers, "Authorization")) { | 223 if (ContainsKey(request.headers, "Authorization")) { |
| 148 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 224 scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 | 265 |
| 190 protected: | 266 protected: |
| 191 content::WebContents* WebContents() { | 267 content::WebContents* WebContents() { |
| 192 return browser()->tab_strip_model()->GetActiveWebContents(); | 268 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 193 } | 269 } |
| 194 | 270 |
| 195 content::RenderViewHost* RenderViewHost() { | 271 content::RenderViewHost* RenderViewHost() { |
| 196 return WebContents()->GetRenderViewHost(); | 272 return WebContents()->GetRenderViewHost(); |
| 197 } | 273 } |
| 198 | 274 |
| 199 ManagePasswordsUIController* ui_controller() { | |
| 200 return ManagePasswordsUIController::FromWebContents(WebContents()); | |
| 201 } | |
| 202 | |
| 203 // Wrapper around ui_test_utils::NavigateToURL that waits until | 275 // Wrapper around ui_test_utils::NavigateToURL that waits until |
| 204 // DidFinishLoad() fires. Normally this function returns after | 276 // DidFinishLoad() fires. Normally this function returns after |
| 205 // DidStopLoading(), which caused flakiness as the NavigationObserver | 277 // DidStopLoading(), which caused flakiness as the NavigationObserver |
| 206 // would sometimes see the DidFinishLoad event from a previous navigation and | 278 // would sometimes see the DidFinishLoad event from a previous navigation and |
| 207 // return immediately. | 279 // return immediately. |
| 208 void NavigateToFile(const std::string& path) { | 280 void NavigateToFile(const std::string& path) { |
| 209 if (!embedded_test_server()->Started()) | 281 if (!embedded_test_server()->Started()) |
| 210 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 282 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 211 | 283 |
| 212 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( | 284 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 } | 369 } |
| 298 | 370 |
| 299 // Actual tests --------------------------------------------------------------- | 371 // Actual tests --------------------------------------------------------------- |
| 300 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 372 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 301 PromptForNormalSubmit) { | 373 PromptForNormalSubmit) { |
| 302 NavigateToFile("/password/password_form.html"); | 374 NavigateToFile("/password/password_form.html"); |
| 303 | 375 |
| 304 // Fill a form and submit through a <input type="submit"> button. Nothing | 376 // Fill a form and submit through a <input type="submit"> button. Nothing |
| 305 // special. | 377 // special. |
| 306 NavigationObserver observer(WebContents()); | 378 NavigationObserver observer(WebContents()); |
| 379 scoped_ptr<PromptObserver> prompt_observer( | |
| 380 PromptObserver::Create(WebContents())); | |
| 307 std::string fill_and_submit = | 381 std::string fill_and_submit = |
| 308 "document.getElementById('username_field').value = 'temp';" | 382 "document.getElementById('username_field').value = 'temp';" |
| 309 "document.getElementById('password_field').value = 'random';" | 383 "document.getElementById('password_field').value = 'random';" |
| 310 "document.getElementById('input_submit_button').click()"; | 384 "document.getElementById('input_submit_button').click()"; |
| 311 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 385 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 312 observer.Wait(); | 386 observer.Wait(); |
| 313 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 387 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 314 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 315 } else { | |
| 316 EXPECT_TRUE(observer.infobar_shown()); | |
| 317 } | |
| 318 } | 388 } |
| 319 | 389 |
| 320 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 390 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 321 PromptForSubmitWithInPageNavigation) { | 391 PromptForSubmitWithInPageNavigation) { |
| 322 NavigateToFile("/password/password_navigate_before_submit.html"); | 392 NavigateToFile("/password/password_navigate_before_submit.html"); |
| 323 | 393 |
| 324 // Fill a form and submit through a <input type="submit"> button. Nothing | 394 // Fill a form and submit through a <input type="submit"> button. Nothing |
| 325 // special. The form does an in-page navigation before submitting. | 395 // special. The form does an in-page navigation before submitting. |
| 326 NavigationObserver observer(WebContents()); | 396 NavigationObserver observer(WebContents()); |
| 397 scoped_ptr<PromptObserver> prompt_observer( | |
| 398 PromptObserver::Create(WebContents())); | |
| 327 std::string fill_and_submit = | 399 std::string fill_and_submit = |
| 328 "document.getElementById('username_field').value = 'temp';" | 400 "document.getElementById('username_field').value = 'temp';" |
| 329 "document.getElementById('password_field').value = 'random';" | 401 "document.getElementById('password_field').value = 'random';" |
| 330 "document.getElementById('input_submit_button').click()"; | 402 "document.getElementById('input_submit_button').click()"; |
| 331 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 403 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 332 observer.Wait(); | 404 observer.Wait(); |
| 333 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 405 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 334 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 335 } else { | |
| 336 EXPECT_TRUE(observer.infobar_shown()); | |
| 337 } | |
| 338 } | 406 } |
| 339 | 407 |
| 340 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 408 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 341 LoginSuccessWithUnrelatedForm) { | 409 LoginSuccessWithUnrelatedForm) { |
| 342 // Log in, see a form on the landing page. That form is not related to the | 410 // Log in, see a form on the landing page. That form is not related to the |
| 343 // login form (=has a different action), so we should offer saving the | 411 // login form (=has a different action), so we should offer saving the |
| 344 // password. | 412 // password. |
| 345 NavigateToFile("/password/password_form.html"); | 413 NavigateToFile("/password/password_form.html"); |
| 346 | 414 |
| 347 NavigationObserver observer(WebContents()); | 415 NavigationObserver observer(WebContents()); |
| 416 scoped_ptr<PromptObserver> prompt_observer( | |
| 417 PromptObserver::Create(WebContents())); | |
| 348 std::string fill_and_submit = | 418 std::string fill_and_submit = |
| 349 "document.getElementById('username_unrelated').value = 'temp';" | 419 "document.getElementById('username_unrelated').value = 'temp';" |
| 350 "document.getElementById('password_unrelated').value = 'random';" | 420 "document.getElementById('password_unrelated').value = 'random';" |
| 351 "document.getElementById('submit_unrelated').click()"; | 421 "document.getElementById('submit_unrelated').click()"; |
| 352 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 422 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 353 observer.Wait(); | 423 observer.Wait(); |
| 354 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 424 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 355 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 356 } else { | |
| 357 EXPECT_TRUE(observer.infobar_shown()); | |
| 358 } | |
| 359 } | 425 } |
| 360 | 426 |
| 361 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, LoginFailed) { | 427 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, LoginFailed) { |
| 362 // Log in, see a form on the landing page. That form is not related to the | 428 // Log in, see a form on the landing page. That form is not related to the |
| 363 // login form (=has a different action), so we should offer saving the | 429 // login form (=has a different action), so we should offer saving the |
| 364 // password. | 430 // password. |
| 365 NavigateToFile("/password/password_form.html"); | 431 NavigateToFile("/password/password_form.html"); |
| 366 | 432 |
| 367 NavigationObserver observer(WebContents()); | 433 NavigationObserver observer(WebContents()); |
| 434 scoped_ptr<PromptObserver> prompt_observer( | |
| 435 PromptObserver::Create(WebContents())); | |
| 368 std::string fill_and_submit = | 436 std::string fill_and_submit = |
| 369 "document.getElementById('username_failed').value = 'temp';" | 437 "document.getElementById('username_failed').value = 'temp';" |
| 370 "document.getElementById('password_failed').value = 'random';" | 438 "document.getElementById('password_failed').value = 'random';" |
| 371 "document.getElementById('submit_failed').click()"; | 439 "document.getElementById('submit_failed').click()"; |
| 372 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 440 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 373 observer.Wait(); | 441 observer.Wait(); |
| 374 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 442 EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| 375 EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); | |
| 376 } else { | |
| 377 EXPECT_FALSE(observer.infobar_shown()); | |
| 378 } | |
| 379 } | 443 } |
| 380 | 444 |
| 381 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, Redirects) { | 445 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, Redirects) { |
| 382 NavigateToFile("/password/password_form.html"); | 446 NavigateToFile("/password/password_form.html"); |
| 383 | 447 |
| 384 // Fill a form and submit through a <input type="submit"> button. The form | 448 // Fill a form and submit through a <input type="submit"> button. The form |
| 385 // points to a redirection page. | 449 // points to a redirection page. |
| 386 NavigationObserver observer(WebContents()); | 450 NavigationObserver observer(WebContents()); |
| 451 scoped_ptr<PromptObserver> prompt_observer( | |
| 452 PromptObserver::Create(WebContents())); | |
| 387 std::string fill_and_submit = | 453 std::string fill_and_submit = |
| 388 "document.getElementById('username_redirect').value = 'temp';" | 454 "document.getElementById('username_redirect').value = 'temp';" |
| 389 "document.getElementById('password_redirect').value = 'random';" | 455 "document.getElementById('password_redirect').value = 'random';" |
| 390 "document.getElementById('submit_redirect').click()"; | 456 "document.getElementById('submit_redirect').click()"; |
| 391 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 457 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 392 observer.disable_should_automatically_accept_infobar(); | |
| 393 observer.Wait(); | 458 observer.Wait(); |
| 394 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 459 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 395 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 396 } else { | |
| 397 EXPECT_TRUE(observer.infobar_shown()); | |
| 398 } | |
| 399 | 460 |
| 400 // The redirection page now redirects via Javascript. We check that the | 461 // The redirection page now redirects via Javascript. We check that the |
| 401 // infobar stays. | 462 // infobar stays. |
| 402 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), | 463 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), |
| 403 "window.location.href = 'done.html';")); | 464 "window.location.href = 'done.html';")); |
| 404 observer.Wait(); | 465 observer.Wait(); |
| 405 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 466 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 406 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 407 } else { | |
| 408 EXPECT_FALSE(observer.infobar_removed()); | |
| 409 } | |
| 410 } | 467 } |
| 411 | 468 |
| 412 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 469 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 413 PromptForSubmitUsingJavaScript) { | 470 PromptForSubmitUsingJavaScript) { |
| 414 NavigateToFile("/password/password_form.html"); | 471 NavigateToFile("/password/password_form.html"); |
| 415 | 472 |
| 416 // Fill a form and submit using <button> that calls submit() on the form. | 473 // Fill a form and submit using <button> that calls submit() on the form. |
| 417 // This should work regardless of the type of element, as long as submit() is | 474 // This should work regardless of the type of element, as long as submit() is |
| 418 // called. | 475 // called. |
| 419 NavigationObserver observer(WebContents()); | 476 NavigationObserver observer(WebContents()); |
| 477 scoped_ptr<PromptObserver> prompt_observer( | |
| 478 PromptObserver::Create(WebContents())); | |
| 420 std::string fill_and_submit = | 479 std::string fill_and_submit = |
| 421 "document.getElementById('username_field').value = 'temp';" | 480 "document.getElementById('username_field').value = 'temp';" |
| 422 "document.getElementById('password_field').value = 'random';" | 481 "document.getElementById('password_field').value = 'random';" |
| 423 "document.getElementById('submit_button').click()"; | 482 "document.getElementById('submit_button').click()"; |
| 424 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 483 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 425 observer.Wait(); | 484 observer.Wait(); |
| 426 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 485 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 427 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 428 } else { | |
| 429 EXPECT_TRUE(observer.infobar_shown()); | |
| 430 } | |
| 431 } | 486 } |
| 432 | 487 |
| 433 // Flaky: crbug.com/301547, observed on win and mac. Probably happens on all | 488 // Flaky: crbug.com/301547, observed on win and mac. Probably happens on all |
| 434 // platforms. | 489 // platforms. |
| 435 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 490 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 436 DISABLED_PromptForDynamicForm) { | 491 DISABLED_PromptForDynamicForm) { |
| 437 NavigateToFile("/password/dynamic_password_form.html"); | 492 NavigateToFile("/password/dynamic_password_form.html"); |
| 438 | 493 |
| 439 // Fill the dynamic password form and submit. | 494 // Fill the dynamic password form and submit. |
| 440 NavigationObserver observer(WebContents()); | 495 NavigationObserver observer(WebContents()); |
| 496 scoped_ptr<PromptObserver> prompt_observer( | |
| 497 PromptObserver::Create(WebContents())); | |
| 441 std::string fill_and_submit = | 498 std::string fill_and_submit = |
| 442 "document.getElementById('create_form_button').click();" | 499 "document.getElementById('create_form_button').click();" |
| 443 "window.setTimeout(function() {" | 500 "window.setTimeout(function() {" |
| 444 " document.dynamic_form.username.value = 'tempro';" | 501 " document.dynamic_form.username.value = 'tempro';" |
| 445 " document.dynamic_form.password.value = 'random';" | 502 " document.dynamic_form.password.value = 'random';" |
| 446 " document.dynamic_form.submit();" | 503 " document.dynamic_form.submit();" |
| 447 "}, 0)"; | 504 "}, 0)"; |
| 448 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 505 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 449 observer.Wait(); | 506 observer.Wait(); |
| 450 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 507 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 451 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 452 } else { | |
| 453 EXPECT_TRUE(observer.infobar_shown()); | |
| 454 } | |
| 455 } | 508 } |
| 456 | 509 |
| 457 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptForNavigation) { | 510 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptForNavigation) { |
| 458 NavigateToFile("/password/password_form.html"); | 511 NavigateToFile("/password/password_form.html"); |
| 459 | 512 |
| 460 // Don't fill the password form, just navigate away. Shouldn't prompt. | 513 // Don't fill the password form, just navigate away. Shouldn't prompt. |
| 461 NavigationObserver observer(WebContents()); | 514 NavigationObserver observer(WebContents()); |
| 515 scoped_ptr<PromptObserver> prompt_observer( | |
| 516 PromptObserver::Create(WebContents())); | |
| 462 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), | 517 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), |
| 463 "window.location.href = 'done.html';")); | 518 "window.location.href = 'done.html';")); |
| 464 observer.Wait(); | 519 observer.Wait(); |
| 465 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 520 EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| 466 EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); | |
| 467 } else { | |
| 468 EXPECT_FALSE(observer.infobar_shown()); | |
| 469 } | |
| 470 } | 521 } |
| 471 | 522 |
| 472 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 523 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 473 NoPromptForSubFrameNavigation) { | 524 NoPromptForSubFrameNavigation) { |
| 474 NavigateToFile("/password/multi_frames.html"); | 525 NavigateToFile("/password/multi_frames.html"); |
| 475 | 526 |
| 476 // If you are filling out a password form in one frame and a different frame | 527 // If you are filling out a password form in one frame and a different frame |
| 477 // navigates, this should not trigger the infobar. | 528 // navigates, this should not trigger the infobar. |
| 478 NavigationObserver observer(WebContents()); | 529 NavigationObserver observer(WebContents()); |
| 530 scoped_ptr<PromptObserver> prompt_observer( | |
| 531 PromptObserver::Create(WebContents())); | |
| 479 observer.SetPathToWaitFor("/password/done.html"); | 532 observer.SetPathToWaitFor("/password/done.html"); |
| 480 std::string fill = | 533 std::string fill = |
| 481 "var first_frame = document.getElementById('first_frame');" | 534 "var first_frame = document.getElementById('first_frame');" |
| 482 "var frame_doc = first_frame.contentDocument;" | 535 "var frame_doc = first_frame.contentDocument;" |
| 483 "frame_doc.getElementById('username_field').value = 'temp';" | 536 "frame_doc.getElementById('username_field').value = 'temp';" |
| 484 "frame_doc.getElementById('password_field').value = 'random';"; | 537 "frame_doc.getElementById('password_field').value = 'random';"; |
| 485 std::string navigate_frame = | 538 std::string navigate_frame = |
| 486 "var second_iframe = document.getElementById('second_frame');" | 539 "var second_iframe = document.getElementById('second_frame');" |
| 487 "second_iframe.contentWindow.location.href = 'done.html';"; | 540 "second_iframe.contentWindow.location.href = 'done.html';"; |
| 488 | 541 |
| 489 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill)); | 542 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill)); |
| 490 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); | 543 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); |
| 491 observer.Wait(); | 544 observer.Wait(); |
| 492 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 545 EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| 493 EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); | |
| 494 } else { | |
| 495 EXPECT_FALSE(observer.infobar_shown()); | |
| 496 } | |
| 497 } | 546 } |
| 498 | 547 |
| 499 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 548 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 500 PromptAfterSubmitWithSubFrameNavigation) { | 549 PromptAfterSubmitWithSubFrameNavigation) { |
| 501 NavigateToFile("/password/multi_frames.html"); | 550 NavigateToFile("/password/multi_frames.html"); |
| 502 | 551 |
| 503 // Make sure that we prompt to save password even if a sub-frame navigation | 552 // Make sure that we prompt to save password even if a sub-frame navigation |
| 504 // happens first. | 553 // happens first. |
| 505 NavigationObserver observer(WebContents()); | 554 NavigationObserver observer(WebContents()); |
| 555 scoped_ptr<PromptObserver> prompt_observer( | |
| 556 PromptObserver::Create(WebContents())); | |
| 506 observer.SetPathToWaitFor("/password/done.html"); | 557 observer.SetPathToWaitFor("/password/done.html"); |
| 507 std::string navigate_frame = | 558 std::string navigate_frame = |
| 508 "var second_iframe = document.getElementById('second_frame');" | 559 "var second_iframe = document.getElementById('second_frame');" |
| 509 "second_iframe.contentWindow.location.href = 'other.html';"; | 560 "second_iframe.contentWindow.location.href = 'other.html';"; |
| 510 std::string fill_and_submit = | 561 std::string fill_and_submit = |
| 511 "var first_frame = document.getElementById('first_frame');" | 562 "var first_frame = document.getElementById('first_frame');" |
| 512 "var frame_doc = first_frame.contentDocument;" | 563 "var frame_doc = first_frame.contentDocument;" |
| 513 "frame_doc.getElementById('username_field').value = 'temp';" | 564 "frame_doc.getElementById('username_field').value = 'temp';" |
| 514 "frame_doc.getElementById('password_field').value = 'random';" | 565 "frame_doc.getElementById('password_field').value = 'random';" |
| 515 "frame_doc.getElementById('input_submit_button').click();"; | 566 "frame_doc.getElementById('input_submit_button').click();"; |
| 516 | 567 |
| 517 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); | 568 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); |
| 518 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 569 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 519 observer.Wait(); | 570 observer.Wait(); |
| 520 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 571 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 521 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 522 } else { | |
| 523 EXPECT_TRUE(observer.infobar_shown()); | |
| 524 } | |
| 525 } | 572 } |
| 526 | 573 |
| 527 IN_PROC_BROWSER_TEST_F( | 574 IN_PROC_BROWSER_TEST_F( |
| 528 PasswordManagerBrowserTest, | 575 PasswordManagerBrowserTest, |
| 529 NoPromptForFailedLoginFromMainFrameWithMultiFramesInPage) { | 576 NoPromptForFailedLoginFromMainFrameWithMultiFramesInPage) { |
| 530 NavigateToFile("/password/multi_frames.html"); | 577 NavigateToFile("/password/multi_frames.html"); |
| 531 | 578 |
| 532 // Make sure that we don't prompt to save the password for a failed login | 579 // Make sure that we don't prompt to save the password for a failed login |
| 533 // from the main frame with multiple frames in the same page. | 580 // from the main frame with multiple frames in the same page. |
| 534 NavigationObserver observer(WebContents()); | 581 NavigationObserver observer(WebContents()); |
| 582 scoped_ptr<PromptObserver> prompt_observer( | |
| 583 PromptObserver::Create(WebContents())); | |
| 535 std::string fill_and_submit = | 584 std::string fill_and_submit = |
| 536 "document.getElementById('username_failed').value = 'temp';" | 585 "document.getElementById('username_failed').value = 'temp';" |
| 537 "document.getElementById('password_failed').value = 'random';" | 586 "document.getElementById('password_failed').value = 'random';" |
| 538 "document.getElementById('submit_failed').click();"; | 587 "document.getElementById('submit_failed').click();"; |
| 539 | 588 |
| 540 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 589 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 541 observer.Wait(); | 590 observer.Wait(); |
| 542 EXPECT_FALSE(observer.infobar_shown()); | 591 EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| 543 } | 592 } |
| 544 | 593 |
| 545 IN_PROC_BROWSER_TEST_F( | 594 IN_PROC_BROWSER_TEST_F( |
| 546 PasswordManagerBrowserTest, | 595 PasswordManagerBrowserTest, |
| 547 NoPromptForFailedLoginFromSubFrameWithMultiFramesInPage) { | 596 NoPromptForFailedLoginFromSubFrameWithMultiFramesInPage) { |
| 548 NavigateToFile("/password/multi_frames.html"); | 597 NavigateToFile("/password/multi_frames.html"); |
| 549 | 598 |
| 550 // Make sure that we don't prompt to save the password for a failed login | 599 // Make sure that we don't prompt to save the password for a failed login |
| 551 // from a sub-frame with multiple frames in the same page. | 600 // from a sub-frame with multiple frames in the same page. |
| 552 NavigationObserver observer(WebContents()); | 601 NavigationObserver observer(WebContents()); |
| 602 scoped_ptr<PromptObserver> prompt_observer( | |
| 603 PromptObserver::Create(WebContents())); | |
| 553 std::string fill_and_submit = | 604 std::string fill_and_submit = |
| 554 "var first_frame = document.getElementById('first_frame');" | 605 "var first_frame = document.getElementById('first_frame');" |
| 555 "var frame_doc = first_frame.contentDocument;" | 606 "var frame_doc = first_frame.contentDocument;" |
| 556 "frame_doc.getElementById('username_failed').value = 'temp';" | 607 "frame_doc.getElementById('username_failed').value = 'temp';" |
| 557 "frame_doc.getElementById('password_failed').value = 'random';" | 608 "frame_doc.getElementById('password_failed').value = 'random';" |
| 558 "frame_doc.getElementById('submit_failed').click();" | 609 "frame_doc.getElementById('submit_failed').click();" |
| 559 "window.parent.location.href = 'multi_frames.html';"; | 610 "window.parent.location.href = 'multi_frames.html';"; |
| 560 | 611 |
| 561 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 612 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 562 observer.Wait(); | 613 observer.Wait(); |
| 563 EXPECT_FALSE(observer.infobar_shown()); | 614 EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| 564 } | 615 } |
| 565 | 616 |
| 566 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 617 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForXHRSubmit) { |
| 567 PromptForXHRSubmit) { | |
| 568 #if defined(OS_WIN) && defined(USE_ASH) | 618 #if defined(OS_WIN) && defined(USE_ASH) |
| 569 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 619 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 570 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 620 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
| 571 return; | 621 return; |
| 572 #endif | 622 #endif |
| 573 NavigateToFile("/password/password_xhr_submit.html"); | 623 NavigateToFile("/password/password_xhr_submit.html"); |
| 574 | 624 |
| 575 // Verify that we show the save password prompt if a form returns false | 625 // Verify that we show the save password prompt if a form returns false |
| 576 // in its onsubmit handler but instead logs in/navigates via XHR. | 626 // in its onsubmit handler but instead logs in/navigates via XHR. |
| 577 // Note that calling 'submit()' on a form with javascript doesn't call | 627 // Note that calling 'submit()' on a form with javascript doesn't call |
| 578 // the onsubmit handler, so we click the submit button instead. | 628 // the onsubmit handler, so we click the submit button instead. |
| 579 NavigationObserver observer(WebContents()); | 629 NavigationObserver observer(WebContents()); |
| 630 scoped_ptr<PromptObserver> prompt_observer( | |
| 631 PromptObserver::Create(WebContents())); | |
| 580 std::string fill_and_submit = | 632 std::string fill_and_submit = |
| 581 "document.getElementById('username_field').value = 'temp';" | 633 "document.getElementById('username_field').value = 'temp';" |
| 582 "document.getElementById('password_field').value = 'random';" | 634 "document.getElementById('password_field').value = 'random';" |
| 583 "document.getElementById('submit_button').click()"; | 635 "document.getElementById('submit_button').click()"; |
| 584 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 636 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 585 observer.Wait(); | 637 observer.Wait(); |
| 586 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 638 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 587 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 588 } else { | |
| 589 EXPECT_TRUE(observer.infobar_shown()); | |
| 590 } | |
| 591 } | 639 } |
| 592 | 640 |
| 593 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 641 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 594 PromptForXHRWithoutOnSubmit) { | 642 PromptForXHRWithoutOnSubmit) { |
| 595 NavigateToFile("/password/password_xhr_submit.html"); | 643 NavigateToFile("/password/password_xhr_submit.html"); |
| 596 | 644 |
| 597 // Verify that if XHR navigation occurs and the form is properly filled out, | 645 // Verify that if XHR navigation occurs and the form is properly filled out, |
| 598 // we try and save the password even though onsubmit hasn't been called. | 646 // we try and save the password even though onsubmit hasn't been called. |
| 599 NavigationObserver observer(WebContents()); | 647 NavigationObserver observer(WebContents()); |
| 648 scoped_ptr<PromptObserver> prompt_observer( | |
| 649 PromptObserver::Create(WebContents())); | |
| 600 std::string fill_and_navigate = | 650 std::string fill_and_navigate = |
| 601 "document.getElementById('username_field').value = 'temp';" | 651 "document.getElementById('username_field').value = 'temp';" |
| 602 "document.getElementById('password_field').value = 'random';" | 652 "document.getElementById('password_field').value = 'random';" |
| 603 "send_xhr()"; | 653 "send_xhr()"; |
| 604 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); | 654 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); |
| 605 observer.Wait(); | 655 observer.Wait(); |
| 606 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 656 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 607 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 608 } else { | |
| 609 EXPECT_TRUE(observer.infobar_shown()); | |
| 610 } | |
| 611 } | 657 } |
| 612 | 658 |
| 613 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 659 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptIfLinkClicked) { |
| 614 NoPromptIfLinkClicked) { | |
| 615 NavigateToFile("/password/password_form.html"); | 660 NavigateToFile("/password/password_form.html"); |
| 616 | 661 |
| 617 // Verify that if the user takes a direct action to leave the page, we don't | 662 // Verify that if the user takes a direct action to leave the page, we don't |
| 618 // prompt to save the password even if the form is already filled out. | 663 // prompt to save the password even if the form is already filled out. |
| 619 NavigationObserver observer(WebContents()); | 664 NavigationObserver observer(WebContents()); |
| 665 scoped_ptr<PromptObserver> prompt_observer( | |
| 666 PromptObserver::Create(WebContents())); | |
| 620 std::string fill_and_click_link = | 667 std::string fill_and_click_link = |
| 621 "document.getElementById('username_field').value = 'temp';" | 668 "document.getElementById('username_field').value = 'temp';" |
| 622 "document.getElementById('password_field').value = 'random';" | 669 "document.getElementById('password_field').value = 'random';" |
| 623 "document.getElementById('link').click();"; | 670 "document.getElementById('link').click();"; |
| 624 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_click_link)); | 671 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_click_link)); |
| 625 observer.Wait(); | 672 observer.Wait(); |
| 626 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 673 EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| 627 EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); | |
| 628 } else { | |
| 629 EXPECT_FALSE(observer.infobar_shown()); | |
| 630 } | |
| 631 } | 674 } |
| 632 | 675 |
| 633 // TODO(jam): http://crbug.com/350550 | 676 // TODO(jam): http://crbug.com/350550 |
| 634 #if !defined(OS_WIN) | 677 #if !defined(OS_WIN) |
| 635 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 678 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 636 VerifyPasswordGenerationUpload) { | 679 VerifyPasswordGenerationUpload) { |
| 637 // Prevent Autofill requests from actually going over the wire. | 680 // Prevent Autofill requests from actually going over the wire. |
| 638 net::TestURLFetcherFactory factory; | 681 net::TestURLFetcherFactory factory; |
| 639 // Disable Autofill requesting access to AddressBook data. This causes | 682 // Disable Autofill requesting access to AddressBook data. This causes |
| 640 // the test to hang on Mac. | 683 // the test to hang on Mac. |
| 641 autofill::test::DisableSystemServices(browser()->profile()->GetPrefs()); | 684 autofill::test::DisableSystemServices(browser()->profile()->GetPrefs()); |
| 642 | 685 |
| 643 // Visit a signup form. | 686 // Visit a signup form. |
| 644 NavigateToFile("/password/signup_form.html"); | 687 NavigateToFile("/password/signup_form.html"); |
| 645 | 688 |
| 646 // Enter a password and save it. | 689 // Enter a password and save it. |
| 647 NavigationObserver first_observer(WebContents()); | 690 NavigationObserver first_observer(WebContents()); |
| 691 scoped_ptr<PromptObserver> prompt_observer( | |
| 692 PromptObserver::Create(WebContents())); | |
| 648 std::string fill_and_submit = | 693 std::string fill_and_submit = |
| 649 "document.getElementById('other_info').value = 'stuff';" | 694 "document.getElementById('other_info').value = 'stuff';" |
| 650 "document.getElementById('username_field').value = 'my_username';" | 695 "document.getElementById('username_field').value = 'my_username';" |
| 651 "document.getElementById('password_field').value = 'password';" | 696 "document.getElementById('password_field').value = 'password';" |
| 652 "document.getElementById('input_submit_button').click()"; | 697 "document.getElementById('input_submit_button').click()"; |
| 653 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 698 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 654 | 699 |
| 655 first_observer.Wait(); | 700 first_observer.Wait(); |
| 656 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 701 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 657 ASSERT_TRUE(ui_controller()->PasswordPendingUserDecision()); | 702 prompt_observer->Accept(); |
| 658 ui_controller()->SavePassword(); | |
| 659 } else { | |
| 660 ASSERT_TRUE(first_observer.infobar_shown()); | |
| 661 } | |
| 662 | 703 |
| 663 // Now navigate to a login form that has similar HTML markup. | 704 // Now navigate to a login form that has similar HTML markup. |
| 664 NavigateToFile("/password/password_form.html"); | 705 NavigateToFile("/password/password_form.html"); |
| 665 | 706 |
| 666 // Simulate a user click to force an autofill of the form's DOM value, not | 707 // Simulate a user click to force an autofill of the form's DOM value, not |
| 667 // just the suggested value. | 708 // just the suggested value. |
| 668 content::SimulateMouseClick( | 709 content::SimulateMouseClick( |
| 669 WebContents(), 0, blink::WebMouseEvent::ButtonLeft); | 710 WebContents(), 0, blink::WebMouseEvent::ButtonLeft); |
| 670 | 711 |
| 671 // The form should be filled with the previously submitted username. | 712 // The form should be filled with the previously submitted username. |
| 672 std::string get_username = | 713 std::string get_username = |
| 673 "window.domAutomationController.send(" | 714 "window.domAutomationController.send(" |
| 674 "document.getElementById('username_field').value);"; | 715 "document.getElementById('username_field').value);"; |
| 675 std::string actual_username; | 716 std::string actual_username; |
| 676 ASSERT_TRUE(content::ExecuteScriptAndExtractString(RenderViewHost(), | 717 ASSERT_TRUE(content::ExecuteScriptAndExtractString(RenderViewHost(), |
| 677 get_username, | 718 get_username, |
| 678 &actual_username)); | 719 &actual_username)); |
| 679 ASSERT_EQ("my_username", actual_username); | 720 ASSERT_EQ("my_username", actual_username); |
| 680 | 721 |
| 681 // Submit the form and verify that there is no infobar (as the password | 722 // Submit the form and verify that there is no infobar (as the password |
| 682 // has already been saved). | 723 // has already been saved). |
| 683 NavigationObserver second_observer(WebContents()); | 724 NavigationObserver second_observer(WebContents()); |
| 725 scoped_ptr<PromptObserver> second_prompt_observer( | |
| 726 PromptObserver::Create(WebContents())); | |
|
engedy
2014/07/11 18:07:26
Could you please confirm that this really a differ
vabr (Chromium)
2014/07/11 18:48:01
The thing is that I'm not sure -- it should be the
| |
| 684 std::string submit_form = | 727 std::string submit_form = |
| 685 "document.getElementById('input_submit_button').click()"; | 728 "document.getElementById('input_submit_button').click()"; |
| 686 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit_form)); | 729 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit_form)); |
| 687 second_observer.Wait(); | 730 second_observer.Wait(); |
| 688 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 731 EXPECT_FALSE(second_prompt_observer->IsPromptShown()); |
| 689 EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); | |
| 690 } else { | |
| 691 EXPECT_FALSE(second_observer.infobar_shown()); | |
| 692 } | |
| 693 | 732 |
| 694 // Verify that we sent a ping to Autofill saying that the original form | 733 // Verify that we sent a ping to Autofill saying that the original form |
| 695 // was likely an account creation form since it has more than 2 text input | 734 // was likely an account creation form since it has more than 2 text input |
| 696 // fields and was used for the first time on a different form. | 735 // fields and was used for the first time on a different form. |
| 697 base::HistogramBase* upload_histogram = | 736 base::HistogramBase* upload_histogram = |
| 698 base::StatisticsRecorder::FindHistogram( | 737 base::StatisticsRecorder::FindHistogram( |
| 699 "PasswordGeneration.UploadStarted"); | 738 "PasswordGeneration.UploadStarted"); |
| 700 ASSERT_TRUE(upload_histogram); | 739 ASSERT_TRUE(upload_histogram); |
| 701 scoped_ptr<base::HistogramSamples> snapshot = | 740 scoped_ptr<base::HistogramSamples> snapshot = |
| 702 upload_histogram->SnapshotSamples(); | 741 upload_histogram->SnapshotSamples(); |
| 703 EXPECT_EQ(0, snapshot->GetCount(0 /* failure */)); | 742 EXPECT_EQ(0, snapshot->GetCount(0 /* failure */)); |
| 704 EXPECT_EQ(1, snapshot->GetCount(1 /* success */)); | 743 EXPECT_EQ(1, snapshot->GetCount(1 /* success */)); |
| 705 } | 744 } |
| 706 #endif | 745 #endif |
| 707 | 746 |
| 708 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForSubmitFromIframe) { | 747 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForSubmitFromIframe) { |
| 709 NavigateToFile("/password/password_submit_from_iframe.html"); | 748 NavigateToFile("/password/password_submit_from_iframe.html"); |
| 710 | 749 |
| 711 // Submit a form in an iframe, then cause the whole page to navigate without a | 750 // Submit a form in an iframe, then cause the whole page to navigate without a |
| 712 // user gesture. We expect the save password prompt to be shown here, because | 751 // user gesture. We expect the save password prompt to be shown here, because |
| 713 // some pages use such iframes for login forms. | 752 // some pages use such iframes for login forms. |
| 714 NavigationObserver observer(WebContents()); | 753 NavigationObserver observer(WebContents()); |
| 754 scoped_ptr<PromptObserver> prompt_observer( | |
| 755 PromptObserver::Create(WebContents())); | |
| 715 std::string fill_and_submit = | 756 std::string fill_and_submit = |
| 716 "var iframe = document.getElementById('test_iframe');" | 757 "var iframe = document.getElementById('test_iframe');" |
| 717 "var iframe_doc = iframe.contentDocument;" | 758 "var iframe_doc = iframe.contentDocument;" |
| 718 "iframe_doc.getElementById('username_field').value = 'temp';" | 759 "iframe_doc.getElementById('username_field').value = 'temp';" |
| 719 "iframe_doc.getElementById('password_field').value = 'random';" | 760 "iframe_doc.getElementById('password_field').value = 'random';" |
| 720 "iframe_doc.getElementById('submit_button').click()"; | 761 "iframe_doc.getElementById('submit_button').click()"; |
| 721 | 762 |
| 722 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 763 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 723 observer.Wait(); | 764 observer.Wait(); |
| 724 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 765 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 725 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 726 } else { | |
| 727 EXPECT_TRUE(observer.infobar_shown()); | |
| 728 } | |
| 729 } | 766 } |
| 730 | 767 |
| 731 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 768 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 732 PromptForInputElementWithoutName) { | 769 PromptForInputElementWithoutName) { |
| 733 // Check that the prompt is shown for forms where input elements lack the | 770 // Check that the prompt is shown for forms where input elements lack the |
| 734 // "name" attribute but the "id" is present. | 771 // "name" attribute but the "id" is present. |
| 735 NavigateToFile("/password/password_form.html"); | 772 NavigateToFile("/password/password_form.html"); |
| 736 | 773 |
| 737 NavigationObserver observer(WebContents()); | 774 NavigationObserver observer(WebContents()); |
| 775 scoped_ptr<PromptObserver> prompt_observer( | |
| 776 PromptObserver::Create(WebContents())); | |
| 738 std::string fill_and_submit = | 777 std::string fill_and_submit = |
| 739 "document.getElementById('username_field_no_name').value = 'temp';" | 778 "document.getElementById('username_field_no_name').value = 'temp';" |
| 740 "document.getElementById('password_field_no_name').value = 'random';" | 779 "document.getElementById('password_field_no_name').value = 'random';" |
| 741 "document.getElementById('input_submit_button_no_name').click()"; | 780 "document.getElementById('input_submit_button_no_name').click()"; |
| 742 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 781 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 743 observer.Wait(); | 782 observer.Wait(); |
| 744 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 783 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 745 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 746 } else { | |
| 747 EXPECT_TRUE(observer.infobar_shown()); | |
| 748 } | |
| 749 } | 784 } |
| 750 | 785 |
| 751 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 786 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 752 PromptForInputElementWithoutId) { | 787 PromptForInputElementWithoutId) { |
| 753 // Check that the prompt is shown for forms where input elements lack the | 788 // Check that the prompt is shown for forms where input elements lack the |
| 754 // "id" attribute but the "name" attribute is present. | 789 // "id" attribute but the "name" attribute is present. |
| 755 NavigateToFile("/password/password_form.html"); | 790 NavigateToFile("/password/password_form.html"); |
| 756 | 791 |
| 757 NavigationObserver observer(WebContents()); | 792 NavigationObserver observer(WebContents()); |
| 793 scoped_ptr<PromptObserver> prompt_observer( | |
| 794 PromptObserver::Create(WebContents())); | |
| 758 std::string fill_and_submit = | 795 std::string fill_and_submit = |
| 759 "document.getElementsByName('username_field_no_id')[0].value = 'temp';" | 796 "document.getElementsByName('username_field_no_id')[0].value = 'temp';" |
| 760 "document.getElementsByName('password_field_no_id')[0].value = 'random';" | 797 "document.getElementsByName('password_field_no_id')[0].value = 'random';" |
| 761 "document.getElementsByName('input_submit_button_no_id')[0].click()"; | 798 "document.getElementsByName('input_submit_button_no_id')[0].click()"; |
| 762 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 799 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 763 observer.Wait(); | 800 observer.Wait(); |
| 764 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 801 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 765 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 766 } else { | |
| 767 EXPECT_TRUE(observer.infobar_shown()); | |
| 768 } | |
| 769 } | 802 } |
| 770 | 803 |
| 771 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 804 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 772 NoPromptForInputElementWithoutIdAndName) { | 805 NoPromptForInputElementWithoutIdAndName) { |
| 773 // Check that no prompt is shown for forms where the input fields lack both | 806 // Check that no prompt is shown for forms where the input fields lack both |
| 774 // the "id" and the "name" attributes. | 807 // the "id" and the "name" attributes. |
| 775 NavigateToFile("/password/password_form.html"); | 808 NavigateToFile("/password/password_form.html"); |
| 776 | 809 |
| 777 NavigationObserver observer(WebContents()); | 810 NavigationObserver observer(WebContents()); |
| 811 scoped_ptr<PromptObserver> prompt_observer( | |
| 812 PromptObserver::Create(WebContents())); | |
| 778 std::string fill_and_submit = | 813 std::string fill_and_submit = |
| 779 "var form = document.getElementById('testform_elements_no_id_no_name');" | 814 "var form = document.getElementById('testform_elements_no_id_no_name');" |
| 780 "var username = form.children[0];" | 815 "var username = form.children[0];" |
| 781 "username.value = 'temp';" | 816 "username.value = 'temp';" |
| 782 "var password = form.children[1];" | 817 "var password = form.children[1];" |
| 783 "password.value = 'random';" | 818 "password.value = 'random';" |
| 784 "form.children[2].click()"; // form.children[2] is the submit button. | 819 "form.children[2].click()"; // form.children[2] is the submit button. |
| 785 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 820 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 786 observer.Wait(); | 821 observer.Wait(); |
| 787 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 822 EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| 788 EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); | |
| 789 } else { | |
| 790 EXPECT_FALSE(observer.infobar_shown()); | |
| 791 } | |
| 792 } | 823 } |
| 793 | 824 |
| 794 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, DeleteFrameBeforeSubmit) { | 825 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, DeleteFrameBeforeSubmit) { |
| 795 NavigateToFile("/password/multi_frames.html"); | 826 NavigateToFile("/password/multi_frames.html"); |
| 796 | 827 |
| 797 NavigationObserver observer(WebContents()); | 828 NavigationObserver observer(WebContents()); |
| 798 // Make sure we save some password info from an iframe and then destroy it. | 829 // Make sure we save some password info from an iframe and then destroy it. |
| 799 std::string save_and_remove = | 830 std::string save_and_remove = |
| 800 "var first_frame = document.getElementById('first_frame');" | 831 "var first_frame = document.getElementById('first_frame');" |
| 801 "var frame_doc = first_frame.contentDocument;" | 832 "var frame_doc = first_frame.contentDocument;" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 823 // Click on a link to open a new tab, then switch back to the first one. | 854 // Click on a link to open a new tab, then switch back to the first one. |
| 824 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 855 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 825 std::string click = | 856 std::string click = |
| 826 "document.getElementById('testlink').click();"; | 857 "document.getElementById('testlink').click();"; |
| 827 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), click)); | 858 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), click)); |
| 828 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 859 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 829 browser()->tab_strip_model()->ActivateTabAt(0, false); | 860 browser()->tab_strip_model()->ActivateTabAt(0, false); |
| 830 | 861 |
| 831 // Fill in the credentials, and make sure they are saved. | 862 // Fill in the credentials, and make sure they are saved. |
| 832 NavigationObserver form_submit_observer(WebContents()); | 863 NavigationObserver form_submit_observer(WebContents()); |
| 864 scoped_ptr<PromptObserver> prompt_observer( | |
| 865 PromptObserver::Create(WebContents())); | |
| 833 std::string fill_and_submit = | 866 std::string fill_and_submit = |
| 834 "document.getElementById('username_field').value = 'temp';" | 867 "document.getElementById('username_field').value = 'temp';" |
| 835 "document.getElementById('password_field').value = 'random';" | 868 "document.getElementById('password_field').value = 'random';" |
| 836 "document.getElementById('input_submit_button').click();"; | 869 "document.getElementById('input_submit_button').click();"; |
| 837 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 870 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 838 form_submit_observer.Wait(); | 871 form_submit_observer.Wait(); |
| 839 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 872 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 840 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | 873 prompt_observer->Accept(); |
| 841 ui_controller()->SavePassword(); | |
| 842 } else { | |
| 843 EXPECT_TRUE(form_submit_observer.infobar_shown()); | |
| 844 } | |
| 845 | 874 |
| 846 // Reload the original page to have the saved credentials autofilled. | 875 // Reload the original page to have the saved credentials autofilled. |
| 847 NavigationObserver reload_observer(WebContents()); | 876 NavigationObserver reload_observer(WebContents()); |
| 848 NavigateToFile("/password/form_and_link.html"); | 877 NavigateToFile("/password/form_and_link.html"); |
| 849 reload_observer.Wait(); | 878 reload_observer.Wait(); |
| 850 | 879 |
| 851 // Wait until the username is filled, to make sure autofill kicked in. | 880 // Wait until the username is filled, to make sure autofill kicked in. |
| 852 WaitForElementValue("username_field", "temp"); | 881 WaitForElementValue("username_field", "temp"); |
| 853 // Now check that the password is not accessible yet. | 882 // Now check that the password is not accessible yet. |
| 854 CheckElementValue("password_field", ""); | 883 CheckElementValue("password_field", ""); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 866 // RenderWidgetHostViewGuest::ProcessAckedTouchEvent is, and | 895 // RenderWidgetHostViewGuest::ProcessAckedTouchEvent is, and |
| 867 // ProcessAckedTouchEvent is what triggers the translation of touch events to | 896 // ProcessAckedTouchEvent is what triggers the translation of touch events to |
| 868 // gesture events. | 897 // gesture events. |
| 869 #if defined(USE_AURA) | 898 #if defined(USE_AURA) |
| 870 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 899 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 871 PasswordValueAccessibleOnSubmit) { | 900 PasswordValueAccessibleOnSubmit) { |
| 872 NavigateToFile("/password/form_and_link.html"); | 901 NavigateToFile("/password/form_and_link.html"); |
| 873 | 902 |
| 874 // Fill in the credentials, and make sure they are saved. | 903 // Fill in the credentials, and make sure they are saved. |
| 875 NavigationObserver form_submit_observer(WebContents()); | 904 NavigationObserver form_submit_observer(WebContents()); |
| 905 scoped_ptr<PromptObserver> prompt_observer( | |
| 906 PromptObserver::Create(WebContents())); | |
| 876 std::string fill_and_submit = | 907 std::string fill_and_submit = |
| 877 "document.getElementById('username_field').value = 'temp';" | 908 "document.getElementById('username_field').value = 'temp';" |
| 878 "document.getElementById('password_field').value = 'random_secret';" | 909 "document.getElementById('password_field').value = 'random_secret';" |
| 879 "document.getElementById('input_submit_button').click();"; | 910 "document.getElementById('input_submit_button').click();"; |
| 880 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 911 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 881 form_submit_observer.Wait(); | 912 form_submit_observer.Wait(); |
| 882 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 913 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 883 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | 914 prompt_observer->Accept(); |
| 884 ui_controller()->SavePassword(); | |
| 885 } else { | |
| 886 EXPECT_TRUE(form_submit_observer.infobar_shown()); | |
| 887 } | |
| 888 | 915 |
| 889 // Reload the original page to have the saved credentials autofilled. | 916 // Reload the original page to have the saved credentials autofilled. |
| 890 NavigationObserver reload_observer(WebContents()); | 917 NavigationObserver reload_observer(WebContents()); |
| 891 NavigateToFile("/password/form_and_link.html"); | 918 NavigateToFile("/password/form_and_link.html"); |
| 892 reload_observer.Wait(); | 919 reload_observer.Wait(); |
| 893 | 920 |
| 894 NavigationObserver submit_observer(WebContents()); | 921 NavigationObserver submit_observer(WebContents()); |
| 895 // Submit the form via a tap on the submit button. The button is placed at 0, | 922 // Submit the form via a tap on the submit button. The button is placed at 0, |
| 896 // 100, and has height 300 and width 700. | 923 // 100, and has height 300 and width 700. |
| 897 content::SimulateTapAt(WebContents(), gfx::Point(350, 250)); | 924 content::SimulateTapAt(WebContents(), gfx::Point(350, 250)); |
| 898 submit_observer.Wait(); | 925 submit_observer.Wait(); |
| 899 std::string query = WebContents()->GetURL().query(); | 926 std::string query = WebContents()->GetURL().query(); |
| 900 EXPECT_NE(std::string::npos, query.find("random_secret")) << query; | 927 EXPECT_NE(std::string::npos, query.find("random_secret")) << query; |
| 901 } | 928 } |
| 902 #endif | 929 #endif |
| 903 | 930 |
| 904 // Test fix for crbug.com/338650. | 931 // Test fix for crbug.com/338650. |
| 905 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 932 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 906 DontPromptForPasswordFormWithDefaultValue) { | 933 DontPromptForPasswordFormWithDefaultValue) { |
| 907 NavigateToFile("/password/password_form_with_default_value.html"); | 934 NavigateToFile("/password/password_form_with_default_value.html"); |
| 908 | 935 |
| 909 // Don't prompt if we navigate away even if there is a password value since | 936 // Don't prompt if we navigate away even if there is a password value since |
| 910 // it's not coming from the user. | 937 // it's not coming from the user. |
| 911 NavigationObserver observer(WebContents()); | 938 NavigationObserver observer(WebContents()); |
| 939 scoped_ptr<PromptObserver> prompt_observer( | |
| 940 PromptObserver::Create(WebContents())); | |
| 912 NavigateToFile("/password/done.html"); | 941 NavigateToFile("/password/done.html"); |
| 913 observer.Wait(); | 942 observer.Wait(); |
| 914 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 943 EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| 915 EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); | |
| 916 } else { | |
| 917 EXPECT_FALSE(observer.infobar_shown()); | |
| 918 } | |
| 919 } | 944 } |
| 920 | 945 |
| 921 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 946 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 922 PromptWhenEnableAutomaticPasswordSavingSwitchIsNotSet) { | 947 PromptWhenEnableAutomaticPasswordSavingSwitchIsNotSet) { |
| 923 NavigateToFile("/password/password_form.html"); | 948 NavigateToFile("/password/password_form.html"); |
| 924 | 949 |
| 925 // Fill a form and submit through a <input type="submit"> button. | 950 // Fill a form and submit through a <input type="submit"> button. |
| 926 NavigationObserver observer(WebContents()); | 951 NavigationObserver observer(WebContents()); |
| 952 scoped_ptr<PromptObserver> prompt_observer( | |
| 953 PromptObserver::Create(WebContents())); | |
| 927 std::string fill_and_submit = | 954 std::string fill_and_submit = |
| 928 "document.getElementById('username_field').value = 'temp';" | 955 "document.getElementById('username_field').value = 'temp';" |
| 929 "document.getElementById('password_field').value = 'random';" | 956 "document.getElementById('password_field').value = 'random';" |
| 930 "document.getElementById('input_submit_button').click()"; | 957 "document.getElementById('input_submit_button').click()"; |
| 931 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 958 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 932 observer.Wait(); | 959 observer.Wait(); |
| 933 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 960 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 934 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 935 } else { | |
| 936 EXPECT_TRUE(observer.infobar_shown()); | |
| 937 } | |
| 938 } | 961 } |
| 939 | 962 |
| 940 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 963 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 941 DontPromptWhenEnableAutomaticPasswordSavingSwitchIsSet) { | 964 DontPromptWhenEnableAutomaticPasswordSavingSwitchIsSet) { |
| 942 password_manager::TestPasswordStore* password_store = | 965 password_manager::TestPasswordStore* password_store = |
| 943 static_cast<password_manager::TestPasswordStore*>( | 966 static_cast<password_manager::TestPasswordStore*>( |
| 944 PasswordStoreFactory::GetForProfile(browser()->profile(), | 967 PasswordStoreFactory::GetForProfile(browser()->profile(), |
| 945 Profile::IMPLICIT_ACCESS).get()); | 968 Profile::IMPLICIT_ACCESS).get()); |
| 946 | 969 |
| 947 EXPECT_TRUE(password_store->IsEmpty()); | 970 EXPECT_TRUE(password_store->IsEmpty()); |
| 948 | 971 |
| 949 NavigateToFile("/password/password_form.html"); | 972 NavigateToFile("/password/password_form.html"); |
| 950 | 973 |
| 951 // Add the enable-automatic-password-saving switch. | 974 // Add the enable-automatic-password-saving switch. |
| 952 CommandLine::ForCurrentProcess()->AppendSwitch( | 975 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 953 password_manager::switches::kEnableAutomaticPasswordSaving); | 976 password_manager::switches::kEnableAutomaticPasswordSaving); |
| 954 | 977 |
| 955 // Fill a form and submit through a <input type="submit"> button. | 978 // Fill a form and submit through a <input type="submit"> button. |
| 956 NavigationObserver observer(WebContents()); | 979 NavigationObserver observer(WebContents()); |
| 980 scoped_ptr<PromptObserver> prompt_observer( | |
| 981 PromptObserver::Create(WebContents())); | |
| 957 // Make sure that the only passwords saved are the auto-saved ones. | 982 // Make sure that the only passwords saved are the auto-saved ones. |
| 958 observer.disable_should_automatically_accept_infobar(); | |
| 959 std::string fill_and_submit = | 983 std::string fill_and_submit = |
| 960 "document.getElementById('username_field').value = 'temp';" | 984 "document.getElementById('username_field').value = 'temp';" |
| 961 "document.getElementById('password_field').value = 'random';" | 985 "document.getElementById('password_field').value = 'random';" |
| 962 "document.getElementById('input_submit_button').click()"; | 986 "document.getElementById('input_submit_button').click()"; |
| 963 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 987 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 964 observer.Wait(); | 988 observer.Wait(); |
| 965 if (chrome::VersionInfo::GetChannel() == | 989 if (chrome::VersionInfo::GetChannel() == |
| 966 chrome::VersionInfo::CHANNEL_UNKNOWN) { | 990 chrome::VersionInfo::CHANNEL_UNKNOWN) { |
| 967 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 991 // Passwords getting auto-saved, no prompt. |
| 968 EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); | 992 EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| 969 } else { | |
| 970 EXPECT_FALSE(observer.infobar_shown()); | |
| 971 } | |
| 972 EXPECT_FALSE(password_store->IsEmpty()); | 993 EXPECT_FALSE(password_store->IsEmpty()); |
| 973 } else { | 994 } else { |
| 974 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 995 // Prompt shown, and no passwords saved automatically. |
| 975 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | 996 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 976 } else { | |
| 977 EXPECT_TRUE(observer.infobar_shown()); | |
| 978 } | |
| 979 EXPECT_TRUE(password_store->IsEmpty()); | 997 EXPECT_TRUE(password_store->IsEmpty()); |
| 980 } | 998 } |
| 981 } | 999 } |
| 982 | 1000 |
| 983 // Test fix for crbug.com/368690. | 1001 // Test fix for crbug.com/368690. |
| 984 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptWhenReloading) { | 1002 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptWhenReloading) { |
| 985 NavigateToFile("/password/password_form.html"); | 1003 NavigateToFile("/password/password_form.html"); |
| 986 | 1004 |
| 987 std::string fill = | 1005 std::string fill = |
| 988 "document.getElementById('username_redirect').value = 'temp';" | 1006 "document.getElementById('username_redirect').value = 'temp';" |
| 989 "document.getElementById('password_redirect').value = 'random';"; | 1007 "document.getElementById('password_redirect').value = 'random';"; |
| 990 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill)); | 1008 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill)); |
| 991 | 1009 |
| 992 NavigationObserver observer(WebContents()); | 1010 NavigationObserver observer(WebContents()); |
| 1011 scoped_ptr<PromptObserver> prompt_observer( | |
| 1012 PromptObserver::Create(WebContents())); | |
| 993 GURL url = embedded_test_server()->GetURL("/password/password_form.html"); | 1013 GURL url = embedded_test_server()->GetURL("/password/password_form.html"); |
| 994 chrome::NavigateParams params(browser(), url, | 1014 chrome::NavigateParams params(browser(), url, |
| 995 content::PAGE_TRANSITION_RELOAD); | 1015 content::PAGE_TRANSITION_RELOAD); |
| 996 ui_test_utils::NavigateToURL(¶ms); | 1016 ui_test_utils::NavigateToURL(¶ms); |
| 997 observer.Wait(); | 1017 observer.Wait(); |
| 998 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 1018 EXPECT_FALSE(prompt_observer->IsPromptShown()); |
| 999 EXPECT_FALSE(ui_controller()->PasswordPendingUserDecision()); | |
| 1000 } else { | |
| 1001 EXPECT_FALSE(observer.infobar_shown()); | |
| 1002 } | |
| 1003 } | 1019 } |
| 1004 | 1020 |
| 1005 // Test that if a form gets dynamically added between the form parsing and | 1021 // Test that if a form gets dynamically added between the form parsing and |
| 1006 // rendering, and while the main frame still loads, it still is registered, and | 1022 // rendering, and while the main frame still loads, it still is registered, and |
| 1007 // thus saving passwords from it works. | 1023 // thus saving passwords from it works. |
| 1008 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | 1024 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 1009 FormsAddedBetweenParsingAndRendering) { | 1025 FormsAddedBetweenParsingAndRendering) { |
| 1010 NavigateToFile("/password/between_parsing_and_rendering.html"); | 1026 NavigateToFile("/password/between_parsing_and_rendering.html"); |
| 1011 | 1027 |
| 1012 NavigationObserver observer(WebContents()); | 1028 NavigationObserver observer(WebContents()); |
| 1029 scoped_ptr<PromptObserver> prompt_observer( | |
| 1030 PromptObserver::Create(WebContents())); | |
| 1013 std::string submit = | 1031 std::string submit = |
| 1014 "document.getElementById('username').value = 'temp';" | 1032 "document.getElementById('username').value = 'temp';" |
| 1015 "document.getElementById('password').value = 'random';" | 1033 "document.getElementById('password').value = 'random';" |
| 1016 "document.getElementById('submit-button').click();"; | 1034 "document.getElementById('submit-button').click();"; |
| 1017 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit)); | 1035 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit)); |
| 1018 observer.Wait(); | 1036 observer.Wait(); |
| 1019 | 1037 |
| 1020 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 1038 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 1021 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | |
| 1022 } else { | |
| 1023 EXPECT_TRUE(observer.infobar_shown()); | |
| 1024 } | |
| 1025 } | 1039 } |
| 1026 | 1040 |
| 1027 // Test that if there was no previous page load then the PasswordManagerDriver | 1041 // Test that if there was no previous page load then the PasswordManagerDriver |
| 1028 // does not think that there were SSL errors on the current page. The test opens | 1042 // does not think that there were SSL errors on the current page. The test opens |
| 1029 // a new tab with a URL for which the embedded test server issues a basic auth | 1043 // a new tab with a URL for which the embedded test server issues a basic auth |
| 1030 // challenge. | 1044 // challenge. |
| 1031 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoLastLoadGoodLastLoad) { | 1045 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoLastLoadGoodLastLoad) { |
| 1032 // Teach the embedded server to handle requests by issuing the basic auth | 1046 // Teach the embedded server to handle requests by issuing the basic auth |
| 1033 // challenge. | 1047 // challenge. |
| 1034 embedded_test_server()->RegisterRequestHandler( | 1048 embedded_test_server()->RegisterRequestHandler( |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1050 // authentication. | 1064 // authentication. |
| 1051 ui_test_utils::NavigateToURLWithDisposition( | 1065 ui_test_utils::NavigateToURLWithDisposition( |
| 1052 browser(), | 1066 browser(), |
| 1053 embedded_test_server()->GetURL("/basic_auth"), | 1067 embedded_test_server()->GetURL("/basic_auth"), |
| 1054 NEW_FOREGROUND_TAB, | 1068 NEW_FOREGROUND_TAB, |
| 1055 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1069 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 1056 | 1070 |
| 1057 content::NavigationController* nav_controller = | 1071 content::NavigationController* nav_controller = |
| 1058 &WebContents()->GetController(); | 1072 &WebContents()->GetController(); |
| 1059 NavigationObserver nav_observer(WebContents()); | 1073 NavigationObserver nav_observer(WebContents()); |
| 1074 scoped_ptr<PromptObserver> prompt_observer( | |
| 1075 PromptObserver::Create(WebContents())); | |
| 1060 WindowedAuthNeededObserver auth_needed_observer(nav_controller); | 1076 WindowedAuthNeededObserver auth_needed_observer(nav_controller); |
| 1061 auth_needed_observer.Wait(); | 1077 auth_needed_observer.Wait(); |
| 1062 | 1078 |
| 1063 WindowedAuthSuppliedObserver auth_supplied_observer(nav_controller); | 1079 WindowedAuthSuppliedObserver auth_supplied_observer(nav_controller); |
| 1064 // Offer valid credentials on the auth challenge. | 1080 // Offer valid credentials on the auth challenge. |
| 1065 ASSERT_EQ(1u, login_observer.handlers().size()); | 1081 ASSERT_EQ(1u, login_observer.handlers().size()); |
| 1066 LoginHandler* handler = *login_observer.handlers().begin(); | 1082 LoginHandler* handler = *login_observer.handlers().begin(); |
| 1067 ASSERT_TRUE(handler); | 1083 ASSERT_TRUE(handler); |
| 1068 // Any username/password will work. | 1084 // Any username/password will work. |
| 1069 handler->SetAuth(base::UTF8ToUTF16("user"), base::UTF8ToUTF16("pwd")); | 1085 handler->SetAuth(base::UTF8ToUTF16("user"), base::UTF8ToUTF16("pwd")); |
| 1070 auth_supplied_observer.Wait(); | 1086 auth_supplied_observer.Wait(); |
| 1071 | 1087 |
| 1072 // The password manager should be working correctly. | 1088 // The password manager should be working correctly. |
| 1073 nav_observer.Wait(); | 1089 nav_observer.Wait(); |
| 1074 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 1090 EXPECT_TRUE(prompt_observer->IsPromptShown()); |
| 1075 EXPECT_TRUE(ui_controller()->PasswordPendingUserDecision()); | 1091 prompt_observer->Accept(); |
| 1076 ui_controller()->SavePassword(); | 1092 |
| 1077 } else { | |
| 1078 EXPECT_TRUE(nav_observer.infobar_shown()); | |
| 1079 } | |
| 1080 // Spin the message loop to make sure the password store had a chance to save | 1093 // Spin the message loop to make sure the password store had a chance to save |
| 1081 // the password. | 1094 // the password. |
| 1082 base::RunLoop run_loop; | 1095 base::RunLoop run_loop; |
| 1083 run_loop.RunUntilIdle(); | 1096 run_loop.RunUntilIdle(); |
| 1084 EXPECT_FALSE(password_store->IsEmpty()); | 1097 EXPECT_FALSE(password_store->IsEmpty()); |
| 1085 } | 1098 } |
| OLD | NEW |