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

Unified Diff: chrome/browser/autofill/autofill_manager_unittest.cc

Issue 3226001: Detecting form locale (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Unit test for top websites Created 10 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | chrome/browser/autofill/autofill_xml_parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autofill/autofill_manager_unittest.cc
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index 7d78a9bc60d18f24a84728f2e3e9ec8251810ed0..d0cb0b394b09ae400d30d238e01e355f2a633cbc 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -20,6 +20,8 @@
#include "chrome/browser/renderer_host/test/test_render_view_host.h"
#include "chrome/browser/tab_contents/test_tab_contents.h"
#include "chrome/common/ipc_test_sink.h"
+#include "chrome/common/notification_source.h"
+#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h"
#include "googleurl/src/gurl.h"
@@ -129,6 +131,11 @@ class TestAutoFillManager : public AutoFillManager {
test_personal_data_->AddProfile(profile);
}
+ size_t NumFormStructures() const { return form_structures()->size(); }
+ const FormStructure* GetFormStructureAtIndex(size_t index) const {
+ return (*form_structures())[index];
+ }
+
private:
TestPersonalDataManager* test_personal_data_;
@@ -1245,3 +1252,66 @@ TEST_F(AutoFillManagerTest, AuxiliaryProfilesReset) {
#endif
}
+// Make sure that we properly respond to language detected notifications.
+TEST_F(AutoFillManagerTest, LanguageDetectedNotification) {
+ FormData form1;
+ CreateTestFormData(&form1);
+ form1.name = ASCIIToUTF16("MyForm1");
+ form1.origin = GURL("http://myform.co.uk/form.html");
+ form1.action = GURL("http://myform.co.uk/submit.html");
+ form1.locale = "xx";
+
+ FormData form2;
+ CreateTestFormData(&form2);
+ form2.name = ASCIIToUTF16("MyForm2");
+ form2.origin = GURL("http://myform.fr/form.html");
+ form2.action = GURL("http://myform.fr/submit.html");
+ form2.locale = "xx";
+
+ // Set up our FormStructures.
+ std::vector<FormData> forms;
+ forms.push_back(form1);
+ autofill_manager_->FormsSeen(forms);
+
+ // We should not yet have tried to detect the locale.
+ ASSERT_EQ(1U, autofill_manager_->NumFormStructures());
+ EXPECT_EQ("xx", autofill_manager_->GetFormStructureAtIndex(0)->locale());
+
+ TabContents* tab_contents = autofill_manager_->tab_contents();
+ autofill_manager_->Observe(NotificationType::TAB_LANGUAGE_DETERMINED,
+ Source<TabContents>(tab_contents),
+ NotificationService::NoDetails());
+
+ // Now we should have detected the locale.
+ ASSERT_EQ(1U, autofill_manager_->NumFormStructures());
+ EXPECT_EQ("en-GB", autofill_manager_->GetFormStructureAtIndex(0)->locale());
+
+ forms.clear();
+ forms.push_back(form2);
+ autofill_manager_->FormsSeen(forms);
+
+ // We should detect the locale of this new form immediately.
+ ASSERT_EQ(2U, autofill_manager_->NumFormStructures());
+ EXPECT_EQ("en-GB", autofill_manager_->GetFormStructureAtIndex(0)->locale());
+ EXPECT_EQ("fr-FR", autofill_manager_->GetFormStructureAtIndex(1)->locale());
+
+ forms.clear();
+ forms.push_back(form1);
+ forms.push_back(form2);
+ autofill_manager_->Reset();
+ autofill_manager_->FormsSeen(forms);
+
+ // We should not yet have tried to detect the locale.
+ ASSERT_EQ(2U, autofill_manager_->NumFormStructures());
+ EXPECT_EQ("xx", autofill_manager_->GetFormStructureAtIndex(0)->locale());
+ EXPECT_EQ("xx", autofill_manager_->GetFormStructureAtIndex(1)->locale());
+
+ autofill_manager_->Observe(NotificationType::TAB_LANGUAGE_DETERMINED,
+ Source<TabContents>(tab_contents),
+ NotificationService::NoDetails());
+
+ // Now we should have detected both locales.
+ ASSERT_EQ(2U, autofill_manager_->NumFormStructures());
+ EXPECT_EQ("en-GB", autofill_manager_->GetFormStructureAtIndex(0)->locale());
+ EXPECT_EQ("fr-FR", autofill_manager_->GetFormStructureAtIndex(1)->locale());
+}
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | chrome/browser/autofill/autofill_xml_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698