| 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/prefs/testing_pref_service.h" | 8 #include "base/prefs/testing_pref_service.h" |
| 9 #include "base/string16.h" | 9 #include "base/string16.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 208 |
| 209 class MockAutofillExternalDelegate : public AutofillExternalDelegate { | 209 class MockAutofillExternalDelegate : public AutofillExternalDelegate { |
| 210 public: | 210 public: |
| 211 explicit MockAutofillExternalDelegate(content::WebContents* web_contents) | 211 explicit MockAutofillExternalDelegate(content::WebContents* web_contents) |
| 212 : AutofillExternalDelegate( | 212 : AutofillExternalDelegate( |
| 213 web_contents, AutofillManager::FromWebContents(web_contents)) {} | 213 web_contents, AutofillManager::FromWebContents(web_contents)) {} |
| 214 virtual ~MockAutofillExternalDelegate() {} | 214 virtual ~MockAutofillExternalDelegate() {} |
| 215 | 215 |
| 216 MOCK_METHOD5(OnSuggestionsReturned, | 216 MOCK_METHOD5(OnSuggestionsReturned, |
| 217 void(int query_id, | 217 void(int query_id, |
| 218 const std::vector<string16>& autofill_values, | 218 const std::vector<base::string16>& autofill_values, |
| 219 const std::vector<string16>& autofill_labels, | 219 const std::vector<base::string16>& autofill_labels, |
| 220 const std::vector<string16>& autofill_icons, | 220 const std::vector<base::string16>& autofill_icons, |
| 221 const std::vector<int>& autofill_unique_ids)); | 221 const std::vector<int>& autofill_unique_ids)); |
| 222 | 222 |
| 223 private: | 223 private: |
| 224 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | 224 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 class AutocompleteHistoryManagerStubSend : public AutocompleteHistoryManager { | 227 class AutocompleteHistoryManagerStubSend : public AutocompleteHistoryManager { |
| 228 public: | 228 public: |
| 229 explicit AutocompleteHistoryManagerStubSend(WebContents* web_contents) | 229 explicit AutocompleteHistoryManagerStubSend(WebContents* web_contents) |
| 230 : AutocompleteHistoryManager(web_contents) {} | 230 : AutocompleteHistoryManager(web_contents) {} |
| 231 | 231 |
| 232 // Increase visibility for testing. | 232 // Increase visibility for testing. |
| 233 void SendSuggestions(const std::vector<string16>* suggestions) { | 233 void SendSuggestions(const std::vector<base::string16>* suggestions) { |
| 234 AutocompleteHistoryManager::SendSuggestions(suggestions); | 234 AutocompleteHistoryManager::SendSuggestions(suggestions); |
| 235 } | 235 } |
| 236 | 236 |
| 237 // Intentionally swallow the message. | 237 // Intentionally swallow the message. |
| 238 virtual bool Send(IPC::Message* message) OVERRIDE { | 238 virtual bool Send(IPC::Message* message) OVERRIDE { |
| 239 delete message; | 239 delete message; |
| 240 return true; | 240 return true; |
| 241 } | 241 } |
| 242 }; | 242 }; |
| 243 | 243 |
| 244 } // namespace | 244 } // namespace |
| 245 | 245 |
| 246 // Make sure our external delegate is called at the right time. | 246 // Make sure our external delegate is called at the right time. |
| 247 TEST_F(AutocompleteHistoryManagerTest, ExternalDelegate) { | 247 TEST_F(AutocompleteHistoryManagerTest, ExternalDelegate) { |
| 248 // Local version with a stubbed out Send() | 248 // Local version with a stubbed out Send() |
| 249 AutocompleteHistoryManagerStubSend autocomplete_history_manager( | 249 AutocompleteHistoryManagerStubSend autocomplete_history_manager( |
| 250 web_contents()); | 250 web_contents()); |
| 251 | 251 |
| 252 AutofillManager::CreateForWebContentsAndDelegate( | 252 AutofillManager::CreateForWebContentsAndDelegate( |
| 253 web_contents(), &manager_delegate, "en-US"); | 253 web_contents(), &manager_delegate, "en-US"); |
| 254 | 254 |
| 255 MockAutofillExternalDelegate external_delegate(web_contents()); | 255 MockAutofillExternalDelegate external_delegate(web_contents()); |
| 256 autocomplete_history_manager.SetExternalDelegate(&external_delegate); | 256 autocomplete_history_manager.SetExternalDelegate(&external_delegate); |
| 257 | 257 |
| 258 // Should trigger a call to OnSuggestionsReturned, verified by the mock. | 258 // Should trigger a call to OnSuggestionsReturned, verified by the mock. |
| 259 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); | 259 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); |
| 260 autocomplete_history_manager.SendSuggestions(NULL); | 260 autocomplete_history_manager.SendSuggestions(NULL); |
| 261 } | 261 } |
| OLD | NEW |