#include <utility>
#include <vector>
#include "base/feature_list.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/site_isolation/chrome_site_per_process_test.h"
#include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/prefs/pref_service.h"
#include "components/spellcheck/browser/pref_names.h"
#include "components/spellcheck/common/spellcheck.mojom.h"
#include "components/spellcheck/common/spellcheck_features.h"
#include "components/spellcheck/spellcheck_buildflags.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#if BUILDFLAG(HAS_SPELLCHECK_PANEL)
#include "chrome/browser/spellchecker/test/spellcheck_panel_browsertest_helper.h"
#include "components/spellcheck/common/spellcheck_panel.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
#endif
class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost { … };
class SpellCheckBrowserTestHelper { … };
class ChromeSitePerProcessSpellCheckTest : public ChromeSitePerProcessTest { … };
IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessSpellCheckTest,
OOPIFSpellCheckTest) { … }
IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessSpellCheckTest,
OOPIFDisabledSpellCheckTest) { … }
#if BUILDFLAG(HAS_SPELLCHECK_PANEL)
IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessSpellCheckTest,
OOPIFSpellCheckPanelTest) {
spellcheck::SpellCheckPanelBrowserTestHelper test_helper;
GURL main_url(embedded_test_server()->GetURL(
"a.com", "/page_with_contenteditable_in_cross_site_subframe.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), main_url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
content::RenderFrameHost* cross_site_subframe =
ChildFrameAt(web_contents->GetPrimaryMainFrame(), 0);
EXPECT_TRUE(cross_site_subframe->IsCrossProcessSubframe());
mojo::Remote<spellcheck::mojom::SpellCheckPanel> spell_check_panel_client;
cross_site_subframe->GetRemoteInterfaces()->GetInterface(
spell_check_panel_client.BindNewPipeAndPassReceiver());
spell_check_panel_client->ToggleSpellPanel(false);
test_helper.RunUntilBind();
spellcheck::SpellCheckMockPanelHost* host =
test_helper.GetSpellCheckMockPanelHostForProcess(
cross_site_subframe->GetProcess());
EXPECT_TRUE(host->SpellingPanelVisible());
}
#endif
#if BUILDFLAG(IS_WIN) && BUILDFLAG(USE_BROWSER_SPELLCHECKER)
class ChromeSitePerProcessSpellCheckTestDelayInit
: public ChromeSitePerProcessSpellCheckTest {
public:
ChromeSitePerProcessSpellCheckTestDelayInit() = default;
void SetUp() override {
feature_list_.InitAndEnableFeature(
spellcheck::kWinDelaySpellcheckServiceInit);
ChromeSitePerProcessTest::SetUp();
}
};
IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessSpellCheckTestDelayInit,
OOPIFSpellCheckTest) {
RunOOPIFSpellCheckTest();
}
IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessSpellCheckTestDelayInit,
OOPIFDisabledSpellCheckTest) {
RunOOPIFDisabledSpellCheckTest();
}
#endif