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 "chrome/browser/autofill/autofill_external_delegate_unittest.h" | |
|
Ilya Sherman
2012/02/04 04:10:52
Hmm, I don't see this file in the CL -- did you me
csharp
2012/02/07 22:30:58
Ya, I missed including this file. I changed it up
| |
| 6 | |
| 5 #include <vector> | 7 #include <vector> |
| 6 | 8 |
| 7 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 8 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 9 #include "base/string16.h" | 11 #include "base/string16.h" |
| 10 #include "chrome/browser/autofill/autofill_external_delegate.h" | |
| 11 #include "chrome/browser/autofill/autofill_manager.h" | 12 #include "chrome/browser/autofill/autofill_manager.h" |
| 12 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 14 #include "content/test/test_browser_thread.h" | 15 #include "content/test/test_browser_thread.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 18 #include "webkit/forms/form_data.h" | 18 #include "webkit/forms/form_data.h" |
| 19 #include "webkit/forms/form_field.h" | 19 #include "webkit/forms/form_field.h" |
| 20 | 20 |
| 21 using content::BrowserThread; | 21 using content::BrowserThread; |
| 22 using testing::_; | 22 using testing::_; |
| 23 using webkit::forms::FormData; | 23 using webkit::forms::FormData; |
| 24 using webkit::forms::FormField; | 24 using webkit::forms::FormField; |
| 25 | 25 |
| 26 namespace { | 26 class AutofillManagerMock : public AutofillManager { |
|
Ilya Sherman
2012/02/04 04:10:52
nit: Any reason not to move this into an anonymous
Ilya Sherman
2012/02/04 04:10:52
nit: "AutofillManagerMock" -> "MockAutofillManager
csharp
2012/02/07 22:30:58
Done.
csharp
2012/02/07 22:30:58
Nope, moved.
| |
| 27 public: | |
| 28 explicit AutofillManagerMock(TabContentsWrapper* tab_contents) | |
| 29 : AutofillManager(tab_contents) {} | |
| 30 ~AutofillManagerMock() {} | |
| 27 | 31 |
| 28 class MockAutofillExternalDelegate : public AutofillExternalDelegate { | 32 virtual void OnFillAutofillFormData(int query_id, |
| 29 public: | 33 const webkit::forms::FormData& form, |
| 30 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, | 34 const webkit::forms::FormField& field, |
| 31 AutofillManager* autofill_manager) | 35 int unique_id) {} |
| 32 : AutofillExternalDelegate(wrapper, autofill_manager) {} | |
| 33 virtual ~MockAutofillExternalDelegate() {} | |
| 34 | |
| 35 virtual void HideAutofillPopup() OVERRIDE {} | |
| 36 | |
| 37 MOCK_METHOD5(ApplyAutofillSuggestions, void( | |
| 38 const std::vector<string16>& autofill_values, | |
| 39 const std::vector<string16>& autofill_labels, | |
| 40 const std::vector<string16>& autofill_icons, | |
| 41 const std::vector<int>& autofill_unique_ids, | |
| 42 int separator_index)); | |
| 43 | |
| 44 MOCK_METHOD4(OnQueryPlatformSpecific, | |
| 45 void(int query_id, | |
| 46 const webkit::forms::FormData& form, | |
| 47 const webkit::forms::FormField& field, | |
| 48 const gfx::Rect& bounds)); | |
| 49 | |
| 50 private: | |
| 51 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | |
| 52 }; | 36 }; |
| 53 | 37 |
| 54 } // namespace | |
| 55 | |
| 56 class AutofillExternalDelegateTest : public TabContentsWrapperTestHarness { | 38 class AutofillExternalDelegateTest : public TabContentsWrapperTestHarness { |
| 57 public: | 39 public: |
| 58 AutofillExternalDelegateTest() | 40 AutofillExternalDelegateTest() |
| 59 : ui_thread_(BrowserThread::UI, &message_loop_) {} | 41 : ui_thread_(BrowserThread::UI, &message_loop_) {} |
| 60 virtual ~AutofillExternalDelegateTest() {} | 42 virtual ~AutofillExternalDelegateTest() {} |
| 61 | 43 |
| 62 virtual void SetUp() OVERRIDE { | 44 virtual void SetUp() OVERRIDE { |
| 63 TabContentsWrapperTestHarness::SetUp(); | 45 TabContentsWrapperTestHarness::SetUp(); |
| 64 autofill_manager_ = new AutofillManager(contents_wrapper()); | 46 autofill_manager_ = new AutofillManagerMock(contents_wrapper()); |
| 65 } | 47 } |
| 66 | 48 |
| 67 protected: | 49 protected: |
| 68 scoped_refptr<AutofillManager> autofill_manager_; | 50 scoped_refptr<AutofillManagerMock> autofill_manager_; |
| 69 | 51 |
| 70 private: | 52 private: |
| 71 content::TestBrowserThread ui_thread_; | 53 content::TestBrowserThread ui_thread_; |
| 72 | 54 |
| 73 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateTest); | 55 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateTest); |
| 74 }; | 56 }; |
| 75 | 57 |
| 76 // Test that our external delegate called the virtual methods at the right time. | 58 // Test that our external delegate called the virtual methods at the right time. |
| 77 TEST_F(AutofillExternalDelegateTest, TestExternalDelegateVirtualCalls) { | 59 TEST_F(AutofillExternalDelegateTest, TestExternalDelegateVirtualCalls) { |
| 78 MockAutofillExternalDelegate external_delegate(contents_wrapper(), | 60 MockAutofillExternalDelegate external_delegate(contents_wrapper(), |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 96 // This should call ApplyAutofillSuggestions. | 78 // This should call ApplyAutofillSuggestions. |
| 97 std::vector<string16> autofill_item; | 79 std::vector<string16> autofill_item; |
| 98 autofill_item.push_back(string16()); | 80 autofill_item.push_back(string16()); |
| 99 std::vector<int> autofill_ids; | 81 std::vector<int> autofill_ids; |
| 100 autofill_ids.push_back(1); | 82 autofill_ids.push_back(1); |
| 101 external_delegate.OnSuggestionsReturned(kQueryId, | 83 external_delegate.OnSuggestionsReturned(kQueryId, |
| 102 autofill_item, | 84 autofill_item, |
| 103 autofill_item, | 85 autofill_item, |
| 104 autofill_item, | 86 autofill_item, |
| 105 autofill_ids); | 87 autofill_ids); |
| 88 | |
| 89 | |
| 90 EXPECT_CALL(external_delegate, HideAutofillPopupInternal()); | |
|
Ilya Sherman
2012/02/04 04:10:52
nit: It's generally better to test the public inte
csharp
2012/02/07 22:30:58
Nope, fixed.
| |
| 91 | |
| 92 // This should trigger a call to hide the popup since | |
| 93 // we've selected an option. | |
| 94 external_delegate.didAcceptAutofillSuggestions(autofill_item[0], | |
| 95 autofill_ids[0], 0); | |
| 106 } | 96 } |
| OLD | NEW |