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

Unified Diff: chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl_unittest.cc

Issue 2466273004: MD Settings: test passwordsPrivate.get{SavedPassword,PasswordExceptions}List (Closed)
Patch Set: asdf Created 4 years, 1 month 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: chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl_unittest.cc
diff --git a/chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl_unittest.cc b/chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..87e1a39c2ca704843de50f0f4a3146c49d76bc5b
--- /dev/null
+++ b/chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl_unittest.cc
@@ -0,0 +1,84 @@
+// Copyright 2016 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 <stddef.h>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.h"
+#include "chrome/test/base/testing_profile.h"
+#include "components/autofill/core/common/password_form.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+
+template <typename T>
+class CallbackTracker {
+ public:
+ CallbackTracker() : callback_(
+ base::Bind(&CallbackTracker::Callback, base::Unretained(this))) {}
+
+ using TypedCallback = base::Callback<void(const T&)>;
+
+ const TypedCallback& callback() const { return callback_; }
+
+ size_t call_count() const { return call_count_; }
+
+ private:
+ void Callback(const T& args) {
+ EXPECT_FALSE(args.empty());
+ ++call_count_;
+ }
+
+ size_t call_count_ = 0;
+
+ TypedCallback callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(CallbackTracker);
+};
+
+using PasswordFormList = std::vector<std::unique_ptr<autofill::PasswordForm>>;
+
+TEST(PasswordsPrivateDelegateImplTest, GetSavedPasswordsList) {
+ CallbackTracker<PasswordsPrivateDelegate::UiEntries> tracker;
+
+ content::TestBrowserThreadBundle thread_bundle;
+ TestingProfile profile;
+ PasswordsPrivateDelegateImpl delegate(&profile);
+
+ delegate.GetSavedPasswordsList(tracker.callback());
+ EXPECT_EQ(0u, tracker.call_count());
+
+ PasswordFormList list;
+ list.push_back(base::MakeUnique<autofill::PasswordForm>());
+ delegate.SetPasswordList(list);
+ EXPECT_EQ(1u, tracker.call_count());
+
+ delegate.GetSavedPasswordsList(tracker.callback());
+ EXPECT_EQ(2u, tracker.call_count());
+}
+
+TEST(PasswordsPrivateDelegateImplTest, GetPasswordExceptionsList) {
+ CallbackTracker<PasswordsPrivateDelegate::ExceptionPairs> tracker;
+
+ content::TestBrowserThreadBundle thread_bundle;
+ TestingProfile profile;
+ PasswordsPrivateDelegateImpl delegate(&profile);
+
+ delegate.GetPasswordExceptionsList(tracker.callback());
+ EXPECT_EQ(0u, tracker.call_count());
+
+ PasswordFormList list;
+ list.push_back(base::MakeUnique<autofill::PasswordForm>());
+ delegate.SetPasswordExceptionList(list);
+ EXPECT_EQ(1u, tracker.call_count());
+
+ delegate.GetPasswordExceptionsList(tracker.callback());
+ EXPECT_EQ(2u, tracker.call_count());
+}
+
+} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698