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

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

Issue 11876007: Connecting webrtc-internals WebUI frontend with the backend (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@main
Patch Set: Created 7 years, 11 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 (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop.h"
7 #include "base/values.h"
8 #include "content/browser/media/webrtc_internals.h"
9 #include "content/browser/media/webrtc_internals_ui_observer.h"
10 #include "content/common/media/peer_connection_tracker_messages.h"
11 #include "content/public/test/test_browser_thread.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace content {
15 class MockWebRTCInternalsProxy : public content::WebRTCInternalsUIObserver {
16 public:
17 void OnUpdate(const std::string& command, const Value* value) OVERRIDE {
18 data_ = command;
19 }
20
21 std::string data() {
22 return data_;
23 }
24
25 private:
26 std::string data_;
27 };
28
29 class WebRTCInternalsTest : public testing::Test {
30 public:
31 WebRTCInternalsTest()
32 : io_thread_(content::BrowserThread::IO, &io_loop_) {}
33
34 protected:
35 virtual void SetUp() {
36 webrtc_internals_ = WebRTCInternals::GetInstance();
37 }
38
39 PeerConnectionInfo GetPeerConnectionInfo(uintptr_t lid) {
40 PeerConnectionInfo info;
41 info.lid = lid;
42 info.servers = "s";
43 info.constraints = "c";
44 info.url = "u";
45 return info;
46 }
47 std::string ExpectedInfo(std::string prefix,
48 std::string id,
49 std::string suffix) {
50 static const std::string kstatic_part1 = std::string(
51 "{\"constraints\":\"c\",");
52 static const std::string kstatic_part2 = std::string(
53 ",\"servers\":\"s\",\"url\":\"u\"}");
54 return prefix + kstatic_part1 + id + kstatic_part2 + suffix;
55 }
56
57 MessageLoop io_loop_;
58 content::TestBrowserThread io_thread_;
59 WebRTCInternals *webrtc_internals_;
60 };
61
62 TEST_F(WebRTCInternalsTest, GetInstance) {
63 EXPECT_TRUE(webrtc_internals_);
64 }
65
66 TEST_F(WebRTCInternalsTest, AddRemoveObserver) {
67 scoped_ptr<MockWebRTCInternalsProxy> observer(
68 new MockWebRTCInternalsProxy());
69 webrtc_internals_->AddObserver(observer.get());
70 webrtc_internals_->RemoveObserver(observer.get());
71 webrtc_internals_->AddPeerConnection(3, GetPeerConnectionInfo(4));
72 EXPECT_EQ("", observer->data());
73
74 webrtc_internals_->RemovePeerConnection(3, 4);
75 }
76
77 TEST_F(WebRTCInternalsTest, SendAddPeerConnectionUpdate) {
78 scoped_ptr<MockWebRTCInternalsProxy> observer(
79 new MockWebRTCInternalsProxy());
80 webrtc_internals_->AddObserver(observer.get());
81 webrtc_internals_->AddPeerConnection(1, GetPeerConnectionInfo(2));
82 EXPECT_EQ("updatePeerConnectionAdded", observer->data());
83
84 webrtc_internals_->RemoveObserver(observer.get());
85 webrtc_internals_->RemovePeerConnection(1, 2);
86 }
87
88 TEST_F(WebRTCInternalsTest, SendRemovePeerConnectionUpdate) {
89 scoped_ptr<MockWebRTCInternalsProxy> observer(
90 new MockWebRTCInternalsProxy());
91 webrtc_internals_->AddObserver(observer.get());
92 webrtc_internals_->AddPeerConnection(1, GetPeerConnectionInfo(2));
93 webrtc_internals_->RemovePeerConnection(1, 2);
94 EXPECT_EQ("updatePeerConnectionRemoved", observer->data());
95
96 webrtc_internals_->RemoveObserver(observer.get());
97 }
98
99 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698