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

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

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT 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 | Annotate | Revision Log
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/string16.h" 8 #include "base/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_external_delegate.h" 13 #include "components/autofill/browser/test_autofill_external_delegate.h"
14 #include "components/autofill/browser/test_autofill_manager_delegate.h" 14 #include "components/autofill/browser/test_autofill_manager_delegate.h"
15 #include "components/autofill/common/form_data.h" 15 #include "components/autofill/common/form_data.h"
16 #include "components/autofill/common/form_field_data.h" 16 #include "components/autofill/common/form_field_data.h"
17 #include "components/autofill/common/password_form_fill_data.h" 17 #include "components/autofill/common/password_form_fill_data.h"
18 #include "content/public/test/test_browser_thread.h"
19 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
22 #include "ui/gfx/rect.h" 21 #include "ui/gfx/rect.h"
23 22
24 using content::BrowserThread;
25 using testing::_; 23 using testing::_;
26 using WebKit::WebAutofillClient; 24 using WebKit::WebAutofillClient;
27 25
28 namespace autofill { 26 namespace autofill {
29 27
30 namespace { 28 namespace {
31 29
32 // A constant value to use as the Autofill query ID. 30 // A constant value to use as the Autofill query ID.
33 const int kQueryId = 5; 31 const int kQueryId = 5;
34 32
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 int unique_id)); 83 int unique_id));
86 84
87 private: 85 private:
88 DISALLOW_COPY_AND_ASSIGN(MockAutofillManager); 86 DISALLOW_COPY_AND_ASSIGN(MockAutofillManager);
89 }; 87 };
90 88
91 } // namespace 89 } // namespace
92 90
93 class AutofillExternalDelegateUnitTest 91 class AutofillExternalDelegateUnitTest
94 : public ChromeRenderViewHostTestHarness { 92 : public ChromeRenderViewHostTestHarness {
95 public:
96 AutofillExternalDelegateUnitTest()
97 : ui_thread_(BrowserThread::UI, &message_loop_) {}
98 virtual ~AutofillExternalDelegateUnitTest() {}
99
100 protected: 93 protected:
101 // Issue an OnQuery call with the given |query_id|.
102 void IssueOnQuery(int query_id) {
103 const FormData form;
104 FormFieldData field;
105 field.is_focusable = true;
106 field.should_autocomplete = true;
107 const gfx::RectF element_bounds;
108
109 external_delegate_->OnQuery(query_id, form, field, element_bounds, false);
110 }
111
112 MockAutofillManagerDelegate manager_delegate_;
113 scoped_ptr<MockAutofillManager> autofill_manager_;
114 scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> >
115 external_delegate_;
116
117 private:
118 virtual void SetUp() OVERRIDE { 94 virtual void SetUp() OVERRIDE {
119 ChromeRenderViewHostTestHarness::SetUp(); 95 ChromeRenderViewHostTestHarness::SetUp();
120 autofill_manager_.reset( 96 autofill_manager_.reset(
121 new MockAutofillManager(web_contents(), &manager_delegate_)); 97 new MockAutofillManager(web_contents(), &manager_delegate_));
122 external_delegate_.reset( 98 external_delegate_.reset(
123 new testing::NiceMock<MockAutofillExternalDelegate>( 99 new testing::NiceMock<MockAutofillExternalDelegate>(
124 web_contents(), 100 web_contents(),
125 autofill_manager_.get())); 101 autofill_manager_.get()));
126 } 102 }
127 103
128 virtual void TearDown() OVERRIDE { 104 virtual void TearDown() OVERRIDE {
129 // Order of destruction is important as AutofillManager relies on 105 // Order of destruction is important as AutofillManager relies on
130 // PersonalDataManager to be around when it gets destroyed. Also, a real 106 // PersonalDataManager to be around when it gets destroyed. Also, a real
131 // AutofillManager is tied to the lifetime of the WebContents, so it must 107 // AutofillManager is tied to the lifetime of the WebContents, so it must
132 // be destroyed at the destruction of the WebContents. 108 // be destroyed at the destruction of the WebContents.
133 autofill_manager_.reset(); 109 autofill_manager_.reset();
134 external_delegate_.reset(); 110 external_delegate_.reset();
135 ChromeRenderViewHostTestHarness::TearDown(); 111 ChromeRenderViewHostTestHarness::TearDown();
136 } 112 }
137 113
138 content::TestBrowserThread ui_thread_; 114 // Issue an OnQuery call with the given |query_id|.
115 void IssueOnQuery(int query_id) {
116 const FormData form;
117 FormFieldData field;
118 field.is_focusable = true;
119 field.should_autocomplete = true;
120 const gfx::RectF element_bounds;
139 121
140 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest); 122 external_delegate_->OnQuery(query_id, form, field, element_bounds, false);
123 }
124
125 MockAutofillManagerDelegate manager_delegate_;
126 scoped_ptr<MockAutofillManager> autofill_manager_;
127 scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> >
128 external_delegate_;
141 }; 129 };
142 130
143 // Test that our external delegate called the virtual methods at the right time. 131 // Test that our external delegate called the virtual methods at the right time.
144 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { 132 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) {
145 IssueOnQuery(kQueryId); 133 IssueOnQuery(kQueryId);
146 134
147 // The enums must be cast to ints to prevent compile errors on linux_rel. 135 // The enums must be cast to ints to prevent compile errors on linux_rel.
148 EXPECT_CALL(manager_delegate_, 136 EXPECT_CALL(manager_delegate_,
149 ShowAutofillPopup( 137 ShowAutofillPopup(
150 _, _, _, _, 138 _, _, _, _,
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 323 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
336 324
337 external_delegate_->OnSuggestionsReturned(kQueryId, 325 external_delegate_->OnSuggestionsReturned(kQueryId,
338 autofill_items, 326 autofill_items,
339 autofill_items, 327 autofill_items,
340 autofill_items, 328 autofill_items,
341 autofill_ids); 329 autofill_ids);
342 } 330 }
343 331
344 } // namespace autofill 332 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698