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

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

Issue 12713007: Fix the no password save issue for ajax login (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove dead code Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | content/public/renderer/document_state.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_contents_observer.h"
20 #include "content/public/test/browser_test_utils.h"
21 #include "content/public/test/test_utils.h"
22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "ui/base/keycodes/keyboard_codes.h"
24
25 namespace {
26
27 class NavigationObserver : public content::NotificationObserver,
28 public content::WebContentsObserver {
29 public:
30 explicit NavigationObserver(content::WebContents* web_contents)
31 : content::WebContentsObserver(web_contents),
32 message_loop_runner_(new content::MessageLoopRunner),
33 info_bar_shown_(false),
34 web_contents_(web_contents),
35 infobar_service_(InfoBarService::FromWebContents(web_contents)) {
36 registrar_.Add(this,
37 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
38 content::Source<InfoBarService>(infobar_service_));
39 }
40
41 virtual ~NavigationObserver() {}
42
43 void Wait() {
44 message_loop_runner_->Run();
45 }
46
47 bool InfoBarWasShown() {
48 return info_bar_shown_;
49 }
50
51 // content::NotificationObserver:
52 virtual void Observe(int type,
53 const content::NotificationSource& source,
54 const content::NotificationDetails& details) OVERRIDE {
55 // Accept in the infobar.
56 InfoBarDelegate* infobar = infobar_service_->GetInfoBarDelegateAt(0);
57 ConfirmInfoBarDelegate* confirm_infobar =
58 infobar->AsConfirmInfoBarDelegate();
59 confirm_infobar->Accept();
60 info_bar_shown_ = true;
61 }
62
63 // content::WebContentsObserver
64 virtual void DidFinishLoad(int64 frame_id,
65 const GURL& validated_url,
66 bool is_main_frame,
67 content::RenderViewHost* render_view_host) {
68 message_loop_runner_->Quit();
69 }
70
71 private:
72 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
73 bool info_bar_shown_;
74 content::NotificationRegistrar registrar_;
75 content::WebContents* web_contents_;
76 InfoBarService* infobar_service_;
77 };
78
79 } // namespace
80
81 class PasswordManagerBrowserTest : public InProcessBrowserTest {
82 protected:
83 content::WebContents* WebContents() {
84 return browser()->tab_strip_model()->GetActiveWebContents();
85 }
Ilya Sherman 2013/03/23 01:10:58 nit: Please leave a blank line after this one.
Garrett Casto 2013/03/26 00:00:27 Done.
86 content::RenderViewHost* RenderViewHost() {
87 return WebContents()->GetRenderViewHost();
88 }
89 };
90
91 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForXHRSubmit) {
92 ASSERT_TRUE(test_server()->Start());
93
94 GURL url = test_server()->GetURL("files/password/password_xhr_submit.html");
95 ui_test_utils::NavigateToURL(browser(), url);
96
97 // Verify that we show the save password prompt if a form returns false
98 // in its onsubmit handler but instead logs in/navigates via XHR.
99 // Note that calling 'submit()' on a form with javascript doesn't call
100 // the onsubmit handler, so we click the submit button instead.
101 NavigationObserver observer(WebContents());
102 std::string fill_and_submit =
103 "document.getElementById('username_field').value = 'temp';"
104 "document.getElementById('password_field').value = 'random';"
105 "document.getElementById('submit_button').click()";
106 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
107 observer.Wait();
108 EXPECT_TRUE(observer.InfoBarWasShown());
109 }
110
111 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptForOtherXHR) {
112 ASSERT_TRUE(test_server()->Start());
113
114 GURL url = test_server()->GetURL("files/password/password_xhr_submit.html");
115 ui_test_utils::NavigateToURL(browser(), url);
116
117 // Verify that if random XHR navigation occurs, we don't try and save the
118 // password.
119 //
120 // We may want to change this functionality in the future to account for
121 // cases where the element that users click on isn't a submit button.
122 NavigationObserver observer(WebContents());
123 std::string fill_and_navigate =
124 "document.getElementById('username_field').value = 'temp';"
125 "document.getElementById('password_field').value = 'random';"
126 "send_xhr()";
127 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate));
128 observer.Wait();
129 EXPECT_FALSE(observer.InfoBarWasShown());
130 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | content/public/renderer/document_state.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698