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

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

Issue 11000016: Move forms/ out of webkit/. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to review Created 8 years, 2 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
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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/autofill/test_autofill_external_delegate.h" 25 #include "chrome/browser/autofill/test_autofill_external_delegate.h"
26 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/sync/profile_sync_service.h" 27 #include "chrome/browser/sync/profile_sync_service.h"
28 #include "chrome/browser/sync/profile_sync_service_factory.h" 28 #include "chrome/browser/sync/profile_sync_service_factory.h"
29 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" 29 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
30 #include "chrome/browser/ui/browser.h" 30 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/tab_contents/tab_contents.h" 31 #include "chrome/browser/ui/tab_contents/tab_contents.h"
32 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" 32 #include "chrome/browser/ui/tab_contents/test_tab_contents.h"
33 #include "chrome/common/autofill_messages.h" 33 #include "chrome/common/autofill_messages.h"
34 #include "chrome/common/chrome_switches.h" 34 #include "chrome/common/chrome_switches.h"
35 #include "chrome/common/form_data.h"
36 #include "chrome/common/form_field.h"
35 #include "chrome/common/pref_names.h" 37 #include "chrome/common/pref_names.h"
36 #include "chrome/test/base/testing_profile.h" 38 #include "chrome/test/base/testing_profile.h"
37 #include "content/public/browser/web_contents.h" 39 #include "content/public/browser/web_contents.h"
38 #include "content/public/test/mock_render_process_host.h" 40 #include "content/public/test/mock_render_process_host.h"
39 #include "content/public/test/test_browser_thread.h" 41 #include "content/public/test/test_browser_thread.h"
40 #include "googleurl/src/gurl.h" 42 #include "googleurl/src/gurl.h"
41 #include "grit/generated_resources.h" 43 #include "grit/generated_resources.h"
42 #include "ipc/ipc_test_sink.h" 44 #include "ipc/ipc_test_sink.h"
43 #include "testing/gmock/include/gmock/gmock.h" 45 #include "testing/gmock/include/gmock/gmock.h"
44 #include "testing/gtest/include/gtest/gtest.h" 46 #include "testing/gtest/include/gtest/gtest.h"
45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
46 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
47 #include "ui/gfx/rect.h" 49 #include "ui/gfx/rect.h"
48 #include "webkit/forms/form_data.h"
49 #include "webkit/forms/form_field.h"
50 50
51 using chrome::FormData;
52 using chrome::FormField;
51 using content::BrowserThread; 53 using content::BrowserThread;
52 using content::WebContents; 54 using content::WebContents;
53 using testing::_; 55 using testing::_;
54 using webkit::forms::FormData;
55 using webkit::forms::FormField;
56 56
57 namespace { 57 namespace {
58 58
59 // The page ID sent to the AutofillManager from the RenderView, used to send 59 // The page ID sent to the AutofillManager from the RenderView, used to send
60 // an IPC message back to the renderer. 60 // an IPC message back to the renderer.
61 const int kDefaultPageID = 137; 61 const int kDefaultPageID = 137;
62 62
63 typedef Tuple5<int, 63 typedef Tuple5<int,
64 std::vector<string16>, 64 std::vector<string16>,
65 std::vector<string16>, 65 std::vector<string16>,
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 EXPECT_EQ(expected_labels[i], labels[i]); 294 EXPECT_EQ(expected_labels[i], labels[i]);
295 EXPECT_EQ(expected_icons[i], icons[i]); 295 EXPECT_EQ(expected_icons[i], icons[i]);
296 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); 296 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]);
297 } 297 }
298 } 298 }
299 299
300 void ExpectFilledField(const char* expected_label, 300 void ExpectFilledField(const char* expected_label,
301 const char* expected_name, 301 const char* expected_name,
302 const char* expected_value, 302 const char* expected_value,
303 const char* expected_form_control_type, 303 const char* expected_form_control_type,
304 const webkit::forms::FormField& field) { 304 const chrome::FormField& field) {
305 SCOPED_TRACE(expected_label); 305 SCOPED_TRACE(expected_label);
306 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); 306 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label);
307 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); 307 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name);
308 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); 308 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value);
309 EXPECT_EQ(UTF8ToUTF16(expected_form_control_type), field.form_control_type); 309 EXPECT_EQ(UTF8ToUTF16(expected_form_control_type), field.form_control_type);
310 } 310 }
311 311
312 // Verifies that the |filled_form| has been filled with the given data. 312 // Verifies that the |filled_form| has been filled with the given data.
313 // Verifies address fields if |has_address_fields| is true, and verifies 313 // Verifies address fields if |has_address_fields| is true, and verifies
314 // credit card fields if |has_credit_card_fields| is true. Verifies both if both 314 // credit card fields if |has_credit_card_fields| is true. Verifies both if both
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 virtual void TearDown() OVERRIDE { 616 virtual void TearDown() OVERRIDE {
617 file_thread_.Stop(); 617 file_thread_.Stop();
618 TabContentsTestHarness::TearDown(); 618 TabContentsTestHarness::TearDown();
619 } 619 }
620 620
621 void UpdatePasswordGenerationState(bool new_renderer) { 621 void UpdatePasswordGenerationState(bool new_renderer) {
622 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); 622 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer);
623 } 623 }
624 624
625 void GetAutofillSuggestions(int query_id, 625 void GetAutofillSuggestions(int query_id,
626 const webkit::forms::FormData& form, 626 const chrome::FormData& form,
627 const webkit::forms::FormField& field) { 627 const chrome::FormField& field) {
628 autofill_manager_->OnQueryFormFieldAutofill(query_id, 628 autofill_manager_->OnQueryFormFieldAutofill(query_id,
629 form, 629 form,
630 field, 630 field,
631 gfx::Rect(), 631 gfx::Rect(),
632 false); 632 false);
633 } 633 }
634 634
635 void GetAutofillSuggestions(const webkit::forms::FormData& form, 635 void GetAutofillSuggestions(const chrome::FormData& form,
636 const webkit::forms::FormField& field) { 636 const chrome::FormField& field) {
637 GetAutofillSuggestions(kDefaultPageID, form, field); 637 GetAutofillSuggestions(kDefaultPageID, form, field);
638 } 638 }
639 639
640 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { 640 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) {
641 AutocompleteHistoryManager::FromWebContents(web_contents())-> 641 AutocompleteHistoryManager::FromWebContents(web_contents())->
642 SendSuggestions(&result); 642 SendSuggestions(&result);
643 } 643 }
644 644
645 void FormsSeen(const std::vector<webkit::forms::FormData>& forms) { 645 void FormsSeen(const std::vector<chrome::FormData>& forms) {
646 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); 646 autofill_manager_->OnFormsSeen(forms, base::TimeTicks());
647 } 647 }
648 648
649 void FormSubmitted(const FormData& form) { 649 void FormSubmitted(const FormData& form) {
650 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) 650 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now()))
651 autofill_manager_->WaitForAsyncFormSubmit(); 651 autofill_manager_->WaitForAsyncFormSubmit();
652 } 652 }
653 653
654 void FillAutofillFormData(int query_id, 654 void FillAutofillFormData(int query_id,
655 const webkit::forms::FormData& form, 655 const chrome::FormData& form,
656 const webkit::forms::FormField& field, 656 const chrome::FormField& field,
657 int unique_id) { 657 int unique_id) {
658 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); 658 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id);
659 } 659 }
660 660
661 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { 661 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const {
662 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); 662 return autofill_manager_->PackGUIDs(cc_guid, profile_guid);
663 } 663 }
664 664
665 bool GetAutofillSuggestionsMessage(int* page_id, 665 bool GetAutofillSuggestionsMessage(int* page_id,
666 std::vector<string16>* values, 666 std::vector<string16>* values,
(...skipping 2409 matching lines...) Expand 10 before | Expand all | Expand 10 after
3076 namespace { 3076 namespace {
3077 3077
3078 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { 3078 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate {
3079 public: 3079 public:
3080 explicit MockAutofillExternalDelegate(TabContents* tab_contents, 3080 explicit MockAutofillExternalDelegate(TabContents* tab_contents,
3081 AutofillManager* autofill_manager) 3081 AutofillManager* autofill_manager)
3082 : TestAutofillExternalDelegate(tab_contents, autofill_manager) {} 3082 : TestAutofillExternalDelegate(tab_contents, autofill_manager) {}
3083 virtual ~MockAutofillExternalDelegate() {} 3083 virtual ~MockAutofillExternalDelegate() {}
3084 3084
3085 MOCK_METHOD5(OnQuery, void(int query_id, 3085 MOCK_METHOD5(OnQuery, void(int query_id,
3086 const webkit::forms::FormData& form, 3086 const chrome::FormData& form,
3087 const webkit::forms::FormField& field, 3087 const chrome::FormField& field,
3088 const gfx::Rect& bounds, 3088 const gfx::Rect& bounds,
3089 bool display_warning)); 3089 bool display_warning));
3090 3090
3091 virtual void OnQueryPlatformSpecific(int query_id, 3091 virtual void OnQueryPlatformSpecific(int query_id,
3092 const webkit::forms::FormData& form, 3092 const chrome::FormData& form,
3093 const webkit::forms::FormField& field, 3093 const chrome::FormField& field,
3094 const gfx::Rect& bounds) OVERRIDE {} 3094 const gfx::Rect& bounds) OVERRIDE {}
3095 3095
3096 private: 3096 private:
3097 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); 3097 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate);
3098 }; 3098 };
3099 3099
3100 } // namespace 3100 } // namespace
3101 3101
3102 // Test our external delegate is called at the right time. 3102 // Test our external delegate is called at the right time.
3103 TEST_F(AutofillManagerTest, TestExternalDelegate) { 3103 TEST_F(AutofillManagerTest, TestExternalDelegate) {
(...skipping 29 matching lines...) Expand all
3133 3133
3134 AutofillManager* autofill_manager = tab_contents()->autofill_manager(); 3134 AutofillManager* autofill_manager = tab_contents()->autofill_manager();
3135 EXPECT_TRUE(autofill_manager->external_delegate()); 3135 EXPECT_TRUE(autofill_manager->external_delegate());
3136 3136
3137 AutocompleteHistoryManager* autocomplete_history_manager = 3137 AutocompleteHistoryManager* autocomplete_history_manager =
3138 AutocompleteHistoryManager::FromWebContents(web_contents()); 3138 AutocompleteHistoryManager::FromWebContents(web_contents());
3139 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); 3139 EXPECT_TRUE(autocomplete_history_manager->external_delegate());
3140 } 3140 }
3141 3141
3142 #endif // OS_ANDROID 3142 #endif // OS_ANDROID
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698