| 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 18 matching lines...) Expand all Loading... |
| 29 using testing::_; | 29 using testing::_; |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 class MockWebDataService : public WebDataService { | 33 class MockWebDataService : public WebDataService { |
| 34 public: | 34 public: |
| 35 MockWebDataService() { | 35 MockWebDataService() { |
| 36 current_mock_web_data_service_ = this; | 36 current_mock_web_data_service_ = this; |
| 37 } | 37 } |
| 38 | 38 |
| 39 static scoped_refptr<RefcountedProfileKeyedService> Build(Profile* profile) { | 39 MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&)); |
| 40 |
| 41 static scoped_refptr<MockWebDataService> GetCurrent() { |
| 42 if (!current_mock_web_data_service_) { |
| 43 return new MockWebDataService(); |
| 44 } |
| 40 return current_mock_web_data_service_; | 45 return current_mock_web_data_service_; |
| 41 } | 46 } |
| 42 | 47 |
| 43 virtual void ShutdownOnUIThread() OVERRIDE {} | |
| 44 | |
| 45 MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&)); | |
| 46 | |
| 47 protected: | 48 protected: |
| 48 virtual ~MockWebDataService() {} | 49 virtual ~MockWebDataService() {} |
| 49 | 50 |
| 50 private: | 51 private: |
| 51 // Keep track of the most recently created instance, so that it can be | 52 // Keep track of the most recently created instance, so that it can be |
| 52 // associated with the current profile when Build() is called. | 53 // associated with the current profile when Build() is called. |
| 53 static MockWebDataService* current_mock_web_data_service_; | 54 static MockWebDataService* current_mock_web_data_service_; |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 MockWebDataService* MockWebDataService::current_mock_web_data_service_ = NULL; | 57 MockWebDataService* MockWebDataService::current_mock_web_data_service_ = NULL; |
| 57 | 58 |
| 59 class MockWebDataServiceWrapper : public WebDataServiceWrapper { |
| 60 public: |
| 61 static ProfileKeyedService* Build(Profile* profile) { |
| 62 return new MockWebDataServiceWrapper(); |
| 63 } |
| 64 |
| 65 MockWebDataServiceWrapper() { |
| 66 } |
| 67 |
| 68 void Shutdown() OVERRIDE {} |
| 69 |
| 70 ~MockWebDataServiceWrapper() {} |
| 71 |
| 72 scoped_refptr<WebDataService> GetWebData() OVERRIDE { |
| 73 return MockWebDataService::GetCurrent(); |
| 74 } |
| 75 |
| 76 private: |
| 77 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapper); |
| 78 }; |
| 79 |
| 58 class MockAutofillManagerDelegate | 80 class MockAutofillManagerDelegate |
| 59 : public autofill::TestAutofillManagerDelegate { | 81 : public autofill::TestAutofillManagerDelegate { |
| 60 public: | 82 public: |
| 61 MockAutofillManagerDelegate() {} | 83 MockAutofillManagerDelegate() {} |
| 62 virtual ~MockAutofillManagerDelegate() {} | 84 virtual ~MockAutofillManagerDelegate() {} |
| 63 virtual PrefService* GetPrefs() OVERRIDE { return &prefs_; } | 85 virtual PrefService* GetPrefs() OVERRIDE { return &prefs_; } |
| 64 | 86 |
| 65 private: | 87 private: |
| 66 TestingPrefServiceSimple prefs_; | 88 TestingPrefServiceSimple prefs_; |
| 67 | 89 |
| 68 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); | 90 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); |
| 69 }; | 91 }; |
| 70 | 92 |
| 71 } // namespace | 93 } // namespace |
| 72 | 94 |
| 73 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { | 95 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { |
| 74 protected: | 96 protected: |
| 75 AutocompleteHistoryManagerTest() | 97 AutocompleteHistoryManagerTest() |
| 76 : db_thread_(BrowserThread::DB) { | 98 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 99 db_thread_(BrowserThread::DB) { |
| 77 } | 100 } |
| 78 | 101 |
| 79 virtual void SetUp() OVERRIDE { | 102 virtual void SetUp() OVERRIDE { |
| 80 ChromeRenderViewHostTestHarness::SetUp(); | 103 ChromeRenderViewHostTestHarness::SetUp(); |
| 81 web_data_service_ = new MockWebDataService(); | 104 web_data_service_ = new MockWebDataService(); |
| 82 WebDataServiceFactory::GetInstance()->SetTestingFactory( | 105 WebDataServiceFactory::GetInstance()->SetTestingFactory( |
| 83 profile(), MockWebDataService::Build); | 106 profile(), MockWebDataServiceWrapper::Build); |
| 84 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents())); | 107 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents())); |
| 85 } | 108 } |
| 86 | 109 |
| 87 virtual void TearDown() OVERRIDE { | 110 virtual void TearDown() OVERRIDE { |
| 88 autocomplete_manager_.reset(); | 111 autocomplete_manager_.reset(); |
| 89 web_data_service_ = NULL; | 112 web_data_service_ = NULL; |
| 90 ChromeRenderViewHostTestHarness::TearDown(); | 113 ChromeRenderViewHostTestHarness::TearDown(); |
| 114 message_loop_.RunUntilIdle(); |
| 115 |
| 91 } | 116 } |
| 92 | 117 |
| 118 content::TestBrowserThread ui_thread_; |
| 93 content::TestBrowserThread db_thread_; | 119 content::TestBrowserThread db_thread_; |
| 94 scoped_refptr<MockWebDataService> web_data_service_; | 120 scoped_refptr<MockWebDataService> web_data_service_; |
| 95 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; | 121 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; |
| 96 MockAutofillManagerDelegate manager_delegate; | 122 MockAutofillManagerDelegate manager_delegate; |
| 97 }; | 123 }; |
| 98 | 124 |
| 99 // Tests that credit card numbers are not sent to the WebDatabase to be saved. | 125 // Tests that credit card numbers are not sent to the WebDatabase to be saved. |
| 100 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { | 126 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { |
| 101 FormData form; | 127 FormData form; |
| 102 form.name = ASCIIToUTF16("MyForm"); | 128 form.name = ASCIIToUTF16("MyForm"); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 AutofillManager::CreateForWebContentsAndDelegate( | 255 AutofillManager::CreateForWebContentsAndDelegate( |
| 230 web_contents(), &manager_delegate); | 256 web_contents(), &manager_delegate); |
| 231 | 257 |
| 232 MockAutofillExternalDelegate external_delegate(web_contents()); | 258 MockAutofillExternalDelegate external_delegate(web_contents()); |
| 233 autocomplete_history_manager.SetExternalDelegate(&external_delegate); | 259 autocomplete_history_manager.SetExternalDelegate(&external_delegate); |
| 234 | 260 |
| 235 // Should trigger a call to OnSuggestionsReturned, verified by the mock. | 261 // Should trigger a call to OnSuggestionsReturned, verified by the mock. |
| 236 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); | 262 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); |
| 237 autocomplete_history_manager.SendSuggestions(NULL); | 263 autocomplete_history_manager.SendSuggestions(NULL); |
| 238 } | 264 } |
| OLD | NEW |