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

Unified Diff: chrome/browser/webdata/web_data_service_unittest.cc

Issue 12476031: Refactor notifications of chrome/browser/webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again Created 7 years, 9 months 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/webdata/web_data_service_unittest.cc
diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc
index 1e74bac1a4ccc735c49d2761c67099b1a0f09a4e..2f81578e2825e712cbeffb60d14d5868eef12deb 100644
--- a/chrome/browser/webdata/web_data_service_unittest.cc
+++ b/chrome/browser/webdata/web_data_service_unittest.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/webdata/autofill_change.h"
#include "chrome/browser/webdata/autofill_entry.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/browser/webdata/web_data_service_observer.h"
#include "chrome/browser/webdata/web_data_service_test_util.h"
#include "chrome/browser/webdata/web_database_service_impl.h"
#include "chrome/common/chrome_constants.h"
@@ -45,26 +46,18 @@ using testing::ElementsAreArray;
using testing::Pointee;
using testing::Property;
-typedef std::vector<AutofillChange> AutofillChangeList;
-
static const int kWebDataServiceTimeoutSeconds = 8;
ACTION_P(SignalEvent, event) {
event->Signal();
}
-class AutofillDBThreadObserverHelper : public DBThreadObserverHelper {
- protected:
- virtual ~AutofillDBThreadObserverHelper() {}
-
- virtual void RegisterObservers() OVERRIDE {
- registrar_.Add(&observer_,
- chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
- content::NotificationService::AllSources());
- registrar_.Add(&observer_,
- chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
- content::NotificationService::AllSources());
- }
+class MockWebDataServiceObserver : public WebDataServiceObserver {
+ public:
+ MOCK_METHOD1(AutofillEntriesChanged,
+ void(const AutofillChangeList& changes));
+ MOCK_METHOD1(AutofillProfileChanged,
+ void(const AutofillProfileChange& change));
};
class WebDataServiceTest : public testing::Test {
@@ -132,13 +125,11 @@ class WebDataServiceAutofillTest : public WebDataServiceTest {
name2_ = ASCIIToUTF16("name2");
value1_ = ASCIIToUTF16("value1");
value2_ = ASCIIToUTF16("value2");
- observer_helper_ = new AutofillDBThreadObserverHelper();
- observer_helper_->Init();
+ wds_->AddObserver(&observer_);
}
virtual void TearDown() {
- // Release this first so it can get destructed on the db thread.
- observer_helper_ = NULL;
+ wds_->RemoveObserver(&observer_);
WebDataServiceTest::TearDown();
}
@@ -157,7 +148,7 @@ class WebDataServiceAutofillTest : public WebDataServiceTest {
string16 value2_;
int unique_id1_, unique_id2_;
const TimeDelta test_timeout_;
- scoped_refptr<AutofillDBThreadObserverHelper> observer_helper_;
+ testing::NiceMock<MockWebDataServiceObserver> observer_;
WaitableEvent done_event_;
};
@@ -196,13 +187,9 @@ TEST_F(WebDataServiceAutofillTest, FormFillAdd) {
// This will verify that the correct notification is triggered,
// passing the correct list of autofill keys in the details.
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED),
- content::Source<WebDataService>(wds_.get()),
- Property(&content::Details<const AutofillChangeList>::ptr,
- Pointee(ElementsAreArray(expected_changes))))).
- WillOnce(SignalEvent(&done_event_));
+ EXPECT_CALL(observer_,
+ AutofillEntriesChanged(ElementsAreArray(expected_changes)))
+ .WillOnce(SignalEvent(&done_event_));
std::vector<FormFieldData> form_fields;
AppendFormField(name1_, value1_, &form_fields);
@@ -228,8 +215,9 @@ TEST_F(WebDataServiceAutofillTest, FormFillAdd) {
TEST_F(WebDataServiceAutofillTest, FormFillRemoveOne) {
// First add some values to autofill.
- EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)).
- WillOnce(SignalEvent(&done_event_));
+ EXPECT_CALL(observer_, AutofillEntriesChanged(_))
+ .WillOnce(SignalEvent(&done_event_));
+
std::vector<FormFieldData> form_fields;
AppendFormField(name1_, value1_, &form_fields);
wds_->AddFormFields(form_fields);
@@ -242,13 +230,10 @@ TEST_F(WebDataServiceAutofillTest, FormFillRemoveOne) {
const AutofillChange expected_changes[] = {
AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_))
};
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED),
- content::Source<WebDataService>(wds_.get()),
- Property(&content::Details<const AutofillChangeList>::ptr,
- Pointee(ElementsAreArray(expected_changes))))).
- WillOnce(SignalEvent(&done_event_));
+ EXPECT_CALL(observer_,
+ AutofillEntriesChanged(ElementsAreArray(expected_changes)))
+ .WillOnce(SignalEvent(&done_event_));
+
wds_->RemoveFormValueForElementName(name1_, value1_);
// The event will be signaled when the mock observer is notified.
@@ -259,8 +244,9 @@ TEST_F(WebDataServiceAutofillTest, FormFillRemoveMany) {
TimeDelta one_day(TimeDelta::FromDays(1));
Time t = Time::Now();
- EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)).
- WillOnce(SignalEvent(&done_event_));
+ EXPECT_CALL(observer_, AutofillEntriesChanged(_))
+ .WillOnce(SignalEvent(&done_event_));
+
std::vector<FormFieldData> form_fields;
AppendFormField(name1_, value1_, &form_fields);
AppendFormField(name2_, value2_, &form_fields);
@@ -275,13 +261,9 @@ TEST_F(WebDataServiceAutofillTest, FormFillRemoveMany) {
AutofillChange(AutofillChange::REMOVE, AutofillKey(name1_, value1_)),
AutofillChange(AutofillChange::REMOVE, AutofillKey(name2_, value2_))
};
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(int(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED),
- content::Source<WebDataService>(wds_.get()),
- Property(&content::Details<const AutofillChangeList>::ptr,
- Pointee(ElementsAreArray(expected_changes))))).
- WillOnce(SignalEvent(&done_event_));
+ EXPECT_CALL(observer_,
+ AutofillEntriesChanged(ElementsAreArray(expected_changes)))
+ .WillOnce(SignalEvent(&done_event_));
wds_->RemoveFormElementsAddedBetween(t, t + one_day);
// The event will be signaled when the mock observer is notified.
@@ -294,13 +276,8 @@ TEST_F(WebDataServiceAutofillTest, ProfileAdd) {
// Check that GUID-based notification was sent.
const AutofillProfileChange expected_change(
AutofillProfileChange::ADD, profile.guid(), &profile);
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED),
- content::Source<WebDataService>(wds_.get()),
- Property(&content::Details<const AutofillProfileChange>::ptr,
- Pointee(expected_change)))).
- WillOnce(SignalEvent(&done_event_));
+ EXPECT_CALL(observer_, AutofillProfileChanged(expected_change))
+ .WillOnce(SignalEvent(&done_event_));
wds_->AddAutofillProfile(profile);
done_event_.TimedWait(test_timeout_);
@@ -319,9 +296,8 @@ TEST_F(WebDataServiceAutofillTest, ProfileRemove) {
AutofillProfile profile;
// Add a profile.
- EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)).
- Times(1).
- WillOnce(SignalEvent(&done_event_));
+ EXPECT_CALL(observer_, AutofillProfileChanged(_))
+ .WillOnce(SignalEvent(&done_event_));
wds_->AddAutofillProfile(profile);
done_event_.TimedWait(test_timeout_);
@@ -337,13 +313,8 @@ TEST_F(WebDataServiceAutofillTest, ProfileRemove) {
// Check that GUID-based notification was sent.
const AutofillProfileChange expected_change(
AutofillProfileChange::REMOVE, profile.guid(), NULL);
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED),
- content::Source<WebDataService>(wds_.get()),
- Property(&content::Details<const AutofillProfileChange>::ptr,
- Pointee(expected_change)))).
- WillOnce(SignalEvent(&done_event_));
+ EXPECT_CALL(observer_, AutofillProfileChanged(expected_change))
+ .WillOnce(SignalEvent(&done_event_));
// Remove the profile.
wds_->RemoveAutofillProfile(profile.guid());
@@ -363,9 +334,10 @@ TEST_F(WebDataServiceAutofillTest, ProfileUpdate) {
AutofillProfile profile2;
profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Alice"));
- EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)).
- WillOnce(DoDefault()).
- WillOnce(SignalEvent(&done_event_));
+ EXPECT_CALL(observer_, AutofillProfileChanged(_))
+ .WillOnce(DoDefault())
+ .WillOnce(SignalEvent(&done_event_));
+
wds_->AddAutofillProfile(profile1);
wds_->AddAutofillProfile(profile2);
done_event_.TimedWait(test_timeout_);
@@ -385,13 +357,8 @@ TEST_F(WebDataServiceAutofillTest, ProfileUpdate) {
const AutofillProfileChange expected_change(
AutofillProfileChange::UPDATE, profile1.guid(), &profile1_changed);
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED),
- content::Source<WebDataService>(wds_.get()),
- Property(&content::Details<const AutofillProfileChange>::ptr,
- Pointee(expected_change)))).
- WillOnce(SignalEvent(&done_event_));
+ EXPECT_CALL(observer_, AutofillProfileChanged(expected_change))
+ .WillOnce(SignalEvent(&done_event_));
// Update the profile.
wds_->UpdateAutofillProfile(profile1_changed);
@@ -492,9 +459,8 @@ TEST_F(WebDataServiceAutofillTest, CreditUpdate) {
TEST_F(WebDataServiceAutofillTest, AutofillRemoveModifiedBetween) {
// Add a profile.
- EXPECT_CALL(*observer_helper_->observer(), Observe(_, _, _)).
- Times(1).
- WillOnce(SignalEvent(&done_event_));
+ EXPECT_CALL(observer_, AutofillProfileChanged(_))
+ .WillOnce(SignalEvent(&done_event_));
AutofillProfile profile;
wds_->AddAutofillProfile(profile);
done_event_.TimedWait(test_timeout_);
@@ -526,13 +492,8 @@ TEST_F(WebDataServiceAutofillTest, AutofillRemoveModifiedBetween) {
// Check that GUID-based notification was sent for the profile.
const AutofillProfileChange expected_profile_change(
AutofillProfileChange::REMOVE, profile.guid(), NULL);
- EXPECT_CALL(
- *observer_helper_->observer(),
- Observe(int(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED),
- content::Source<WebDataService>(wds_.get()),
- Property(&content::Details<const AutofillProfileChange>::ptr,
- Pointee(expected_profile_change)))).
- WillOnce(SignalEvent(&done_event_));
+ EXPECT_CALL(observer_, AutofillProfileChanged(expected_profile_change))
+ .WillOnce(SignalEvent(&done_event_));
// Remove the profile using time range of "all time".
wds_->RemoveAutofillProfilesAndCreditCardsModifiedBetween(Time(), Time());

Powered by Google App Engine
This is Rietveld 408576698