| 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 "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 #include <string> |
| 9 | 9 |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 // Make sure we don't have a log entry since there was no observer. | 135 // Make sure we don't have a log entry since there was no observer. |
| 136 MockWebRtcInternalsProxy observer; | 136 MockWebRtcInternalsProxy observer; |
| 137 webrtc_internals.UpdateObserver(&observer); | 137 webrtc_internals.UpdateObserver(&observer); |
| 138 EXPECT_EQ("updateAllPeerConnections", observer.command()); | 138 EXPECT_EQ("updateAllPeerConnections", observer.command()); |
| 139 | 139 |
| 140 base::ListValue* list = nullptr; | 140 base::ListValue* list = nullptr; |
| 141 ASSERT_TRUE(observer.value()->GetAsList(&list)); | 141 ASSERT_TRUE(observer.value()->GetAsList(&list)); |
| 142 EXPECT_EQ(1U, list->GetSize()); | 142 EXPECT_EQ(1U, list->GetSize()); |
| 143 base::DictionaryValue* dict = nullptr; | 143 base::DictionaryValue* dict = nullptr; |
| 144 ASSERT_TRUE((*list->begin()).GetAsDictionary(&dict)); | 144 ASSERT_TRUE((*list->begin())->GetAsDictionary(&dict)); |
| 145 base::ListValue* log = nullptr; | 145 base::ListValue* log = nullptr; |
| 146 ASSERT_FALSE(dict->GetList("log", &log)); | 146 ASSERT_FALSE(dict->GetList("log", &log)); |
| 147 | 147 |
| 148 webrtc_internals.OnRemovePeerConnection(3, 4); | 148 webrtc_internals.OnRemovePeerConnection(3, 4); |
| 149 } | 149 } |
| 150 | 150 |
| 151 TEST_F(WebRtcInternalsTest, EnsureLogIsRemovedWhenObserverIsRemoved) { | 151 TEST_F(WebRtcInternalsTest, EnsureLogIsRemovedWhenObserverIsRemoved) { |
| 152 base::RunLoop loop; | 152 base::RunLoop loop; |
| 153 WebRTCInternalsForTest webrtc_internals; | 153 WebRTCInternalsForTest webrtc_internals; |
| 154 MockWebRtcInternalsProxy observer; | 154 MockWebRtcInternalsProxy observer; |
| 155 webrtc_internals.AddObserver(&observer); | 155 webrtc_internals.AddObserver(&observer); |
| 156 webrtc_internals.OnAddPeerConnection(0, 3, 4, kUrl, kRtcConfiguration, | 156 webrtc_internals.OnAddPeerConnection(0, 3, 4, kUrl, kRtcConfiguration, |
| 157 kContraints); | 157 kContraints); |
| 158 webrtc_internals.OnUpdatePeerConnection(3, 4, "update_type", "update_value"); | 158 webrtc_internals.OnUpdatePeerConnection(3, 4, "update_type", "update_value"); |
| 159 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, loop.QuitClosure()); | 159 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, loop.QuitClosure()); |
| 160 loop.Run(); | 160 loop.Run(); |
| 161 | 161 |
| 162 // Make sure we have a log entry since there was an observer. | 162 // Make sure we have a log entry since there was an observer. |
| 163 webrtc_internals.UpdateObserver(&observer); | 163 webrtc_internals.UpdateObserver(&observer); |
| 164 EXPECT_EQ("updateAllPeerConnections", observer.command()); | 164 EXPECT_EQ("updateAllPeerConnections", observer.command()); |
| 165 | 165 |
| 166 base::ListValue* list = nullptr; | 166 base::ListValue* list = nullptr; |
| 167 ASSERT_TRUE(observer.value()->GetAsList(&list)); | 167 ASSERT_TRUE(observer.value()->GetAsList(&list)); |
| 168 EXPECT_EQ(1U, list->GetSize()); | 168 EXPECT_EQ(1U, list->GetSize()); |
| 169 base::DictionaryValue* dict = nullptr; | 169 base::DictionaryValue* dict = nullptr; |
| 170 ASSERT_TRUE((*list->begin()).GetAsDictionary(&dict)); | 170 ASSERT_TRUE((*list->begin())->GetAsDictionary(&dict)); |
| 171 base::ListValue* log = nullptr; | 171 base::ListValue* log = nullptr; |
| 172 ASSERT_TRUE(dict->GetList("log", &log)); | 172 ASSERT_TRUE(dict->GetList("log", &log)); |
| 173 | 173 |
| 174 // Make sure we the log entry was removed when the last observer was removed. | 174 // Make sure we the log entry was removed when the last observer was removed. |
| 175 webrtc_internals.RemoveObserver(&observer); | 175 webrtc_internals.RemoveObserver(&observer); |
| 176 webrtc_internals.UpdateObserver(&observer); | 176 webrtc_internals.UpdateObserver(&observer); |
| 177 EXPECT_EQ("updateAllPeerConnections", observer.command()); | 177 EXPECT_EQ("updateAllPeerConnections", observer.command()); |
| 178 | 178 |
| 179 ASSERT_TRUE(observer.value()->GetAsList(&list)); | 179 ASSERT_TRUE(observer.value()->GetAsList(&list)); |
| 180 EXPECT_EQ(1U, list->GetSize()); | 180 EXPECT_EQ(1U, list->GetSize()); |
| 181 ASSERT_TRUE((*list->begin()).GetAsDictionary(&dict)); | 181 ASSERT_TRUE((*list->begin())->GetAsDictionary(&dict)); |
| 182 ASSERT_FALSE(dict->GetList("log", &log)); | 182 ASSERT_FALSE(dict->GetList("log", &log)); |
| 183 | 183 |
| 184 webrtc_internals.OnRemovePeerConnection(3, 4); | 184 webrtc_internals.OnRemovePeerConnection(3, 4); |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST_F(WebRtcInternalsTest, SendAddPeerConnectionUpdate) { | 187 TEST_F(WebRtcInternalsTest, SendAddPeerConnectionUpdate) { |
| 188 base::RunLoop loop; | 188 base::RunLoop loop; |
| 189 MockWebRtcInternalsProxy observer(&loop); | 189 MockWebRtcInternalsProxy observer(&loop); |
| 190 WebRTCInternalsForTest webrtc_internals; | 190 WebRTCInternalsForTest webrtc_internals; |
| 191 webrtc_internals.AddObserver(&observer); | 191 webrtc_internals.AddObserver(&observer); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 webrtc_internals.UpdateObserver(&observer); | 325 webrtc_internals.UpdateObserver(&observer); |
| 326 | 326 |
| 327 EXPECT_EQ("updateAllPeerConnections", observer.command()); | 327 EXPECT_EQ("updateAllPeerConnections", observer.command()); |
| 328 ASSERT_TRUE(observer.value()); | 328 ASSERT_TRUE(observer.value()); |
| 329 | 329 |
| 330 base::ListValue* list = NULL; | 330 base::ListValue* list = NULL; |
| 331 EXPECT_TRUE(observer.value()->GetAsList(&list)); | 331 EXPECT_TRUE(observer.value()->GetAsList(&list)); |
| 332 EXPECT_EQ(1U, list->GetSize()); | 332 EXPECT_EQ(1U, list->GetSize()); |
| 333 | 333 |
| 334 base::DictionaryValue* dict = NULL; | 334 base::DictionaryValue* dict = NULL; |
| 335 EXPECT_TRUE((*list->begin()).GetAsDictionary(&dict)); | 335 EXPECT_TRUE((*list->begin())->GetAsDictionary(&dict)); |
| 336 | 336 |
| 337 VerifyInt(dict, "rid", rid); | 337 VerifyInt(dict, "rid", rid); |
| 338 VerifyInt(dict, "pid", pid); | 338 VerifyInt(dict, "pid", pid); |
| 339 VerifyInt(dict, "lid", lid); | 339 VerifyInt(dict, "lid", lid); |
| 340 VerifyString(dict, "url", kUrl); | 340 VerifyString(dict, "url", kUrl); |
| 341 VerifyString(dict, "rtcConfiguration", kRtcConfiguration); | 341 VerifyString(dict, "rtcConfiguration", kRtcConfiguration); |
| 342 VerifyString(dict, "constraints", kContraints); | 342 VerifyString(dict, "constraints", kContraints); |
| 343 | 343 |
| 344 base::ListValue* log = NULL; | 344 base::ListValue* log = NULL; |
| 345 ASSERT_TRUE(dict->GetList("log", &log)); | 345 ASSERT_TRUE(dict->GetList("log", &log)); |
| 346 EXPECT_EQ(1U, log->GetSize()); | 346 EXPECT_EQ(1U, log->GetSize()); |
| 347 | 347 |
| 348 EXPECT_TRUE((*log->begin()).GetAsDictionary(&dict)); | 348 EXPECT_TRUE((*log->begin())->GetAsDictionary(&dict)); |
| 349 VerifyString(dict, "type", update_type); | 349 VerifyString(dict, "type", update_type); |
| 350 VerifyString(dict, "value", update_value); | 350 VerifyString(dict, "value", update_value); |
| 351 std::string time; | 351 std::string time; |
| 352 EXPECT_TRUE(dict->GetString("time", &time)); | 352 EXPECT_TRUE(dict->GetString("time", &time)); |
| 353 EXPECT_FALSE(time.empty()); | 353 EXPECT_FALSE(time.empty()); |
| 354 } | 354 } |
| 355 | 355 |
| 356 TEST_F(WebRtcInternalsTest, OnAddStats) { | 356 TEST_F(WebRtcInternalsTest, OnAddStats) { |
| 357 const int rid = 0, pid = 1, lid = 2; | 357 const int rid = 0, pid = 1, lid = 2; |
| 358 base::RunLoop loop; | 358 base::RunLoop loop; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 webrtc_internals.OnRemovePeerConnection(pid, lid[1]); | 438 webrtc_internals.OnRemovePeerConnection(pid, lid[1]); |
| 439 EXPECT_EQ(0, webrtc_internals.num_open_connections()); | 439 EXPECT_EQ(0, webrtc_internals.num_open_connections()); |
| 440 EXPECT_FALSE(webrtc_internals.IsPowerSavingBlocked()); | 440 EXPECT_FALSE(webrtc_internals.IsPowerSavingBlocked()); |
| 441 | 441 |
| 442 webrtc_internals.OnRemovePeerConnection(pid, lid[0]); | 442 webrtc_internals.OnRemovePeerConnection(pid, lid[0]); |
| 443 EXPECT_EQ(0, webrtc_internals.num_open_connections()); | 443 EXPECT_EQ(0, webrtc_internals.num_open_connections()); |
| 444 EXPECT_FALSE(webrtc_internals.IsPowerSavingBlocked()); | 444 EXPECT_FALSE(webrtc_internals.IsPowerSavingBlocked()); |
| 445 } | 445 } |
| 446 | 446 |
| 447 } // namespace content | 447 } // namespace content |
| OLD | NEW |