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

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: Mostly cosmetic fixup 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 17 matching lines...) Expand all
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/pref_names.h" 35 #include "chrome/common/pref_names.h"
36 #include "chrome/test/base/testing_profile.h" 36 #include "chrome/test/base/testing_profile.h"
37 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
38 #include "content/public/common/form_data.h"
39 #include "content/public/common/form_field.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 content::BrowserThread; 51 using content::BrowserThread;
52 using content::FormData;
53 using content::FormField;
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 content::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 content::FormData& form,
627 const webkit::forms::FormField& field) { 627 const content::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 content::FormData& form,
636 const webkit::forms::FormField& field) { 636 const content::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 tab_contents()->autocomplete_history_manager()-> 641 tab_contents()->autocomplete_history_manager()->
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<content::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 content::FormData& form,
656 const webkit::forms::FormField& field, 656 const content::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 2408 matching lines...) Expand 10 before | Expand all | Expand 10 after
3075 namespace { 3075 namespace {
3076 3076
3077 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { 3077 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate {
3078 public: 3078 public:
3079 explicit MockAutofillExternalDelegate(TabContents* tab_contents, 3079 explicit MockAutofillExternalDelegate(TabContents* tab_contents,
3080 AutofillManager* autofill_manager) 3080 AutofillManager* autofill_manager)
3081 : TestAutofillExternalDelegate(tab_contents, autofill_manager) {} 3081 : TestAutofillExternalDelegate(tab_contents, autofill_manager) {}
3082 virtual ~MockAutofillExternalDelegate() {} 3082 virtual ~MockAutofillExternalDelegate() {}
3083 3083
3084 MOCK_METHOD5(OnQuery, void(int query_id, 3084 MOCK_METHOD5(OnQuery, void(int query_id,
3085 const webkit::forms::FormData& form, 3085 const content::FormData& form,
3086 const webkit::forms::FormField& field, 3086 const content::FormField& field,
3087 const gfx::Rect& bounds, 3087 const gfx::Rect& bounds,
3088 bool display_warning)); 3088 bool display_warning));
3089 3089
3090 virtual void OnQueryPlatformSpecific(int query_id, 3090 virtual void OnQueryPlatformSpecific(int query_id,
3091 const webkit::forms::FormData& form, 3091 const content::FormData& form,
3092 const webkit::forms::FormField& field, 3092 const content::FormField& field,
3093 const gfx::Rect& bounds) OVERRIDE {} 3093 const gfx::Rect& bounds) OVERRIDE {}
3094 3094
3095 private: 3095 private:
3096 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); 3096 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate);
3097 }; 3097 };
3098 3098
3099 } // namespace 3099 } // namespace
3100 3100
3101 // Test our external delegate is called at the right time. 3101 // Test our external delegate is called at the right time.
3102 TEST_F(AutofillManagerTest, TestExternalDelegate) { 3102 TEST_F(AutofillManagerTest, TestExternalDelegate) {
(...skipping 29 matching lines...) Expand all
3132 3132
3133 AutofillManager* autofill_manager = tab_contents()->autofill_manager(); 3133 AutofillManager* autofill_manager = tab_contents()->autofill_manager();
3134 EXPECT_TRUE(autofill_manager->external_delegate()); 3134 EXPECT_TRUE(autofill_manager->external_delegate());
3135 3135
3136 AutocompleteHistoryManager* autocomplete_history_manager = 3136 AutocompleteHistoryManager* autocomplete_history_manager =
3137 tab_contents()->autocomplete_history_manager(); 3137 tab_contents()->autocomplete_history_manager();
3138 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); 3138 EXPECT_TRUE(autocomplete_history_manager->external_delegate());
3139 } 3139 }
3140 3140
3141 #endif // OS_ANDROID 3141 #endif // OS_ANDROID
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698