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

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

Issue 1685003002: Plumb the correct owner document through DocumentInit::m_owner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 9 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 DEFINE_STATIC_LOCAL(TestWebFrameClient, client, ()); 95 DEFINE_STATIC_LOCAL(TestWebFrameClient, client, ());
96 return &client; 96 return &client;
97 } 97 }
98 98
99 TestWebViewClient* defaultWebViewClient() 99 TestWebViewClient* defaultWebViewClient()
100 { 100 {
101 DEFINE_STATIC_LOCAL(TestWebViewClient, client, ()); 101 DEFINE_STATIC_LOCAL(TestWebViewClient, client, ());
102 return &client; 102 return &client;
103 } 103 }
104 104
105 // |uniqueName| is normally calculated in a somewhat complicated way by the
106 // FrameTree class, but for test purposes the approximation below should be
107 // close enough.
108 String nameToUniqueName(const String& name)
109 {
110 static int uniqueNameCounter = 0;
111 StringBuilder uniqueName;
112 uniqueName.append(name);
113 uniqueName.append(" ");
114 uniqueName.appendNumber(uniqueNameCounter++);
115 return uniqueName.toString();
116 }
117
105 } // namespace 118 } // namespace
106 119
107 void loadFrame(WebFrame* frame, const std::string& url) 120 void loadFrame(WebFrame* frame, const std::string& url)
108 { 121 {
109 WebURLRequest urlRequest; 122 WebURLRequest urlRequest;
110 urlRequest.initialize(); 123 urlRequest.initialize();
111 urlRequest.setURL(URLTestHelpers::toKURL(url)); 124 urlRequest.setURL(URLTestHelpers::toKURL(url));
112 frame->loadRequest(urlRequest); 125 frame->loadRequest(urlRequest);
113 pumpPendingRequests(frame); 126 pumpPendingRequests(frame);
114 } 127 }
(...skipping 25 matching lines...) Expand all
140 void pumpPendingRequestsDoNotUse(WebFrame* frame) 153 void pumpPendingRequestsDoNotUse(WebFrame* frame)
141 { 154 {
142 pumpPendingRequests(frame); 155 pumpPendingRequests(frame);
143 } 156 }
144 157
145 WebLocalFrame* createLocalChild(WebRemoteFrame* parent, const WebString& name, W ebFrameClient* client, WebFrame* previousSibling, const WebFrameOwnerProperties& properties) 158 WebLocalFrame* createLocalChild(WebRemoteFrame* parent, const WebString& name, W ebFrameClient* client, WebFrame* previousSibling, const WebFrameOwnerProperties& properties)
146 { 159 {
147 if (!client) 160 if (!client)
148 client = defaultWebFrameClient(); 161 client = defaultWebFrameClient();
149 162
150 // |uniqueName| is normally calculated in a somewhat complicated way by the 163 return parent->createLocalChild(WebTreeScopeType::Document, name, nameToUniq ueName(name), WebSandboxFlags::None, client, previousSibling, properties, nullpt r);
151 // FrameTree class, but for test purposes the approximation below should be 164 }
152 // close enough.
153 static int uniqueNameCounter = 0;
154 StringBuilder uniqueName;
155 uniqueName.append(name);
156 uniqueName.appendNumber(uniqueNameCounter++);
157 165
158 return parent->createLocalChild(WebTreeScopeType::Document, name, uniqueName .toString(), WebSandboxFlags::None, client, previousSibling, properties); 166 WebRemoteFrame* createRemoteChild(WebRemoteFrame* parent, WebRemoteFrameClient* client, const WebString& name)
167 {
168 return parent->createRemoteChild(WebTreeScopeType::Document, name, nameToUni queName(name), WebSandboxFlags::None, client, nullptr);
159 } 169 }
160 170
161 WebViewHelper::WebViewHelper(SettingOverrider* settingOverrider) 171 WebViewHelper::WebViewHelper(SettingOverrider* settingOverrider)
162 : m_webView(nullptr) 172 : m_webView(nullptr)
163 , m_webViewWidget(nullptr) 173 , m_webViewWidget(nullptr)
164 , m_settingOverrider(settingOverrider) 174 , m_settingOverrider(settingOverrider)
165 { 175 {
166 } 176 }
167 177
168 WebViewHelper::~WebViewHelper() 178 WebViewHelper::~WebViewHelper()
169 { 179 {
170 reset(); 180 reset();
171 } 181 }
172 182
173 WebViewImpl* WebViewHelper::initialize(bool enableJavascript, TestWebFrameClient * webFrameClient, TestWebViewClient* webViewClient, void (*updateSettingsFunc)(W ebSettings*)) 183 WebViewImpl* WebViewHelper::initializeWithOpener(WebFrame* opener, bool enableJa vascript, TestWebFrameClient* webFrameClient, TestWebViewClient* webViewClient, void (*updateSettingsFunc)(WebSettings*))
174 { 184 {
175 reset(); 185 reset();
176 186
177 if (!webFrameClient) 187 if (!webFrameClient)
178 webFrameClient = defaultWebFrameClient(); 188 webFrameClient = defaultWebFrameClient();
179 if (!webViewClient) 189 if (!webViewClient)
180 webViewClient = defaultWebViewClient(); 190 webViewClient = defaultWebViewClient();
181 m_webView = WebViewImpl::create(webViewClient); 191 m_webView = WebViewImpl::create(webViewClient);
182 m_webView->settings()->setJavaScriptEnabled(enableJavascript); 192 m_webView->settings()->setJavaScriptEnabled(enableJavascript);
183 m_webView->settings()->setPluginsEnabled(true); 193 m_webView->settings()->setPluginsEnabled(true);
184 // Enable (mocked) network loads of image URLs, as this simplifies 194 // Enable (mocked) network loads of image URLs, as this simplifies
185 // the completion of resource loads upon test shutdown & helps avoid 195 // the completion of resource loads upon test shutdown & helps avoid
186 // dormant loads trigger Resource leaks for image loads. 196 // dormant loads trigger Resource leaks for image loads.
187 // 197 //
188 // Consequently, all external image resources must be mocked. 198 // Consequently, all external image resources must be mocked.
189 m_webView->settings()->setLoadsImagesAutomatically(true); 199 m_webView->settings()->setLoadsImagesAutomatically(true);
190 if (updateSettingsFunc) 200 if (updateSettingsFunc)
191 updateSettingsFunc(m_webView->settings()); 201 updateSettingsFunc(m_webView->settings());
192 else 202 else
193 m_webView->settings()->setDeviceSupportsMouse(false); 203 m_webView->settings()->setDeviceSupportsMouse(false);
194 if (m_settingOverrider) 204 if (m_settingOverrider)
195 m_settingOverrider->overrideSettings(m_webView->settings()); 205 m_settingOverrider->overrideSettings(m_webView->settings());
196 m_webView->setDeviceScaleFactor(webViewClient->screenInfo().deviceScaleFacto r); 206 m_webView->setDeviceScaleFactor(webViewClient->screenInfo().deviceScaleFacto r);
197 m_webView->setDefaultPageScaleLimits(1, 4); 207 m_webView->setDefaultPageScaleLimits(1, 4);
198 WebLocalFrame* frame = WebLocalFrameImpl::create(WebTreeScopeType::Document, webFrameClient); 208 WebLocalFrame* frame = WebLocalFrameImpl::create(WebTreeScopeType::Document, webFrameClient, opener);
199 m_webView->setMainFrame(frame); 209 m_webView->setMainFrame(frame);
200 // TODO(dcheng): The main frame widget currently has a special case. 210 // TODO(dcheng): The main frame widget currently has a special case.
201 // Eliminate this once WebView is no longer a WebWidget. 211 // Eliminate this once WebView is no longer a WebWidget.
202 m_webViewWidget = blink::WebFrameWidget::create(webViewClient, m_webView, fr ame); 212 m_webViewWidget = blink::WebFrameWidget::create(webViewClient, m_webView, fr ame);
203 213
204 m_testWebViewClient = webViewClient; 214 m_testWebViewClient = webViewClient;
205 215
206 return m_webView; 216 return m_webView;
207 } 217 }
208 218
219 WebViewImpl* WebViewHelper::initialize(bool enableJavascript, TestWebFrameClient * webFrameClient, TestWebViewClient* webViewClient, void (*updateSettingsFunc)(W ebSettings*))
220 {
221 return initializeWithOpener(nullptr, enableJavascript, webFrameClient, webVi ewClient, updateSettingsFunc);
222 }
223
209 WebViewImpl* WebViewHelper::initializeAndLoad(const std::string& url, bool enabl eJavascript, TestWebFrameClient* webFrameClient, TestWebViewClient* webViewClien t, void (*updateSettingsFunc)(WebSettings*)) 224 WebViewImpl* WebViewHelper::initializeAndLoad(const std::string& url, bool enabl eJavascript, TestWebFrameClient* webFrameClient, TestWebViewClient* webViewClien t, void (*updateSettingsFunc)(WebSettings*))
210 { 225 {
211 initialize(enableJavascript, webFrameClient, webViewClient, updateSettingsFu nc); 226 initialize(enableJavascript, webFrameClient, webViewClient, updateSettingsFu nc);
212 227
213 loadFrame(webView()->mainFrame(), url); 228 loadFrame(webView()->mainFrame(), url);
214 229
215 return webViewImpl(); 230 return webViewImpl();
216 } 231 }
217 232
218 void WebViewHelper::reset() 233 void WebViewHelper::reset()
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // and asynchronous parsing make use of off main thread HTML parser. 290 // and asynchronous parsing make use of off main thread HTML parser.
276 testing::runPendingTasks(); 291 testing::runPendingTasks();
277 if (!isLoading()) 292 if (!isLoading())
278 break; 293 break;
279 294
280 testing::yieldCurrentThread(); 295 testing::yieldCurrentThread();
281 } 296 }
282 } 297 }
283 298
284 TestWebRemoteFrameClient::TestWebRemoteFrameClient() 299 TestWebRemoteFrameClient::TestWebRemoteFrameClient()
285 : m_frame(WebRemoteFrameImpl::create(WebTreeScopeType::Document, this)) 300 : m_frame(WebRemoteFrameImpl::create(WebTreeScopeType::Document, this, nullp tr))
286 { 301 {
287 } 302 }
288 303
289 void TestWebRemoteFrameClient::frameDetached(DetachType type) 304 void TestWebRemoteFrameClient::frameDetached(DetachType type)
290 { 305 {
291 if (type == DetachType::Remove && m_frame->parent()) 306 if (type == DetachType::Remove && m_frame->parent())
292 m_frame->parent()->removeChild(m_frame); 307 m_frame->parent()->removeChild(m_frame);
293 m_frame->close(); 308 m_frame->close();
294 } 309 }
295 310
296 void TestWebViewClient::initializeLayerTreeView() 311 void TestWebViewClient::initializeLayerTreeView()
297 { 312 {
298 m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->createLay erTreeViewForTesting()); 313 m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->createLay erTreeViewForTesting());
299 ASSERT(m_layerTreeView); 314 ASSERT(m_layerTreeView);
300 } 315 }
301 316
302 } // namespace FrameTestHelpers 317 } // namespace FrameTestHelpers
303 } // namespace blink 318 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698