This source file includes following definitions.
- ShouldRunPopupTest
- 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
- IN_PROC_BROWSER_TEST_F
#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/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.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 "extensions/browser/extension_system.h"
#include "extensions/common/permissions/permissions_data.h"
namespace extensions {
namespace {
class BrowserActionInteractiveTest : public ExtensionApiTest {
public:
BrowserActionInteractiveTest() {}
virtual ~BrowserActionInteractiveTest() {}
protected:
bool ShouldRunPopupTest() {
#if defined(OS_WIN) && !defined(NDEBUG)
return false;
#elif defined(OS_MACOSX)
return false;
#else
return true;
#endif
}
};
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TestOpenPopup) {
if (!ShouldRunPopupTest())
return;
BrowserActionTestUtil browserActionBar = BrowserActionTestUtil(browser());
ExtensionTestMessageListener listener("ready", true);
{
content::WindowedNotificationObserver frame_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup",
"open_popup_succeeds.html")) << message_;
frame_observer.Wait();
EXPECT_TRUE(browserActionBar.HasPopup());
browserActionBar.HidePopup();
}
EXPECT_TRUE(listener.WaitUntilSatisfied());
Browser* new_browser = NULL;
{
content::WindowedNotificationObserver frame_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
new_browser = chrome::FindBrowserWithWebContents(
browser()->OpenURL(content::OpenURLParams(
GURL("about:"), content::Referrer(), NEW_WINDOW,
content::PAGE_TRANSITION_TYPED, false)));
#if defined(OS_WIN)
browserActionBar.SetIconVisibilityCount(0);
#endif
frame_observer.Wait();
}
EXPECT_TRUE(new_browser != NULL);
#if !(defined(OS_LINUX) && !defined(USE_AURA))
ResultCatcher catcher;
{
content::WindowedNotificationObserver frame_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
listener.Reply("");
frame_observer.Wait();
EXPECT_TRUE(BrowserActionTestUtil(new_browser).HasPopup());
}
ASSERT_TRUE(catcher.GetNextResult()) << message_;
#endif
}
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TestOpenPopupIncognito) {
if (!ShouldRunPopupTest())
return;
content::WindowedNotificationObserver frame_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup",
"open_popup_succeeds.html",
kFlagEnableIncognito | kFlagUseIncognito))
<< message_;
frame_observer.Wait();
#if !(defined(OS_LINUX) && !defined(USE_AURA))
EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup());
#endif
EXPECT_TRUE(BrowserActionTestUtil(BrowserList::GetInstance(
chrome::GetActiveDesktop())->GetLastActive()).HasPopup());
}
#if defined(OS_LINUX)
#define MAYBE_TestOpenPopupDoesNotCloseOtherPopups DISABLED_TestOpenPopupDoesNotCloseOtherPopups
#else
#define MAYBE_TestOpenPopupDoesNotCloseOtherPopups TestOpenPopupDoesNotCloseOtherPopups
#endif
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
MAYBE_TestOpenPopupDoesNotCloseOtherPopups) {
if (!ShouldRunPopupTest())
return;
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"browser_action/popup")));
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
ExtensionTestMessageListener listener("ready", true);
ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup",
"open_popup_fails.html")) << message_;
EXPECT_TRUE(listener.WaitUntilSatisfied());
content::WindowedNotificationObserver frame_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
BrowserActionTestUtil(browser()).Press(0);
frame_observer.Wait();
EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup());
ResultCatcher catcher;
listener.Reply("");
ASSERT_TRUE(catcher.GetNextResult()) << message_;
}
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
TestOpenPopupDoesNotGrantTabPermissions) {
if (!ShouldRunPopupTest())
return;
content::WindowedNotificationObserver frame_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup",
"open_popup_succeeds.html")) << message_;
frame_observer.Wait();
ExtensionService* service = extensions::ExtensionSystem::Get(
browser()->profile())->extension_service();
ASSERT_FALSE(PermissionsData::HasAPIPermissionForTab(
service->GetExtensionById(last_loaded_extension_id(), false),
SessionID::IdForTab(browser()->tab_strip_model()->GetActiveWebContents()),
APIPermission::kTab));
}
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, BrowserClickClosesPopup1) {
if (!ShouldRunPopupTest())
return;
content::WindowedNotificationObserver frame_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup",
"open_popup_succeeds.html")) << message_;
frame_observer.Wait();
EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup());
ui_test_utils::ClickOnView(browser(), VIEW_ID_OMNIBOX);
EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup());
}
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, BrowserClickClosesPopup2) {
if (!ShouldRunPopupTest())
return;
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"browser_action/popup")));
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
content::WindowedNotificationObserver frame_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
BrowserActionTestUtil(browser()).Press(0);
frame_observer.Wait();
EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup());
ui_test_utils::ClickOnView(browser(), VIEW_ID_OMNIBOX);
EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup());
}
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TabSwitchClosesPopup) {
if (!ShouldRunPopupTest())
return;
chrome::NewTab(browser());
ASSERT_EQ(2, browser()->tab_strip_model()->count());
content::WindowedNotificationObserver frame_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup",
"open_popup_succeeds.html")) << message_;
frame_observer.Wait();
EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup());
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_TAB, true, false, false, false));
EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup());
}
}
}