Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Unified Diff: components/autofill/content/browser/autofill_driver_impl_unittest.cc

Issue 17450010: Create AutofillDriverImpl unit test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Response to review Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/autofill/content/browser/autofill_driver_impl_unittest.cc
diff --git a/components/autofill/content/browser/autofill_driver_impl_unittest.cc b/components/autofill/content/browser/autofill_driver_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1b736f31f02616b47896607a25299e93997126da
--- /dev/null
+++ b/components/autofill/content/browser/autofill_driver_impl_unittest.cc
@@ -0,0 +1,102 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <algorithm>
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/test/base/chrome_render_view_host_test_harness.h"
+#include "components/autofill/content/browser/autofill_driver_impl.h"
+#include "components/autofill/core/browser/autofill_external_delegate.h"
+#include "components/autofill/core/browser/autofill_manager.h"
+#include "components/autofill/core/browser/test_autofill_manager_delegate.h"
+#include "content/public/browser/navigation_details.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/common/frame_navigate_params.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace autofill {
+
+class MockAutofillManager : public AutofillManager {
+ public:
+ MockAutofillManager(AutofillDriver* driver,
+ AutofillManagerDelegate* delegate,
+ const std::string& app_locale,
+ AutofillDownloadManagerState enable_download_manager)
+ : AutofillManager(driver, delegate, app_locale, enable_download_manager) {
+ }
+ virtual ~MockAutofillManager() {}
+
+ MOCK_METHOD0(Reset, void());
+};
+
+class TestAutofillDriverImpl : public AutofillDriverImpl {
+ public:
+ TestAutofillDriverImpl(content::WebContents* contents,
+ AutofillManagerDelegate* delegate,
+ const std::string& app_locale,
+ 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.
+ : 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.
+ contents, delegate, app_locale, enable_download_manager, true) {
+ 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.
+ this, delegate, app_locale, enable_download_manager);
+ SetAutofillManager(scoped_ptr<AutofillManager>(autofill_manager));
+ }
+ virtual ~TestAutofillDriverImpl() {}
+
+ using AutofillDriverImpl::DidNavigateMainFrame;
+};
+
+class AutofillDriverImplTest : public ChromeRenderViewHostTestHarness {
+ public:
+ virtual void SetUp() OVERRIDE {
+ ChromeRenderViewHostTestHarness::SetUp();
+
+ test_manager_delegate_.reset(new TestAutofillManagerDelegate());
+ std::string app_locale = "en-US";
+ AutofillManager::AutofillDownloadManagerState download_state =
+ AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER;
+ driver_.reset(new TestAutofillDriverImpl(web_contents(),
+ test_manager_delegate_.get(),
+ app_locale,
+ download_state));
+ autofill_manager_ =
+ static_cast<MockAutofillManager*>(driver_->autofill_manager());
+ }
+
+ virtual void TearDown() OVERRIDE {
+ // Reset the driver now to cause all pref observers to be removed and avoid
+ // crashes that otherwise occur in the destructor.
+ driver_.reset();
+ ChromeRenderViewHostTestHarness::TearDown();
+ }
+
+ protected:
+ scoped_ptr<TestAutofillManagerDelegate> test_manager_delegate_;
+ scoped_ptr<TestAutofillDriverImpl> driver_;
+ // Owned by |driver_|.
+ 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
+};
+
+TEST_F(AutofillDriverImplTest, NavigatedToDifferentPage) {
+ EXPECT_CALL(*autofill_manager_, Reset());
+ content::LoadCommittedDetails details = content::LoadCommittedDetails();
+ details.is_main_frame = true;
+ details.is_in_page = false;
+ 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.
+ content::FrameNavigateParams params = content::FrameNavigateParams();
+ driver_->DidNavigateMainFrame(details, params);
+}
+
+TEST_F(AutofillDriverImplTest, NavigatedWithinSamePage) {
+ EXPECT_CALL(*autofill_manager_, Reset()).Times(0);
+ content::LoadCommittedDetails details = content::LoadCommittedDetails();
+ details.is_main_frame = false;
+ 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.
+ content::FrameNavigateParams params = content::FrameNavigateParams();
+ driver_->DidNavigateMainFrame(details, params);
+}
+
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698