Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / password_manager / password_store_x_unittest.cc
index da0a34f..0a06360 100644 (file)
 #include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
 #include "base/time/time.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/password_manager/password_form_data.h"
-#include "chrome/browser/password_manager/password_store_change.h"
-#include "chrome/browser/password_manager/password_store_consumer.h"
 #include "chrome/browser/password_manager/password_store_x.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/test/base/testing_browser_process.h"
-#include "chrome/test/base/testing_profile.h"
+#include "components/password_manager/core/browser/password_form_data.h"
+#include "components/password_manager/core/browser/password_store_change.h"
+#include "components/password_manager/core/browser/password_store_consumer.h"
 #include "content/public/browser/browser_thread.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_source.h"
-#include "content/public/test/mock_notification_observer.h"
 #include "content/public/test/test_browser_thread_bundle.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -51,29 +45,10 @@ class MockPasswordStoreConsumer : public PasswordStoreConsumer {
                void(const std::vector<PasswordForm*>&));
 };
 
-// This class will add and remove a mock notification observer from
-// the DB thread.
-class DBThreadObserverHelper {
+class MockPasswordStoreObserver : public PasswordStore::Observer {
  public:
-  DBThreadObserverHelper() {}
-
-  ~DBThreadObserverHelper() {
-    registrar_.RemoveAll();
-  }
-
-  void Init(PasswordStore* password_store) {
-    registrar_.Add(&observer_,
-                   chrome::NOTIFICATION_LOGINS_CHANGED,
-                   content::Source<PasswordStore>(password_store));
-  }
-
-  content::MockNotificationObserver& observer() {
-    return observer_;
-  }
-
- private:
-  content::NotificationRegistrar registrar_;
-  content::MockNotificationObserver observer_;
+  MOCK_METHOD1(OnLoginsChanged,
+               void(const PasswordStoreChangeList& changes));
 };
 
 class FailingBackend : public PasswordStoreX::NativeBackend {
@@ -250,8 +225,6 @@ class PasswordStoreXTest : public testing::TestWithParam<BackendType> {
   virtual void SetUp() {
     ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
 
-    profile_.reset(new TestingProfile());
-
     login_db_.reset(new LoginDatabase());
     ASSERT_TRUE(login_db_->Init(temp_dir_.path().Append("login_test")));
   }
@@ -274,7 +247,6 @@ class PasswordStoreXTest : public testing::TestWithParam<BackendType> {
   content::TestBrowserThreadBundle thread_bundle_;
 
   scoped_ptr<LoginDatabase> login_db_;
-  scoped_ptr<TestingProfile> profile_;
   base::ScopedTempDir temp_dir_;
 };
 
@@ -284,8 +256,9 @@ ACTION(STLDeleteElements0) {
 
 TEST_P(PasswordStoreXTest, Notifications) {
   scoped_refptr<PasswordStoreX> store(
-      new PasswordStoreX(login_db_.release(),
-                         profile_.get(),
+      new PasswordStoreX(base::MessageLoopProxy::current(),
+                         base::MessageLoopProxy::current(),
+                         login_db_.release(),
                          GetBackend()));
   store->Init();
 
@@ -302,19 +275,16 @@ TEST_P(PasswordStoreXTest, Notifications) {
     true, false, 1 };
   scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data));
 
-  DBThreadObserverHelper helper;
-  helper.Init(store.get());
+  MockPasswordStoreObserver observer;
+  store->AddObserver(&observer);
 
   const PasswordStoreChange expected_add_changes[] = {
     PasswordStoreChange(PasswordStoreChange::ADD, *form),
   };
 
   EXPECT_CALL(
-      helper.observer(),
-      Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED),
-              content::Source<PasswordStore>(store.get()),
-              Property(&content::Details<const PasswordStoreChangeList>::ptr,
-                       Pointee(ElementsAreArray(expected_add_changes)))));
+      observer,
+      OnLoginsChanged(ElementsAreArray(expected_add_changes)));
 
   // Adding a login should trigger a notification.
   store->AddLogin(*form);
@@ -331,11 +301,8 @@ TEST_P(PasswordStoreXTest, Notifications) {
   };
 
   EXPECT_CALL(
-      helper.observer(),
-      Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED),
-              content::Source<PasswordStore>(store.get()),
-              Property(&content::Details<const PasswordStoreChangeList>::ptr,
-                       Pointee(ElementsAreArray(expected_update_changes)))));
+      observer,
+      OnLoginsChanged(ElementsAreArray(expected_update_changes)));
 
   // Updating the login with the new password should trigger a notification.
   store->UpdateLogin(*form);
@@ -348,11 +315,8 @@ TEST_P(PasswordStoreXTest, Notifications) {
   };
 
   EXPECT_CALL(
-      helper.observer(),
-      Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED),
-              content::Source<PasswordStore>(store.get()),
-              Property(&content::Details<const PasswordStoreChangeList>::ptr,
-                       Pointee(ElementsAreArray(expected_delete_changes)))));
+      observer,
+      OnLoginsChanged(ElementsAreArray(expected_delete_changes)));
 
   // Deleting the login should trigger a notification.
   store->RemoveLogin(*form);
@@ -360,8 +324,9 @@ TEST_P(PasswordStoreXTest, Notifications) {
   // Wait for PasswordStore to execute.
   base::RunLoop().RunUntilIdle();
 
-  // Public in PasswordStore, protected in PasswordStoreX.
-  static_cast<PasswordStore*>(store.get())->ShutdownOnUIThread();
+  store->RemoveObserver(&observer);
+
+  store->Shutdown();
 }
 
 TEST_P(PasswordStoreXTest, NativeMigration) {
@@ -396,8 +361,9 @@ TEST_P(PasswordStoreXTest, NativeMigration) {
 
   // Initializing the PasswordStore shouldn't trigger a native migration (yet).
   scoped_refptr<PasswordStoreX> store(
-      new PasswordStoreX(login_db_.release(),
-                         profile_.get(),
+      new PasswordStoreX(base::MessageLoopProxy::current(),
+                         base::MessageLoopProxy::current(),
+                         login_db_.release(),
                          GetBackend()));
   store->Init();
 
@@ -471,8 +437,7 @@ TEST_P(PasswordStoreXTest, NativeMigration) {
   STLDeleteElements(&expected_autofillable);
   STLDeleteElements(&expected_blacklisted);
 
-  // Public in PasswordStore, protected in PasswordStoreX.
-  static_cast<PasswordStore*>(store.get())->ShutdownOnUIThread();
+  store->Shutdown();
 }
 
 INSTANTIATE_TEST_CASE_P(NoBackend,