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

Side by Side Diff: chrome/browser/autofill/autofill_browsertest.cc

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/autofill/autofill_common_test.h" 12 #include "chrome/browser/autofill/autofill_common_test.h"
13 #include "chrome/browser/autofill/autofill_profile.h" 13 #include "chrome/browser/autofill/autofill_profile.h"
14 #include "chrome/browser/autofill/personal_data_manager.h" 14 #include "chrome/browser/autofill/personal_data_manager.h"
15 #include "chrome/browser/autofill/personal_data_manager_factory.h" 15 #include "chrome/browser/autofill/personal_data_manager_factory.h"
16 #include "chrome/browser/autofill/personal_data_manager_observer.h" 16 #include "chrome/browser/autofill/personal_data_manager_observer.h"
17 #include "chrome/browser/infobars/infobar_tab_helper.h" 17 #include "chrome/browser/infobars/infobar_tab_helper.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/translate/translate_infobar_delegate.h" 19 #include "chrome/browser/translate/translate_infobar_delegate.h"
20 #include "chrome/browser/translate/translate_manager.h" 20 #include "chrome/browser/translate/translate_manager.h"
21 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_tabstrip.h"
22 #include "chrome/browser/ui/browser_window.h" 23 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/tab_contents/tab_contents.h" 24 #include "chrome/browser/ui/tab_contents/tab_contents.h"
24 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/render_messages.h" 26 #include "chrome/common/render_messages.h"
26 #include "chrome/test/base/in_process_browser_test.h" 27 #include "chrome/test/base/in_process_browser_test.h"
27 #include "chrome/test/base/ui_test_utils.h" 28 #include "chrome/test/base/ui_test_utils.h"
28 #include "content/public/browser/navigation_controller.h" 29 #include "content/public/browser/navigation_controller.h"
29 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/render_view_host.h" 31 #include "content/public/browser/render_view_host.h"
31 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // AddProfile is asynchronous. Wait for it to finish before continuing the 126 // AddProfile is asynchronous. Wait for it to finish before continuing the
126 // tests. 127 // tests.
127 observer.Wait(); 128 observer.Wait();
128 personal_data_manager->RemoveObserver(&observer); 129 personal_data_manager->RemoveObserver(&observer);
129 } 130 }
130 131
131 void ExpectFieldValue(const std::wstring& field_name, 132 void ExpectFieldValue(const std::wstring& field_name,
132 const std::string& expected_value) { 133 const std::string& expected_value) {
133 std::string value; 134 std::string value;
134 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 135 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
135 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", 136 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"",
136 L"window.domAutomationController.send(" 137 L"window.domAutomationController.send("
137 L"document.getElementById('" + field_name + L"').value);", &value)); 138 L"document.getElementById('" + field_name + L"').value);", &value));
138 EXPECT_EQ(expected_value, value); 139 EXPECT_EQ(expected_value, value);
139 } 140 }
140 141
141 RenderViewHost* render_view_host() { 142 RenderViewHost* render_view_host() {
142 return browser()->GetActiveWebContents()->GetRenderViewHost(); 143 return chrome::GetActiveWebContents(browser())->GetRenderViewHost();
143 } 144 }
144 145
145 void SimulateURLFetch(bool success) { 146 void SimulateURLFetch(bool success) {
146 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 147 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
147 ASSERT_TRUE(fetcher); 148 ASSERT_TRUE(fetcher);
148 net::URLRequestStatus status; 149 net::URLRequestStatus status;
149 status.set_status(success ? net::URLRequestStatus::SUCCESS : 150 status.set_status(success ? net::URLRequestStatus::SUCCESS :
150 net::URLRequestStatus::FAILED); 151 net::URLRequestStatus::FAILED);
151 152
152 std::string script = " var google = {};" 153 std::string script = " var google = {};"
(...skipping 24 matching lines...) Expand all
177 178
178 fetcher->set_url(fetcher->GetOriginalURL()); 179 fetcher->set_url(fetcher->GetOriginalURL());
179 fetcher->set_status(status); 180 fetcher->set_status(status);
180 fetcher->set_response_code(success ? 200 : 500); 181 fetcher->set_response_code(success ? 200 : 500);
181 fetcher->SetResponseString(script); 182 fetcher->SetResponseString(script);
182 fetcher->delegate()->OnURLFetchComplete(fetcher); 183 fetcher->delegate()->OnURLFetchComplete(fetcher);
183 } 184 }
184 185
185 void FocusFirstNameField() { 186 void FocusFirstNameField() {
186 LOG(WARNING) << "Clicking on the tab."; 187 LOG(WARNING) << "Clicking on the tab.";
187 ui_test_utils::SimulateMouseClick(browser()->GetActiveWebContents()); 188 ui_test_utils::SimulateMouseClick(chrome::GetActiveWebContents(browser()));
188 189
189 LOG(WARNING) << "Focusing the first name field."; 190 LOG(WARNING) << "Focusing the first name field.";
190 bool result = false; 191 bool result = false;
191 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 192 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
192 render_view_host(), L"", 193 render_view_host(), L"",
193 L"if (document.readyState === 'complete')" 194 L"if (document.readyState === 'complete')"
194 L" document.getElementById('firstname').focus();" 195 L" document.getElementById('firstname').focus();"
195 L"else" 196 L"else"
196 L" domAutomationController.send(false);", 197 L" domAutomationController.send(false);",
197 &result)); 198 &result));
198 ASSERT_TRUE(result); 199 ASSERT_TRUE(result);
199 } 200 }
200 201
201 void ExpectFilledTestForm() { 202 void ExpectFilledTestForm() {
202 ExpectFieldValue(L"firstname", "Milton"); 203 ExpectFieldValue(L"firstname", "Milton");
203 ExpectFieldValue(L"lastname", "Waddams"); 204 ExpectFieldValue(L"lastname", "Waddams");
204 ExpectFieldValue(L"address1", "4120 Freidrich Lane"); 205 ExpectFieldValue(L"address1", "4120 Freidrich Lane");
205 ExpectFieldValue(L"address2", "Basement"); 206 ExpectFieldValue(L"address2", "Basement");
206 ExpectFieldValue(L"city", "Austin"); 207 ExpectFieldValue(L"city", "Austin");
207 ExpectFieldValue(L"state", "TX"); 208 ExpectFieldValue(L"state", "TX");
208 ExpectFieldValue(L"zip", "78744"); 209 ExpectFieldValue(L"zip", "78744");
209 ExpectFieldValue(L"country", "US"); 210 ExpectFieldValue(L"country", "US");
210 ExpectFieldValue(L"phone", "5125551234"); 211 ExpectFieldValue(L"phone", "5125551234");
211 } 212 }
212 213
213 void SendKeyAndWait(ui::KeyboardCode key, int notification_type) { 214 void SendKeyAndWait(ui::KeyboardCode key, int notification_type) {
214 ui_test_utils::WindowedNotificationObserver observer( 215 ui_test_utils::WindowedNotificationObserver observer(
215 notification_type, content::Source<RenderViewHost>(render_view_host())); 216 notification_type, content::Source<RenderViewHost>(render_view_host()));
216 ui_test_utils::SimulateKeyPress( 217 ui_test_utils::SimulateKeyPress(chrome::GetActiveWebContents(
217 browser()->GetActiveWebContents(), key, false, false, false, false); 218 browser()), key, false, false, false, false);
218 observer.Wait(); 219 observer.Wait();
219 } 220 }
220 221
221 void TryBasicFormFill() { 222 void TryBasicFormFill() {
222 FocusFirstNameField(); 223 FocusFirstNameField();
223 224
224 // Start filling the first name field with "M" and wait for the popup to be 225 // Start filling the first name field with "M" and wait for the popup to be
225 // shown. 226 // shown.
226 LOG(WARNING) << "Typing 'M' to bring up the Autofill popup."; 227 LOG(WARNING) << "Typing 'M' to bring up the Autofill popup.";
227 SendKeyAndWait( 228 SendKeyAndWait(
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 616
616 // Load the test page. 617 // Load the test page.
617 LOG(WARNING) << "Bringing browser window to front."; 618 LOG(WARNING) << "Bringing browser window to front.";
618 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 619 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
619 LOG(WARNING) << "Navigating to URL."; 620 LOG(WARNING) << "Navigating to URL.";
620 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), 621 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
621 GURL(std::string(kDataURIPrefix) + kTestFormString))); 622 GURL(std::string(kDataURIPrefix) + kTestFormString)));
622 623
623 // Reload the page. 624 // Reload the page.
624 LOG(WARNING) << "Reloading the page."; 625 LOG(WARNING) << "Reloading the page.";
625 WebContents* tab = browser()->GetActiveWebContents(); 626 WebContents* tab = chrome::GetActiveWebContents(browser());
626 tab->GetController().Reload(false); 627 tab->GetController().Reload(false);
627 ui_test_utils::WaitForLoadStop(tab); 628 ui_test_utils::WaitForLoadStop(tab);
628 629
629 // Invoke Autofill. 630 // Invoke Autofill.
630 LOG(WARNING) << "Trying to fill the form."; 631 LOG(WARNING) << "Trying to fill the form.";
631 TryBasicFormFill(); 632 TryBasicFormFill();
632 } 633 }
633 634
634 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) 635 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
635 // Test that autofill works after page translation. 636 // Test that autofill works after page translation.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 " <input type=\"text\" id=\"ph\"><br>" 673 " <input type=\"text\" id=\"ph\"><br>"
673 "</form>"); 674 "</form>");
674 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 675 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
675 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), url)); 676 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), url));
676 677
677 // Get translation bar. 678 // Get translation bar.
678 RenderViewHostTester::TestOnMessageReceived( 679 RenderViewHostTester::TestOnMessageReceived(
679 render_view_host(), 680 render_view_host(),
680 ChromeViewHostMsg_TranslateLanguageDetermined(0, "ja", true)); 681 ChromeViewHostMsg_TranslateLanguageDetermined(0, "ja", true));
681 TranslateInfoBarDelegate* infobar = 682 TranslateInfoBarDelegate* infobar =
682 browser()->GetActiveTabContents()->infobar_tab_helper()-> 683 chrome::GetActiveTabContents(browser())->infobar_tab_helper()->
683 GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate(); 684 GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate();
684 685
685 ASSERT_TRUE(infobar != NULL); 686 ASSERT_TRUE(infobar != NULL);
686 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); 687 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type());
687 688
688 // Simulate translation button press. 689 // Simulate translation button press.
689 infobar->Translate(); 690 infobar->Translate();
690 691
691 // Simulate the translate script being retrieved. 692 // Simulate the translate script being retrieved.
692 // Pass fake google.translate lib as the translate script. 693 // Pass fake google.translate lib as the translate script.
693 SimulateURLFetch(true); 694 SimulateURLFetch(true);
694 695
695 ui_test_utils::WindowedNotificationObserver translation_observer( 696 ui_test_utils::WindowedNotificationObserver translation_observer(
696 chrome::NOTIFICATION_PAGE_TRANSLATED, 697 chrome::NOTIFICATION_PAGE_TRANSLATED,
697 content::NotificationService::AllSources()); 698 content::NotificationService::AllSources());
698 699
699 // Simulate translation to kick onTranslateElementLoad. 700 // Simulate translation to kick onTranslateElementLoad.
700 // But right now, the call stucks here. 701 // But right now, the call stucks here.
701 // Once click the text field, it starts again. 702 // Once click the text field, it starts again.
702 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 703 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
703 render_view_host(), L"", 704 render_view_host(), L"",
704 L"cr.googleTranslate.onTranslateElementLoad();")); 705 L"cr.googleTranslate.onTranslateElementLoad();"));
705 706
706 // Simulate the render notifying the translation has been done. 707 // Simulate the render notifying the translation has been done.
707 translation_observer.Wait(); 708 translation_observer.Wait();
708 709
709 TryBasicFormFill(); 710 TryBasicFormFill();
710 } 711 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_browsertest.cc ('k') | chrome/browser/autofill/autofill_popup_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698