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