Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: Source/web/tests/FrameTestHelpers.cpp

Issue 23506013: Make the embedder responsible for creating the WebFrame (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: address comments Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 {
dcheng 2013/09/20 02:29:59 Any reason we can't just use WebFrameClient and We
awong 2013/09/20 23:57:14 Good point. Was just cut and paste, but it does se
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 initialize(enableJavascript, webFrameClient, webViewClient, updateSettingsFu nc);
132
133 loadFrame(webView()->mainFrame(), url);
134 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
135
136 return webViewImpl();
137 }
138
139 void WebViewHelper::reset()
140 {
141 if (m_webView) {
142 m_webView->close();
143 m_webView = 0;
144 }
145 if (m_mainFrame) {
146 m_mainFrame->close();
147 m_mainFrame = 0;
148 }
149 }
150
116 } // namespace FrameTestHelpers 151 } // namespace FrameTestHelpers
117 } // namespace WebKit 152 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698