This source file includes following definitions.
- GetBrowserActionsBar
- IsGrantedForTab
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/command_line.h"
#include "chrome/browser/extensions/active_tab_permission_granter.h"
#include "chrome/browser/extensions/browser_action_test_util.h"
#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/common/extension.h"
#include "extensions/common/feature_switch.h"
#include "extensions/common/permissions/permissions_data.h"
using content::WebContents;
namespace extensions {
class CommandsApiTest : public ExtensionApiTest {
public:
CommandsApiTest() {}
virtual ~CommandsApiTest() {}
protected:
BrowserActionTestUtil GetBrowserActionsBar() {
return BrowserActionTestUtil(browser());
}
bool IsGrantedForTab(const Extension* extension,
const content::WebContents* web_contents) {
return PermissionsData::HasAPIPermissionForTab(
extension,
SessionID::IdForTab(web_contents),
APIPermission::kTab);
}
};
IN_PROC_BROWSER_TEST_F(CommandsApiTest, Basic) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
ASSERT_TRUE(RunExtensionTest("keybinding/conflicting")) << message_;
ASSERT_EQ(2, GetBrowserActionsBar().NumberOfBrowserActions());
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/extensions/test_file.txt"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(tab);
EXPECT_FALSE(IsGrantedForTab(extension, tab));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_F, true, true, false, false));
EXPECT_TRUE(IsGrantedForTab(extension, tab));
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"setInterval(function(){"
" if(document.body.bgColor == 'red'){"
" window.domAutomationController.send(true)}}, 100)",
&result));
ASSERT_TRUE(result);
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_Y, true, true, false, false));
result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"setInterval(function(){"
" if(document.body.bgColor == 'blue'){"
" window.domAutomationController.send(true)}}, 100)",
&result));
ASSERT_TRUE(result);
}
#if defined(OS_MACOSX) || defined(OS_WIN)
#define MAYBE_PageAction PageAction
#else
#define MAYBE_PageAction DISABLED_PageAction
#endif
IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_PageAction) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
{
ResultCatcher catcher;
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/extensions/test_file.txt"));
ASSERT_TRUE(catcher.GetNextResult());
}
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
int tab_id = SessionTabHelper::FromWebContents(
browser()->tab_strip_model()->GetActiveWebContents())->session_id().id();
ExtensionAction* action =
ExtensionActionManager::Get(browser()->profile())->
GetPageAction(*extension);
ASSERT_TRUE(action);
EXPECT_EQ("Make this page red", action->GetTitle(tab_id));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_F, false, true, true, false));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"setInterval(function(){"
" if(document.body.bgColor == 'red'){"
" window.domAutomationController.send(true)}}, 100)",
&result));
ASSERT_TRUE(result);
}
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
#define MAYBE_SynthesizedCommand DISABLED_SynthesizedCommand
#else
#define MAYBE_SynthesizedCommand SynthesizedCommand
#endif
IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_SynthesizedCommand) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(RunExtensionTest("keybinding/synthesized")) << message_;
}
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
#define MAYBE_DontOverwriteSystemShortcuts DISABLED_DontOverwriteSystemShortcuts
#else
#define MAYBE_DontOverwriteSystemShortcuts DontOverwriteSystemShortcuts
#endif
IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_DontOverwriteSystemShortcuts) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
ASSERT_TRUE(RunExtensionTest("keybinding/dont_overwrite_system")) << message_;
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/extensions/test_file.txt"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(tab);
{
ResultCatcher catcher;
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_F, false, true, true, false));
ASSERT_TRUE(catcher.GetNextResult());
}
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"setInterval(function() {"
" if (document.body.bgColor == 'blue') {"
" window.domAutomationController.send(true)}}, 100)",
&result));
ASSERT_TRUE(result);
#if defined(OS_MACOSX)
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_D, false, false, false, true));
#else
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_D, true, false, false, false));
#endif
result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"setInterval(function() {"
" if (document.body.bgColor == 'blue') {"
" window.domAutomationController.send(true)}}, 100)",
&result));
ASSERT_TRUE(result);
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_F, true, false, false, false));
result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"setInterval(function() {"
" if (document.body.bgColor == 'blue') {"
" window.domAutomationController.send(true)}}, 100)",
&result));
ASSERT_TRUE(result);
}
IN_PROC_BROWSER_TEST_F(CommandsApiTest, OverwriteBookmarkShortcut) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
"--enable-override-bookmarks-ui",
"1");
ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut"))
<< message_;
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/extensions/test_file.txt"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(tab);
{
ResultCatcher catcher;
#if defined(OS_MACOSX)
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_D, false, false, false, true));
#else
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_D, true, false, false, false));
#endif
ASSERT_TRUE(catcher.GetNextResult());
}
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"setInterval(function() {"
" if (document.body.bgColor == 'green') {"
" window.domAutomationController.send(true)}}, 100)",
&result));
ASSERT_TRUE(result);
}
#if defined(OS_WIN)
#define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys
#else
#define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys
#endif
IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) {
ResultCatcher catcher;
ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_0"))
<< message_;
ASSERT_TRUE(catcher.GetNextResult());
ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_1"))
<< message_;
ASSERT_TRUE(catcher.GetNextResult());
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_MEDIA_STOP, false, false, false, false));
ASSERT_TRUE(catcher.GetNextResult());
ASSERT_TRUE(catcher.GetNextResult());
}
}