#include "extensions/browser/renderer_startup_helper.h"
#include "base/containers/contains.h"
#include "base/memory/raw_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "components/crx_file/id_util.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_factory.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/extensions_test.h"
#include "extensions/browser/test_extensions_browser_client.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/mojom/host_id.mojom.h"
#include "extensions/common/mojom/renderer.mojom.h"
#include "extensions/common/permissions/permissions_data.h"
#include "mojo/public/cpp/bindings/associated_receiver_set.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/testing_pref_service.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "chromeos/startup/browser_init_params.h"
#endif
namespace extensions {
class RendererStartupHelperInterceptor : public RendererStartupHelper,
public mojom::Renderer { … };
class RendererStartupHelperTest : public ExtensionsTest { … };
TEST_F(RendererStartupHelperTest, NormalExtensionLifecycle) { … }
TEST_F(RendererStartupHelperTest, EnabledBeforeProcessInitialized) { … }
TEST_F(RendererStartupHelperTest, LoadTheme) { … }
TEST_F(RendererStartupHelperTest, ExtensionInIncognitoRenderer) { … }
TEST_F(RendererStartupHelperTest, PlatformAppInIncognitoRenderer) { … }
#if BUILDFLAG(IS_CHROMEOS)
class RendererStartupHelperTestCaptivePortalPopupWindow
: public RendererStartupHelperTest {
public:
RendererStartupHelperTestCaptivePortalPopupWindow() = default;
~RendererStartupHelperTestCaptivePortalPopupWindow() override = default;
void SetUp() override {
#if BUILDFLAG(IS_CHROMEOS_ASH)
feature_list_.InitAndEnableFeature(
chromeos::features::kCaptivePortalPopupWindow);
#elif BUILDFLAG(IS_CHROMEOS_LACROS)
crosapi::mojom::BrowserInitParamsPtr init_params =
chromeos::BrowserInitParams::GetForTests()->Clone();
init_params->is_captive_portal_popup_window_enabled = true;
chromeos::BrowserInitParams::SetInitParamsForTests(std::move(init_params));
#endif
RendererStartupHelperTest::SetUp();
static_cast<TestingPrefServiceSimple*>(pref_service())
->registry()
->RegisterBooleanPref(chromeos::prefs::kCaptivePortalSignin, false);
}
private:
base::test::ScopedFeatureList feature_list_;
};
TEST_F(RendererStartupHelperTestCaptivePortalPopupWindow,
ExtensionInCaptivePortalSigninRenderer) {
ASSERT_TRUE(pref_service());
pref_service()->SetBoolean(chromeos::prefs::kCaptivePortalSignin, true);
extensions_browser_client()->set_pref_service_for_context(incognito_context(),
pref_service());
EXPECT_FALSE(IsProcessInitialized(incognito_render_process_host_.get()));
SimulateRenderProcessCreated(incognito_render_process_host_.get());
EXPECT_TRUE(IsProcessInitialized(incognito_render_process_host_.get()));
helper_->clear_extensions();
AddExtensionToRegistry(extension_);
helper_->OnExtensionLoaded(*extension_);
EXPECT_TRUE(util::IsIncognitoEnabled(extension_->id(), incognito_context()));
EXPECT_TRUE(IsExtensionLoaded(*extension_));
}
#endif
}