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

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: Nits 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..d510ec282b38178b28bcd679b50bd23221a2f50a
--- /dev/null
+++ b/components/autofill/content/browser/autofill_driver_impl_unittest.cc
@@ -0,0 +1,73 @@
+// 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/browser/ui/autofill/tab_autofill_manager_delegate.h"
blundell 2013/06/19 17:49:37 Is there a way around creating the real AutofillMa
Ilya Sherman 2013/06/20 00:07:16 You can probably use components/autofill/browser/t
blundell 2013/06/21 12:55:23 Done.
+#include "chrome/test/base/chrome_render_view_host_test_harness.h"
blundell 2013/06/19 17:49:37 My understanding is that I can't change this to be
Ilya Sherman 2013/06/20 00:07:16 Yeah, that seems to be what Jói concluded as well.
+#include "components/autofill/browser/autofill_external_delegate.h"
+#include "components/autofill/browser/autofill_manager.h"
+#include "components/autofill/content/browser/autofill_driver_impl.h"
+#include "content/public/browser/web_contents.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace autofill {
+
+class AutofillManagerMock : public AutofillManager {
Ilya Sherman 2013/06/20 00:07:16 nit: "MockAutofillManager"
blundell 2013/06/21 12:55:23 Done.
+ public:
+ AutofillManagerMock(AutofillDriver* driver,
+ autofill::AutofillManagerDelegate* delegate,
Ilya Sherman 2013/06/20 00:07:16 nit: Since this code is in the autofill namespace
blundell 2013/06/21 12:55:23 Done.
+ const std::string& app_locale,
+ AutofillDownloadManagerState enable_download_manager)
+ : AutofillManager(driver, delegate, app_locale, enable_download_manager) {
+ }
+ virtual ~AutofillManagerMock() {}
+
+ MOCK_METHOD1(SetExternalDelegate, void(AutofillExternalDelegate*));
+};
+
+class AutofillDriverImplTest : public ChromeRenderViewHostTestHarness {
+ public:
+ virtual void SetUp() OVERRIDE {
+ ChromeRenderViewHostTestHarness::SetUp();
+
+ TabAutofillManagerDelegate::CreateForWebContents(web_contents());
+ TabAutofillManagerDelegate* delegate =
+ TabAutofillManagerDelegate::FromWebContents(web_contents());
+
+ std::string app_locale = "en-US";
+ AutofillManager::AutofillDownloadManagerState download_state =
+ AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER;
+ driver_ = new AutofillDriverImpl(web_contents(),
+ delegate,
+ app_locale,
+ download_state,
+ true);
+ autofill_manager_ = new AutofillManagerMock(driver_,
+ delegate, app_locale, download_state);
+ driver_->set_autofill_manager(
+ scoped_ptr<AutofillManager>(autofill_manager_));
Ilya Sherman 2013/06/20 00:07:16 note: If you take my advice about creating a subcl
blundell 2013/06/21 12:55:23 Done.
+ }
+
+ virtual void TearDown() OVERRIDE {
+ delete driver_;
+ ChromeRenderViewHostTestHarness::TearDown();
+ }
+
+ protected:
+ // Owned by this object.
+ AutofillDriverImpl* driver_;
blundell 2013/06/19 17:49:37 I had made this a scoped ptr but got complaints ab
Ilya Sherman 2013/06/20 00:07:16 Please create a "class TestAutofillDriverImpl : pu
blundell 2013/06/21 12:55:23 Done.
+ // Owned by |driver_|.
+ AutofillManagerMock* autofill_manager_;
+};
+
+TEST_F(AutofillDriverImplTest, SetExternalDelegate) {
+ EXPECT_CALL(*autofill_manager_, SetExternalDelegate(NULL));
+ driver_->SetAutofillExternalDelegate(scoped_ptr<AutofillExternalDelegate>());
Ilya Sherman 2013/06/20 00:07:16 Hmm, this is testing deprecated functionality, i.e
blundell 2013/06/21 12:55:23 Replaced this test with tests to test response to
+}
+
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698