| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code if governed by a BSD-style license that can be | 2 // Use of this source code if governed by a BSD-style license that can be |
| 3 // found in LICENSE file. | 3 // found in LICENSE file. |
| 4 | 4 |
| 5 #include "platform/testing/TestingPlatformSupport.h" | |
| 6 #include "public/platform/WebRTCError.h" | |
| 7 #include "public/platform/WebRTCPeerConnectionHandler.h" | |
| 8 #include "public/platform/WebRTCSessionDescription.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/WebKit/public/platform/WebViewScheduler.h" | 6 #include "third_party/WebKit/public/platform/WebViewScheduler.h" |
| 11 #include "web/WebViewImpl.h" | 7 #include "web/WebViewImpl.h" |
| 12 #include "web/tests/sim/SimRequest.h" | 8 #include "web/tests/sim/SimRequest.h" |
| 13 #include "web/tests/sim/SimTest.h" | 9 #include "web/tests/sim/SimTest.h" |
| 14 | 10 |
| 15 using testing::_; | 11 using testing::_; |
| 16 | 12 |
| 17 namespace blink { | 13 namespace blink { |
| 18 | 14 |
| 19 class ActiveConnectionThrottlingTest : public SimTest {}; | 15 class ActiveConnectionThrottlingTest : public SimTest {}; |
| 20 | 16 |
| 21 TEST_F(ActiveConnectionThrottlingTest, WebSocketStopsThrottling) { | 17 TEST_F(ActiveConnectionThrottlingTest, WebSocketStopsThrottling) { |
| 22 SimRequest mainResource("https://example.com/", "text/html"); | 18 SimRequest mainResource("https://example.com/", "text/html"); |
| 23 | 19 |
| 24 loadURL("https://example.com/"); | 20 loadURL("https://example.com/"); |
| 25 | 21 |
| 26 EXPECT_FALSE(webView().scheduler()->hasActiveConnectionForTest()); | 22 EXPECT_FALSE(webView().scheduler()->hasActiveConnectionForTest()); |
| 27 | 23 |
| 28 mainResource.complete( | 24 mainResource.complete( |
| 29 "(<script>" | 25 "(<script>" |
| 30 " var socket = new WebSocket(\"ws://www.example.com/websocket\");" | 26 " var socket = new WebSocket(\"ws://www.example.com/websocket\");" |
| 31 "</script>)"); | 27 "</script>)"); |
| 32 | 28 |
| 33 EXPECT_TRUE(webView().scheduler()->hasActiveConnectionForTest()); | 29 EXPECT_TRUE(webView().scheduler()->hasActiveConnectionForTest()); |
| 34 } | 30 } |
| 35 | 31 |
| 36 namespace { | |
| 37 | |
| 38 class MockWebRTCPeerConnectionHandler : public WebRTCPeerConnectionHandler { | |
| 39 public: | |
| 40 MockWebRTCPeerConnectionHandler() {} | |
| 41 ~MockWebRTCPeerConnectionHandler() override {} | |
| 42 | |
| 43 bool initialize(const WebRTCConfiguration&, | |
| 44 const WebMediaConstraints&) override { | |
| 45 return true; | |
| 46 } | |
| 47 | |
| 48 void createOffer(const WebRTCSessionDescriptionRequest&, | |
| 49 const WebMediaConstraints&) override {} | |
| 50 void createOffer(const WebRTCSessionDescriptionRequest&, | |
| 51 const WebRTCOfferOptions&) override {} | |
| 52 void createAnswer(const WebRTCSessionDescriptionRequest&, | |
| 53 const WebMediaConstraints&) override {} | |
| 54 void createAnswer(const WebRTCSessionDescriptionRequest&, | |
| 55 const WebRTCAnswerOptions&) override {} | |
| 56 void setLocalDescription(const WebRTCVoidRequest&, | |
| 57 const WebRTCSessionDescription&) override {} | |
| 58 void setRemoteDescription(const WebRTCVoidRequest&, | |
| 59 const WebRTCSessionDescription&) override {} | |
| 60 WebRTCSessionDescription localDescription() override { | |
| 61 return WebRTCSessionDescription(); | |
| 62 } | |
| 63 WebRTCSessionDescription remoteDescription() override { | |
| 64 return WebRTCSessionDescription(); | |
| 65 } | |
| 66 WebRTCErrorType setConfiguration(const WebRTCConfiguration&) override { | |
| 67 return WebRTCErrorType::kNone; | |
| 68 } | |
| 69 bool addStream(const WebMediaStream&, const WebMediaConstraints&) override { | |
| 70 return true; | |
| 71 } | |
| 72 void removeStream(const WebMediaStream&) override {} | |
| 73 void getStats(const WebRTCStatsRequest&) override {} | |
| 74 void getStats(std::unique_ptr<WebRTCStatsReportCallback>) override {} | |
| 75 WebRTCDataChannelHandler* createDataChannel( | |
| 76 const WebString& label, | |
| 77 const WebRTCDataChannelInit&) override { | |
| 78 return nullptr; | |
| 79 } | |
| 80 WebRTCDTMFSenderHandler* createDTMFSender( | |
| 81 const WebMediaStreamTrack&) override { | |
| 82 return nullptr; | |
| 83 } | |
| 84 void stop() override {} | |
| 85 }; | |
| 86 | |
| 87 class TestingPlatformSupportWithWebRTC : public TestingPlatformSupport { | |
| 88 public: | |
| 89 blink::WebRTCPeerConnectionHandler* createRTCPeerConnectionHandler( | |
| 90 blink::WebRTCPeerConnectionHandlerClient*) override { | |
| 91 return new MockWebRTCPeerConnectionHandler(); | |
| 92 } | |
| 93 }; | |
| 94 | |
| 95 } // namespace | |
| 96 | |
| 97 TEST_F(ActiveConnectionThrottlingTest, WebRTCStopsThrottling) { | |
| 98 ScopedTestingPlatformSupport<TestingPlatformSupportWithWebRTC> platform; | |
| 99 | |
| 100 SimRequest mainResource("https://example.com/", "text/html"); | |
| 101 | |
| 102 loadURL("https://example.com/"); | |
| 103 | |
| 104 EXPECT_FALSE(webView().scheduler()->hasActiveConnectionForTest()); | |
| 105 | |
| 106 mainResource.complete( | |
| 107 "(<script>" | |
| 108 " var data_channel = new RTCPeerConnection();" | |
| 109 "</script>)"); | |
| 110 | |
| 111 EXPECT_TRUE(webView().scheduler()->hasActiveConnectionForTest()); | |
| 112 } | |
| 113 | |
| 114 } // namespace blink | 32 } // namespace blink |
| OLD | NEW |