summaryrefslogtreecommitdiffstats
path: root/chrome/browser/webdata
diff options
context:
space:
mode:
authorskrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-01 20:48:47 +0000
committerskrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-01 20:48:47 +0000
commita37ae1dd538a8cc96d749cf580646bf7b00bffd6 (patch)
tree32d58cbe18a4acd071cf88b4275f9135e0bd5d62 /chrome/browser/webdata
parentae5e8a47d6ce8b13b47834b1032ff7b46a5e9d76 (diff)
downloadchromium_src-a37ae1dd538a8cc96d749cf580646bf7b00bffd6.zip
chromium_src-a37ae1dd538a8cc96d749cf580646bf7b00bffd6.tar.gz
chromium_src-a37ae1dd538a8cc96d749cf580646bf7b00bffd6.tar.bz2
Add the beginnings of a unit test for the autofill features of the WebDataService.
This is so I can start adding change notification to the autofill methods, which is need to sync this data type. Review URL: http://codereview.chromium.org/435030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33475 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata')
-rw-r--r--chrome/browser/webdata/web_data_service_unittest.cc91
1 files changed, 91 insertions, 0 deletions
diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc
new file mode 100644
index 0000000..1386792
--- /dev/null
+++ b/chrome/browser/webdata/web_data_service_unittest.cc
@@ -0,0 +1,91 @@
+// Copyright (c) 2009 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 <vector>
+
+#include "base/basictypes.h"
+#include "base/file_util.h"
+#include "base/message_loop.h"
+#include "base/path_service.h"
+#include "base/scoped_ptr.h"
+#include "base/string16.h"
+#include "base/string_util.h"
+#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/common/chrome_paths.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/glue/form_field.h"
+
+class AutofillWebDataServiceConsumer: public WebDataServiceConsumer {
+ public:
+ AutofillWebDataServiceConsumer() {}
+ virtual ~AutofillWebDataServiceConsumer() {}
+
+ virtual void OnWebDataServiceRequestDone(WebDataService::Handle handle,
+ const WDTypedResult* result) {
+ DCHECK(result->GetType() == AUTOFILL_VALUE_RESULT);
+ handle_ = handle;
+ const WDResult<std::vector<string16> >* autofill_result =
+ static_cast<const WDResult<std::vector<string16> >*>(result);
+ // Copy the values.
+ values_ = autofill_result->GetValue();
+ MessageLoop::current()->Quit();
+ }
+
+ WebDataService::Handle const handle() { return handle_; }
+ const std::vector<string16>& values() { return values_; }
+
+ private:
+ WebDataService::Handle handle_;
+ std::vector<string16> values_;
+ DISALLOW_COPY_AND_ASSIGN(AutofillWebDataServiceConsumer);
+};
+
+class WebDataServiceTest : public testing::Test {
+ protected:
+
+ virtual void SetUp() {
+ PathService::Get(chrome::DIR_TEST_DATA, &profile_dir_);
+ const std::string test_profile = "WebDataServiceTest";
+ profile_dir_ = profile_dir_.AppendASCII(test_profile);
+ file_util::Delete(profile_dir_, true);
+ file_util::CreateDirectory(profile_dir_);
+ wds_ = new WebDataService();
+ wds_->Init(profile_dir_);
+ }
+
+ virtual void TearDown() {
+ if (wds_.get())
+ wds_->Shutdown();
+ file_util::Delete(profile_dir_, true);
+
+ MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
+ MessageLoop::current()->Run();
+ }
+
+ MessageLoopForUI message_loop_;
+ FilePath profile_dir_;
+ scoped_refptr<WebDataService> wds_;
+};
+
+TEST_F(WebDataServiceTest, AutofillAdd) {
+ std::vector<webkit_glue::FormField> form_fields;
+ form_fields.push_back(webkit_glue::FormField(EmptyString16(),
+ ASCIIToUTF16("name"),
+ EmptyString16(),
+ ASCIIToUTF16("value")));
+ wds_->AddFormFieldValues(form_fields);
+
+ AutofillWebDataServiceConsumer consumer;
+ WebDataService::Handle handle;
+ static const int limit = 10;
+ handle = wds_->GetFormValuesForElementName(ASCIIToUTF16("name"),
+ EmptyString16(),
+ limit,
+ &consumer);
+ MessageLoop::current()->Run();
+
+ EXPECT_EQ(handle, consumer.handle());
+ ASSERT_EQ(1U, consumer.values().size());
+ EXPECT_EQ(ASCIIToUTF16("value"), consumer.values()[0]);
+}