This source file includes following definitions.
- PostThis
- run
- defaultWebFrameClient
- defaultWebViewClient
- loadFrame
- runPendingTasks
- initialize
- initializeAndLoad
- reset
- createChildFrame
- frameDetached
#include "config.h"
#include "FrameTestHelpers.h"
#include "URLTestHelpers.h"
#include "wtf/StdLibExtras.h"
#include "WebFrameImpl.h"
#include "WebSettings.h"
#include "WebViewClient.h"
#include "public/platform/Platform.h"
#include "public/platform/WebString.h"
#include "public/platform/WebThread.h"
#include "public/platform/WebURLRequest.h"
#include "public/platform/WebURLResponse.h"
#include "public/platform/WebUnitTestSupport.h"
namespace blink {
namespace FrameTestHelpers {
namespace {
class QuitTask : public WebThread::Task {
public:
void PostThis(WebCore::Timer<QuitTask>*)
{
Platform::current()->currentThread()->postTask(this);
}
virtual void run()
{
Platform::current()->currentThread()->exitRunLoop();
}
};
WebFrameClient* defaultWebFrameClient()
{
DEFINE_STATIC_LOCAL(TestWebFrameClient, client, ());
return &client;
}
WebViewClient* defaultWebViewClient()
{
DEFINE_STATIC_LOCAL(WebViewClient, client, ());
return &client;
}
}
void loadFrame(WebFrame* frame, const std::string& url)
{
WebURLRequest urlRequest;
urlRequest.initialize();
urlRequest.setURL(URLTestHelpers::toKURL(url));
frame->loadRequest(urlRequest);
}
void runPendingTasks()
{
WebCore::Timer<QuitTask> quitOnTimeout(new QuitTask, &QuitTask::PostThis);
quitOnTimeout.startOneShot(0, FROM_HERE);
Platform::current()->currentThread()->enterRunLoop();
}
WebViewHelper::WebViewHelper()
: m_webView(0)
{
}
WebViewHelper::~WebViewHelper()
{
reset();
}
WebViewImpl* WebViewHelper::initialize(bool enableJavascript, WebFrameClient* webFrameClient, WebViewClient* webViewClient, void (*updateSettingsFunc)(WebSettings*))
{
reset();
if (!webFrameClient)
webFrameClient = defaultWebFrameClient();
if (!webViewClient)
webViewClient = defaultWebViewClient();
m_webView = WebViewImpl::create(webViewClient);
m_webView->settings()->setJavaScriptEnabled(enableJavascript);
if (updateSettingsFunc) {
updateSettingsFunc(m_webView->settings());
} else {
m_webView->settings()->setDeviceSupportsMouse(false);
m_webView->settings()->setForceCompositingMode(true);
}
m_webView->setMainFrame(WebFrameImpl::create(webFrameClient));
return m_webView;
}
WebViewImpl* WebViewHelper::initializeAndLoad(const std::string& url, bool enableJavascript, WebFrameClient* webFrameClient, WebViewClient* webViewClient, void (*updateSettingsFunc)(WebSettings*))
{
initialize(enableJavascript, webFrameClient, webViewClient, updateSettingsFunc);
loadFrame(webView()->mainFrame(), url);
Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
return webViewImpl();
}
void WebViewHelper::reset()
{
if (m_webView) {
m_webView->close();
m_webView = 0;
}
}
WebFrame* TestWebFrameClient::createChildFrame(WebLocalFrame* parent, const WebString& frameName)
{
WebFrame* frame = WebFrame::create(this);
parent->appendChild(frame);
return frame;
}
void TestWebFrameClient::frameDetached(WebFrame* frame)
{
if (frame->parent())
frame->parent()->removeChild(frame);
frame->close();
}
}
}