Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / password_manager / password_store_x_unittest.cc
index dbd8065..abbedde 100644 (file)
@@ -5,9 +5,8 @@
 #include "base/basictypes.h"
 #include "base/bind.h"
 #include "base/bind_helpers.h"
-#include "base/file_util.h"
+#include "base/files/file_util.h"
 #include "base/files/scoped_temp_dir.h"
-#include "base/platform_file.h"
 #include "base/prefs/pref_service.h"
 #include "base/run_loop.h"
 #include "base/stl_util.h"
@@ -30,6 +29,7 @@ using autofill::PasswordForm;
 using content::BrowserThread;
 using password_manager::ContainsAllPasswordForms;
 using password_manager::PasswordStoreChange;
+using password_manager::PasswordStoreChangeList;
 using testing::_;
 using testing::DoAll;
 using testing::ElementsAreArray;
@@ -59,24 +59,31 @@ class FailingBackend : public PasswordStoreX::NativeBackend {
  public:
   virtual bool Init() OVERRIDE { return true; }
 
-  virtual bool AddLogin(const PasswordForm& form) OVERRIDE { return false; }
-  virtual bool UpdateLogin(const PasswordForm& form) OVERRIDE { return false; }
+  virtual PasswordStoreChangeList AddLogin(const PasswordForm& form) OVERRIDE {
+    return PasswordStoreChangeList();
+  }
+  virtual bool UpdateLogin(const PasswordForm& form,
+                           PasswordStoreChangeList* changes) OVERRIDE {
+    return false;
+  }
   virtual bool RemoveLogin(const PasswordForm& form) OVERRIDE { return false; }
 
   virtual bool RemoveLoginsCreatedBetween(
-      const base::Time& delete_begin,
-      const base::Time& delete_end) OVERRIDE {
+      base::Time delete_begin,
+      base::Time delete_end,
+      password_manager::PasswordStoreChangeList* changes) OVERRIDE {
     return false;
   }
 
-  virtual bool GetLogins(const PasswordForm& form,
-                         PasswordFormList* forms) OVERRIDE {
+  virtual bool RemoveLoginsSyncedBetween(
+      base::Time delete_begin,
+      base::Time delete_end,
+      password_manager::PasswordStoreChangeList* changes) OVERRIDE {
     return false;
   }
 
-  virtual bool GetLoginsCreatedBetween(const base::Time& get_begin,
-                                       const base::Time& get_end,
-                                       PasswordFormList* forms) OVERRIDE {
+  virtual bool GetLogins(const PasswordForm& form,
+                         PasswordFormList* forms) OVERRIDE {
     return false;
   }
 
@@ -92,15 +99,20 @@ class MockBackend : public PasswordStoreX::NativeBackend {
  public:
   virtual bool Init() OVERRIDE { return true; }
 
-  virtual bool AddLogin(const PasswordForm& form) OVERRIDE {
+  virtual PasswordStoreChangeList AddLogin(const PasswordForm& form) OVERRIDE {
     all_forms_.push_back(form);
-    return true;
+    PasswordStoreChange change(PasswordStoreChange::ADD, form);
+    return PasswordStoreChangeList(1, change);
   }
 
-  virtual bool UpdateLogin(const PasswordForm& form) OVERRIDE {
+  virtual bool UpdateLogin(const PasswordForm& form,
+                           PasswordStoreChangeList* changes) OVERRIDE {
     for (size_t i = 0; i < all_forms_.size(); ++i)
-      if (CompareForms(all_forms_[i], form, true))
+      if (CompareForms(all_forms_[i], form, true)) {
         all_forms_[i] = form;
+        changes->push_back(PasswordStoreChange(PasswordStoreChange::UPDATE,
+                                               form));
+      }
     return true;
   }
 
@@ -112,8 +124,9 @@ class MockBackend : public PasswordStoreX::NativeBackend {
   }
 
   virtual bool RemoveLoginsCreatedBetween(
-      const base::Time& delete_begin,
-      const base::Time& delete_end) OVERRIDE {
+      base::Time delete_begin,
+      base::Time delete_end,
+      password_manager::PasswordStoreChangeList* changes) OVERRIDE {
     for (size_t i = 0; i < all_forms_.size(); ++i) {
       if (delete_begin <= all_forms_[i].date_created &&
           (delete_end.is_null() || all_forms_[i].date_created < delete_end))
@@ -122,20 +135,26 @@ class MockBackend : public PasswordStoreX::NativeBackend {
     return true;
   }
 
-  virtual bool GetLogins(const PasswordForm& form,
-                         PasswordFormList* forms) OVERRIDE {
-    for (size_t i = 0; i < all_forms_.size(); ++i)
-      if (all_forms_[i].signon_realm == form.signon_realm)
-        forms->push_back(new PasswordForm(all_forms_[i]));
+  virtual bool RemoveLoginsSyncedBetween(
+      base::Time delete_begin,
+      base::Time delete_end,
+      password_manager::PasswordStoreChangeList* changes) OVERRIDE {
+    DCHECK(changes);
+    for (size_t i = 0; i < all_forms_.size(); ++i) {
+      if (delete_begin <= all_forms_[i].date_synced &&
+          (delete_end.is_null() || all_forms_[i].date_synced < delete_end)) {
+        changes->push_back(password_manager::PasswordStoreChange(
+            password_manager::PasswordStoreChange::REMOVE, all_forms_[i]));
+        erase(i--);
+      }
+    }
     return true;
   }
 
-  virtual bool GetLoginsCreatedBetween(const base::Time& get_begin,
-                                       const base::Time& get_end,
-                                       PasswordFormList* forms) OVERRIDE {
+  virtual bool GetLogins(const PasswordForm& form,
+                         PasswordFormList* forms) OVERRIDE {
     for (size_t i = 0; i < all_forms_.size(); ++i)
-      if (get_begin <= all_forms_[i].date_created &&
-          (get_end.is_null() || all_forms_[i].date_created < get_end))
+      if (all_forms_[i].signon_realm == form.signon_realm)
         forms->push_back(new PasswordForm(all_forms_[i]));
     return true;
   }
@@ -266,7 +285,7 @@ TEST_P(PasswordStoreXTest, Notifications) {
                          base::MessageLoopProxy::current(),
                          login_db_.release(),
                          GetBackend()));
-  store->Init(syncer::SyncableService::StartSyncFlare());
+  store->Init(syncer::SyncableService::StartSyncFlare(), "");
 
   password_manager::PasswordFormData form_data = {
       PasswordForm::SCHEME_HTML,       "http://bar.example.com",
@@ -367,7 +386,7 @@ TEST_P(PasswordStoreXTest, NativeMigration) {
                          base::MessageLoopProxy::current(),
                          login_db_.release(),
                          GetBackend()));
-  store->Init(syncer::SyncableService::StartSyncFlare());
+  store->Init(syncer::SyncableService::StartSyncFlare(), "");
 
   MockPasswordStoreConsumer consumer;