| Index: components/autofill/core/browser/autofill_driver_factory_unittest.cc
|
| diff --git a/components/autofill/core/browser/autofill_driver_factory_unittest.cc b/components/autofill/core/browser/autofill_driver_factory_unittest.cc
|
| index e79c47160005cc9d2e7b47525a5b953c71230f86..8355161333cf574bab50c46a523ff40712cc4907 100644
|
| --- a/components/autofill/core/browser/autofill_driver_factory_unittest.cc
|
| +++ b/components/autofill/core/browser/autofill_driver_factory_unittest.cc
|
| @@ -25,7 +25,8 @@ class MockAutofillClient : public TestAutofillClient {
|
| };
|
|
|
| // Just a stub AutofillDriver implementation which announces its construction
|
| -// and desctruction by updating the passed |instance_counter|.
|
| +// and desctruction by updating the passed |instance_counter|. It also records
|
| +// when "user gesture observed" was signalled to it.
|
| class CountingAutofillDriver : public TestAutofillDriver {
|
| public:
|
| CountingAutofillDriver(int* instance_counter)
|
| @@ -35,8 +36,19 @@ class CountingAutofillDriver : public TestAutofillDriver {
|
|
|
| ~CountingAutofillDriver() override { --*instance_counter_; }
|
|
|
| + // Note that EXPECT_CALL cannot be used here, because creation and
|
| + // notification of the same driver might be done by a single AddForKey call
|
| + // from the test. Therefore tracking the "gesture_observed" flag is done
|
| + // explicitly here.
|
| + void NotifyFirstUserGestureObservedInTab() override {
|
| + gesture_observed_ = true;
|
| + }
|
| +
|
| + bool gesture_observed() { return gesture_observed_; }
|
| +
|
| private:
|
| int* const instance_counter_;
|
| + bool gesture_observed_ = false;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(CountingAutofillDriver);
|
| };
|
| @@ -51,11 +63,8 @@ class PublicAutofillDriverFactory : public AutofillDriverFactory {
|
|
|
| ~PublicAutofillDriverFactory() {}
|
|
|
| - using AutofillDriverFactory::DriverForKey;
|
| using AutofillDriverFactory::AddForKey;
|
| using AutofillDriverFactory::DeleteForKey;
|
| - using AutofillDriverFactory::NavigationFinished;
|
| - using AutofillDriverFactory::TabHidden;
|
| };
|
|
|
| // Wrapper around an integer, checking that the integer is 0 on desctruction.
|
| @@ -85,6 +94,11 @@ class AutofillDriverFactoryTest : public testing::Test {
|
| // constants.
|
| void* KeyFrom(int x) { return reinterpret_cast<void*>(x); }
|
|
|
| + // Convenience accessor with a cast to CountingAutofillDriver.
|
| + CountingAutofillDriver* GetDriver(void* key) {
|
| + return static_cast<CountingAutofillDriver*>(factory_.DriverForKey(key));
|
| + }
|
| +
|
| std::unique_ptr<AutofillDriver> CreateDriver() {
|
| ++drivers_created_;
|
| return base::MakeUnique<CountingAutofillDriver>(instance_counter_.val());
|
| @@ -173,4 +187,54 @@ TEST_F(AutofillDriverFactoryTest, TabHidden) {
|
| factory_.TabHidden();
|
| }
|
|
|
| +// Without calling OnFirstUserGestureObserved on the factory, the factory will
|
| +// not call NotifyFirstUserGestureObservedInTab on a driver.
|
| +TEST_F(AutofillDriverFactoryTest, OnFirstUserGestureObserved_NotCalled) {
|
| + factory_.AddForKey(KeyFrom(1), CreateDriverCallback());
|
| + EXPECT_FALSE(GetDriver(KeyFrom(1))->gesture_observed());
|
| +}
|
| +
|
| +// Call OnFirstUserGestureObserved on the factory with one driver. The factory
|
| +// will call NotifyFirstUserGestureObservedInTab on that driver.
|
| +TEST_F(AutofillDriverFactoryTest, OnFirstUserGestureObserved_CalledOld) {
|
| + factory_.AddForKey(KeyFrom(1), CreateDriverCallback());
|
| + factory_.OnFirstUserGestureObserved();
|
| + EXPECT_TRUE(GetDriver(KeyFrom(1))->gesture_observed());
|
| +}
|
| +
|
| +// Call OnFirstUserGestureObserved on the factory without drivers. Add a
|
| +// driver. The factory will call NotifyFirstUserGestureObservedInTab on that
|
| +// driver.
|
| +TEST_F(AutofillDriverFactoryTest, OnFirstUserGestureObserved_CalledNew) {
|
| + factory_.OnFirstUserGestureObserved();
|
| + factory_.AddForKey(KeyFrom(1), CreateDriverCallback());
|
| + EXPECT_TRUE(GetDriver(KeyFrom(1))->gesture_observed());
|
| +}
|
| +
|
| +// Combining the CalledOld and CalledNew test cases into one.
|
| +TEST_F(AutofillDriverFactoryTest, OnFirstUserGestureObserved_MultipleDrivers) {
|
| + factory_.AddForKey(KeyFrom(1), CreateDriverCallback());
|
| + factory_.OnFirstUserGestureObserved();
|
| + EXPECT_TRUE(GetDriver(KeyFrom(1))->gesture_observed());
|
| +
|
| + factory_.AddForKey(KeyFrom(7), CreateDriverCallback());
|
| + EXPECT_TRUE(GetDriver(KeyFrom(7))->gesture_observed());
|
| +}
|
| +
|
| +// Call OnFirstUserGestureObserved on the factory with one driver. Simulate
|
| +// navigation to a different page. Add a driver. The factory will not call
|
| +// NotifyFirstUserGestureObservedInTab on that driver.
|
| +TEST_F(AutofillDriverFactoryTest, OnFirstUserGestureObserved_CalledNavigation) {
|
| + factory_.AddForKey(KeyFrom(1), CreateDriverCallback());
|
| + factory_.OnFirstUserGestureObserved();
|
| + EXPECT_TRUE(GetDriver(KeyFrom(1))->gesture_observed());
|
| +
|
| + EXPECT_CALL(client_, HideAutofillPopup());
|
| + factory_.NavigationFinished();
|
| +
|
| + // Adding a sub-frame
|
| + factory_.AddForKey(KeyFrom(2), CreateDriverCallback());
|
| + EXPECT_FALSE(GetDriver(KeyFrom(2))->gesture_observed());
|
| +}
|
| +
|
| } // namespace autofill
|
|
|