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

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

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

Powered by Google App Engine
This is Rietveld 408576698