#include "content/browser/keyboard_lock_browsertest.h"
#include <string>
#include "base/metrics/histogram_base.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "content/browser/keyboard_lock/keyboard_lock_metrics.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/content_mock_cert_verifier.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "content/test/content_browser_test_utils_internal.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "third_party/blink/public/mojom/frame/fullscreen.mojom.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/events/keycodes/keyboard_code_conversion.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/native_widget_types.h"
#ifdef USE_AURA
#include "content/browser/renderer_host/render_widget_host_view_aura.h"
#include "content/browser/web_contents/web_contents_view_aura.h"
#endif
namespace content {
namespace {
constexpr char kFullscreenFramePath[] = …;
constexpr char kHelloFramePath[] = …;
constexpr char kInputFieldFramePath[] = …;
constexpr char kCrossSiteFramePath[] = …;
constexpr char kCrossSiteTopLevelDomain[] = …;
constexpr char kChildIframeName_0[] = …;
constexpr char kChildIframeName_1[] = …;
constexpr char kChildIframeName_2[] = …;
constexpr char kCrossSiteChildDomain1[] = …;
constexpr char kCrossSiteChildDomain2[] = …;
constexpr char kKeyboardLockMethodExistanceCheck[] = …;
constexpr char kKeyboardLockMethodCallWithAllKeys[] = …;
constexpr char kKeyboardLockMethodCallWithSomeKeys[] = …;
constexpr char kKeyboardLockMethodCallWithAllInvalidKeys[] = …;
constexpr char kKeyboardLockMethodCallWithSomeInvalidKeys[] = …;
constexpr char kKeyboardUnlockMethodCall[] = …;
constexpr char kFocusInputFieldScript[] = …;
void SimulateKeyPress(WebContents* web_contents,
RenderFrameHost* event_recipient,
const std::string& code_string,
const std::string& expected_result) { … }
#if defined(USE_AURA)
bool g_window_has_focus = …;
class TestRenderWidgetHostView : public RenderWidgetHostViewAura { … };
#endif
class FakeKeyboardLockWebContentsDelegate : public WebContentsDelegate { … };
void FakeKeyboardLockWebContentsDelegate::EnterFullscreenModeForTab(
RenderFrameHost* requesting_frame,
const blink::mojom::FullscreenOptions& options) { … }
void FakeKeyboardLockWebContentsDelegate::ExitFullscreenModeForTab(
WebContents* web_contents) { … }
bool FakeKeyboardLockWebContentsDelegate::IsFullscreenForTabOrPending(
const WebContents* web_contents) { … }
void FakeKeyboardLockWebContentsDelegate::RequestKeyboardLock(
WebContents* web_contents,
bool esc_key_locked) { … }
void FakeKeyboardLockWebContentsDelegate::CancelKeyboardLockRequest(
WebContents* web_contents) { … }
}
#if defined(USE_AURA)
void SetWindowFocusForKeyboardLockBrowserTests(bool is_focused) { … }
void InstallCreateHooksForKeyboardLockBrowserTests() { … }
#endif
class KeyboardLockBrowserTest : public ContentBrowserTest { … };
KeyboardLockBrowserTest::KeyboardLockBrowserTest()
: … { … }
KeyboardLockBrowserTest::~KeyboardLockBrowserTest() = default;
void KeyboardLockBrowserTest::SetUp() { … }
void KeyboardLockBrowserTest::SetUpCommandLine(
base::CommandLine* command_line) { … }
void KeyboardLockBrowserTest::SetUpOnMainThread() { … }
void KeyboardLockBrowserTest::SetUpInProcessBrowserTestFixture() { … }
void KeyboardLockBrowserTest::TearDownInProcessBrowserTestFixture() { … }
bool KeyboardLockBrowserTest::KeyboardLockApiExists() { … }
void KeyboardLockBrowserTest::NavigateToTestURL(const GURL& gurl) { … }
void KeyboardLockBrowserTest::RequestKeyboardLock(
const base::Location& from_here,
bool lock_all_keys ) { … }
void KeyboardLockBrowserTest::CancelKeyboardLock(
const base::Location& from_here) { … }
void KeyboardLockBrowserTest::EnterFullscreen(const base::Location& from_here) { … }
void KeyboardLockBrowserTest::ExitFullscreen(const base::Location& from_here) { … }
void KeyboardLockBrowserTest::FocusContent(const base::Location& from_here) { … }
void KeyboardLockBrowserTest::BlurContent(const base::Location& from_here) { … }
void KeyboardLockBrowserTest::VerifyKeyboardLockState(
const base::Location& from_here) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, SingleLockCall) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, SingleLockCallForSomeKeys) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, SingleLockWithCancelCall) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, LockCalledBeforeFullscreen) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, LockCalledAfterFullscreen) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
LockAndCancelCyclingNoActivation) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
LockAndCancelCyclingInFullscreen) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, CancelInFullscreen) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, EnterAndExitFullscreenCycling) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, GainAndLoseFocusInWindowMode) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, EnterFullscreenWithoutFocus) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
GainAndLoseFocusCyclingInFullscreen) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, CancelWithoutLock) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, MultipleLockCalls) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, MultipleCancelCalls) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, LockCallWithAllInvalidKeys) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, LockCallWithSomeInvalidKeys) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
ValidLockCallFollowedByInvalidLockCall) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
KeyboardLockNotAllowedForSameOriginIFrame) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
KeyboardLockNotAllowedForCrossOriginIFrame) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
KeyboardUnlockedWhenNavigatingToSameUrl) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
KeyboardUnlockedWhenNavigatingAway) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
KeyboardRemainsLockedWhenIframeNavigates) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
CrossOriginIFrameReceivesInputWhenFocused) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
LockRequestBeforeCrossOriginIFrameIsFullscreen) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
LockRequestWhileCrossOriginIFrameIsFullscreen) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
LockRequestFailsFromInnerWebContents) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest,
InnerContentsFullscreenBehavior) { … }
IN_PROC_BROWSER_TEST_F(KeyboardLockBrowserTest, InnerContentsInputBehavior) { … }
}