Chromium Code Reviews| 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 | |
|
dhollowa
2013/03/18 18:50:59
nit: remove empty line.
Cait (Slow)
2013/03/18 19:10:35
Done.
| |
| 76 }; | |
|
dhollowa
2013/03/18 18:50:59
DISALLOW_COPY_AND_ASSIGN
Cait (Slow)
2013/03/18 19:10:35
Done.
| |
| 77 | |
| 58 class MockAutofillManagerDelegate | 78 class MockAutofillManagerDelegate |
| 59 : public autofill::TestAutofillManagerDelegate { | 79 : public autofill::TestAutofillManagerDelegate { |
| 60 public: | 80 public: |
| 61 MockAutofillManagerDelegate() {} | 81 MockAutofillManagerDelegate() {} |
| 62 virtual ~MockAutofillManagerDelegate() {} | 82 virtual ~MockAutofillManagerDelegate() {} |
| 63 virtual PrefService* GetPrefs() OVERRIDE { return &prefs_; } | 83 virtual PrefService* GetPrefs() OVERRIDE { return &prefs_; } |
| 64 | 84 |
| 65 private: | 85 private: |
| 66 TestingPrefServiceSimple prefs_; | 86 TestingPrefServiceSimple prefs_; |
| 67 | 87 |
| 68 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); | 88 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); |
| 69 }; | 89 }; |
| 70 | 90 |
| 71 } // namespace | 91 } // namespace |
| 72 | 92 |
| 73 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { | 93 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { |
| 74 protected: | 94 protected: |
| 75 AutocompleteHistoryManagerTest() | 95 AutocompleteHistoryManagerTest() |
| 76 : db_thread_(BrowserThread::DB) { | 96 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 97 db_thread_(BrowserThread::DB) { | |
| 77 } | 98 } |
| 78 | 99 |
| 79 virtual void SetUp() OVERRIDE { | 100 virtual void SetUp() OVERRIDE { |
| 80 ChromeRenderViewHostTestHarness::SetUp(); | 101 ChromeRenderViewHostTestHarness::SetUp(); |
| 81 web_data_service_ = new MockWebDataService(); | 102 web_data_service_ = new MockWebDataService(); |
| 82 WebDataServiceFactory::GetInstance()->SetTestingFactory( | 103 WebDataServiceFactory::GetInstance()->SetTestingFactory( |
| 83 profile(), MockWebDataService::Build); | 104 profile(), MockWebDataServiceWrapper::Build); |
| 84 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents())); | 105 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents())); |
| 85 } | 106 } |
| 86 | 107 |
| 87 virtual void TearDown() OVERRIDE { | 108 virtual void TearDown() OVERRIDE { |
| 88 autocomplete_manager_.reset(); | 109 autocomplete_manager_.reset(); |
| 89 web_data_service_ = NULL; | 110 web_data_service_ = NULL; |
| 90 ChromeRenderViewHostTestHarness::TearDown(); | 111 ChromeRenderViewHostTestHarness::TearDown(); |
| 112 message_loop_.RunUntilIdle(); | |
| 113 | |
| 91 } | 114 } |
| 92 | 115 |
| 116 content::TestBrowserThread ui_thread_; | |
| 93 content::TestBrowserThread db_thread_; | 117 content::TestBrowserThread db_thread_; |
| 94 scoped_refptr<MockWebDataService> web_data_service_; | 118 scoped_refptr<MockWebDataService> web_data_service_; |
| 95 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; | 119 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; |
| 96 MockAutofillManagerDelegate manager_delegate; | 120 MockAutofillManagerDelegate manager_delegate; |
| 97 }; | 121 }; |
| 98 | 122 |
| 99 // Tests that credit card numbers are not sent to the WebDatabase to be saved. | 123 // Tests that credit card numbers are not sent to the WebDatabase to be saved. |
| 100 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { | 124 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { |
| 101 FormData form; | 125 FormData form; |
| 102 form.name = ASCIIToUTF16("MyForm"); | 126 form.name = ASCIIToUTF16("MyForm"); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 AutofillManager::CreateForWebContentsAndDelegate( | 253 AutofillManager::CreateForWebContentsAndDelegate( |
| 230 web_contents(), &manager_delegate); | 254 web_contents(), &manager_delegate); |
| 231 | 255 |
| 232 MockAutofillExternalDelegate external_delegate(web_contents()); | 256 MockAutofillExternalDelegate external_delegate(web_contents()); |
| 233 autocomplete_history_manager.SetExternalDelegate(&external_delegate); | 257 autocomplete_history_manager.SetExternalDelegate(&external_delegate); |
| 234 | 258 |
| 235 // Should trigger a call to OnSuggestionsReturned, verified by the mock. | 259 // Should trigger a call to OnSuggestionsReturned, verified by the mock. |
| 236 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); | 260 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); |
| 237 autocomplete_history_manager.SendSuggestions(NULL); | 261 autocomplete_history_manager.SendSuggestions(NULL); |
| 238 } | 262 } |
| OLD | NEW |