Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <algorithm> | |
| 6 #include <vector> | |
| 7 | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 10 #include "components/autofill/content/browser/autofill_driver_impl.h" | |
| 11 #include "components/autofill/core/browser/autofill_external_delegate.h" | |
| 12 #include "components/autofill/core/browser/autofill_manager.h" | |
| 13 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" | |
| 14 #include "content/public/browser/navigation_details.h" | |
| 15 #include "content/public/browser/web_contents.h" | |
| 16 #include "content/public/common/frame_navigate_params.h" | |
| 17 #include "testing/gmock/include/gmock/gmock.h" | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | |
| 19 | |
| 20 namespace autofill { | |
| 21 | |
| 22 class MockAutofillManager : public AutofillManager { | |
| 23 public: | |
| 24 MockAutofillManager(AutofillDriver* driver, | |
| 25 AutofillManagerDelegate* delegate, | |
| 26 const std::string& app_locale, | |
| 27 AutofillDownloadManagerState enable_download_manager) | |
| 28 : AutofillManager(driver, delegate, app_locale, enable_download_manager) { | |
| 29 } | |
| 30 virtual ~MockAutofillManager() {} | |
| 31 | |
| 32 MOCK_METHOD0(Reset, void()); | |
| 33 }; | |
| 34 | |
| 35 class TestAutofillDriverImpl : public AutofillDriverImpl { | |
| 36 public: | |
| 37 TestAutofillDriverImpl(content::WebContents* contents, | |
| 38 AutofillManagerDelegate* delegate, | |
| 39 const std::string& app_locale, | |
| 40 AutofillManager::AutofillDownloadManagerState enable_download_manager) | |
|
Ilya Sherman
2013/06/21 20:19:24
nit: This should be indented to be aligned with al
blundell
2013/06/22 06:29:06
Done.
| |
| 41 : AutofillDriverImpl( | |
|
Ilya Sherman
2013/06/21 20:19:24
nit: This line should be indented two more spaces.
blundell
2013/06/22 06:29:06
Done.
| |
| 42 contents, delegate, app_locale, enable_download_manager, true) { | |
| 43 MockAutofillManager* autofill_manager = new MockAutofillManager( | |
|
Ilya Sherman
2013/06/21 20:19:24
nit: Please declare this as a scoped_ptr. Basical
blundell
2013/06/22 06:29:06
Done.
| |
| 44 this, delegate, app_locale, enable_download_manager); | |
| 45 SetAutofillManager(scoped_ptr<AutofillManager>(autofill_manager)); | |
| 46 } | |
| 47 virtual ~TestAutofillDriverImpl() {} | |
| 48 | |
| 49 using AutofillDriverImpl::DidNavigateMainFrame; | |
| 50 }; | |
| 51 | |
| 52 class AutofillDriverImplTest : public ChromeRenderViewHostTestHarness { | |
| 53 public: | |
| 54 virtual void SetUp() OVERRIDE { | |
| 55 ChromeRenderViewHostTestHarness::SetUp(); | |
| 56 | |
| 57 test_manager_delegate_.reset(new TestAutofillManagerDelegate()); | |
| 58 std::string app_locale = "en-US"; | |
| 59 AutofillManager::AutofillDownloadManagerState download_state = | |
| 60 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER; | |
| 61 driver_.reset(new TestAutofillDriverImpl(web_contents(), | |
| 62 test_manager_delegate_.get(), | |
| 63 app_locale, | |
| 64 download_state)); | |
| 65 autofill_manager_ = | |
| 66 static_cast<MockAutofillManager*>(driver_->autofill_manager()); | |
| 67 } | |
| 68 | |
| 69 virtual void TearDown() OVERRIDE { | |
| 70 // Reset the driver now to cause all pref observers to be removed and avoid | |
| 71 // crashes that otherwise occur in the destructor. | |
| 72 driver_.reset(); | |
| 73 ChromeRenderViewHostTestHarness::TearDown(); | |
| 74 } | |
| 75 | |
| 76 protected: | |
| 77 scoped_ptr<TestAutofillManagerDelegate> test_manager_delegate_; | |
| 78 scoped_ptr<TestAutofillDriverImpl> driver_; | |
| 79 // Owned by |driver_|. | |
| 80 MockAutofillManager* autofill_manager_; | |
|
Ilya Sherman
2013/06/21 20:19:24
nit: Why store this as a variable, rather than jus
blundell
2013/06/22 06:29:06
Done. Had to create a TestAutofillDriverImpl metho
| |
| 81 }; | |
| 82 | |
| 83 TEST_F(AutofillDriverImplTest, NavigatedToDifferentPage) { | |
| 84 EXPECT_CALL(*autofill_manager_, Reset()); | |
| 85 content::LoadCommittedDetails details = content::LoadCommittedDetails(); | |
| 86 details.is_main_frame = true; | |
| 87 details.is_in_page = false; | |
| 88 DCHECK(details.is_navigation_to_different_page()); | |
|
Ilya Sherman
2013/06/21 20:19:24
nit: Please use ASSERT_TRUE rather than DCHECK, as
blundell
2013/06/22 06:29:06
Done.
| |
| 89 content::FrameNavigateParams params = content::FrameNavigateParams(); | |
| 90 driver_->DidNavigateMainFrame(details, params); | |
| 91 } | |
| 92 | |
| 93 TEST_F(AutofillDriverImplTest, NavigatedWithinSamePage) { | |
| 94 EXPECT_CALL(*autofill_manager_, Reset()).Times(0); | |
| 95 content::LoadCommittedDetails details = content::LoadCommittedDetails(); | |
| 96 details.is_main_frame = false; | |
| 97 DCHECK(!details.is_navigation_to_different_page()); | |
|
Ilya Sherman
2013/06/21 20:19:24
nit: Please use ASSERT_TRUE rather than DCHECK, as
blundell
2013/06/22 06:29:06
Done.
| |
| 98 content::FrameNavigateParams params = content::FrameNavigateParams(); | |
| 99 driver_->DidNavigateMainFrame(details, params); | |
| 100 } | |
| 101 | |
| 102 } // namespace autofill | |
| OLD | NEW |