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