Index: components/password_manager/core/browser/password_store_origin_unittest.h |
diff --git a/components/password_manager/core/browser/password_store_origin_unittest.h b/components/password_manager/core/browser/password_store_origin_unittest.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2144b0d82d31453dae7aaca22e47f33e32a71b5e |
--- /dev/null |
+++ b/components/password_manager/core/browser/password_store_origin_unittest.h |
@@ -0,0 +1,106 @@ |
+// Copyright 2015 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. |
+ |
+#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_ORIGIN_UNITTEST_H_ |
+#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_ORIGIN_UNITTEST_H_ |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "base/run_loop.h" |
+#include "base/time/time.h" |
+#include "components/password_manager/core/browser/password_manager_test_utils.h" |
+#include "components/password_manager/core/browser/password_store.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/origin.h" |
+ |
+using autofill::PasswordForm; |
+using password_manager::PasswordStore; |
+using testing::_; |
+using testing::ElementsAre; |
+ |
+namespace password_manager { |
+ |
+PasswordFormData CreateTestPasswordFormDataByOrigin(const char* origin_url) { |
+ PasswordFormData data = {PasswordForm::SCHEME_HTML, origin_url, origin_url, |
+ origin_url, L"submit_element", L"username_element", |
+ L"password_element", L"username_value", |
+ // Ignore cleared password values on Mac. |
+ // crbug.com/466638 |
+ nullptr, true, false, 1}; |
+ return data; |
+} |
+ |
+// Collection of origin-related testcases common to all platform-specific |
+// stores. |
+// The template type T represents a test delegate that must implement the |
+// following methods: |
+// // Returns a pointer to a fully initialized store for polymorphic usage. |
+// PasswordStore* store(); |
+// |
+// // Finishes all asnychronous processing on the store. |
+// void FinishAsyncProcessing(); |
+template <typename T> |
+class PasswordStoreOriginTest : public testing::Test { |
+ protected: |
+ void SetUp() override { |
+ VLOG(0) << "PasswordStoreOriginTest::SetUp: Creating temp directory."; |
+ ASSERT_TRUE(this->temp_dir_.CreateUniqueTempDir()); |
+ VLOG(0) << "PasswordStoreOriginTest::SetUp: Initializing."; |
+ this->delegate_.Initialize(test_login_db_file_path()); |
+ VLOG(0) << "PasswordStoreOriginTest::SetUp: Done."; |
+ } |
+ |
+ void TearDown() override { |
+ VLOG(0) << "PasswordStoreOriginTest::TearDown: Closing password store."; |
+ this->delegate_.ClosePasswordStore(); |
+ VLOG(0) << "PasswordStoreOriginTest::TearDown: Deleting temp dir."; |
+ ASSERT_TRUE(this->temp_dir_.Delete()); |
+ VLOG(0) << "PasswordStoreOriginTest::TearDown: Done."; |
+ } |
+ |
+ base::FilePath test_login_db_file_path() const { |
+ return temp_dir_.path().Append(FILE_PATH_LITERAL("login_test")); |
+ } |
+ |
+ base::MessageLoopForUI message_loop_; |
+ base::ScopedTempDir temp_dir_; |
+ T delegate_; |
+}; |
+ |
+TYPED_TEST_CASE_P(PasswordStoreOriginTest); |
+ |
+TYPED_TEST_P(PasswordStoreOriginTest, |
+ RemoveLoginsByOriginAndTimeImpl_FittingOriginAndTime) { |
+ VLOG(0) << "Test: Starting."; |
+ const char origin_url[] = "http://foo.example.com"; |
+ scoped_ptr<PasswordForm> form = CreatePasswordFormFromDataForTesting( |
+ CreateTestPasswordFormDataByOrigin(origin_url)); |
+ VLOG(0) << "Test: Adding login form:" << std::endl << *form; |
+ this->delegate_.store()->AddLogin(*form); |
+ base::MessageLoop::current()->RunUntilIdle(); |
+ |
+ MockPasswordStoreObserver observer; |
+ VLOG(0) << "Test: Adding observer."; |
+ ASSERT_TRUE(this->delegate_.store()->AddObserver(&observer)); |
+ |
+ const url::Origin origin((GURL(origin_url))); |
+ EXPECT_CALL(observer, OnLoginsChanged(ElementsAre(PasswordStoreChange( |
+ PasswordStoreChange::REMOVE, *form)))); |
+ VLOG(0) << "Test: Removing logins by origin and time."; |
+ this->delegate_.store()->RemoveLoginsByOriginAndTime( |
+ origin, base::Time::Time(), base::Time::Max(), base::Closure()); |
vasilii
2015/12/17 13:12:20
base::Time()
|
+ base::MessageLoop::current()->RunUntilIdle(); |
+ |
+ VLOG(0) << "Test: Removing observer."; |
+ this->delegate_.store()->RemoveObserver(&observer); |
+ VLOG(0) << "Test: Completed."; |
+} |
+ |
+REGISTER_TYPED_TEST_CASE_P( |
+ PasswordStoreOriginTest, |
+ RemoveLoginsByOriginAndTimeImpl_FittingOriginAndTime); |
+ |
+} // namespace password_manager |
+ |
+#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_ORIGIN_UNITTEST_H_ |