OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/ref_counted.h" | 7 #include "base/ref_counted.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "base/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
11 #include "base/tuple.h" | 11 #include "base/tuple.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/autofill/autofill_common_unittest.h" | 13 #include "chrome/browser/autofill/autofill_common_unittest.h" |
14 #include "chrome/browser/autofill/autofill_manager.h" | 14 #include "chrome/browser/autofill/autofill_manager.h" |
15 #include "chrome/browser/autofill/autofill_profile.h" | 15 #include "chrome/browser/autofill/autofill_profile.h" |
16 #include "chrome/browser/autofill/credit_card.h" | 16 #include "chrome/browser/autofill/credit_card.h" |
17 #include "chrome/browser/autofill/personal_data_manager.h" | 17 #include "chrome/browser/autofill/personal_data_manager.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
20 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 20 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
21 #include "chrome/browser/tab_contents/test_tab_contents.h" | 21 #include "chrome/browser/tab_contents/test_tab_contents.h" |
22 #include "chrome/common/ipc_test_sink.h" | 22 #include "chrome/common/ipc_test_sink.h" |
| 23 #include "chrome/common/notification_source.h" |
| 24 #include "chrome/common/notification_service.h" |
23 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
24 #include "chrome/common/render_messages.h" | 26 #include "chrome/common/render_messages.h" |
25 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "webkit/glue/form_data.h" | 29 #include "webkit/glue/form_data.h" |
28 #include "webkit/glue/form_field.h" | 30 #include "webkit/glue/form_field.h" |
29 | 31 |
30 using webkit_glue::FormData; | 32 using webkit_glue::FormData; |
31 | 33 |
32 typedef Tuple5<int, | 34 typedef Tuple5<int, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 virtual bool IsAutoFillEnabled() const { return true; } | 124 virtual bool IsAutoFillEnabled() const { return true; } |
123 | 125 |
124 AutoFillProfile* GetLabeledProfile(const char* label) { | 126 AutoFillProfile* GetLabeledProfile(const char* label) { |
125 return test_personal_data_->GetLabeledProfile(label); | 127 return test_personal_data_->GetLabeledProfile(label); |
126 } | 128 } |
127 | 129 |
128 void AddProfile(AutoFillProfile* profile) { | 130 void AddProfile(AutoFillProfile* profile) { |
129 test_personal_data_->AddProfile(profile); | 131 test_personal_data_->AddProfile(profile); |
130 } | 132 } |
131 | 133 |
| 134 size_t NumFormStructures() const { return form_structures()->size(); } |
| 135 const FormStructure* GetFormStructureAtIndex(size_t index) const { |
| 136 return (*form_structures())[index]; |
| 137 } |
| 138 |
132 private: | 139 private: |
133 TestPersonalDataManager* test_personal_data_; | 140 TestPersonalDataManager* test_personal_data_; |
134 | 141 |
135 DISALLOW_COPY_AND_ASSIGN(TestAutoFillManager); | 142 DISALLOW_COPY_AND_ASSIGN(TestAutoFillManager); |
136 }; | 143 }; |
137 | 144 |
138 void CreateTestFormData(FormData* form) { | 145 void CreateTestFormData(FormData* form) { |
139 form->name = ASCIIToUTF16("MyForm"); | 146 form->name = ASCIIToUTF16("MyForm"); |
140 form->method = ASCIIToUTF16("POST"); | 147 form->method = ASCIIToUTF16("POST"); |
141 form->origin = GURL("http://myform.com/form.html"); | 148 form->origin = GURL("http://myform.com/form.html"); |
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1245 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
1239 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1246 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
1240 profile()->GetPrefs()->SetBoolean( | 1247 profile()->GetPrefs()->SetBoolean( |
1241 prefs::kAutoFillAuxiliaryProfilesEnabled, true); | 1248 prefs::kAutoFillAuxiliaryProfilesEnabled, true); |
1242 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); | 1249 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); |
1243 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1250 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
1244 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1251 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
1245 #endif | 1252 #endif |
1246 } | 1253 } |
1247 | 1254 |
| 1255 // Make sure that we properly respond to language detected notifications. |
| 1256 TEST_F(AutoFillManagerTest, LanguageDetectedNotification) { |
| 1257 FormData form1; |
| 1258 CreateTestFormData(&form1); |
| 1259 form1.name = ASCIIToUTF16("MyForm1"); |
| 1260 form1.origin = GURL("http://myform.co.uk/form.html"); |
| 1261 form1.action = GURL("http://myform.co.uk/submit.html"); |
| 1262 form1.locale = "xx"; |
| 1263 |
| 1264 FormData form2; |
| 1265 CreateTestFormData(&form2); |
| 1266 form2.name = ASCIIToUTF16("MyForm2"); |
| 1267 form2.origin = GURL("http://myform.fr/form.html"); |
| 1268 form2.action = GURL("http://myform.fr/submit.html"); |
| 1269 form2.locale = "xx"; |
| 1270 |
| 1271 // Set up our FormStructures. |
| 1272 std::vector<FormData> forms; |
| 1273 forms.push_back(form1); |
| 1274 autofill_manager_->FormsSeen(forms); |
| 1275 |
| 1276 // We should not yet have tried to detect the locale. |
| 1277 ASSERT_EQ(1U, autofill_manager_->NumFormStructures()); |
| 1278 EXPECT_EQ("xx", autofill_manager_->GetFormStructureAtIndex(0)->locale()); |
| 1279 |
| 1280 TabContents* tab_contents = autofill_manager_->tab_contents(); |
| 1281 autofill_manager_->Observe(NotificationType::TAB_LANGUAGE_DETERMINED, |
| 1282 Source<TabContents>(tab_contents), |
| 1283 NotificationService::NoDetails()); |
| 1284 |
| 1285 // Now we should have detected the locale. |
| 1286 ASSERT_EQ(1U, autofill_manager_->NumFormStructures()); |
| 1287 EXPECT_EQ("en-GB", autofill_manager_->GetFormStructureAtIndex(0)->locale()); |
| 1288 |
| 1289 forms.clear(); |
| 1290 forms.push_back(form2); |
| 1291 autofill_manager_->FormsSeen(forms); |
| 1292 |
| 1293 // We should detect the locale of this new form immediately. |
| 1294 ASSERT_EQ(2U, autofill_manager_->NumFormStructures()); |
| 1295 EXPECT_EQ("en-GB", autofill_manager_->GetFormStructureAtIndex(0)->locale()); |
| 1296 EXPECT_EQ("fr-FR", autofill_manager_->GetFormStructureAtIndex(1)->locale()); |
| 1297 |
| 1298 forms.clear(); |
| 1299 forms.push_back(form1); |
| 1300 forms.push_back(form2); |
| 1301 autofill_manager_->Reset(); |
| 1302 autofill_manager_->FormsSeen(forms); |
| 1303 |
| 1304 // We should not yet have tried to detect the locale. |
| 1305 ASSERT_EQ(2U, autofill_manager_->NumFormStructures()); |
| 1306 EXPECT_EQ("xx", autofill_manager_->GetFormStructureAtIndex(0)->locale()); |
| 1307 EXPECT_EQ("xx", autofill_manager_->GetFormStructureAtIndex(1)->locale()); |
| 1308 |
| 1309 autofill_manager_->Observe(NotificationType::TAB_LANGUAGE_DETERMINED, |
| 1310 Source<TabContents>(tab_contents), |
| 1311 NotificationService::NoDetails()); |
| 1312 |
| 1313 // Now we should have detected both locales. |
| 1314 ASSERT_EQ(2U, autofill_manager_->NumFormStructures()); |
| 1315 EXPECT_EQ("en-GB", autofill_manager_->GetFormStructureAtIndex(0)->locale()); |
| 1316 EXPECT_EQ("fr-FR", autofill_manager_->GetFormStructureAtIndex(1)->locale()); |
| 1317 } |
OLD | NEW |