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

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

Issue 11185011: Remove TabContents from autofill unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: de(r)ps 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 | 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/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"
14 #include "chrome/common/form_data.h" 13 #include "chrome/common/form_data.h"
15 #include "chrome/common/form_field_data.h" 14 #include "chrome/common/form_field_data.h"
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "content/public/test/test_browser_thread.h" 17 #include "content/public/test/test_browser_thread.h"
18 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
21 #include "ui/gfx/rect.h" 21 #include "ui/gfx/rect.h"
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 using testing::_; 24 using testing::_;
25 using WebKit::WebAutofillClient; 25 using WebKit::WebAutofillClient;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 const FormData& form, 73 const FormData& form,
74 const FormFieldData& field, 74 const FormFieldData& field,
75 int unique_id)); 75 int unique_id));
76 76
77 protected: 77 protected:
78 virtual ~MockAutofillManager() {} 78 virtual ~MockAutofillManager() {}
79 }; 79 };
80 80
81 } // namespace 81 } // namespace
82 82
83 class AutofillExternalDelegateUnitTest : public TabContentsTestHarness { 83 class AutofillExternalDelegateUnitTest
84 : public ChromeRenderViewHostTestHarness {
84 public: 85 public:
85 AutofillExternalDelegateUnitTest() 86 AutofillExternalDelegateUnitTest()
86 : ui_thread_(BrowserThread::UI, &message_loop_) {} 87 : ui_thread_(BrowserThread::UI, &message_loop_) {}
87 virtual ~AutofillExternalDelegateUnitTest() {} 88 virtual ~AutofillExternalDelegateUnitTest() {}
88 89
89 protected: 90 protected:
90 // Set up the expectation for a platform specific OnQuery call and then 91 // Set up the expectation for a platform specific OnQuery call and then
91 // execute it with the given QueryId. 92 // execute it with the given QueryId.
92 void IssueOnQuery(int query_id) { 93 void IssueOnQuery(int query_id) {
93 const FormData form; 94 const FormData form;
94 FormFieldData field; 95 FormFieldData field;
95 field.is_focusable = true; 96 field.is_focusable = true;
96 field.should_autocomplete = true; 97 field.should_autocomplete = true;
97 const gfx::Rect bounds; 98 const gfx::Rect bounds;
98 99
99 EXPECT_CALL(*external_delegate_, 100 EXPECT_CALL(*external_delegate_,
100 OnQueryPlatformSpecific(query_id, form, field, bounds)); 101 OnQueryPlatformSpecific(query_id, form, field, bounds));
101 102
102 // This should call OnQueryPlatform specific. 103 // This should call OnQueryPlatform specific.
103 external_delegate_->OnQuery(query_id, form, field, bounds, false); 104 external_delegate_->OnQuery(query_id, form, field, bounds, false);
104 } 105 }
105 106
106 scoped_refptr<MockAutofillManager> autofill_manager_; 107 scoped_refptr<MockAutofillManager> autofill_manager_;
107 scoped_ptr<MockAutofillExternalDelegate> external_delegate_; 108 scoped_ptr<MockAutofillExternalDelegate> external_delegate_;
108 109
109 private: 110 private:
110 virtual void SetUp() OVERRIDE { 111 virtual void SetUp() OVERRIDE {
111 TabContentsTestHarness::SetUp(); 112 ChromeRenderViewHostTestHarness::SetUp();
112 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); 113 TabAutofillManagerDelegate::CreateForWebContents(web_contents());
113 autofill_manager_ = new MockAutofillManager( 114 autofill_manager_ = new MockAutofillManager(
114 web_contents(), 115 web_contents(),
115 TabAutofillManagerDelegate::FromWebContents(web_contents())); 116 TabAutofillManagerDelegate::FromWebContents(web_contents()));
116 external_delegate_.reset(new MockAutofillExternalDelegate( 117 external_delegate_.reset(new MockAutofillExternalDelegate(
117 web_contents(), 118 web_contents(),
118 autofill_manager_)); 119 autofill_manager_));
119 } 120 }
120 121
121 virtual void TearDown() OVERRIDE { 122 virtual void TearDown() OVERRIDE {
122 // Order of destruction is important as AutofillManager relies on 123 // Order of destruction is important as AutofillManager relies on
123 // PersonalDataManager to be around when it gets destroyed. Also, a real 124 // PersonalDataManager to be around when it gets destroyed. Also, a real
124 // AutofillManager is tied to the lifetime of the WebContents, so it must 125 // AutofillManager is tied to the lifetime of the WebContents, so it must
125 // be destroyed at the destruction of the WebContents. 126 // be destroyed at the destruction of the WebContents.
126 autofill_manager_ = NULL; 127 autofill_manager_ = NULL;
127 TabContentsTestHarness::TearDown(); 128 ChromeRenderViewHostTestHarness::TearDown();
128 } 129 }
129 130
130 content::TestBrowserThread ui_thread_; 131 content::TestBrowserThread ui_thread_;
131 132
132 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest); 133 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest);
133 }; 134 };
134 135
135 // 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.
136 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { 137 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) {
137 IssueOnQuery(kQueryId); 138 IssueOnQuery(kQueryId);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 external_delegate_->SelectAutofillSuggestionAtIndex(1); 253 external_delegate_->SelectAutofillSuggestionAtIndex(1);
253 } 254 }
254 255
255 // Test that the popup is hidden once we are done editing the autofill field. 256 // Test that the popup is hidden once we are done editing the autofill field.
256 TEST_F(AutofillExternalDelegateUnitTest, 257 TEST_F(AutofillExternalDelegateUnitTest,
257 ExternalDelegateHidePopupAfterEditing) { 258 ExternalDelegateHidePopupAfterEditing) {
258 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); 259 EXPECT_CALL(*external_delegate_, HideAutofillPopup());
259 260
260 external_delegate_->DidEndTextFieldEditing(); 261 external_delegate_->DidEndTextFieldEditing();
261 } 262 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_external_delegate.cc ('k') | chrome/browser/autofill/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698