This source file includes following definitions.
- userAgentOverride
- setUserAgentOverride
- SetUp
- TearDown
- setUserAgentOverride
- userAgent
- TEST_F
#include "config.h"
#include "FrameLoaderClientImpl.h"
#include "WebFrameClient.h"
#include "WebFrameImpl.h"
#include "WebView.h"
#include "core/loader/FrameLoader.h"
#include "platform/weborigin/KURL.h"
#include "wtf/text/CString.h"
#include "wtf/text/WTFString.h"
#include <gtest/gtest.h>
using namespace blink;
namespace {
class TestWebFrameClient : public WebFrameClient {
public:
WebString userAgentOverride(WebLocalFrame* frame, const WebURL& url) OVERRIDE
{
if (m_userAgentOverride.isEmpty())
return WebString();
return m_userAgentOverride;
}
void setUserAgentOverride(const WebString& userAgent)
{
m_userAgentOverride = userAgent;
}
private:
WebString m_userAgentOverride;
};
class FrameLoaderClientImplTest : public testing::Test {
public:
void SetUp()
{
m_webView = WebView::create(0);
m_mainFrame = WebFrame::create(&m_webFrameClient);
m_webView->setMainFrame(m_mainFrame);
m_frameLoaderClientImpl = toFrameLoaderClientImpl(toWebFrameImpl(m_webView->mainFrame())->frame()->loader().client());
}
void TearDown()
{
m_webView->close();
m_mainFrame->close();
}
void setUserAgentOverride(const WebString& userAgent)
{
return m_webFrameClient.setUserAgentOverride(userAgent);
}
const WebString userAgent()
{
WebCore::KURL dummyURL(WebCore::ParsedURLString, "about:blank");
WTF::CString userAgent = m_frameLoaderClientImpl->userAgent(dummyURL).utf8();
return WebString::fromUTF8(userAgent.data(), userAgent.length());
}
protected:
TestWebFrameClient m_webFrameClient;
FrameLoaderClientImpl* m_frameLoaderClientImpl;
WebView* m_webView;
WebFrame* m_mainFrame;
};
TEST_F(FrameLoaderClientImplTest, UserAgentOverride)
{
const WebString defaultUserAgent = userAgent();
const WebString override = WebString::fromUTF8("dummy override");
setUserAgentOverride(override);
EXPECT_TRUE(override.equals(userAgent()));
setUserAgentOverride(WebString());
EXPECT_TRUE(defaultUserAgent.equals(userAgent()));
}
}