| 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 "modules/websockets/DOMWebSocket.h" | 5 #include "modules/websockets/DOMWebSocket.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/V8Binding.h" | 8 #include "bindings/core/v8/V8Binding.h" |
| 9 #include "bindings/core/v8/V8BindingForTesting.h" | 9 #include "bindings/core/v8/V8BindingForTesting.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/dom/SecurityContext.h" |
| 14 #include "core/fileapi/Blob.h" | 14 #include "core/fileapi/Blob.h" |
| 15 #include "core/testing/DummyPageHolder.h" | 15 #include "core/testing/DummyPageHolder.h" |
| 16 #include "platform/heap/Handle.h" | 16 #include "platform/heap/Handle.h" |
| 17 #include "platform/v8_inspector/public/ConsoleTypes.h" | 17 #include "platform/v8_inspector/public/ConsoleTypes.h" |
| 18 #include "public/platform/WebInsecureRequestPolicy.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "wtf/OwnPtr.h" | 21 #include "wtf/OwnPtr.h" |
| 21 #include "wtf/Vector.h" | 22 #include "wtf/Vector.h" |
| 22 #include "wtf/text/CString.h" | 23 #include "wtf/text/CString.h" |
| 23 #include "wtf/text/WTFString.h" | 24 #include "wtf/text/WTFString.h" |
| 24 #include <v8.h> | 25 #include <v8.h> |
| 25 | 26 |
| 26 using testing::_; | 27 using testing::_; |
| 27 using testing::AnyNumber; | 28 using testing::AnyNumber; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState()); | 203 EXPECT_EQ(DOMWebSocket::CLOSED, m_websocket->readyState()); |
| 203 } | 204 } |
| 204 | 205 |
| 205 TEST_F(DOMWebSocketTest, insecureRequestsUpgrade) | 206 TEST_F(DOMWebSocketTest, insecureRequestsUpgrade) |
| 206 { | 207 { |
| 207 { | 208 { |
| 208 InSequence s; | 209 InSequence s; |
| 209 EXPECT_CALL(channel(), connect(KURL(KURL(), "wss://example.com/endpoint"
), String())).WillOnce(Return(true)); | 210 EXPECT_CALL(channel(), connect(KURL(KURL(), "wss://example.com/endpoint"
), String())).WillOnce(Return(true)); |
| 210 } | 211 } |
| 211 | 212 |
| 212 m_pageHolder->document().setInsecureRequestsPolicy(SecurityContext::Insecure
RequestsUpgrade); | 213 m_pageHolder->document().setInsecureRequestPolicy(kUpgradeInsecureRequests); |
| 213 m_websocket->connect("ws://example.com/endpoint", Vector<String>(), m_except
ionState); | 214 m_websocket->connect("ws://example.com/endpoint", Vector<String>(), m_except
ionState); |
| 214 | 215 |
| 215 EXPECT_FALSE(m_exceptionState.hadException()); | 216 EXPECT_FALSE(m_exceptionState.hadException()); |
| 216 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 217 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
| 217 EXPECT_EQ(KURL(KURL(), "wss://example.com/endpoint"), m_websocket->url()); | 218 EXPECT_EQ(KURL(KURL(), "wss://example.com/endpoint"), m_websocket->url()); |
| 218 } | 219 } |
| 219 | 220 |
| 220 TEST_F(DOMWebSocketTest, insecureRequestsDoNotUpgrade) | 221 TEST_F(DOMWebSocketTest, insecureRequestsDoNotUpgrade) |
| 221 { | 222 { |
| 222 { | 223 { |
| 223 InSequence s; | 224 InSequence s; |
| 224 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/endpoint")
, String())).WillOnce(Return(true)); | 225 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/endpoint")
, String())).WillOnce(Return(true)); |
| 225 } | 226 } |
| 226 | 227 |
| 227 m_pageHolder->document().setInsecureRequestsPolicy(SecurityContext::Insecure
RequestsDoNotUpgrade); | 228 m_pageHolder->document().setInsecureRequestPolicy(kLeaveInsecureRequestsAlon
e); |
| 228 m_websocket->connect("ws://example.com/endpoint", Vector<String>(), m_except
ionState); | 229 m_websocket->connect("ws://example.com/endpoint", Vector<String>(), m_except
ionState); |
| 229 | 230 |
| 230 EXPECT_FALSE(m_exceptionState.hadException()); | 231 EXPECT_FALSE(m_exceptionState.hadException()); |
| 231 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 232 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
| 232 EXPECT_EQ(KURL(KURL(), "ws://example.com/endpoint"), m_websocket->url()); | 233 EXPECT_EQ(KURL(KURL(), "ws://example.com/endpoint"), m_websocket->url()); |
| 233 } | 234 } |
| 234 | 235 |
| 235 TEST_F(DOMWebSocketTest, channelConnectSuccess) | 236 TEST_F(DOMWebSocketTest, channelConnectSuccess) |
| 236 { | 237 { |
| 237 Vector<String> subprotocols; | 238 Vector<String> subprotocols; |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); | 758 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); |
| 758 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); | 759 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); |
| 759 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); | 760 EXPECT_EQ(DOMWebSocket::CONNECTING, m_websocket->readyState()); |
| 760 } | 761 } |
| 761 | 762 |
| 762 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi
ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); | 763 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi
ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); |
| 763 | 764 |
| 764 } // namespace | 765 } // namespace |
| 765 | 766 |
| 766 } // namespace blink | 767 } // namespace blink |
| OLD | NEW |