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

Side by Side Diff: components/autofill/browser/autofill_external_delegate_unittest.cc

Issue 16286020: Abstract WebContentsObserver from Autofill shared code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to review Created 7 years, 6 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/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
11 #include "chrome/test/base/testing_profile.h" 11 #include "chrome/test/base/testing_profile.h"
12 #include "components/autofill/browser/autofill_manager.h" 12 #include "components/autofill/browser/autofill_manager.h"
13 #include "components/autofill/browser/test_autofill_driver.h"
13 #include "components/autofill/browser/test_autofill_external_delegate.h" 14 #include "components/autofill/browser/test_autofill_external_delegate.h"
14 #include "components/autofill/browser/test_autofill_manager_delegate.h" 15 #include "components/autofill/browser/test_autofill_manager_delegate.h"
15 #include "components/autofill/common/form_data.h" 16 #include "components/autofill/common/form_data.h"
16 #include "components/autofill/common/form_field_data.h" 17 #include "components/autofill/common/form_field_data.h"
17 #include "components/autofill/common/password_form_fill_data.h" 18 #include "components/autofill/common/password_form_fill_data.h"
18 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
21 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
22 23
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 base::WeakPtr<AutofillPopupDelegate> delegate)); 62 base::WeakPtr<AutofillPopupDelegate> delegate));
62 63
63 MOCK_METHOD0(HideAutofillPopup, void()); 64 MOCK_METHOD0(HideAutofillPopup, void());
64 65
65 private: 66 private:
66 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); 67 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
67 }; 68 };
68 69
69 class MockAutofillManager : public AutofillManager { 70 class MockAutofillManager : public AutofillManager {
70 public: 71 public:
71 MockAutofillManager(content::WebContents* web_contents, 72 MockAutofillManager(AutofillDriver* driver,
72 MockAutofillManagerDelegate* delegate) 73 MockAutofillManagerDelegate* delegate)
73 // Force to use the constructor designated for unit test, but we don't 74 // Force to use the constructor designated for unit test, but we don't
74 // really need personal_data in this test so we pass a NULL pointer. 75 // really need personal_data in this test so we pass a NULL pointer.
75 : AutofillManager(web_contents, delegate, NULL) { 76 : AutofillManager(driver, delegate, NULL) {
76 } 77 }
77 virtual ~MockAutofillManager() {} 78 virtual ~MockAutofillManager() {}
78 79
79 MOCK_METHOD4(OnFillAutofillFormData, 80 MOCK_METHOD4(OnFillAutofillFormData,
80 void(int query_id, 81 void(int query_id,
81 const FormData& form, 82 const FormData& form,
82 const FormFieldData& field, 83 const FormFieldData& field,
83 int unique_id)); 84 int unique_id));
84 85
85 private: 86 private:
86 DISALLOW_COPY_AND_ASSIGN(MockAutofillManager); 87 DISALLOW_COPY_AND_ASSIGN(MockAutofillManager);
87 }; 88 };
88 89
89 } // namespace 90 } // namespace
90 91
91 class AutofillExternalDelegateUnitTest 92 class AutofillExternalDelegateUnitTest
92 : public ChromeRenderViewHostTestHarness { 93 : public ChromeRenderViewHostTestHarness {
93 protected: 94 protected:
94 virtual void SetUp() OVERRIDE { 95 virtual void SetUp() OVERRIDE {
95 ChromeRenderViewHostTestHarness::SetUp(); 96 ChromeRenderViewHostTestHarness::SetUp();
97 autofill_driver_.reset(new TestAutofillDriver(web_contents()));
96 autofill_manager_.reset( 98 autofill_manager_.reset(
97 new MockAutofillManager(web_contents(), &manager_delegate_)); 99 new MockAutofillManager(autofill_driver_.get(),
100 &manager_delegate_));
98 external_delegate_.reset( 101 external_delegate_.reset(
99 new testing::NiceMock<MockAutofillExternalDelegate>( 102 new testing::NiceMock<MockAutofillExternalDelegate>(
100 web_contents(), 103 web_contents(),
101 autofill_manager_.get())); 104 autofill_manager_.get()));
102 } 105 }
103 106
104 virtual void TearDown() OVERRIDE { 107 virtual void TearDown() OVERRIDE {
105 // Order of destruction is important as AutofillManager relies on 108 // Order of destruction is important as AutofillManager relies on
106 // PersonalDataManager to be around when it gets destroyed. Also, a real 109 // PersonalDataManager to be around when it gets destroyed. Also, a real
107 // AutofillManager is tied to the lifetime of the WebContents, so it must 110 // AutofillManager is tied to the lifetime of the WebContents, so it must
108 // be destroyed at the destruction of the WebContents. 111 // be destroyed at the destruction of the WebContents.
109 autofill_manager_.reset(); 112 autofill_manager_.reset();
110 external_delegate_.reset(); 113 external_delegate_.reset();
114 autofill_driver_.reset();
111 ChromeRenderViewHostTestHarness::TearDown(); 115 ChromeRenderViewHostTestHarness::TearDown();
112 } 116 }
113 117
114 // Issue an OnQuery call with the given |query_id|. 118 // Issue an OnQuery call with the given |query_id|.
115 void IssueOnQuery(int query_id) { 119 void IssueOnQuery(int query_id) {
116 const FormData form; 120 const FormData form;
117 FormFieldData field; 121 FormFieldData field;
118 field.is_focusable = true; 122 field.is_focusable = true;
119 field.should_autocomplete = true; 123 field.should_autocomplete = true;
120 const gfx::RectF element_bounds; 124 const gfx::RectF element_bounds;
121 125
122 external_delegate_->OnQuery(query_id, form, field, element_bounds, true); 126 external_delegate_->OnQuery(query_id, form, field, element_bounds, true);
123 } 127 }
124 128
125 MockAutofillManagerDelegate manager_delegate_; 129 MockAutofillManagerDelegate manager_delegate_;
130 scoped_ptr<AutofillDriver> autofill_driver_;
126 scoped_ptr<MockAutofillManager> autofill_manager_; 131 scoped_ptr<MockAutofillManager> autofill_manager_;
127 scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> > 132 scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> >
128 external_delegate_; 133 external_delegate_;
129 }; 134 };
130 135
131 // Test that our external delegate called the virtual methods at the right time. 136 // Test that our external delegate called the virtual methods at the right time.
132 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { 137 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) {
133 IssueOnQuery(kQueryId); 138 IssueOnQuery(kQueryId);
134 139
135 // The enums must be cast to ints to prevent compile errors on linux_rel. 140 // The enums must be cast to ints to prevent compile errors on linux_rel.
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 355 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
351 356
352 external_delegate_->OnSuggestionsReturned(kQueryId, 357 external_delegate_->OnSuggestionsReturned(kQueryId,
353 autofill_items, 358 autofill_items,
354 autofill_items, 359 autofill_items,
355 autofill_items, 360 autofill_items,
356 autofill_ids); 361 autofill_ids);
357 } 362 }
358 363
359 } // namespace autofill 364 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698