| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/websockets/DOMWebSocket.h" | 6 #include "modules/websockets/DOMWebSocket.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/V8Binding.h" | 9 #include "bindings/core/v8/V8Binding.h" |
| 10 #include "core/dom/DOMTypedArray.h" | 10 #include "core/dom/DOMTypedArray.h" |
| 11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
| 12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/dom/SecurityContext.h" |
| 13 #include "core/fileapi/Blob.h" | 14 #include "core/fileapi/Blob.h" |
| 14 #include "core/frame/ConsoleTypes.h" | 15 #include "core/frame/ConsoleTypes.h" |
| 15 #include "core/testing/DummyPageHolder.h" | 16 #include "core/testing/DummyPageHolder.h" |
| 16 #include "wtf/OwnPtr.h" | 17 #include "wtf/OwnPtr.h" |
| 17 #include "wtf/Vector.h" | 18 #include "wtf/Vector.h" |
| 18 #include "wtf/testing/WTFTestHelpers.h" | 19 #include "wtf/testing/WTFTestHelpers.h" |
| 19 #include "wtf/text/WTFString.h" | 20 #include "wtf/text/WTFString.h" |
| 20 #include <gmock/gmock.h> | 21 #include <gmock/gmock.h> |
| 21 #include <gtest/gtest.h> | 22 #include <gtest/gtest.h> |
| 22 #include <v8.h> | 23 #include <v8.h> |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 subprotocols.append("@subprotocol-|'\"x\x01\x02\x03x"); | 181 subprotocols.append("@subprotocol-|'\"x\x01\x02\x03x"); |
| 181 | 182 |
| 182 m_websocket->connect("ws://example.com/", subprotocols, m_exceptionState); | 183 m_websocket->connect("ws://example.com/", subprotocols, m_exceptionState); |
| 183 | 184 |
| 184 EXPECT_TRUE(m_exceptionState.hadException()); | 185 EXPECT_TRUE(m_exceptionState.hadException()); |
| 185 EXPECT_EQ(SyntaxError, m_exceptionState.code()); | 186 EXPECT_EQ(SyntaxError, m_exceptionState.code()); |
| 186 EXPECT_EQ("The subprotocol '@subprotocol-|'\"x\\u0001\\u0002\\u0003x' is inv
alid.", m_exceptionState.message()); | 187 EXPECT_EQ("The subprotocol '@subprotocol-|'\"x\\u0001\\u0002\\u0003x' is inv
alid.", m_exceptionState.message()); |
| 187 EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState()); | 188 EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState()); |
| 188 } | 189 } |
| 189 | 190 |
| 191 TEST_F(DOMWebSocketTest, insecureContentUpgrade) |
| 192 { |
| 193 { |
| 194 InSequence s; |
| 195 EXPECT_CALL(channel(), connect(KURL(KURL(), "wss://example.com/endpoint"
), String())).WillOnce(Return(true)); |
| 196 } |
| 197 |
| 198 m_pageHolder->document().setInsecureContentPolicy(SecurityContext::InsecureC
ontentUpgrade); |
| 199 m_websocket->connect("ws://example.com/endpoint", Vector<String>(), m_except
ionState); |
| 200 |
| 201 EXPECT_FALSE(m_exceptionState.hadException()); |
| 202 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
| 203 EXPECT_EQ(KURL(KURL(), "wss://example.com/endpoint"), m_websocket->url()); |
| 204 } |
| 205 |
| 206 TEST_F(DOMWebSocketTest, insecureContentDoNotUpgrade) |
| 207 { |
| 208 { |
| 209 InSequence s; |
| 210 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/endpoint")
, String())).WillOnce(Return(true)); |
| 211 } |
| 212 |
| 213 m_pageHolder->document().setInsecureContentPolicy(SecurityContext::InsecureC
ontentDoNotUpgrade); |
| 214 m_websocket->connect("ws://example.com/endpoint", Vector<String>(), m_except
ionState); |
| 215 |
| 216 EXPECT_FALSE(m_exceptionState.hadException()); |
| 217 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
| 218 EXPECT_EQ(KURL(KURL(), "ws://example.com/endpoint"), m_websocket->url()); |
| 219 } |
| 220 |
| 221 TEST_F(DOMWebSocketTest, insecureContentMonitor) |
| 222 { |
| 223 { |
| 224 InSequence s; |
| 225 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/endpoint")
, String())).WillOnce(Return(true)); |
| 226 } |
| 227 |
| 228 m_pageHolder->document().setInsecureContentPolicy(SecurityContext::InsecureC
ontentMonitor); |
| 229 m_websocket->connect("ws://example.com/endpoint", Vector<String>(), m_except
ionState); |
| 230 |
| 231 EXPECT_FALSE(m_exceptionState.hadException()); |
| 232 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
| 233 EXPECT_EQ(KURL(KURL(), "ws://example.com/endpoint"), m_websocket->url()); |
| 234 } |
| 235 |
| 190 TEST_F(DOMWebSocketTest, channelConnectSuccess) | 236 TEST_F(DOMWebSocketTest, channelConnectSuccess) |
| 191 { | 237 { |
| 192 Vector<String> subprotocols; | 238 Vector<String> subprotocols; |
| 193 subprotocols.append("aa"); | 239 subprotocols.append("aa"); |
| 194 subprotocols.append("bb"); | 240 subprotocols.append("bb"); |
| 195 | 241 |
| 196 { | 242 { |
| 197 InSequence s; | 243 InSequence s; |
| 198 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/hoge"), St
ring("aa, bb"))).WillOnce(Return(true)); | 244 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/hoge"), St
ring("aa, bb"))).WillOnce(Return(true)); |
| 199 } | 245 } |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); | 743 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); |
| 698 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); | 744 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); |
| 699 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 745 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
| 700 } | 746 } |
| 701 | 747 |
| 702 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi
ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); | 748 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi
ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); |
| 703 | 749 |
| 704 } // namespace | 750 } // namespace |
| 705 | 751 |
| 706 } // namespace blink | 752 } // namespace blink |
| OLD | NEW |