2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "FrameTestHelpers.h"
34 #include "URLTestHelpers.h"
35 #include "wtf/StdLibExtras.h"
36 #include "WebFrameClient.h"
37 #include "WebFrameImpl.h"
38 #include "WebSettings.h"
39 #include "WebViewClient.h"
40 #include "WebViewImpl.h"
41 #include "public/platform/Platform.h"
42 #include "public/platform/WebString.h"
43 #include "public/platform/WebThread.h"
44 #include "public/platform/WebURLRequest.h"
45 #include "public/platform/WebURLResponse.h"
46 #include "public/platform/WebUnitTestSupport.h"
49 namespace FrameTestHelpers {
53 class QuitTask : public WebThread::Task {
57 Platform::current()->currentThread()->exitRunLoop();
61 WebFrameClient* defaultWebFrameClient()
63 DEFINE_STATIC_LOCAL(WebFrameClient, client, ());
67 WebViewClient* defaultWebViewClient()
69 DEFINE_STATIC_LOCAL(WebViewClient, client, ());
75 void loadFrame(WebFrame* frame, const std::string& url)
77 WebURLRequest urlRequest;
78 urlRequest.initialize();
79 urlRequest.setURL(URLTestHelpers::toKURL(url));
80 frame->loadRequest(urlRequest);
83 void runPendingTasks()
85 Platform::current()->currentThread()->postTask(new QuitTask);
86 Platform::current()->currentThread()->enterRunLoop();
89 WebViewHelper::WebViewHelper()
95 WebViewHelper::~WebViewHelper()
100 WebViewImpl* WebViewHelper::initialize(bool enableJavascript, WebFrameClient* webFrameClient, WebViewClient* webViewClient, void (*updateSettingsFunc)(WebSettings*))
105 webFrameClient = defaultWebFrameClient();
107 webViewClient = defaultWebViewClient();
108 m_webView = WebViewImpl::create(webViewClient);
109 m_webView->settings()->setJavaScriptEnabled(enableJavascript);
110 if (updateSettingsFunc) {
111 updateSettingsFunc(m_webView->settings());
113 m_webView->settings()->setDeviceSupportsMouse(false);
114 m_webView->settings()->setForceCompositingMode(true);
117 m_mainFrame = WebFrameImpl::create(webFrameClient);
118 m_webView->setMainFrame(m_mainFrame);
123 WebViewImpl* WebViewHelper::initializeAndLoad(const std::string& url, bool enableJavascript, WebFrameClient* webFrameClient, WebViewClient* webViewClient, void (*updateSettingsFunc)(WebSettings*))
125 initialize(enableJavascript, webFrameClient, webViewClient, updateSettingsFunc);
127 loadFrame(webView()->mainFrame(), url);
128 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
130 return webViewImpl();
133 void WebViewHelper::reset()
140 m_mainFrame->close();
145 } // namespace FrameTestHelpers
146 } // namespace WebKit