| 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 27 matching lines...) Expand all Loading... |
| 38 value_.reset(value ? value->DeepCopy() : nullptr); | 38 value_.reset(value ? value->DeepCopy() : nullptr); |
| 39 if (loop_) | 39 if (loop_) |
| 40 loop_->Quit(); | 40 loop_->Quit(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 std::string command_; | 43 std::string command_; |
| 44 std::unique_ptr<base::Value> value_; | 44 std::unique_ptr<base::Value> value_; |
| 45 base::RunLoop* loop_; | 45 base::RunLoop* loop_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 class MockWakeLockService : public device::mojom::WakeLockService { | 48 class MockWakeLock : public device::mojom::WakeLock { |
| 49 public: | 49 public: |
| 50 MockWakeLockService(device::mojom::WakeLockServiceRequest request) | 50 MockWakeLock(device::mojom::WakeLockRequest request) |
| 51 : binding_(this, std::move(request)), has_wakelock_(false) {} | 51 : binding_(this, std::move(request)), has_wakelock_(false) {} |
| 52 ~MockWakeLockService() override {} | 52 ~MockWakeLock() override {} |
| 53 | 53 |
| 54 // Implement device::mojom::WakeLockService: | 54 // Implement device::mojom::WakeLock: |
| 55 void RequestWakeLock() override { has_wakelock_ = true; } | 55 void RequestWakeLock() override { has_wakelock_ = true; } |
| 56 void CancelWakeLock() override { has_wakelock_ = false; } | 56 void CancelWakeLock() override { has_wakelock_ = false; } |
| 57 void AddClient(device::mojom::WakeLockServiceRequest request) override {} | 57 void AddClient(device::mojom::WakeLockRequest request) override {} |
| 58 void HasWakeLockForTests(HasWakeLockForTestsCallback callback) override {} | 58 void HasWakeLockForTests(HasWakeLockForTestsCallback callback) override {} |
| 59 | 59 |
| 60 bool HasWakeLock() { | 60 bool HasWakeLock() { |
| 61 base::RunLoop().RunUntilIdle(); | 61 base::RunLoop().RunUntilIdle(); |
| 62 return has_wakelock_; | 62 return has_wakelock_; |
| 63 } | 63 } |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 mojo::Binding<device::mojom::WakeLockService> binding_; | 66 mojo::Binding<device::mojom::WakeLock> binding_; |
| 67 bool has_wakelock_; | 67 bool has_wakelock_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 // Derived class for testing only. Allows the tests to have their own instance | 70 // Derived class for testing only. Allows the tests to have their own instance |
| 71 // for testing and control the period for which WebRTCInternals will bulk up | 71 // for testing and control the period for which WebRTCInternals will bulk up |
| 72 // updates (changes down from 500ms to 1ms). | 72 // updates (changes down from 500ms to 1ms). |
| 73 class WebRTCInternalsForTest : public NON_EXPORTED_BASE(WebRTCInternals) { | 73 class WebRTCInternalsForTest : public NON_EXPORTED_BASE(WebRTCInternals) { |
| 74 public: | 74 public: |
| 75 WebRTCInternalsForTest() | 75 WebRTCInternalsForTest() |
| 76 : WebRTCInternals(1, true), | 76 : WebRTCInternals(1, true), |
| 77 mock_wake_lock_service_(mojo::MakeRequest(&wake_lock_service_)) {} | 77 mock_wake_lock_(mojo::MakeRequest(&wake_lock_)) {} |
| 78 ~WebRTCInternalsForTest() override {} | 78 ~WebRTCInternalsForTest() override {} |
| 79 bool HasWakeLock() { return mock_wake_lock_service_.HasWakeLock(); } | 79 bool HasWakeLock() { return mock_wake_lock_.HasWakeLock(); } |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 MockWakeLockService mock_wake_lock_service_; | 82 MockWakeLock mock_wake_lock_; |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 } // namespace | 85 } // namespace |
| 86 | 86 |
| 87 class WebRtcInternalsTest : public testing::Test { | 87 class WebRtcInternalsTest : public testing::Test { |
| 88 public: | 88 public: |
| 89 WebRtcInternalsTest() : io_thread_(BrowserThread::UI, &io_loop_) {} | 89 WebRtcInternalsTest() : io_thread_(BrowserThread::UI, &io_loop_) {} |
| 90 | 90 |
| 91 protected: | 91 protected: |
| 92 void VerifyString(const base::DictionaryValue* dict, | 92 void VerifyString(const base::DictionaryValue* dict, |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 webrtc_internals.OnRemovePeerConnection(pid, lid[1]); | 467 webrtc_internals.OnRemovePeerConnection(pid, lid[1]); |
| 468 EXPECT_EQ(0, webrtc_internals.num_open_connections()); | 468 EXPECT_EQ(0, webrtc_internals.num_open_connections()); |
| 469 EXPECT_FALSE(webrtc_internals.HasWakeLock()); | 469 EXPECT_FALSE(webrtc_internals.HasWakeLock()); |
| 470 | 470 |
| 471 webrtc_internals.OnRemovePeerConnection(pid, lid[0]); | 471 webrtc_internals.OnRemovePeerConnection(pid, lid[0]); |
| 472 EXPECT_EQ(0, webrtc_internals.num_open_connections()); | 472 EXPECT_EQ(0, webrtc_internals.num_open_connections()); |
| 473 EXPECT_FALSE(webrtc_internals.HasWakeLock()); | 473 EXPECT_FALSE(webrtc_internals.HasWakeLock()); |
| 474 } | 474 } |
| 475 | 475 |
| 476 } // namespace content | 476 } // namespace content |
| OLD | NEW |