OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "FrameTestHelpers.h" | 32 #include "FrameTestHelpers.h" |
33 | 33 |
34 #include "URLTestHelpers.h" | 34 #include "URLTestHelpers.h" |
35 #include "wtf/StdLibExtras.h" | 35 #include "wtf/StdLibExtras.h" |
36 #include "WebFrame.h" | |
37 #include "WebFrameClient.h" | 36 #include "WebFrameClient.h" |
| 37 #include "WebFrameImpl.h" |
38 #include "WebSettings.h" | 38 #include "WebSettings.h" |
39 #include "WebView.h" | |
40 #include "WebViewClient.h" | 39 #include "WebViewClient.h" |
| 40 #include "WebViewImpl.h" |
41 #include "public/platform/Platform.h" | 41 #include "public/platform/Platform.h" |
42 #include "public/platform/WebString.h" | 42 #include "public/platform/WebString.h" |
43 #include "public/platform/WebThread.h" | 43 #include "public/platform/WebThread.h" |
44 #include "public/platform/WebURLRequest.h" | 44 #include "public/platform/WebURLRequest.h" |
45 #include "public/platform/WebURLResponse.h" | 45 #include "public/platform/WebURLResponse.h" |
46 #include "public/platform/WebUnitTestSupport.h" | 46 #include "public/platform/WebUnitTestSupport.h" |
47 | 47 |
48 namespace WebKit { | 48 namespace WebKit { |
49 namespace FrameTestHelpers { | 49 namespace FrameTestHelpers { |
50 | 50 |
| 51 namespace { |
| 52 |
| 53 class QuitTask : public WebThread::Task { |
| 54 public: |
| 55 virtual void run() |
| 56 { |
| 57 Platform::current()->currentThread()->exitRunLoop(); |
| 58 } |
| 59 }; |
| 60 |
| 61 WebFrameClient* defaultWebFrameClient() |
| 62 { |
| 63 DEFINE_STATIC_LOCAL(WebFrameClient, client, ()); |
| 64 return &client; |
| 65 } |
| 66 |
| 67 WebViewClient* defaultWebViewClient() |
| 68 { |
| 69 DEFINE_STATIC_LOCAL(WebViewClient, client, ()); |
| 70 return &client; |
| 71 } |
| 72 |
| 73 } // namespace |
| 74 |
51 void loadFrame(WebFrame* frame, const std::string& url) | 75 void loadFrame(WebFrame* frame, const std::string& url) |
52 { | 76 { |
53 WebURLRequest urlRequest; | 77 WebURLRequest urlRequest; |
54 urlRequest.initialize(); | 78 urlRequest.initialize(); |
55 urlRequest.setURL(URLTestHelpers::toKURL(url)); | 79 urlRequest.setURL(URLTestHelpers::toKURL(url)); |
56 frame->loadRequest(urlRequest); | 80 frame->loadRequest(urlRequest); |
57 } | 81 } |
58 | 82 |
59 class TestWebFrameClient : public WebFrameClient { | |
60 }; | |
61 | |
62 static WebFrameClient* defaultWebFrameClient() | |
63 { | |
64 DEFINE_STATIC_LOCAL(TestWebFrameClient, client, ()); | |
65 return &client; | |
66 } | |
67 | |
68 class TestWebViewClient : public WebViewClient { | |
69 }; | |
70 | |
71 static WebViewClient* defaultWebViewClient() | |
72 { | |
73 DEFINE_STATIC_LOCAL(TestWebViewClient, client, ()); | |
74 return &client; | |
75 } | |
76 | |
77 WebView* createWebView(bool enableJavascript, WebFrameClient* webFrameClient, We
bViewClient* webViewClient) | |
78 { | |
79 if (!webFrameClient) | |
80 webFrameClient = defaultWebFrameClient(); | |
81 if (!webViewClient) | |
82 webViewClient = defaultWebViewClient(); | |
83 WebView* webView = WebView::create(webViewClient); | |
84 webView->settings()->setJavaScriptEnabled(enableJavascript); | |
85 webView->settings()->setDeviceSupportsMouse(false); | |
86 webView->settings()->setForceCompositingMode(true); | |
87 webView->initializeMainFrame(webFrameClient); | |
88 | |
89 return webView; | |
90 } | |
91 | |
92 WebView* createWebViewAndLoad(const std::string& url, bool enableJavascript, Web
FrameClient* webFrameClient, WebViewClient* webViewClient) | |
93 { | |
94 WebView* webView = createWebView(enableJavascript, webFrameClient, webViewCl
ient); | |
95 | |
96 loadFrame(webView->mainFrame(), url); | |
97 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | |
98 | |
99 return webView; | |
100 } | |
101 | |
102 class QuitTask : public WebThread::Task { | |
103 public: | |
104 virtual void run() | |
105 { | |
106 Platform::current()->currentThread()->exitRunLoop(); | |
107 } | |
108 }; | |
109 | |
110 void runPendingTasks() | 83 void runPendingTasks() |
111 { | 84 { |
112 Platform::current()->currentThread()->postTask(new QuitTask); | 85 Platform::current()->currentThread()->postTask(new QuitTask); |
113 Platform::current()->currentThread()->enterRunLoop(); | 86 Platform::current()->currentThread()->enterRunLoop(); |
114 } | 87 } |
115 | 88 |
| 89 WebViewHelper::WebViewHelper() |
| 90 : m_mainFrame(0) |
| 91 , m_webView(0) |
| 92 { |
| 93 } |
| 94 |
| 95 WebViewHelper::~WebViewHelper() |
| 96 { |
| 97 reset(); |
| 98 } |
| 99 |
| 100 WebViewImpl* WebViewHelper::initialize(bool enableJavascript, WebFrameClient* we
bFrameClient, WebViewClient* webViewClient, void (*updateSettingsFunc)(WebSettin
gs*)) |
| 101 { |
| 102 reset(); |
| 103 |
| 104 if (!webFrameClient) |
| 105 webFrameClient = defaultWebFrameClient(); |
| 106 if (!webViewClient) |
| 107 webViewClient = defaultWebViewClient(); |
| 108 m_webView = WebViewImpl::create(webViewClient); |
| 109 m_webView->settings()->setJavaScriptEnabled(enableJavascript); |
| 110 if (updateSettingsFunc) { |
| 111 updateSettingsFunc(m_webView->settings()); |
| 112 } else { |
| 113 m_webView->settings()->setDeviceSupportsMouse(false); |
| 114 m_webView->settings()->setForceCompositingMode(true); |
| 115 } |
| 116 |
| 117 m_mainFrame = WebFrameImpl::create(webFrameClient); |
| 118 m_webView->setMainFrame(m_mainFrame); |
| 119 |
| 120 return m_webView; |
| 121 } |
| 122 |
| 123 WebViewImpl* WebViewHelper::initializeAndLoad(const std::string& url, bool enabl
eJavascript, WebFrameClient* webFrameClient, WebViewClient* webViewClient, void
(*updateSettingsFunc)(WebSettings*)) |
| 124 { |
| 125 initialize(enableJavascript, webFrameClient, webViewClient, updateSettingsFu
nc); |
| 126 |
| 127 loadFrame(webView()->mainFrame(), url); |
| 128 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 129 |
| 130 return webViewImpl(); |
| 131 } |
| 132 |
| 133 void WebViewHelper::reset() |
| 134 { |
| 135 if (m_webView) { |
| 136 m_webView->close(); |
| 137 m_webView = 0; |
| 138 } |
| 139 if (m_mainFrame) { |
| 140 m_mainFrame->close(); |
| 141 m_mainFrame = 0; |
| 142 } |
| 143 } |
| 144 |
116 } // namespace FrameTestHelpers | 145 } // namespace FrameTestHelpers |
117 } // namespace WebKit | 146 } // namespace WebKit |
OLD | NEW |