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

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 1917073002: Block webpages from navigating to view-source URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add layout and browser tests Created 4 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/site_per_process_browsertest.h" 5 #include "content/browser/site_per_process_browsertest.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 }; 455 };
456 456
457 // Helper function to focus a frame by sending it a mouse click and then 457 // Helper function to focus a frame by sending it a mouse click and then
458 // waiting for it to become focused. 458 // waiting for it to become focused.
459 void FocusFrame(FrameTreeNode* frame) { 459 void FocusFrame(FrameTreeNode* frame) {
460 FrameFocusedObserver focus_observer(frame); 460 FrameFocusedObserver focus_observer(frame);
461 SimulateMouseClick(frame->current_frame_host()->GetRenderWidgetHost(), 1, 1); 461 SimulateMouseClick(frame->current_frame_host()->GetRenderWidgetHost(), 1, 1);
462 focus_observer.Wait(); 462 focus_observer.Wait();
463 } 463 }
464 464
465 // A WebContentsDelegate that catches messages sent to the console.
466 class ConsoleObserverDelegate : public WebContentsDelegate {
467 public:
468 ConsoleObserverDelegate(WebContents* web_contents, const std::string& filter)
469 : web_contents_(web_contents),
470 filter_(filter),
471 message_(""),
472 message_loop_runner_(new MessageLoopRunner) {}
473
474 ~ConsoleObserverDelegate() override {}
475
476 bool AddMessageToConsole(WebContents* source,
477 int32_t level,
478 const base::string16& message,
479 int32_t line_no,
480 const base::string16& source_id) override;
481
482 std::string message() { return message_; }
483
484 void Wait();
485
486 private:
487 WebContents* web_contents_;
488 std::string filter_;
489 std::string message_;
490
491 // The MessageLoopRunner used to spin the message loop.
492 scoped_refptr<MessageLoopRunner> message_loop_runner_;
493
494 DISALLOW_COPY_AND_ASSIGN(ConsoleObserverDelegate);
495 };
496
497 void ConsoleObserverDelegate::Wait() {
498 message_loop_runner_->Run();
499 }
500
501 bool ConsoleObserverDelegate::AddMessageToConsole(
502 WebContents* source,
503 int32_t level,
504 const base::string16& message,
505 int32_t line_no,
506 const base::string16& source_id) {
507 DCHECK(source == web_contents_);
508
509 std::string ascii_message = base::UTF16ToASCII(message);
510 if (base::MatchPattern(ascii_message, filter_)) {
511 message_ = ascii_message;
512 message_loop_runner_->Quit();
513 }
514 return false;
515 }
516
517 // A BrowserMessageFilter that drops SwapOut ACK messages. 465 // A BrowserMessageFilter that drops SwapOut ACK messages.
518 class SwapoutACKMessageFilter : public BrowserMessageFilter { 466 class SwapoutACKMessageFilter : public BrowserMessageFilter {
519 public: 467 public:
520 SwapoutACKMessageFilter() : BrowserMessageFilter(FrameMsgStart) {} 468 SwapoutACKMessageFilter() : BrowserMessageFilter(FrameMsgStart) {}
521 469
522 protected: 470 protected:
523 ~SwapoutACKMessageFilter() override {} 471 ~SwapoutACKMessageFilter() override {}
524 472
525 private: 473 private:
526 // BrowserMessageFilter: 474 // BrowserMessageFilter:
(...skipping 6399 matching lines...) Expand 10 before | Expand all | Expand 10 after
6926 6874
6927 EXPECT_EQ( 6875 EXPECT_EQ(
6928 " Site A ------------ proxies for B\n" 6876 " Site A ------------ proxies for B\n"
6929 " +--Site B ------- proxies for A\n" 6877 " +--Site B ------- proxies for A\n"
6930 "Where A = http://a.com/\n" 6878 "Where A = http://a.com/\n"
6931 " B = http://b.com/", 6879 " B = http://b.com/",
6932 DepictFrameTree(root)); 6880 DepictFrameTree(root));
6933 } 6881 }
6934 6882
6935 } // namespace content 6883 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698