| OLD | NEW |
| 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/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/autocomplete_history_manager.h" | 10 #include "chrome/browser/autocomplete_history_manager.h" |
| 11 #include "chrome/browser/autofill/autofill_external_delegate.h" | 11 #include "chrome/browser/autofill/test_autofill_external_delegate.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 13 #include "chrome/browser/webdata/web_data_service.h" | 13 #include "chrome/browser/webdata/web_data_service.h" |
| 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 15 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/browser/tab_contents/test_tab_contents.h" | 17 #include "content/browser/tab_contents/test_tab_contents.h" |
| 18 #include "content/test/test_browser_thread.h" | 18 #include "content/test/test_browser_thread.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 search_field.value = ASCIIToUTF16("my favorite query"); | 132 search_field.value = ASCIIToUTF16("my favorite query"); |
| 133 search_field.form_control_type = ASCIIToUTF16("search"); | 133 search_field.form_control_type = ASCIIToUTF16("search"); |
| 134 form.fields.push_back(search_field); | 134 form.fields.push_back(search_field); |
| 135 | 135 |
| 136 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); | 136 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); |
| 137 autocomplete_manager_->OnFormSubmitted(form); | 137 autocomplete_manager_->OnFormSubmitted(form); |
| 138 } | 138 } |
| 139 | 139 |
| 140 namespace { | 140 namespace { |
| 141 | 141 |
| 142 class MockAutofillExternalDelegate : public AutofillExternalDelegate { | 142 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| 143 public: | 143 public: |
| 144 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper) | 144 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper) |
| 145 : AutofillExternalDelegate(wrapper, NULL) {} | 145 : TestAutofillExternalDelegate(wrapper, NULL) {} |
| 146 virtual ~MockAutofillExternalDelegate() {} | 146 virtual ~MockAutofillExternalDelegate() {} |
| 147 | 147 |
| 148 virtual void OnQuery(int query_id, | 148 virtual void ApplyAutofillSuggestions( |
| 149 const webkit::forms::FormData& form, | 149 const std::vector<string16>& autofill_values, |
| 150 const webkit::forms::FormField& field, | 150 const std::vector<string16>& autofill_labels, |
| 151 const gfx::Rect& bounds, | 151 const std::vector<string16>& autofill_icons, |
| 152 bool display_warning) OVERRIDE {} | 152 const std::vector<int>& autofill_unique_ids, |
| 153 int separator_index) OVERRIDE {}; |
| 153 | 154 |
| 154 MOCK_METHOD5(OnSuggestionsReturned, | 155 MOCK_METHOD5(OnSuggestionsReturned, |
| 155 void(int query_id, | 156 void(int query_id, |
| 156 const std::vector<string16>& autofill_values, | 157 const std::vector<string16>& autofill_values, |
| 157 const std::vector<string16>& autofill_labels, | 158 const std::vector<string16>& autofill_labels, |
| 158 const std::vector<string16>& autofill_icons, | 159 const std::vector<string16>& autofill_icons, |
| 159 const std::vector<int>& autofill_unique_ids)); | 160 const std::vector<int>& autofill_unique_ids)); |
| 160 | 161 |
| 161 virtual void HideAutofillPopup() OVERRIDE {} | |
| 162 | |
| 163 | |
| 164 virtual void ApplyAutofillSuggestions( | |
| 165 const std::vector<string16>& autofill_values, | |
| 166 const std::vector<string16>& autofill_labels, | |
| 167 const std::vector<string16>& autofill_icons, | |
| 168 const std::vector<int>& autofill_unique_ids, | |
| 169 int separator_index) OVERRIDE {} | |
| 170 | |
| 171 virtual void OnQueryPlatformSpecific( | |
| 172 int query_id, | |
| 173 const webkit::forms::FormData& form, | |
| 174 const webkit::forms::FormField& field, | |
| 175 const gfx::Rect& bounds) OVERRIDE {} | |
| 176 | |
| 177 private: | 162 private: |
| 178 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | 163 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
| 179 }; | 164 }; |
| 180 | 165 |
| 181 class AutocompleteHistoryManagerStubSend : public AutocompleteHistoryManager { | 166 class AutocompleteHistoryManagerStubSend : public AutocompleteHistoryManager { |
| 182 public: | 167 public: |
| 183 explicit AutocompleteHistoryManagerStubSend(WebContents* web_contents, | 168 explicit AutocompleteHistoryManagerStubSend(WebContents* web_contents, |
| 184 Profile* profile, | 169 Profile* profile, |
| 185 WebDataService* wds) | 170 WebDataService* wds) |
| 186 : AutocompleteHistoryManager(web_contents, profile, wds) {} | 171 : AutocompleteHistoryManager(web_contents, profile, wds) {} |
| (...skipping 12 matching lines...) Expand all Loading... |
| 199 &profile_, web_data_service_); | 184 &profile_, web_data_service_); |
| 200 | 185 |
| 201 MockAutofillExternalDelegate external_delegate( | 186 MockAutofillExternalDelegate external_delegate( |
| 202 TabContentsWrapper::GetCurrentWrapperForContents(contents())); | 187 TabContentsWrapper::GetCurrentWrapperForContents(contents())); |
| 203 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); | 188 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); |
| 204 autocomplete_history_manager.SetExternalDelegate(&external_delegate); | 189 autocomplete_history_manager.SetExternalDelegate(&external_delegate); |
| 205 | 190 |
| 206 // Should trigger a call to OnSuggestionsReturned, verified by the mock. | 191 // Should trigger a call to OnSuggestionsReturned, verified by the mock. |
| 207 autocomplete_history_manager.SendSuggestions(NULL); | 192 autocomplete_history_manager.SendSuggestions(NULL); |
| 208 } | 193 } |
| OLD | NEW |