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

Unified Diff: Source/modules/websockets/DOMWebSocketTest.cpp

Issue 901903003: CSP: Adding the 'upgrade-insecure-requests' directive. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: WebSockets + Tests. Created 5 years, 10 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 | « Source/modules/websockets/DOMWebSocket.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/websockets/DOMWebSocketTest.cpp
diff --git a/Source/modules/websockets/DOMWebSocketTest.cpp b/Source/modules/websockets/DOMWebSocketTest.cpp
index e72c303ad2bcc813650f245d2c2974fef14e4fdb..4974926726f11cdf2d31867c6b4561e542677bad 100644
--- a/Source/modules/websockets/DOMWebSocketTest.cpp
+++ b/Source/modules/websockets/DOMWebSocketTest.cpp
@@ -10,6 +10,7 @@
#include "core/dom/DOMTypedArray.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
+#include "core/dom/SecurityContext.h"
#include "core/fileapi/Blob.h"
#include "core/frame/ConsoleTypes.h"
#include "core/testing/DummyPageHolder.h"
@@ -187,6 +188,51 @@ TEST_F(DOMWebSocketTest, invalidSubprotocols)
EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState());
}
+TEST_F(DOMWebSocketTest, insecureContentUpgrade)
+{
+ {
+ InSequence s;
+ EXPECT_CALL(channel(), connect(KURL(KURL(), "wss://example.com/endpoint"), String())).WillOnce(Return(true));
+ }
+
+ m_pageHolder->document().setInsecureContentPolicy(SecurityContext::InsecureContentUpgrade);
+ m_websocket->connect("ws://example.com/endpoint", Vector<String>(), m_exceptionState);
+
+ EXPECT_FALSE(m_exceptionState.hadException());
+ EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState());
+ EXPECT_EQ(KURL(KURL(), "wss://example.com/endpoint"), m_websocket->url());
+}
+
+TEST_F(DOMWebSocketTest, insecureContentDoNotUpgrade)
+{
+ {
+ InSequence s;
+ EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/endpoint"), String())).WillOnce(Return(true));
+ }
+
+ m_pageHolder->document().setInsecureContentPolicy(SecurityContext::InsecureContentDoNotUpgrade);
+ m_websocket->connect("ws://example.com/endpoint", Vector<String>(), m_exceptionState);
+
+ EXPECT_FALSE(m_exceptionState.hadException());
+ EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState());
+ EXPECT_EQ(KURL(KURL(), "ws://example.com/endpoint"), m_websocket->url());
+}
+
+TEST_F(DOMWebSocketTest, insecureContentMonitor)
+{
+ {
+ InSequence s;
+ EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/endpoint"), String())).WillOnce(Return(true));
+ }
+
+ m_pageHolder->document().setInsecureContentPolicy(SecurityContext::InsecureContentMonitor);
+ m_websocket->connect("ws://example.com/endpoint", Vector<String>(), m_exceptionState);
+
+ EXPECT_FALSE(m_exceptionState.hadException());
+ EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState());
+ EXPECT_EQ(KURL(KURL(), "ws://example.com/endpoint"), m_websocket->url());
+}
+
TEST_F(DOMWebSocketTest, channelConnectSuccess)
{
Vector<String> subprotocols;
« no previous file with comments | « Source/modules/websockets/DOMWebSocket.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698