chromium/chrome/browser/ui/keyboard_lock_interactive_browsertest.cc

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

#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
#include "chrome/browser/ui/fullscreen_keyboard_browsertest_base.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/safe_browsing/core/common/features.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "third_party/blink/public/common/features.h"
#include "ui/base/ui_base_features.h"

#if BUILDFLAG(IS_MAC)
#include "ui/base/test/scoped_fake_nswindow_fullscreen.h"
#endif

namespace {

// Javascript snippet used to verify the keyboard lock API exists.
// TODO(crbug.com/40501396): These checks can be removed once the blink flag for
// the API is removed.
constexpr char kKeyboardLockMethodExistanceCheck[] =;

// Javascript snippet used to request that all keys be locked.
constexpr char kKeyboardLockMethodCallWithAllKeys[] =;

// Javascript snippet used to request that the 'T' key be locked.  This means
// The Ctrl+T browser shortcut will be intercepted, but other shortcuts should
// continue to function.
constexpr char kKeyboardLockMethodCallWithSomeKeys[] =;

// Javascript snippet used to request that the 'escape' key be locked.  This
// means that all browser shortcuts will continue to work however the user would
// need to press and hold escape to exit tab-initiated fullscreen.
constexpr char kKeyboardLockMethodCallWithEscapeKey[] =;

// Javascript snippet used to release all locked keys.
constexpr char kKeyboardUnlockMethodCall[] =;

// Path to a simple html fragment, used for navigation tests.
constexpr char kSimplePageHTML[] =;

// The test data folder path used for download tests.
constexpr char kDownloadFolder[] =;

// Name of the test file used for download tests.
constexpr char kDownloadFile[] =;

}  // namespace

// Test fixture which sets up the environment and provides helper methods for
// testing keyboard lock functionality at the browser UI level.
class KeyboardLockInteractiveBrowserTest
    : public FullscreenKeyboardBrowserTestBase {};

KeyboardLockInteractiveBrowserTest::KeyboardLockInteractiveBrowserTest()
    :{}

KeyboardLockInteractiveBrowserTest::~KeyboardLockInteractiveBrowserTest() =
    default;

void KeyboardLockInteractiveBrowserTest::SetUpCommandLine(
    base::CommandLine* command_line) {}

void KeyboardLockInteractiveBrowserTest::SetUpOnMainThread() {}

net::EmbeddedTestServer*
KeyboardLockInteractiveBrowserTest::GetEmbeddedTestServer() {}

bool KeyboardLockInteractiveBrowserTest::KeyboardLockApiExists() {}

bool KeyboardLockInteractiveBrowserTest::IsKeyboardLockActive() {}

bool KeyboardLockInteractiveBrowserTest::IsKeyboardLockRequestRegistered() {}

bool KeyboardLockInteractiveBrowserTest::RequestKeyboardLock(
    bool lock_all_keys /*=true*/) {}

bool KeyboardLockInteractiveBrowserTest::CancelKeyboardLock() {}

#if BUILDFLAG(IS_MAC)
void KeyboardLockInteractiveBrowserTest::ExitFullscreen() {
  fake_fullscreen_.reset();
}
#endif

bool KeyboardLockInteractiveBrowserTest::DisablePreventDefaultOnTestPage() {}

// https://crbug.com/1382717 Flaky on Linux
#if BUILDFLAG(IS_LINUX)
#define MAYBE_RequestedButNotActive
#else
#define MAYBE_RequestedButNotActive
#endif
IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       MAYBE_RequestedButNotActive) {}

IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       ActiveWithAllKeysLocked) {}

// https://crbug.com/1382699 Flaky on Linux
#if BUILDFLAG(IS_LINUX)
#define MAYBE_ActiveWithSomeKeysLocked
#else
#define MAYBE_ActiveWithSomeKeysLocked
#endif
IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       MAYBE_ActiveWithSomeKeysLocked) {}

// https://crbug.com/1108391 Flakey on ChromeOS.
// https://crbug.com/1121172 Also flaky on Lacros and Mac
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC)
#define MAYBE_SubsequentLockCallSupersedesPreviousCall
#else
#define MAYBE_SubsequentLockCallSupersedesPreviousCall
#endif
IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       MAYBE_SubsequentLockCallSupersedesPreviousCall) {}

#if BUILDFLAG(IS_MAC)
// TODO(crbug.com/41385780): Enable once browser fullscreen is reliable in
// tests.
#define MAYBE_RequestedButNotActiveInBrowserFullscreen
#else
#define MAYBE_RequestedButNotActiveInBrowserFullscreen
#endif
IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       MAYBE_RequestedButNotActiveInBrowserFullscreen) {}

IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       CancelActiveKeyboardLockInFullscreen) {}

// TODO(crbug.com/40827037): Flaky on mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_CancelActiveKeyboardLockBeforeFullscreen
#else
#define MAYBE_CancelActiveKeyboardLockBeforeFullscreen
#endif
IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       MAYBE_CancelActiveKeyboardLockBeforeFullscreen) {}

IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       PressEscapeExitsFullscreenWhenEscNotLocked) {}

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// BringBrowserWindowToFront hangs on Linux: http://crbug.com/163931
#define MAYBE_GainAndLoseFocusInWindowMode
#else
#define MAYBE_GainAndLoseFocusInWindowMode
#endif
IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       MAYBE_GainAndLoseFocusInWindowMode) {}

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// BringBrowserWindowToFront hangs on Linux: http://crbug.com/163931
#define MAYBE_GainAndLoseFocusInFullscreen
#else
#define MAYBE_GainAndLoseFocusInFullscreen
#endif
IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       MAYBE_GainAndLoseFocusInFullscreen) {}

IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       KeyboardUnlockedWhenNavigatingToSameUrl) {}

IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       KeyboardUnlockedWhenNavigatingAway) {}

IN_PROC_BROWSER_TEST_F(KeyboardLockInteractiveBrowserTest,
                       DownloadNavigationDoesNotUnlock) {}