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

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

Issue 8921026: [Autofill] Fix flakiness in autofill browsertest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/infobars/infobar_tab_helper.h" 17 #include "chrome/browser/infobars/infobar_tab_helper.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/translate/translate_infobar_delegate.h" 19 #include "chrome/browser/translate/translate_infobar_delegate.h"
19 #include "chrome/browser/translate/translate_manager.h" 20 #include "chrome/browser/translate/translate_manager.h"
20 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
23 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/render_messages.h" 25 #include "chrome/common/render_messages.h"
25 #include "chrome/renderer/translate_helper.h" 26 #include "chrome/renderer/translate_helper.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 "<label for=\"country\">Country:</label>" 59 "<label for=\"country\">Country:</label>"
59 " <select id=\"country\">" 60 " <select id=\"country\">"
60 " <option value=\"\" selected=\"yes\">--</option>" 61 " <option value=\"\" selected=\"yes\">--</option>"
61 " <option value=\"CA\">Canada</option>" 62 " <option value=\"CA\">Canada</option>"
62 " <option value=\"US\">United States</option>" 63 " <option value=\"US\">United States</option>"
63 " </select><br>" 64 " </select><br>"
64 "<label for=\"phone\">Phone number:</label>" 65 "<label for=\"phone\">Phone number:</label>"
65 " <input type=\"text\" id=\"phone\"><br>" 66 " <input type=\"text\" id=\"phone\"><br>"
66 "</form>"; 67 "</form>";
67 68
69 class WindowedPersonalDataManagerObserver : public PersonalDataManagerObserver {
70 public:
71 WindowedPersonalDataManagerObserver() :
72 personal_data_changed_(false),
73 has_run_message_loop_(false) {
74 }
75
76 void Wait() {
77 if (!personal_data_changed_) {
78 has_run_message_loop_ = true;
79 ui_test_utils::RunMessageLoop();
80 }
81 }
82
83 void OnPersonalDataChanged() OVERRIDE {
84 if (has_run_message_loop_) {
85 MessageLoopForUI::current()->Quit();
86 has_run_message_loop_ = false;
87 }
88
89 personal_data_changed_ = true;
90 }
91
92 private:
93 bool personal_data_changed_;
94 bool has_run_message_loop_;
95 };
96
68 class AutofillTest : public InProcessBrowserTest { 97 class AutofillTest : public InProcessBrowserTest {
69 protected: 98 protected:
70 AutofillTest() { 99 AutofillTest() {
71 set_show_window(true); 100 set_show_window(true);
72 EnableDOMAutomation(); 101 EnableDOMAutomation();
73 } 102 }
74 103
75 void CreateTestProfile() { 104 void CreateTestProfile() {
76 autofill_test::DisableSystemServices(browser()->profile()); 105 autofill_test::DisableSystemServices(browser()->profile());
77 106
78 AutofillProfile profile; 107 AutofillProfile profile;
79 autofill_test::SetProfileInfo( 108 autofill_test::SetProfileInfo(
80 &profile, "Milton", "C.", "Waddams", 109 &profile, "Milton", "C.", "Waddams",
81 "red.swingline@initech.com", "Initech", "4120 Freidrich Lane", 110 "red.swingline@initech.com", "Initech", "4120 Freidrich Lane",
82 "Basement", "Austin", "Texas", "78744", "United States", "5125551234"); 111 "Basement", "Austin", "Texas", "78744", "United States", "5125551234");
83 112
84 PersonalDataManager* personal_data_manager = 113 PersonalDataManager* personal_data_manager =
85 PersonalDataManagerFactory::GetForProfile(browser()->profile()); 114 PersonalDataManagerFactory::GetForProfile(browser()->profile());
86 ASSERT_TRUE(personal_data_manager); 115 ASSERT_TRUE(personal_data_manager);
87 116
117 WindowedPersonalDataManagerObserver observer;
118 personal_data_manager->SetObserver(&observer);
119
88 personal_data_manager->AddProfile(profile); 120 personal_data_manager->AddProfile(profile);
121
122 // AddProfile is asynchronous. Wait for it to finish before continuing the
123 // tests.
124 observer.Wait();
125 personal_data_manager->RemoveObserver(&observer);
89 } 126 }
90 127
91 void ExpectFieldValue(const std::wstring& field_name, 128 void ExpectFieldValue(const std::wstring& field_name,
92 const std::string& expected_value) { 129 const std::string& expected_value) {
93 std::string value; 130 std::string value;
94 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 131 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
95 browser()->GetSelectedTabContents()->render_view_host(), L"", 132 browser()->GetSelectedTabContents()->render_view_host(), L"",
96 L"window.domAutomationController.send(" 133 L"window.domAutomationController.send("
97 L"document.getElementById('" + field_name + L"').value);", &value)); 134 L"document.getElementById('" + field_name + L"').value);", &value));
98 EXPECT_EQ(expected_value, value); 135 EXPECT_EQ(expected_value, value);
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 // Once click the text field, it starts again. 712 // Once click the text field, it starts again.
676 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 713 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
677 render_view_host(), L"", 714 render_view_host(), L"",
678 L"cr.googleTranslate.onTranslateElementLoad();")); 715 L"cr.googleTranslate.onTranslateElementLoad();"));
679 716
680 // Simulate the render notifying the translation has been done. 717 // Simulate the render notifying the translation has been done.
681 translation_observer.Wait(); 718 translation_observer.Wait();
682 719
683 TryBasicFormFill(); 720 TryBasicFormFill();
684 } 721 }
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