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 class TestWebFrameClient : public WebFrameClient { | |
62 }; | |
63 | |
64 WebFrameClient* defaultWebFrameClient() | |
65 { | |
66 DEFINE_STATIC_LOCAL(TestWebFrameClient, client, ()); | |
67 return &client; | |
68 } | |
69 | |
70 class WebViewHelperClient : public WebViewClient { | |
71 }; | |
72 | |
73 WebViewClient* defaultWebViewClient() | |
74 { | |
75 DEFINE_STATIC_LOCAL(WebViewHelperClient, client, ()); | |
76 return &client; | |
77 } | |
78 | |
79 } // namespace | |
80 | |
51 void loadFrame(WebFrame* frame, const std::string& url) | 81 void loadFrame(WebFrame* frame, const std::string& url) |
52 { | 82 { |
53 WebURLRequest urlRequest; | 83 WebURLRequest urlRequest; |
54 urlRequest.initialize(); | 84 urlRequest.initialize(); |
55 urlRequest.setURL(URLTestHelpers::toKURL(url)); | 85 urlRequest.setURL(URLTestHelpers::toKURL(url)); |
56 frame->loadRequest(urlRequest); | 86 frame->loadRequest(urlRequest); |
57 } | 87 } |
58 | 88 |
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() | 89 void runPendingTasks() |
111 { | 90 { |
112 Platform::current()->currentThread()->postTask(new QuitTask); | 91 Platform::current()->currentThread()->postTask(new QuitTask); |
113 Platform::current()->currentThread()->enterRunLoop(); | 92 Platform::current()->currentThread()->enterRunLoop(); |
114 } | 93 } |
115 | 94 |
95 WebViewHelper::WebViewHelper() | |
96 : m_mainFrame(0) | |
97 , m_webView(0) | |
98 { | |
99 } | |
100 | |
101 WebViewHelper::~WebViewHelper() | |
102 { | |
103 reset(); | |
104 } | |
105 | |
106 WebViewImpl* WebViewHelper::initialize(bool enableJavascript, WebFrameClient* we bFrameClient, WebViewClient* webViewClient, void (*updateSettingsFunc)(WebSettin gs*)) | |
107 { | |
108 reset(); | |
109 | |
110 if (!webFrameClient) | |
111 webFrameClient = defaultWebFrameClient(); | |
112 if (!webViewClient) | |
113 webViewClient = defaultWebViewClient(); | |
114 m_webView = WebViewImpl::create(webViewClient); | |
115 m_webView->settings()->setJavaScriptEnabled(enableJavascript); | |
116 if (updateSettingsFunc) { | |
117 updateSettingsFunc(m_webView->settings()); | |
118 } else { | |
119 m_webView->settings()->setDeviceSupportsMouse(false); | |
120 m_webView->settings()->setForceCompositingMode(true); | |
121 } | |
122 | |
123 m_mainFrame = WebFrameImpl::create(webFrameClient); | |
124 m_webView->setMainFrame(m_mainFrame); | |
125 | |
126 return m_webView; | |
127 } | |
128 | |
129 WebViewImpl* WebViewHelper::initializeAndLoad(const std::string& url, bool enabl eJavascript, WebFrameClient* webFrameClient, WebViewClient* webViewClient, void (*updateSettingsFunc)(WebSettings*)) | |
130 { | |
131 reset(); | |
nasko
2013/09/19 22:54:12
Unneeded reset? The subsequent call to initialize
awong
2013/09/20 00:36:24
Done.
| |
132 | |
133 initialize(enableJavascript, webFrameClient, webViewClient, updateSettingsFu nc); | |
134 | |
135 loadFrame(webView()->mainFrame(), url); | |
136 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | |
137 | |
138 return webViewImpl(); | |
139 } | |
140 | |
141 void WebViewHelper::reset() | |
142 { | |
143 if (m_webView) { | |
144 m_webView->close(); | |
145 m_webView = 0; | |
146 } | |
147 if (m_mainFrame) { | |
nasko
2013/09/19 22:54:12
Shouldn't you close the main frame before destroyi
awong
2013/09/20 00:36:24
Nope...the webview expects the mainframe to be ali
| |
148 m_mainFrame->close(); | |
149 m_mainFrame = 0; | |
150 } | |
151 } | |
152 | |
116 } // namespace FrameTestHelpers | 153 } // namespace FrameTestHelpers |
117 } // namespace WebKit | 154 } // namespace WebKit |
OLD | NEW |