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

Side by Side Diff: chrome/browser/autofill/autofill_external_delegate_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 <vector> 5 #include <vector>
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "chrome/browser/autofill/autofill_manager.h" 10 #include "chrome/browser/autofill/autofill_manager.h"
11 #include "chrome/browser/autofill/test_autofill_external_delegate.h" 11 #include "chrome/browser/autofill/test_autofill_external_delegate.h"
12 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" 12 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
13 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" 13 #include "chrome/browser/ui/tab_contents/test_tab_contents.h"
14 #include "chrome/common/form_data.h"
15 #include "chrome/common/form_field_data.h"
14 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/test/test_browser_thread.h" 17 #include "content/public/test/test_browser_thread.h"
16 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
19 #include "ui/gfx/rect.h" 21 #include "ui/gfx/rect.h"
20 #include "webkit/forms/form_data.h"
21 #include "webkit/forms/form_field.h"
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 using testing::_; 24 using testing::_;
25 using webkit::forms::FormData;
26 using webkit::forms::FormField;
27 using WebKit::WebAutofillClient; 25 using WebKit::WebAutofillClient;
28 26
29 namespace { 27 namespace {
30 28
31 // A constant value to use as the Autofill query ID. 29 // A constant value to use as the Autofill query ID.
32 const int kQueryId = 5; 30 const int kQueryId = 5;
33 31
34 // A constant value to use as an Autofill profile ID. 32 // A constant value to use as an Autofill profile ID.
35 const int kAutofillProfileId = 1; 33 const int kAutofillProfileId = 1;
36 34
37 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { 35 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate {
38 public: 36 public:
39 MockAutofillExternalDelegate(TabContents* tab_contents, 37 MockAutofillExternalDelegate(TabContents* tab_contents,
40 AutofillManager* autofill_manger) 38 AutofillManager* autofill_manger)
41 : TestAutofillExternalDelegate(tab_contents, autofill_manger) {} 39 : TestAutofillExternalDelegate(tab_contents, autofill_manger) {}
42 ~MockAutofillExternalDelegate() {} 40 ~MockAutofillExternalDelegate() {}
43 41
44 MOCK_METHOD4(ApplyAutofillSuggestions, void( 42 MOCK_METHOD4(ApplyAutofillSuggestions, void(
45 const std::vector<string16>& autofill_values, 43 const std::vector<string16>& autofill_values,
46 const std::vector<string16>& autofill_labels, 44 const std::vector<string16>& autofill_labels,
47 const std::vector<string16>& autofill_icons, 45 const std::vector<string16>& autofill_icons,
48 const std::vector<int>& autofill_unique_ids)); 46 const std::vector<int>& autofill_unique_ids));
49 47
50 MOCK_METHOD4(OnQueryPlatformSpecific, 48 MOCK_METHOD4(OnQueryPlatformSpecific,
51 void(int query_id, 49 void(int query_id,
52 const webkit::forms::FormData& form, 50 const FormData& form,
53 const webkit::forms::FormField& field, 51 const FormFieldData& field,
54 const gfx::Rect& bounds)); 52 const gfx::Rect& bounds));
55 53
56 MOCK_METHOD0(ClearPreviewedForm, void()); 54 MOCK_METHOD0(ClearPreviewedForm, void());
57 55
58 MOCK_METHOD0(HideAutofillPopup, void()); 56 MOCK_METHOD0(HideAutofillPopup, void());
59 57
60 private: 58 private:
61 virtual void HideAutofillPopupInternal() {}; 59 virtual void HideAutofillPopupInternal() {};
62 }; 60 };
63 61
64 class MockAutofillManager : public AutofillManager { 62 class MockAutofillManager : public AutofillManager {
65 public: 63 public:
66 explicit MockAutofillManager(autofill::AutofillManagerDelegate* delegate, 64 explicit MockAutofillManager(autofill::AutofillManagerDelegate* delegate,
67 TabContents* tab_contents) 65 TabContents* tab_contents)
68 // Force to use the constructor designated for unit test, but we don't 66 // Force to use the constructor designated for unit test, but we don't
69 // really need personal_data in this test so we pass a NULL pointer. 67 // really need personal_data in this test so we pass a NULL pointer.
70 : AutofillManager(delegate, tab_contents, NULL) { 68 : AutofillManager(delegate, tab_contents, NULL) {
71 } 69 }
72 70
73 MOCK_METHOD4(OnFillAutofillFormData, 71 MOCK_METHOD4(OnFillAutofillFormData,
74 void(int query_id, 72 void(int query_id,
75 const webkit::forms::FormData& form, 73 const FormData& form,
76 const webkit::forms::FormField& field, 74 const FormFieldData& field,
77 int unique_id)); 75 int unique_id));
78 76
79 protected: 77 protected:
80 virtual ~MockAutofillManager() {} 78 virtual ~MockAutofillManager() {}
81 }; 79 };
82 80
83 } // namespace 81 } // namespace
84 82
85 class AutofillExternalDelegateUnitTest : public TabContentsTestHarness { 83 class AutofillExternalDelegateUnitTest : public TabContentsTestHarness {
86 public: 84 public:
87 AutofillExternalDelegateUnitTest() 85 AutofillExternalDelegateUnitTest()
88 : ui_thread_(BrowserThread::UI, &message_loop_) {} 86 : ui_thread_(BrowserThread::UI, &message_loop_) {}
89 virtual ~AutofillExternalDelegateUnitTest() {} 87 virtual ~AutofillExternalDelegateUnitTest() {}
90 88
91 virtual void SetUp() OVERRIDE { 89 virtual void SetUp() OVERRIDE {
92 TabContentsTestHarness::SetUp(); 90 TabContentsTestHarness::SetUp();
93 manager_delegate_.reset(new TabAutofillManagerDelegate(tab_contents())); 91 manager_delegate_.reset(new TabAutofillManagerDelegate(tab_contents()));
94 autofill_manager_ = new MockAutofillManager(manager_delegate_.get(), 92 autofill_manager_ = new MockAutofillManager(manager_delegate_.get(),
95 tab_contents()); 93 tab_contents());
96 external_delegate_.reset(new MockAutofillExternalDelegate( 94 external_delegate_.reset(new MockAutofillExternalDelegate(
97 tab_contents(), 95 tab_contents(),
98 autofill_manager_)); 96 autofill_manager_));
99 } 97 }
100 98
101 protected: 99 protected:
102 // Set up the expectation for a platform specific OnQuery call and then 100 // Set up the expectation for a platform specific OnQuery call and then
103 // execute it with the given QueryId. 101 // execute it with the given QueryId.
104 void IssueOnQuery(int query_id) { 102 void IssueOnQuery(int query_id) {
105 const FormData form; 103 const FormData form;
106 FormField field; 104 FormFieldData field;
107 field.is_focusable = true; 105 field.is_focusable = true;
108 field.should_autocomplete = true; 106 field.should_autocomplete = true;
109 const gfx::Rect bounds; 107 const gfx::Rect bounds;
110 108
111 EXPECT_CALL(*external_delegate_, 109 EXPECT_CALL(*external_delegate_,
112 OnQueryPlatformSpecific(query_id, form, field, bounds)); 110 OnQueryPlatformSpecific(query_id, form, field, bounds));
113 111
114 // This should call OnQueryPlatform specific. 112 // This should call OnQueryPlatform specific.
115 external_delegate_->OnQuery(query_id, form, field, bounds, false); 113 external_delegate_->OnQuery(query_id, form, field, bounds, false);
116 } 114 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 external_delegate_->SelectAutofillSuggestionAtIndex(1); 243 external_delegate_->SelectAutofillSuggestionAtIndex(1);
246 } 244 }
247 245
248 // Test that the popup is hidden once we are done editing the autofill field. 246 // Test that the popup is hidden once we are done editing the autofill field.
249 TEST_F(AutofillExternalDelegateUnitTest, 247 TEST_F(AutofillExternalDelegateUnitTest,
250 ExternalDelegateHidePopupAfterEditing) { 248 ExternalDelegateHidePopupAfterEditing) {
251 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); 249 EXPECT_CALL(*external_delegate_, HideAutofillPopup());
252 250
253 external_delegate_->DidEndTextFieldEditing(); 251 external_delegate_->DidEndTextFieldEditing();
254 } 252 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_external_delegate.cc ('k') | chrome/browser/autofill/autofill_field.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698