#include "base/containers/contains.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/commands/command_service.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/permissions/active_tab_permission_granter.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/extensions_container.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_container.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/sessions/content/session_tab_helper.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/javascript_test_observer.h"
#include "extensions/browser/extension_action.h"
#include "extensions/browser/extension_action_manager.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/test_event_router_observer.h"
#include "extensions/common/api/extension_action/action_info.h"
#include "extensions/common/api/extension_action/action_info_test_util.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
#include "extensions/test/test_extension_dir.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "third_party/blink/public/common/switches.h"
WebContents;
namespace extensions {
namespace {
const char kId[] = …;
const char kAltShiftG[] = …;
const char kBasicsShortcutCommandName[] = …;
#if BUILDFLAG(IS_MAC)
const char kBookmarkKeybinding[] = "Command+D";
#else
const char kBookmarkKeybinding[] = …;
#endif
bool SendBookmarkKeyPressSync(Browser* browser) { … }
const char kMediaKeyTestCommand[] = …;
class DomMessageListener : public content::TestMessageHandler { … };
DomMessageListener::DomMessageListener(content::WebContents* web_contents)
: … { … }
DomMessageListener::~DomMessageListener() { … }
void DomMessageListener::Wait() { … }
void DomMessageListener::Clear() { … }
content::TestMessageHandler::MessageResponse DomMessageListener::HandleMessage(
const std::string& json) { … }
void DomMessageListener::Reset() { … }
void SetActionVisibleOnTab(Profile* profile,
const Extension& extension,
int tab_id) { … }
void SendKeyPressToAction(Browser* browser,
const Extension& extension,
ui::KeyboardCode keyboard_code,
const char* event_name,
bool expect_dispatch) { … }
const char* GetCommandKeyForActionType(ActionInfo::Type action_type) { … }
}
class CommandsApiTest : public ExtensionApiTest { … };
class IncognitoCommandsApiTest : public CommandsApiTest,
public testing::WithParamInterface<bool> { … };
class ActionCommandsApiTest
: public CommandsApiTest,
public testing::WithParamInterface<ActionInfo::Type> { … };
IN_PROC_BROWSER_TEST_F(CommandsApiTest, Basic) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest, InactivePageActionDoesntTrigger) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest, UnpinnedPageActionTriggers) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageActionKeyUpdated) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest, ActionKeyUpdated) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageActionOverrideChromeShortcut) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest, SynthesizedCommand) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest, DontOverwriteSystemShortcuts) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest,
OverwriteBookmarkShortcutByUserOverridesWebKeybinding) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_AllowDuplicatedMediaKeys …
#else
#define MAYBE_AllowDuplicatedMediaKeys …
#endif
IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest, ShortcutAddedOnUpdate) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest, ShortcutChangedOnUpdate) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest, ShortcutRemovedOnUpdate) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest,
ShortcutAddedOnUpdateAfterBeingAssignedByUser) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest,
ShortcutChangedOnUpdateAfterBeingReassignedByUser) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest,
MediaKeyShortcutChangedOnUpdateAfterBeingReassignedByUser) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest,
ShortcutRemovedOnUpdateAfterBeingReassignedByUser) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH) && !defined(NDEBUG)
#define MAYBE_ContinuePropagation …
#else
#define MAYBE_ContinuePropagation …
#endif
IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_ContinuePropagation) { … }
#if BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(CommandsApiTest, ChromeOSConversions) {
ASSERT_TRUE(embedded_test_server()->Start());
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
ASSERT_TRUE(RunExtensionTest("keybinding/chromeos_conversions")) << message_;
ASSERT_TRUE(ui_test_utils::NavigateToURL(
browser(), embedded_test_server()->GetURL("/extensions/test_file.txt")));
ResultCatcher catcher;
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_LEFT, false,
true, false, true));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_UP, false,
true, false, true));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_RIGHT, false,
true, false, true));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_DOWN, false,
true, false, true));
ASSERT_TRUE(catcher.GetNextResult());
}
#endif
IN_PROC_BROWSER_TEST_F(CommandsApiTest, AddRemoveAddComponentExtension) { … }
IN_PROC_BROWSER_TEST_F(CommandsApiTest, TabParameter) { … }
IN_PROC_BROWSER_TEST_P(IncognitoCommandsApiTest, IncognitoMode) { … }
IN_PROC_BROWSER_TEST_P(ActionCommandsApiTest,
TriggeringCommandTriggersListener) { … }
IN_PROC_BROWSER_TEST_P(ActionCommandsApiTest, GetAllReturnsActionCommand) { … }
IN_PROC_BROWSER_TEST_P(ActionCommandsApiTest, TriggeringCommandTriggersPopup) { … }
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
}