| OLD | NEW |
| (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 | |
| OLD | NEW |