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

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

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

Powered by Google App Engine
This is Rietveld 408576698