This source file includes following definitions.
- setCurrentInputEventForTest
- show
- m_webViewClient
- SetUp
- TearDown
- getNavigationPolicyWithMouseEvent
- isNavigationPolicyPopup
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "config.h"
#include "WebFrame.h"
#include "WebFrameClient.h"
#include "WebInputEvent.h"
#include "WebView.h"
#include "WebViewClient.h"
#include "WebViewImpl.h"
#include "core/page/Chrome.h"
#include <gtest/gtest.h>
using namespace blink;
namespace blink {
void setCurrentInputEventForTest(const WebInputEvent* event)
{
WebViewImpl::m_currentInputEvent = event;
}
}
namespace {
class TestWebWidgetClient : public WebWidgetClient {
public:
~TestWebWidgetClient() { }
};
class TestWebViewClient : public WebViewClient {
public:
explicit TestWebViewClient(WebNavigationPolicy* target) : m_target(target) { }
~TestWebViewClient() { }
virtual void show(WebNavigationPolicy policy)
{
*m_target = policy;
}
private:
WebNavigationPolicy* m_target;
};
class TestWebFrameClient : public WebFrameClient {
public:
~TestWebFrameClient() { }
};
class GetNavigationPolicyTest : public testing::Test {
public:
GetNavigationPolicyTest()
: m_result(WebNavigationPolicyIgnore)
, m_webViewClient(&m_result)
{
}
protected:
virtual void SetUp()
{
m_webView = toWebViewImpl(WebView::create(&m_webViewClient));
m_mainFrame = WebFrame::create(&m_webFrameClient);
m_webView->setMainFrame(m_mainFrame);
m_chromeClientImpl = toChromeClientImpl(&m_webView->page()->chrome().client());
m_result = WebNavigationPolicyIgnore;
}
virtual void TearDown()
{
m_webView->close();
m_mainFrame->close();
}
WebNavigationPolicy getNavigationPolicyWithMouseEvent(int modifiers, WebMouseEvent::Button button, bool asPopup)
{
WebMouseEvent event;
event.modifiers = modifiers;
event.type = WebInputEvent::MouseUp;
event.button = button;
setCurrentInputEventForTest(&event);
m_chromeClientImpl->setScrollbarsVisible(!asPopup);
m_chromeClientImpl->show(WebCore::NavigationPolicyIgnore);
setCurrentInputEventForTest(0);
return m_result;
}
bool isNavigationPolicyPopup()
{
m_chromeClientImpl->show(WebCore::NavigationPolicyIgnore);
return m_result == WebNavigationPolicyNewPopup;
}
protected:
WebNavigationPolicy m_result;
TestWebViewClient m_webViewClient;
WebViewImpl* m_webView;
WebFrame* m_mainFrame;
TestWebFrameClient m_webFrameClient;
ChromeClientImpl* m_chromeClientImpl;
};
TEST_F(GetNavigationPolicyTest, LeftClick)
{
int modifiers = 0;
WebMouseEvent::Button button = WebMouseEvent::ButtonLeft;
bool asPopup = false;
EXPECT_EQ(WebNavigationPolicyNewForegroundTab,
getNavigationPolicyWithMouseEvent(modifiers, button, asPopup));
}
TEST_F(GetNavigationPolicyTest, LeftClickPopup)
{
int modifiers = 0;
WebMouseEvent::Button button = WebMouseEvent::ButtonLeft;
bool asPopup = true;
EXPECT_EQ(WebNavigationPolicyNewPopup,
getNavigationPolicyWithMouseEvent(modifiers, button, asPopup));
}
TEST_F(GetNavigationPolicyTest, ShiftLeftClick)
{
int modifiers = WebInputEvent::ShiftKey;
WebMouseEvent::Button button = WebMouseEvent::ButtonLeft;
bool asPopup = false;
EXPECT_EQ(WebNavigationPolicyNewWindow,
getNavigationPolicyWithMouseEvent(modifiers, button, asPopup));
}
TEST_F(GetNavigationPolicyTest, ShiftLeftClickPopup)
{
int modifiers = WebInputEvent::ShiftKey;
WebMouseEvent::Button button = WebMouseEvent::ButtonLeft;
bool asPopup = true;
EXPECT_EQ(WebNavigationPolicyNewPopup,
getNavigationPolicyWithMouseEvent(modifiers, button, asPopup));
}
TEST_F(GetNavigationPolicyTest, ControlOrMetaLeftClick)
{
#if OS(MACOSX)
int modifiers = WebInputEvent::MetaKey;
#else
int modifiers = WebInputEvent::ControlKey;
#endif
WebMouseEvent::Button button = WebMouseEvent::ButtonLeft;
bool asPopup = false;
EXPECT_EQ(WebNavigationPolicyNewBackgroundTab,
getNavigationPolicyWithMouseEvent(modifiers, button, asPopup));
}
TEST_F(GetNavigationPolicyTest, ControlOrMetaLeftClickPopup)
{
#if OS(MACOSX)
int modifiers = WebInputEvent::MetaKey;
#else
int modifiers = WebInputEvent::ControlKey;
#endif
WebMouseEvent::Button button = WebMouseEvent::ButtonLeft;
bool asPopup = true;
EXPECT_EQ(WebNavigationPolicyNewBackgroundTab,
getNavigationPolicyWithMouseEvent(modifiers, button, asPopup));
}
TEST_F(GetNavigationPolicyTest, ControlOrMetaAndShiftLeftClick)
{
#if OS(MACOSX)
int modifiers = WebInputEvent::MetaKey;
#else
int modifiers = WebInputEvent::ControlKey;
#endif
modifiers |= WebInputEvent::ShiftKey;
WebMouseEvent::Button button = WebMouseEvent::ButtonLeft;
bool asPopup = false;
EXPECT_EQ(WebNavigationPolicyNewForegroundTab,
getNavigationPolicyWithMouseEvent(modifiers, button, asPopup));
}
TEST_F(GetNavigationPolicyTest, ControlOrMetaAndShiftLeftClickPopup)
{
#if OS(MACOSX)
int modifiers = WebInputEvent::MetaKey;
#else
int modifiers = WebInputEvent::ControlKey;
#endif
modifiers |= WebInputEvent::ShiftKey;
WebMouseEvent::Button button = WebMouseEvent::ButtonLeft;
bool asPopup = true;
EXPECT_EQ(WebNavigationPolicyNewForegroundTab,
getNavigationPolicyWithMouseEvent(modifiers, button, asPopup));
}
TEST_F(GetNavigationPolicyTest, MiddleClick)
{
int modifiers = 0;
bool asPopup = false;
WebMouseEvent::Button button = WebMouseEvent::ButtonMiddle;
EXPECT_EQ(WebNavigationPolicyNewBackgroundTab,
getNavigationPolicyWithMouseEvent(modifiers, button, asPopup));
}
TEST_F(GetNavigationPolicyTest, MiddleClickPopup)
{
int modifiers = 0;
bool asPopup = true;
WebMouseEvent::Button button = WebMouseEvent::ButtonMiddle;
EXPECT_EQ(WebNavigationPolicyNewBackgroundTab,
getNavigationPolicyWithMouseEvent(modifiers, button, asPopup));
}
TEST_F(GetNavigationPolicyTest, NoToolbarsForcesPopup)
{
m_chromeClientImpl->setToolbarsVisible(false);
EXPECT_TRUE(isNavigationPolicyPopup());
m_chromeClientImpl->setToolbarsVisible(true);
EXPECT_FALSE(isNavigationPolicyPopup());
}
TEST_F(GetNavigationPolicyTest, NoStatusbarForcesPopup)
{
m_chromeClientImpl->setStatusbarVisible(false);
EXPECT_TRUE(isNavigationPolicyPopup());
m_chromeClientImpl->setStatusbarVisible(true);
EXPECT_FALSE(isNavigationPolicyPopup());
}
TEST_F(GetNavigationPolicyTest, NoMenubarForcesPopup)
{
m_chromeClientImpl->setMenubarVisible(false);
EXPECT_TRUE(isNavigationPolicyPopup());
m_chromeClientImpl->setMenubarVisible(true);
EXPECT_FALSE(isNavigationPolicyPopup());
}
TEST_F(GetNavigationPolicyTest, NotResizableForcesPopup)
{
m_chromeClientImpl->setResizable(false);
EXPECT_TRUE(isNavigationPolicyPopup());
m_chromeClientImpl->setResizable(true);
EXPECT_FALSE(isNavigationPolicyPopup());
}
}