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

Side by Side Diff: components/test_runner/web_frame_test_client.cc

Issue 2386683002: Do not store TestRunner in WebFrameTestClient. (Closed)
Patch Set: s/test_runner_/test_runner()/ for one case pulled after rebasing. Created 4 years, 2 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/test_runner/web_frame_test_client.h" 5 #include "components/test_runner/web_frame_test_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 return kFormResubmittedString; 158 return kFormResubmittedString;
159 case blink::WebNavigationTypeOther: 159 case blink::WebNavigationTypeOther:
160 return kOtherString; 160 return kOtherString;
161 } 161 }
162 return kIllegalString; 162 return kIllegalString;
163 } 163 }
164 164
165 } // namespace 165 } // namespace
166 166
167 WebFrameTestClient::WebFrameTestClient( 167 WebFrameTestClient::WebFrameTestClient(
168 TestRunner* test_runner,
169 WebTestDelegate* delegate, 168 WebTestDelegate* delegate,
170 WebViewTestProxyBase* web_view_test_proxy_base, 169 WebViewTestProxyBase* web_view_test_proxy_base,
171 WebFrameTestProxyBase* web_frame_test_proxy_base) 170 WebFrameTestProxyBase* web_frame_test_proxy_base)
172 : test_runner_(test_runner), 171 : delegate_(delegate),
173 delegate_(delegate),
174 web_view_test_proxy_base_(web_view_test_proxy_base), 172 web_view_test_proxy_base_(web_view_test_proxy_base),
175 web_frame_test_proxy_base_(web_frame_test_proxy_base) { 173 web_frame_test_proxy_base_(web_frame_test_proxy_base) {
176 DCHECK(test_runner);
177 DCHECK(delegate_); 174 DCHECK(delegate_);
175 DCHECK(web_frame_test_proxy_base_);
178 DCHECK(web_view_test_proxy_base_); 176 DCHECK(web_view_test_proxy_base_);
179 } 177 }
180 178
181 WebFrameTestClient::~WebFrameTestClient() {} 179 WebFrameTestClient::~WebFrameTestClient() {}
182 180
183 blink::WebColorChooser* WebFrameTestClient::createColorChooser( 181 blink::WebColorChooser* WebFrameTestClient::createColorChooser(
184 blink::WebColorChooserClient* client, 182 blink::WebColorChooserClient* client,
185 const blink::WebColor& color, 183 const blink::WebColor& color,
186 const blink::WebVector<blink::WebColorSuggestion>& suggestions) { 184 const blink::WebVector<blink::WebColorSuggestion>& suggestions) {
187 // This instance is deleted by WebCore::ColorInputType 185 // This instance is deleted by WebCore::ColorInputType
188 return new MockColorChooser(client, delegate_, test_runner_); 186 return new MockColorChooser(client, delegate_, test_runner());
189 } 187 }
190 188
191 void WebFrameTestClient::runModalAlertDialog(const blink::WebString& message) { 189 void WebFrameTestClient::runModalAlertDialog(const blink::WebString& message) {
192 delegate_->PrintMessage(std::string("ALERT: ") + message.utf8().data() + 190 delegate_->PrintMessage(std::string("ALERT: ") + message.utf8().data() +
193 "\n"); 191 "\n");
194 } 192 }
195 193
196 bool WebFrameTestClient::runModalConfirmDialog( 194 bool WebFrameTestClient::runModalConfirmDialog(
197 const blink::WebString& message) { 195 const blink::WebString& message) {
198 delegate_->PrintMessage(std::string("CONFIRM: ") + message.utf8().data() + 196 delegate_->PrintMessage(std::string("CONFIRM: ") + message.utf8().data() +
199 "\n"); 197 "\n");
200 return true; 198 return true;
201 } 199 }
202 200
203 bool WebFrameTestClient::runModalPromptDialog( 201 bool WebFrameTestClient::runModalPromptDialog(
204 const blink::WebString& message, 202 const blink::WebString& message,
205 const blink::WebString& default_value, 203 const blink::WebString& default_value,
206 blink::WebString* actual_value) { 204 blink::WebString* actual_value) {
207 delegate_->PrintMessage(std::string("PROMPT: ") + message.utf8().data() + 205 delegate_->PrintMessage(std::string("PROMPT: ") + message.utf8().data() +
208 ", default text: " + default_value.utf8().data() + 206 ", default text: " + default_value.utf8().data() +
209 "\n"); 207 "\n");
210 return true; 208 return true;
211 } 209 }
212 210
213 bool WebFrameTestClient::runModalBeforeUnloadDialog(bool is_reload) { 211 bool WebFrameTestClient::runModalBeforeUnloadDialog(bool is_reload) {
214 delegate_->PrintMessage(std::string("CONFIRM NAVIGATION\n")); 212 delegate_->PrintMessage(std::string("CONFIRM NAVIGATION\n"));
215 return !test_runner_->shouldStayOnPageAfterHandlingBeforeUnload(); 213 return !test_runner()->shouldStayOnPageAfterHandlingBeforeUnload();
216 } 214 }
217 215
218 blink::WebScreenOrientationClient* 216 blink::WebScreenOrientationClient*
219 WebFrameTestClient::webScreenOrientationClient() { 217 WebFrameTestClient::webScreenOrientationClient() {
220 return test_runner_->getMockScreenOrientationClient(); 218 return test_runner()->getMockScreenOrientationClient();
221 } 219 }
222 220
223 void WebFrameTestClient::postAccessibilityEvent(const blink::WebAXObject& obj, 221 void WebFrameTestClient::postAccessibilityEvent(const blink::WebAXObject& obj,
224 blink::WebAXEvent event) { 222 blink::WebAXEvent event) {
225 // Only hook the accessibility events occured during the test run. 223 // Only hook the accessibility events occured during the test run.
226 // This check prevents false positives in WebLeakDetector. 224 // This check prevents false positives in WebLeakDetector.
227 // The pending tasks in browser/renderer message queue may trigger 225 // The pending tasks in browser/renderer message queue may trigger
228 // accessibility events, 226 // accessibility events,
229 // and AccessibilityController will hold on to their target nodes if we don't 227 // and AccessibilityController will hold on to their target nodes if we don't
230 // ignore them here. 228 // ignore them here.
231 if (!test_runner_->TestIsRunning()) 229 if (!test_runner()->TestIsRunning())
232 return; 230 return;
233 231
234 const char* event_name = NULL; 232 const char* event_name = NULL;
235 switch (event) { 233 switch (event) {
236 case blink::WebAXEventActiveDescendantChanged: 234 case blink::WebAXEventActiveDescendantChanged:
237 event_name = "ActiveDescendantChanged"; 235 event_name = "ActiveDescendantChanged";
238 break; 236 break;
239 case blink::WebAXEventAlert: 237 case blink::WebAXEventAlert:
240 event_name = "Alert"; 238 event_name = "Alert";
241 break; 239 break;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 message += " - id:"; 346 message += " - id:";
349 message += element.getAttribute("id").utf8().data(); 347 message += element.getAttribute("id").utf8().data();
350 } 348 }
351 } 349 }
352 350
353 delegate_->PrintMessage(message + "\n"); 351 delegate_->PrintMessage(message + "\n");
354 } 352 }
355 } 353 }
356 354
357 void WebFrameTestClient::didChangeSelection(bool is_empty_callback) { 355 void WebFrameTestClient::didChangeSelection(bool is_empty_callback) {
358 if (test_runner_->shouldDumpEditingCallbacks()) 356 if (test_runner()->shouldDumpEditingCallbacks())
359 delegate_->PrintMessage( 357 delegate_->PrintMessage(
360 "EDITING DELEGATE: " 358 "EDITING DELEGATE: "
361 "webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n"); 359 "webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n");
362 } 360 }
363 361
364 blink::WebPlugin* WebFrameTestClient::createPlugin( 362 blink::WebPlugin* WebFrameTestClient::createPlugin(
365 blink::WebLocalFrame* frame, 363 blink::WebLocalFrame* frame,
366 const blink::WebPluginParams& params) { 364 const blink::WebPluginParams& params) {
367 if (TestPlugin::IsSupportedMimeType(params.mimeType)) 365 if (TestPlugin::IsSupportedMimeType(params.mimeType))
368 return TestPlugin::create(frame, params, delegate_); 366 return TestPlugin::create(frame, params, delegate_);
369 return delegate_->CreatePluginPlaceholder(frame, params); 367 return delegate_->CreatePluginPlaceholder(frame, params);
370 } 368 }
371 369
372 void WebFrameTestClient::showContextMenu( 370 void WebFrameTestClient::showContextMenu(
373 const blink::WebContextMenuData& context_menu_data) { 371 const blink::WebContextMenuData& context_menu_data) {
374 web_view_test_proxy_base_->event_sender()->SetContextMenuData( 372 web_view_test_proxy_base_->event_sender()->SetContextMenuData(
375 context_menu_data); 373 context_menu_data);
376 } 374 }
377 375
378 blink::WebUserMediaClient* WebFrameTestClient::userMediaClient() { 376 blink::WebUserMediaClient* WebFrameTestClient::userMediaClient() {
379 return test_runner_->getMockWebUserMediaClient(); 377 return test_runner()->getMockWebUserMediaClient();
380 } 378 }
381 379
382 void WebFrameTestClient::loadURLExternally( 380 void WebFrameTestClient::loadURLExternally(
383 const blink::WebURLRequest& request, 381 const blink::WebURLRequest& request,
384 blink::WebNavigationPolicy policy, 382 blink::WebNavigationPolicy policy,
385 const blink::WebString& suggested_name, 383 const blink::WebString& suggested_name,
386 bool replaces_current_history_item) { 384 bool replaces_current_history_item) {
387 if (test_runner_->shouldWaitUntilExternalURLLoad()) { 385 if (test_runner()->shouldWaitUntilExternalURLLoad()) {
388 if (policy == blink::WebNavigationPolicyDownload) { 386 if (policy == blink::WebNavigationPolicyDownload) {
389 delegate_->PrintMessage( 387 delegate_->PrintMessage(
390 std::string("Downloading URL with suggested filename \"") + 388 std::string("Downloading URL with suggested filename \"") +
391 suggested_name.utf8() + "\"\n"); 389 suggested_name.utf8() + "\"\n");
392 } else { 390 } else {
393 delegate_->PrintMessage(std::string("Loading URL externally - \"") + 391 delegate_->PrintMessage(std::string("Loading URL externally - \"") +
394 URLDescription(request.url()) + "\"\n"); 392 URLDescription(request.url()) + "\"\n");
395 } 393 }
396 delegate_->TestFinished(); 394 delegate_->TestFinished();
397 } 395 }
398 } 396 }
399 397
400 void WebFrameTestClient::didStartProvisionalLoad(blink::WebLocalFrame* frame, 398 void WebFrameTestClient::didStartProvisionalLoad(blink::WebLocalFrame* frame,
401 double trigering_event_time) { 399 double trigering_event_time) {
402 test_runner_->tryToSetTopLoadingFrame(frame); 400 test_runner()->tryToSetTopLoadingFrame(frame);
403 401
404 if (test_runner_->shouldDumpFrameLoadCallbacks()) { 402 if (test_runner()->shouldDumpFrameLoadCallbacks()) {
405 PrintFrameDescription(delegate_, frame); 403 PrintFrameDescription(delegate_, frame);
406 delegate_->PrintMessage(" - didStartProvisionalLoadForFrame\n"); 404 delegate_->PrintMessage(" - didStartProvisionalLoadForFrame\n");
407 } 405 }
408 406
409 if (test_runner_->shouldDumpUserGestureInFrameLoadCallbacks()) { 407 if (test_runner()->shouldDumpUserGestureInFrameLoadCallbacks()) {
410 PrintFrameuserGestureStatus(delegate_, frame, 408 PrintFrameuserGestureStatus(delegate_, frame,
411 " - in didStartProvisionalLoadForFrame\n"); 409 " - in didStartProvisionalLoadForFrame\n");
412 } 410 }
413 } 411 }
414 412
415 void WebFrameTestClient::didReceiveServerRedirectForProvisionalLoad( 413 void WebFrameTestClient::didReceiveServerRedirectForProvisionalLoad(
416 blink::WebLocalFrame* frame) { 414 blink::WebLocalFrame* frame) {
417 if (test_runner_->shouldDumpFrameLoadCallbacks()) { 415 if (test_runner()->shouldDumpFrameLoadCallbacks()) {
418 PrintFrameDescription(delegate_, frame); 416 PrintFrameDescription(delegate_, frame);
419 delegate_->PrintMessage( 417 delegate_->PrintMessage(
420 " - didReceiveServerRedirectForProvisionalLoadForFrame\n"); 418 " - didReceiveServerRedirectForProvisionalLoadForFrame\n");
421 } 419 }
422 } 420 }
423 421
424 void WebFrameTestClient::didFailProvisionalLoad( 422 void WebFrameTestClient::didFailProvisionalLoad(
425 blink::WebLocalFrame* frame, 423 blink::WebLocalFrame* frame,
426 const blink::WebURLError& error, 424 const blink::WebURLError& error,
427 blink::WebHistoryCommitType commit_type) { 425 blink::WebHistoryCommitType commit_type) {
428 if (test_runner_->shouldDumpFrameLoadCallbacks()) { 426 if (test_runner()->shouldDumpFrameLoadCallbacks()) {
429 PrintFrameDescription(delegate_, frame); 427 PrintFrameDescription(delegate_, frame);
430 delegate_->PrintMessage(" - didFailProvisionalLoadWithError\n"); 428 delegate_->PrintMessage(" - didFailProvisionalLoadWithError\n");
431 } 429 }
432 } 430 }
433 431
434 void WebFrameTestClient::didCommitProvisionalLoad( 432 void WebFrameTestClient::didCommitProvisionalLoad(
435 blink::WebLocalFrame* frame, 433 blink::WebLocalFrame* frame,
436 const blink::WebHistoryItem& history_item, 434 const blink::WebHistoryItem& history_item,
437 blink::WebHistoryCommitType history_type) { 435 blink::WebHistoryCommitType history_type) {
438 if (test_runner_->shouldDumpFrameLoadCallbacks()) { 436 if (test_runner()->shouldDumpFrameLoadCallbacks()) {
439 PrintFrameDescription(delegate_, frame); 437 PrintFrameDescription(delegate_, frame);
440 delegate_->PrintMessage(" - didCommitLoadForFrame\n"); 438 delegate_->PrintMessage(" - didCommitLoadForFrame\n");
441 } 439 }
442 } 440 }
443 441
444 void WebFrameTestClient::didReceiveTitle(blink::WebLocalFrame* frame, 442 void WebFrameTestClient::didReceiveTitle(blink::WebLocalFrame* frame,
445 const blink::WebString& title, 443 const blink::WebString& title,
446 blink::WebTextDirection direction) { 444 blink::WebTextDirection direction) {
447 if (test_runner_->shouldDumpFrameLoadCallbacks()) { 445 if (test_runner()->shouldDumpFrameLoadCallbacks()) {
448 PrintFrameDescription(delegate_, frame); 446 PrintFrameDescription(delegate_, frame);
449 delegate_->PrintMessage(std::string(" - didReceiveTitle: ") + title.utf8() + 447 delegate_->PrintMessage(std::string(" - didReceiveTitle: ") + title.utf8() +
450 "\n"); 448 "\n");
451 } 449 }
452 450
453 if (test_runner_->shouldDumpTitleChanges()) 451 if (test_runner()->shouldDumpTitleChanges())
454 delegate_->PrintMessage(std::string("TITLE CHANGED: '") + title.utf8() + 452 delegate_->PrintMessage(std::string("TITLE CHANGED: '") + title.utf8() +
455 "'\n"); 453 "'\n");
456 } 454 }
457 455
458 void WebFrameTestClient::didChangeIcon(blink::WebLocalFrame* frame, 456 void WebFrameTestClient::didChangeIcon(blink::WebLocalFrame* frame,
459 blink::WebIconURL::Type icon_type) { 457 blink::WebIconURL::Type icon_type) {
460 if (test_runner_->shouldDumpIconChanges()) { 458 if (test_runner()->shouldDumpIconChanges()) {
461 PrintFrameDescription(delegate_, frame); 459 PrintFrameDescription(delegate_, frame);
462 delegate_->PrintMessage(std::string(" - didChangeIcons\n")); 460 delegate_->PrintMessage(std::string(" - didChangeIcons\n"));
463 } 461 }
464 } 462 }
465 463
466 void WebFrameTestClient::didFinishDocumentLoad(blink::WebLocalFrame* frame) { 464 void WebFrameTestClient::didFinishDocumentLoad(blink::WebLocalFrame* frame) {
467 if (test_runner_->shouldDumpFrameLoadCallbacks()) { 465 if (test_runner()->shouldDumpFrameLoadCallbacks()) {
468 PrintFrameDescription(delegate_, frame); 466 PrintFrameDescription(delegate_, frame);
469 delegate_->PrintMessage(" - didFinishDocumentLoadForFrame\n"); 467 delegate_->PrintMessage(" - didFinishDocumentLoadForFrame\n");
470 } 468 }
471 } 469 }
472 470
473 void WebFrameTestClient::didHandleOnloadEvents(blink::WebLocalFrame* frame) { 471 void WebFrameTestClient::didHandleOnloadEvents(blink::WebLocalFrame* frame) {
474 if (test_runner_->shouldDumpFrameLoadCallbacks()) { 472 if (test_runner()->shouldDumpFrameLoadCallbacks()) {
475 PrintFrameDescription(delegate_, frame); 473 PrintFrameDescription(delegate_, frame);
476 delegate_->PrintMessage(" - didHandleOnloadEventsForFrame\n"); 474 delegate_->PrintMessage(" - didHandleOnloadEventsForFrame\n");
477 } 475 }
478 } 476 }
479 477
480 void WebFrameTestClient::didFailLoad(blink::WebLocalFrame* frame, 478 void WebFrameTestClient::didFailLoad(blink::WebLocalFrame* frame,
481 const blink::WebURLError& error, 479 const blink::WebURLError& error,
482 blink::WebHistoryCommitType commit_type) { 480 blink::WebHistoryCommitType commit_type) {
483 if (test_runner_->shouldDumpFrameLoadCallbacks()) { 481 if (test_runner()->shouldDumpFrameLoadCallbacks()) {
484 PrintFrameDescription(delegate_, frame); 482 PrintFrameDescription(delegate_, frame);
485 delegate_->PrintMessage(" - didFailLoadWithError\n"); 483 delegate_->PrintMessage(" - didFailLoadWithError\n");
486 } 484 }
487 } 485 }
488 486
489 void WebFrameTestClient::didFinishLoad(blink::WebLocalFrame* frame) { 487 void WebFrameTestClient::didFinishLoad(blink::WebLocalFrame* frame) {
490 if (test_runner_->shouldDumpFrameLoadCallbacks()) { 488 if (test_runner()->shouldDumpFrameLoadCallbacks()) {
491 PrintFrameDescription(delegate_, frame); 489 PrintFrameDescription(delegate_, frame);
492 delegate_->PrintMessage(" - didFinishLoadForFrame\n"); 490 delegate_->PrintMessage(" - didFinishLoadForFrame\n");
493 } 491 }
494 } 492 }
495 493
496 void WebFrameTestClient::didNavigateWithinPage( 494 void WebFrameTestClient::didNavigateWithinPage(
497 blink::WebLocalFrame* frame, 495 blink::WebLocalFrame* frame,
498 const blink::WebHistoryItem& history_item, 496 const blink::WebHistoryItem& history_item,
499 blink::WebHistoryCommitType commit_type, 497 blink::WebHistoryCommitType commit_type,
500 bool contentInitiated) { 498 bool contentInitiated) {
501 test_runner_->OnNavigationEnd(); 499 test_runner()->OnNavigationEnd();
502 } 500 }
503 501
504 void WebFrameTestClient::didStartLoading(bool to_different_document) { 502 void WebFrameTestClient::didStartLoading(bool to_different_document) {
505 test_runner_->OnNavigationBegin(web_frame_test_proxy_base_->web_frame()); 503 test_runner()->OnNavigationBegin(web_frame_test_proxy_base_->web_frame());
506 } 504 }
507 505
508 void WebFrameTestClient::didStopLoading() { 506 void WebFrameTestClient::didStopLoading() {
509 test_runner_->tryToClearTopLoadingFrame( 507 test_runner()->tryToClearTopLoadingFrame(
510 web_frame_test_proxy_base_->web_frame()); 508 web_frame_test_proxy_base_->web_frame());
511 } 509 }
512 510
513 void WebFrameTestClient::didDetectXSS(const blink::WebURL& insecure_url, 511 void WebFrameTestClient::didDetectXSS(const blink::WebURL& insecure_url,
514 bool did_block_entire_page) { 512 bool did_block_entire_page) {
515 if (test_runner_->shouldDumpFrameLoadCallbacks()) 513 if (test_runner()->shouldDumpFrameLoadCallbacks())
516 delegate_->PrintMessage("didDetectXSS\n"); 514 delegate_->PrintMessage("didDetectXSS\n");
517 } 515 }
518 516
519 void WebFrameTestClient::didDispatchPingLoader(const blink::WebURL& url) { 517 void WebFrameTestClient::didDispatchPingLoader(const blink::WebURL& url) {
520 if (test_runner_->shouldDumpPingLoaderCallbacks()) 518 if (test_runner()->shouldDumpPingLoaderCallbacks())
521 delegate_->PrintMessage(std::string("PingLoader dispatched to '") + 519 delegate_->PrintMessage(std::string("PingLoader dispatched to '") +
522 URLDescription(url).c_str() + "'.\n"); 520 URLDescription(url).c_str() + "'.\n");
523 } 521 }
524 522
525 void WebFrameTestClient::willSendRequest(blink::WebLocalFrame* frame, 523 void WebFrameTestClient::willSendRequest(blink::WebLocalFrame* frame,
526 blink::WebURLRequest& request) { 524 blink::WebURLRequest& request) {
527 // Need to use GURL for host() and SchemeIs() 525 // Need to use GURL for host() and SchemeIs()
528 GURL url = request.url(); 526 GURL url = request.url();
529 std::string request_url = url.possibly_invalid_spec(); 527 std::string request_url = url.possibly_invalid_spec();
530 528
531 GURL main_document_url = request.firstPartyForCookies(); 529 GURL main_document_url = request.firstPartyForCookies();
532 530
533 if (test_runner_->shouldDumpResourceLoadCallbacks()) { 531 if (test_runner()->shouldDumpResourceLoadCallbacks()) {
534 delegate_->PrintMessage(DescriptionSuitableForTestResult(request_url)); 532 delegate_->PrintMessage(DescriptionSuitableForTestResult(request_url));
535 delegate_->PrintMessage(" - willSendRequest <NSURLRequest URL "); 533 delegate_->PrintMessage(" - willSendRequest <NSURLRequest URL ");
536 delegate_->PrintMessage( 534 delegate_->PrintMessage(
537 DescriptionSuitableForTestResult(request_url).c_str()); 535 DescriptionSuitableForTestResult(request_url).c_str());
538 delegate_->PrintMessage(", main document URL "); 536 delegate_->PrintMessage(", main document URL ");
539 delegate_->PrintMessage(URLDescription(main_document_url).c_str()); 537 delegate_->PrintMessage(URLDescription(main_document_url).c_str());
540 delegate_->PrintMessage(", http method "); 538 delegate_->PrintMessage(", http method ");
541 delegate_->PrintMessage(request.httpMethod().utf8().data()); 539 delegate_->PrintMessage(request.httpMethod().utf8().data());
542 delegate_->PrintMessage(">\n"); 540 delegate_->PrintMessage(">\n");
543 } 541 }
544 542
545 if (test_runner_->httpHeadersToClear()) { 543 if (test_runner()->httpHeadersToClear()) {
546 const std::set<std::string>* clearHeaders = 544 const std::set<std::string>* clearHeaders =
547 test_runner_->httpHeadersToClear(); 545 test_runner()->httpHeadersToClear();
548 for (std::set<std::string>::const_iterator header = clearHeaders->begin(); 546 for (std::set<std::string>::const_iterator header = clearHeaders->begin();
549 header != clearHeaders->end(); ++header) 547 header != clearHeaders->end(); ++header)
550 request.clearHTTPHeaderField(blink::WebString::fromUTF8(*header)); 548 request.clearHTTPHeaderField(blink::WebString::fromUTF8(*header));
551 } 549 }
552 550
553 std::string host = url.host(); 551 std::string host = url.host();
554 if (!host.empty() && 552 if (!host.empty() &&
555 (url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))) { 553 (url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))) {
556 if (!IsLocalHost(host) && !IsTestHost(host) && 554 if (!IsLocalHost(host) && !IsTestHost(host) &&
557 !HostIsUsedBySomeTestsToGenerateError(host) && 555 !HostIsUsedBySomeTestsToGenerateError(host) &&
558 ((!main_document_url.SchemeIs(url::kHttpScheme) && 556 ((!main_document_url.SchemeIs(url::kHttpScheme) &&
559 !main_document_url.SchemeIs(url::kHttpsScheme)) || 557 !main_document_url.SchemeIs(url::kHttpsScheme)) ||
560 IsLocalHost(main_document_url.host())) && 558 IsLocalHost(main_document_url.host())) &&
561 !delegate_->AllowExternalPages()) { 559 !delegate_->AllowExternalPages()) {
562 delegate_->PrintMessage(std::string("Blocked access to external URL ") + 560 delegate_->PrintMessage(std::string("Blocked access to external URL ") +
563 request_url + "\n"); 561 request_url + "\n");
564 BlockRequest(request); 562 BlockRequest(request);
565 return; 563 return;
566 } 564 }
567 } 565 }
568 566
569 // Set the new substituted URL. 567 // Set the new substituted URL.
570 request.setURL(delegate_->RewriteLayoutTestsURL( 568 request.setURL(delegate_->RewriteLayoutTestsURL(
571 request.url().string().utf8(), 569 request.url().string().utf8(),
572 test_runner_->is_web_platform_tests_mode())); 570 test_runner()->is_web_platform_tests_mode()));
573 } 571 }
574 572
575 void WebFrameTestClient::didReceiveResponse( 573 void WebFrameTestClient::didReceiveResponse(
576 const blink::WebURLResponse& response) { 574 const blink::WebURLResponse& response) {
577 if (test_runner_->shouldDumpResourceLoadCallbacks()) { 575 if (test_runner()->shouldDumpResourceLoadCallbacks()) {
578 delegate_->PrintMessage(DescriptionSuitableForTestResult( 576 delegate_->PrintMessage(DescriptionSuitableForTestResult(
579 GURL(response.url()).possibly_invalid_spec())); 577 GURL(response.url()).possibly_invalid_spec()));
580 delegate_->PrintMessage(" - didReceiveResponse "); 578 delegate_->PrintMessage(" - didReceiveResponse ");
581 PrintResponseDescription(delegate_, response); 579 PrintResponseDescription(delegate_, response);
582 delegate_->PrintMessage("\n"); 580 delegate_->PrintMessage("\n");
583 } 581 }
584 if (test_runner_->shouldDumpResourceResponseMIMETypes()) { 582 if (test_runner()->shouldDumpResourceResponseMIMETypes()) {
585 GURL url = response.url(); 583 GURL url = response.url();
586 blink::WebString mime_type = response.mimeType(); 584 blink::WebString mime_type = response.mimeType();
587 delegate_->PrintMessage(url.ExtractFileName()); 585 delegate_->PrintMessage(url.ExtractFileName());
588 delegate_->PrintMessage(" has MIME type "); 586 delegate_->PrintMessage(" has MIME type ");
589 // Simulate NSURLResponse's mapping of empty/unknown MIME types to 587 // Simulate NSURLResponse's mapping of empty/unknown MIME types to
590 // application/octet-stream 588 // application/octet-stream
591 delegate_->PrintMessage(mime_type.isEmpty() ? "application/octet-stream" 589 delegate_->PrintMessage(mime_type.isEmpty() ? "application/octet-stream"
592 : mime_type.utf8().data()); 590 : mime_type.utf8().data());
593 delegate_->PrintMessage("\n"); 591 delegate_->PrintMessage("\n");
594 } 592 }
595 } 593 }
596 594
597 void WebFrameTestClient::didAddMessageToConsole( 595 void WebFrameTestClient::didAddMessageToConsole(
598 const blink::WebConsoleMessage& message, 596 const blink::WebConsoleMessage& message,
599 const blink::WebString& source_name, 597 const blink::WebString& source_name,
600 unsigned source_line, 598 unsigned source_line,
601 const blink::WebString& stack_trace) { 599 const blink::WebString& stack_trace) {
602 if (!test_runner_->ShouldDumpConsoleMessages()) 600 if (!test_runner()->ShouldDumpConsoleMessages())
603 return; 601 return;
604 std::string level; 602 std::string level;
605 switch (message.level) { 603 switch (message.level) {
606 case blink::WebConsoleMessage::LevelDebug: 604 case blink::WebConsoleMessage::LevelDebug:
607 level = "DEBUG"; 605 level = "DEBUG";
608 break; 606 break;
609 case blink::WebConsoleMessage::LevelLog: 607 case blink::WebConsoleMessage::LevelLog:
610 level = "MESSAGE"; 608 level = "MESSAGE";
611 break; 609 break;
612 case blink::WebConsoleMessage::LevelInfo: 610 case blink::WebConsoleMessage::LevelInfo:
(...skipping 20 matching lines...) Expand all
633 new_message = new_message.substr(0, file_protocol) + 631 new_message = new_message.substr(0, file_protocol) +
634 URLSuitableForTestResult(new_message.substr(file_protocol)); 632 URLSuitableForTestResult(new_message.substr(file_protocol));
635 } 633 }
636 delegate_->PrintMessage(new_message); 634 delegate_->PrintMessage(new_message);
637 } 635 }
638 delegate_->PrintMessage(std::string("\n")); 636 delegate_->PrintMessage(std::string("\n"));
639 } 637 }
640 638
641 blink::WebNavigationPolicy WebFrameTestClient::decidePolicyForNavigation( 639 blink::WebNavigationPolicy WebFrameTestClient::decidePolicyForNavigation(
642 const blink::WebFrameClient::NavigationPolicyInfo& info) { 640 const blink::WebFrameClient::NavigationPolicyInfo& info) {
643 if (test_runner_->shouldDumpNavigationPolicy()) { 641 if (test_runner()->shouldDumpNavigationPolicy()) {
644 delegate_->PrintMessage("Default policy for navigation to '" + 642 delegate_->PrintMessage("Default policy for navigation to '" +
645 URLDescription(info.urlRequest.url()) + "' is '" + 643 URLDescription(info.urlRequest.url()) + "' is '" +
646 WebNavigationPolicyToString(info.defaultPolicy) + 644 WebNavigationPolicyToString(info.defaultPolicy) +
647 "'\n"); 645 "'\n");
648 } 646 }
649 647
650 blink::WebNavigationPolicy result; 648 blink::WebNavigationPolicy result;
651 if (!test_runner_->policyDelegateEnabled()) 649 if (!test_runner()->policyDelegateEnabled())
652 return info.defaultPolicy; 650 return info.defaultPolicy;
653 651
654 delegate_->PrintMessage( 652 delegate_->PrintMessage(
655 std::string("Policy delegate: attempt to load ") + 653 std::string("Policy delegate: attempt to load ") +
656 URLDescription(info.urlRequest.url()) + " with navigation type '" + 654 URLDescription(info.urlRequest.url()) + " with navigation type '" +
657 WebNavigationTypeToString(info.navigationType) + "'\n"); 655 WebNavigationTypeToString(info.navigationType) + "'\n");
658 if (test_runner_->policyDelegateIsPermissive()) 656 if (test_runner()->policyDelegateIsPermissive())
659 result = blink::WebNavigationPolicyCurrentTab; 657 result = blink::WebNavigationPolicyCurrentTab;
660 else 658 else
661 result = blink::WebNavigationPolicyIgnore; 659 result = blink::WebNavigationPolicyIgnore;
662 660
663 if (test_runner_->policyDelegateShouldNotifyDone()) { 661 if (test_runner()->policyDelegateShouldNotifyDone()) {
664 test_runner_->policyDelegateDone(); 662 test_runner()->policyDelegateDone();
665 result = blink::WebNavigationPolicyIgnore; 663 result = blink::WebNavigationPolicyIgnore;
666 } 664 }
667 665
668 return result; 666 return result;
669 } 667 }
670 668
671 void WebFrameTestClient::checkIfAudioSinkExistsAndIsAuthorized( 669 void WebFrameTestClient::checkIfAudioSinkExistsAndIsAuthorized(
672 const blink::WebString& sink_id, 670 const blink::WebString& sink_id,
673 const blink::WebSecurityOrigin& security_origin, 671 const blink::WebSecurityOrigin& security_origin,
674 blink::WebSetSinkIdCallbacks* web_callbacks) { 672 blink::WebSetSinkIdCallbacks* web_callbacks) {
(...skipping 15 matching lines...) Expand all
690 bool WebFrameTestClient::runFileChooser( 688 bool WebFrameTestClient::runFileChooser(
691 const blink::WebFileChooserParams& params, 689 const blink::WebFileChooserParams& params,
692 blink::WebFileChooserCompletion* completion) { 690 blink::WebFileChooserCompletion* completion) {
693 delegate_->PrintMessage("Mock: Opening a file chooser.\n"); 691 delegate_->PrintMessage("Mock: Opening a file chooser.\n");
694 // FIXME: Add ability to set file names to a file upload control. 692 // FIXME: Add ability to set file names to a file upload control.
695 return false; 693 return false;
696 } 694 }
697 695
698 blink::WebEffectiveConnectionType 696 blink::WebEffectiveConnectionType
699 WebFrameTestClient::getEffectiveConnectionType() { 697 WebFrameTestClient::getEffectiveConnectionType() {
700 return test_runner_->effective_connection_type(); 698 return test_runner()->effective_connection_type();
699 }
700
701 TestRunner* WebFrameTestClient::test_runner() {
702 return web_view_test_proxy_base_->test_interfaces()->GetTestRunner();
701 } 703 }
702 704
703 } // namespace test_runner 705 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/web_frame_test_client.h ('k') | components/test_runner/web_test_interfaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698