chromium/components/autofill/content/browser/content_autofill_driver_factory_unittest.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/autofill/content/browser/content_autofill_driver_factory.h"

#include <memory>
#include <string_view>
#include <utility>

#include "base/check_deref.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/content/browser/content_autofill_driver_factory_test_api.h"
#include "components/autofill/content/browser/test_autofill_client_injector.h"
#include "components/autofill/content/browser/test_content_autofill_client.h"
#include "components/autofill/content/browser/test_content_autofill_driver.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/test_matchers.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/web_contents_tester.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/features.h"

namespace autofill {

namespace {

LazyRef;
SaveArgPtr;
_;
AllOf;
AtLeast;
Between;
DoAll;
InSequence;
Property;
Ref;
Truly;

auto HasState(AutofillDriver::LifecycleState expected_state) {}

class MockContentAutofillDriverFactoryObserver
    : public ContentAutofillDriverFactory::Observer {};

// Test case with one frame.
class ContentAutofillDriverFactoryTest
    : public content::RenderViewHostTestHarness {};

TEST_F(ContentAutofillDriverFactoryTest, MainDriver) {}

// Test case with two frames: the main frame and one child frame.
class ContentAutofillDriverFactoryTest_WithTwoFrames
    : public ContentAutofillDriverFactoryTest {};

TEST_F(ContentAutofillDriverFactoryTest_WithTwoFrames, TwoDrivers) {}

// Test case with two frames, where the parameter selects one of them.
class ContentAutofillDriverFactoryTest_WithTwoFrames_PickOne
    : public ContentAutofillDriverFactoryTest_WithTwoFrames,
      public ::testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

// Tests that a driver is removed in RenderFrameDeleted().
TEST_P(ContentAutofillDriverFactoryTest_WithTwoFrames_PickOne,
       RenderFrameDeleted) {}

// Test case with one frame, with BFcache enabled or disabled depending on the
// parameter.
class ContentAutofillDriverFactoryTest_WithOrWithoutBfCacheAndIframes
    : public ContentAutofillDriverFactoryTest,
      public ::testing::WithParamInterface<std::tuple<bool>> {};

INSTANTIATE_TEST_SUITE_P();

// Tests that that a same-documentation navigation does not touch the factory's
// router.
TEST_P(ContentAutofillDriverFactoryTest_WithOrWithoutBfCacheAndIframes,
       SameDocumentNavigation) {}

// Tests that that a driver is 1:1 with RenderFrameHost, which might or might
// not change after a same-origin navigation.
TEST_P(ContentAutofillDriverFactoryTest_WithOrWithoutBfCacheAndIframes,
       SameOriginNavigation) {}

// Tests that that a driver is removed and replaced with a fresh one after a
// cross-origin navigation.
TEST_P(ContentAutofillDriverFactoryTest_WithOrWithoutBfCacheAndIframes,
       CrossOriginNavigation) {}

// Fixture for testing that Autofill is enabled in fenced frames.
class ContentAutofillDriverFactoryTest_FencedFrames
    : public ContentAutofillDriverFactoryTest {};

TEST_F(ContentAutofillDriverFactoryTest_FencedFrames,
       DisableAutofillWithinFencedFrame) {}

// Test fixture for the LifecycleState changes of ContentAutofillDriver.
class ContentAutofillDriverFactoryTestLifecycleState
    : public ContentAutofillDriverFactoryTest {};

// Two helper macros to make tests below more readable.
#define EXPECT_DRIVER_CREATED
#define EXPECT_LIFECYCLE_CHANGE

// Tests the lifecycle state changes on a same-document navigation.
TEST_F(ContentAutofillDriverFactoryTestLifecycleState, NavigateSameDocument) {}

// Tests the lifecycle state changes on a same-origin navigation.
// TODO(https://crbug.com/40615943): Remove this case when RenderDocument has
// fully launched, as it's almost identical to the cross-origin case.
TEST_F(ContentAutofillDriverFactoryTestLifecycleState, NavigateSameOrigin) {}

// Tests the lifecycle state changes on a cross-origin navigation.
TEST_F(ContentAutofillDriverFactoryTestLifecycleState, NavigateCrossOrigin) {}

// Tests the lifecycle state changes on a cross-origin navigation (or, more
// precisely, cross-RFH navigations).
TEST_F(ContentAutofillDriverFactoryTestLifecycleState, CloseTab) {}

// Tests the lifecycle state changes when
// 1. a navigation happens
// 2. the reverse navigation is served from the BFCache.
TEST_F(ContentAutofillDriverFactoryTestLifecycleState, NavigateBFCached) {}

// Tests the lifecycle state changes when
// 1. a frame is prerendered and
// 2. that frame is activated afterwards.
TEST_F(ContentAutofillDriverFactoryTestLifecycleState, NavigatePrerendering) {}

#undef EXPECT_LIFECYCLE_CHANGE
#undef EXPECT_DRIVER_CREATED

}  // namespace
}  // namespace autofill