| OLD | NEW |
| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "content/browser/media/webrtc_internals.h" | 8 #include "chrome/browser/media/webrtc_internals.h" |
| 9 #include "content/browser/media/webrtc_internals_ui_observer.h" | 9 #include "chrome/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" | 10 #include "content/public/test/test_browser_thread.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 12 |
| 14 namespace content { | 13 namespace media { |
| 15 class MockWebRTCInternalsProxy : public content::WebRTCInternalsUIObserver { | 14 static const std::string kContraints = "c"; |
| 15 static const std::string kServers = "s"; |
| 16 static const std::string kUrl = "u"; |
| 17 |
| 18 class MockWebRTCInternalsProxy : public WebRTCInternalsUIObserver { |
| 16 public: | 19 public: |
| 17 void OnUpdate(const std::string& command, const Value* value) OVERRIDE { | 20 void OnUpdate(const std::string& command, const Value* value) OVERRIDE { |
| 18 data_ = command; | 21 data_ = command; |
| 19 } | 22 } |
| 20 | 23 |
| 21 std::string data() { | 24 std::string data() { |
| 22 return data_; | 25 return data_; |
| 23 } | 26 } |
| 24 | 27 |
| 25 private: | 28 private: |
| 26 std::string data_; | 29 std::string data_; |
| 27 }; | 30 }; |
| 28 | 31 |
| 29 class WebRTCInternalsTest : public testing::Test { | 32 class WebRTCInternalsTest : public testing::Test { |
| 30 public: | 33 public: |
| 31 WebRTCInternalsTest() | 34 WebRTCInternalsTest() |
| 32 : io_thread_(content::BrowserThread::IO, &io_loop_) {} | 35 : io_thread_(content::BrowserThread::IO, &io_loop_) {} |
| 33 | 36 |
| 34 protected: | 37 protected: |
| 35 virtual void SetUp() { | 38 virtual void SetUp() { |
| 36 webrtc_internals_ = WebRTCInternals::GetInstance(); | 39 webrtc_internals_ = WebRTCInternals::GetInstance(); |
| 37 } | 40 } |
| 38 | 41 |
| 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, | 42 std::string ExpectedInfo(std::string prefix, |
| 48 std::string id, | 43 std::string id, |
| 49 std::string suffix) { | 44 std::string suffix) { |
| 50 static const std::string kstatic_part1 = std::string( | 45 static const std::string kstatic_part1 = std::string( |
| 51 "{\"constraints\":\"c\","); | 46 "{\"constraints\":\"c\","); |
| 52 static const std::string kstatic_part2 = std::string( | 47 static const std::string kstatic_part2 = std::string( |
| 53 ",\"servers\":\"s\",\"url\":\"u\"}"); | 48 ",\"servers\":\"s\",\"url\":\"u\"}"); |
| 54 return prefix + kstatic_part1 + id + kstatic_part2 + suffix; | 49 return prefix + kstatic_part1 + id + kstatic_part2 + suffix; |
| 55 } | 50 } |
| 56 | 51 |
| 57 MessageLoop io_loop_; | 52 MessageLoop io_loop_; |
| 58 content::TestBrowserThread io_thread_; | 53 content::TestBrowserThread io_thread_; |
| 59 WebRTCInternals *webrtc_internals_; | 54 WebRTCInternals *webrtc_internals_; |
| 60 }; | 55 }; |
| 61 | 56 |
| 62 TEST_F(WebRTCInternalsTest, GetInstance) { | 57 TEST_F(WebRTCInternalsTest, GetInstance) { |
| 63 EXPECT_TRUE(webrtc_internals_); | 58 EXPECT_TRUE(webrtc_internals_); |
| 64 } | 59 } |
| 65 | 60 |
| 66 TEST_F(WebRTCInternalsTest, AddRemoveObserver) { | 61 TEST_F(WebRTCInternalsTest, AddRemoveObserver) { |
| 67 scoped_ptr<MockWebRTCInternalsProxy> observer( | 62 scoped_ptr<MockWebRTCInternalsProxy> observer( |
| 68 new MockWebRTCInternalsProxy()); | 63 new MockWebRTCInternalsProxy()); |
| 69 webrtc_internals_->AddObserver(observer.get()); | 64 webrtc_internals_->AddObserver(observer.get()); |
| 70 webrtc_internals_->RemoveObserver(observer.get()); | 65 webrtc_internals_->RemoveObserver(observer.get()); |
| 71 webrtc_internals_->AddPeerConnection(3, GetPeerConnectionInfo(4)); | 66 webrtc_internals_->AddPeerConnection(3, 4, kUrl, kServers, kContraints); |
| 72 EXPECT_EQ("", observer->data()); | 67 EXPECT_EQ("", observer->data()); |
| 73 | 68 |
| 74 webrtc_internals_->RemovePeerConnection(3, 4); | 69 webrtc_internals_->RemovePeerConnection(3, 4); |
| 75 } | 70 } |
| 76 | 71 |
| 77 TEST_F(WebRTCInternalsTest, SendAddPeerConnectionUpdate) { | 72 TEST_F(WebRTCInternalsTest, SendAddPeerConnectionUpdate) { |
| 78 scoped_ptr<MockWebRTCInternalsProxy> observer( | 73 scoped_ptr<MockWebRTCInternalsProxy> observer( |
| 79 new MockWebRTCInternalsProxy()); | 74 new MockWebRTCInternalsProxy()); |
| 80 webrtc_internals_->AddObserver(observer.get()); | 75 webrtc_internals_->AddObserver(observer.get()); |
| 81 webrtc_internals_->AddPeerConnection(1, GetPeerConnectionInfo(2)); | 76 webrtc_internals_->AddPeerConnection(1, 2, kUrl, kServers, kContraints); |
| 82 EXPECT_EQ("updatePeerConnectionAdded", observer->data()); | 77 EXPECT_EQ("addPeerConnection", observer->data()); |
| 83 | 78 |
| 84 webrtc_internals_->RemoveObserver(observer.get()); | 79 webrtc_internals_->RemoveObserver(observer.get()); |
| 85 webrtc_internals_->RemovePeerConnection(1, 2); | 80 webrtc_internals_->RemovePeerConnection(1, 2); |
| 86 } | 81 } |
| 87 | 82 |
| 88 TEST_F(WebRTCInternalsTest, SendRemovePeerConnectionUpdate) { | 83 TEST_F(WebRTCInternalsTest, SendRemovePeerConnectionUpdate) { |
| 89 scoped_ptr<MockWebRTCInternalsProxy> observer( | 84 scoped_ptr<MockWebRTCInternalsProxy> observer( |
| 90 new MockWebRTCInternalsProxy()); | 85 new MockWebRTCInternalsProxy()); |
| 91 webrtc_internals_->AddObserver(observer.get()); | 86 webrtc_internals_->AddObserver(observer.get()); |
| 92 webrtc_internals_->AddPeerConnection(1, GetPeerConnectionInfo(2)); | 87 webrtc_internals_->AddPeerConnection(1, 2, kUrl, kServers, kContraints); |
| 93 webrtc_internals_->RemovePeerConnection(1, 2); | 88 webrtc_internals_->RemovePeerConnection(1, 2); |
| 94 EXPECT_EQ("updatePeerConnectionRemoved", observer->data()); | 89 EXPECT_EQ("removePeerConnection", observer->data()); |
| 95 | 90 |
| 96 webrtc_internals_->RemoveObserver(observer.get()); | 91 webrtc_internals_->RemoveObserver(observer.get()); |
| 97 } | 92 } |
| 98 | 93 |
| 99 } // namespace content | 94 } // namespace media |
| OLD | NEW |