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

Side by Side Diff: content/browser/webrtc/webrtc_internals_unittest.cc

Issue 2502413002: Release PowerSaveBlock on PeerConnection stop instead of removal (Closed)
Patch Set: Created 4 years, 1 month 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/browser/webrtc/webrtc_internals.h" 5 #include "content/browser/webrtc/webrtc_internals.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string>
8 9
9 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "content/browser/webrtc/webrtc_internals_ui_observer.h" 13 #include "content/browser/webrtc/webrtc_internals_ui_observer.h"
13 #include "content/public/test/test_browser_thread.h" 14 #include "content/public/test/test_browser_thread.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace content { 17 namespace content {
17 18
18 namespace { 19 namespace {
19 20
20 static const std::string kContraints = "c"; 21 static const char kContraints[] = "c";
21 static const std::string kRtcConfiguration = "r"; 22 static const char kRtcConfiguration[] = "r";
22 static const std::string kUrl = "u"; 23 static const char kUrl[] = "u";
23 24
24 class MockWebRtcInternalsProxy : public WebRTCInternalsUIObserver { 25 class MockWebRtcInternalsProxy : public WebRTCInternalsUIObserver {
25 public: 26 public:
26 MockWebRtcInternalsProxy() : loop_(nullptr) {} 27 MockWebRtcInternalsProxy() : loop_(nullptr) {}
27 explicit MockWebRtcInternalsProxy(base::RunLoop* loop) : loop_(loop) {} 28 explicit MockWebRtcInternalsProxy(base::RunLoop* loop) : loop_(loop) {}
28 29
29 const std::string& command() const { 30 const std::string& command() const {
30 return command_; 31 return command_;
31 } 32 }
32 33
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 335
335 webrtc_internals.AddObserver(&observer); 336 webrtc_internals.AddObserver(&observer);
336 webrtc_internals.FileSelectionCanceled(nullptr); 337 webrtc_internals.FileSelectionCanceled(nullptr);
337 338
338 loop.Run(); 339 loop.Run();
339 340
340 EXPECT_EQ("audioDebugRecordingsFileSelectionCancelled", observer.command()); 341 EXPECT_EQ("audioDebugRecordingsFileSelectionCancelled", observer.command());
341 EXPECT_EQ(nullptr, observer.value()); 342 EXPECT_EQ(nullptr, observer.value());
342 } 343 }
343 344
345 TEST_F(WebRtcInternalsTest, PowerSaveBlock) {
346 int kRenderProcessId = 1;
347 int pid = 1;
348 int lid[] = {1, 2, 3};
349
350 WebRTCInternalsForTest webrtc_internals;
351
352 // Add a few peer connections.
353 EXPECT_EQ(0, webrtc_internals.num_open_connections());
354 EXPECT_FALSE(webrtc_internals.IsPowerSavingBlocked());
355 webrtc_internals.OnAddPeerConnection(kRenderProcessId, pid, lid[0], kUrl,
356 kRtcConfiguration, kContraints);
357 EXPECT_EQ(1, webrtc_internals.num_open_connections());
358 EXPECT_TRUE(webrtc_internals.IsPowerSavingBlocked());
359
360 webrtc_internals.OnAddPeerConnection(kRenderProcessId, pid, lid[1], kUrl,
361 kRtcConfiguration, kContraints);
362 EXPECT_EQ(2, webrtc_internals.num_open_connections());
363 EXPECT_TRUE(webrtc_internals.IsPowerSavingBlocked());
364
365 webrtc_internals.OnAddPeerConnection(kRenderProcessId, pid, lid[2], kUrl,
366 kRtcConfiguration, kContraints);
367 EXPECT_EQ(3, webrtc_internals.num_open_connections());
368 EXPECT_TRUE(webrtc_internals.IsPowerSavingBlocked());
369
370 // Remove a peer connection without closing it first.
371 webrtc_internals.OnRemovePeerConnection(pid, lid[2]);
372 EXPECT_EQ(2, webrtc_internals.num_open_connections());
373 EXPECT_TRUE(webrtc_internals.IsPowerSavingBlocked());
374
375 // Close the remaining peer connections.
376 webrtc_internals.OnUpdatePeerConnection(pid, lid[1], "stop", std::string());
377 EXPECT_EQ(1, webrtc_internals.num_open_connections());
378 EXPECT_TRUE(webrtc_internals.IsPowerSavingBlocked());
379
380 webrtc_internals.OnUpdatePeerConnection(pid, lid[0], "stop", std::string());
381 EXPECT_EQ(0, webrtc_internals.num_open_connections());
382 EXPECT_FALSE(webrtc_internals.IsPowerSavingBlocked());
383
384 // Remove the remaining peer connections.
385 webrtc_internals.OnRemovePeerConnection(pid, lid[1]);
386 EXPECT_EQ(0, webrtc_internals.num_open_connections());
387 EXPECT_FALSE(webrtc_internals.IsPowerSavingBlocked());
388
389 webrtc_internals.OnRemovePeerConnection(pid, lid[0]);
390 EXPECT_EQ(0, webrtc_internals.num_open_connections());
391 EXPECT_FALSE(webrtc_internals.IsPowerSavingBlocked());
392 }
393
344 } // namespace content 394 } // namespace content
OLDNEW
« content/browser/webrtc/webrtc_internals.h ('K') | « content/browser/webrtc/webrtc_internals.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698