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

Unified Diff: chrome/test/base/in_process_browser_test.cc

Issue 2013573007: Catch CSP violations in InProcessBrowserTest Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: double check test is run Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/base/in_process_browser_test.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/base/in_process_browser_test.cc
diff --git a/chrome/test/base/in_process_browser_test.cc b/chrome/test/base/in_process_browser_test.cc
index e277349d4ab37ad0707039713aee568d43c7fa1d..d5eee317b51bc3aaf33b2dcc89361d8911856395 100644
--- a/chrome/test/base/in_process_browser_test.cc
+++ b/chrome/test/base/in_process_browser_test.cc
@@ -132,12 +132,14 @@ const char kAccessibilityTestString[] =
"domAutomationController.send(error);";
InProcessBrowserTest::InProcessBrowserTest()
- : browser_(NULL),
+ : browser_(nullptr),
exit_when_last_browser_closes_(true),
open_about_blank_on_browser_launch_(true),
+ expect_csp_messages_(false),
+ console_delegate_(nullptr),
run_accessibility_checks_for_test_case_(false)
#if defined(OS_MACOSX)
- , autorelease_pool_(NULL)
+ , autorelease_pool_(nullptr)
#endif // OS_MACOSX
{
#if defined(OS_MACOSX)
@@ -173,6 +175,10 @@ InProcessBrowserTest::InProcessBrowserTest()
}
InProcessBrowserTest::~InProcessBrowserTest() {
+ // Make sure console_delegate_ is active in a function that's guaranteed
+ // to be called. RunTestOnMainThreadLoop() could be overriden.
+ CHECK(console_delegate_);
+ delete console_delegate_;
}
void InProcessBrowserTest::SetUp() {
@@ -403,6 +409,10 @@ bool InProcessBrowserTest::SetUpUserDataDirectory() {
return true;
}
+void InProcessBrowserTest::SetExpectCSPErrorMessages(bool expect) {
+ expect_csp_messages_ = expect;
+}
+
#if !defined(OS_MACOSX)
void InProcessBrowserTest::OpenDevToolsWindow(
content::WebContents* web_contents) {
@@ -535,6 +545,14 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() {
// enable/disable the accessibility audit.
run_accessibility_checks_for_test_case_ = false;
+ // Set up console message listener to look for CSP error messages.
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ console_delegate_ = new content::ConsoleObserverDelegate(
+ web_contents,
+ "*Content Security Policy*");
+ web_contents->SetDelegate(console_delegate_);
+
SetUpOnMainThread();
#if defined(OS_MACOSX)
autorelease_pool_->Recycle();
@@ -559,6 +577,13 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() {
autorelease_pool_->Recycle();
#endif
+ // Check CSP error messages.
+ if (expect_csp_messages_) {
+ EXPECT_NE("", console_delegate_->message());
+ } else {
+ EXPECT_EQ("", console_delegate_->message());
+ }
+
// Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's
// run all pending messages here to avoid preempting the QuitBrowsers tasks.
// TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it
@@ -595,6 +620,6 @@ void InProcessBrowserTest::QuitBrowsers() {
// get deleted.
content::RunAllPendingInMessageLoop();
delete autorelease_pool_;
- autorelease_pool_ = NULL;
+ autorelease_pool_ = nullptr;
#endif
}
« no previous file with comments | « chrome/test/base/in_process_browser_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698