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

Side by Side Diff: third_party/WebKit/Source/web/tests/ActiveConnectionThrottlingTest.cpp

Issue 2885313003: [scheduler] Fix --disable-background-timer-throttling flag. (Closed)
Patch Set: fix test crash Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in LICENSE file.
4
5 #include "core/exported/WebViewBase.h"
6 #include "platform/scheduler/renderer/web_view_scheduler.h"
7 #include "platform/testing/TestingPlatformSupport.h"
8 #include "platform/wtf/PtrUtil.h"
9 #include "public/platform/WebRTCError.h"
10 #include "public/platform/WebRTCPeerConnectionHandler.h"
11 #include "public/platform/WebRTCRtpReceiver.h"
12 #include "public/platform/WebRTCRtpSender.h"
13 #include "public/platform/WebRTCSessionDescription.h"
14 #include "public/web/WebScriptSource.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "web/WebLocalFrameImpl.h"
17 #include "web/tests/sim/SimRequest.h"
18 #include "web/tests/sim/SimTest.h"
19
20 using testing::_;
21
22 namespace blink {
23
24 class ActiveConnectionThrottlingTest : public SimTest {};
25
26 TEST_F(ActiveConnectionThrottlingTest, WebSocketStopsThrottling) {
27 SimRequest main_resource("https://example.com/", "text/html");
28
29 LoadURL("https://example.com/");
30
31 EXPECT_FALSE(WebView().Scheduler()->HasActiveConnectionForTest());
32
33 main_resource.Complete(
34 "(<script>"
35 " var socket = new WebSocket(\"ws://www.example.com/websocket\");"
36 "</script>)");
37
38 EXPECT_TRUE(WebView().Scheduler()->HasActiveConnectionForTest());
39
40 MainFrame().ExecuteScript(WebString("socket.close();"));
41
42 EXPECT_FALSE(WebView().Scheduler()->HasActiveConnectionForTest());
43 }
44
45 namespace {
46
47 class MockWebRTCPeerConnectionHandler : public WebRTCPeerConnectionHandler {
48 public:
49 MockWebRTCPeerConnectionHandler() {}
50 ~MockWebRTCPeerConnectionHandler() override {}
51
52 bool Initialize(const WebRTCConfiguration&,
53 const WebMediaConstraints&) override {
54 return true;
55 }
56
57 void CreateOffer(const WebRTCSessionDescriptionRequest&,
58 const WebMediaConstraints&) override {}
59 void CreateOffer(const WebRTCSessionDescriptionRequest&,
60 const WebRTCOfferOptions&) override {}
61 void CreateAnswer(const WebRTCSessionDescriptionRequest&,
62 const WebMediaConstraints&) override {}
63 void CreateAnswer(const WebRTCSessionDescriptionRequest&,
64 const WebRTCAnswerOptions&) override {}
65 void SetLocalDescription(const WebRTCVoidRequest&,
66 const WebRTCSessionDescription&) override {}
67 void SetRemoteDescription(const WebRTCVoidRequest&,
68 const WebRTCSessionDescription&) override {}
69 WebRTCSessionDescription LocalDescription() override {
70 return WebRTCSessionDescription();
71 }
72 WebRTCSessionDescription RemoteDescription() override {
73 return WebRTCSessionDescription();
74 }
75 WebRTCErrorType SetConfiguration(const WebRTCConfiguration&) override {
76 return WebRTCErrorType::kNone;
77 }
78 bool AddStream(const WebMediaStream&, const WebMediaConstraints&) override {
79 return true;
80 }
81 void RemoveStream(const WebMediaStream&) override {}
82 void GetStats(const WebRTCStatsRequest&) override {}
83 void GetStats(std::unique_ptr<WebRTCStatsReportCallback>) override {}
84 blink::WebVector<std::unique_ptr<blink::WebRTCRtpSender>> GetSenders()
85 override {
86 return blink::WebVector<std::unique_ptr<blink::WebRTCRtpSender>>();
87 }
88 blink::WebVector<std::unique_ptr<blink::WebRTCRtpReceiver>> GetReceivers()
89 override {
90 return blink::WebVector<std::unique_ptr<blink::WebRTCRtpReceiver>>();
91 }
92 WebRTCDataChannelHandler* CreateDataChannel(
93 const WebString& label,
94 const WebRTCDataChannelInit&) override {
95 return nullptr;
96 }
97 WebRTCDTMFSenderHandler* CreateDTMFSender(
98 const WebMediaStreamTrack&) override {
99 return nullptr;
100 }
101 void Stop() override {}
102 };
103
104 class TestingPlatformSupportWithWebRTC : public TestingPlatformSupport {
105 public:
106 std::unique_ptr<blink::WebRTCPeerConnectionHandler>
107 CreateRTCPeerConnectionHandler(
108 blink::WebRTCPeerConnectionHandlerClient*) override {
109 return WTF::MakeUnique<MockWebRTCPeerConnectionHandler>();
110 }
111 };
112
113 } // namespace
114
115 TEST_F(ActiveConnectionThrottlingTest, WebRTCStopsThrottling) {
116 ScopedTestingPlatformSupport<TestingPlatformSupportWithWebRTC> platform;
117
118 SimRequest main_resource("https://example.com/", "text/html");
119
120 LoadURL("https://example.com/");
121
122 EXPECT_FALSE(WebView().Scheduler()->HasActiveConnectionForTest());
123
124 main_resource.Complete(
125 "(<script>"
126 " var data_channel = new RTCPeerConnection();"
127 "</script>)");
128
129 EXPECT_TRUE(WebView().Scheduler()->HasActiveConnectionForTest());
130
131 MainFrame().ExecuteScript(WebString("data_channel.close();"));
132
133 EXPECT_FALSE(WebView().Scheduler()->HasActiveConnectionForTest());
134 }
135
136 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/BUILD.gn ('k') | third_party/WebKit/Source/web/tests/DeferredLoadingTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698