OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chromeos/components/tether/host_scan_cache.h" | 5 #include "chromeos/components/tether/host_scan_cache.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <unordered_map> | 8 #include <unordered_map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/test/scoped_task_environment.h" | 13 #include "base/test/scoped_task_environment.h" |
14 #include "base/timer/mock_timer.h" | 14 #include "base/timer/mock_timer.h" |
15 #include "chromeos/components/tether/device_id_tether_network_guid_map.h" | 15 #include "chromeos/components/tether/device_id_tether_network_guid_map.h" |
16 #include "chromeos/components/tether/fake_active_host.h" | 16 #include "chromeos/components/tether/fake_active_host.h" |
17 #include "chromeos/components/tether/fake_host_scan_cache.h" | 17 #include "chromeos/components/tether/fake_host_scan_cache.h" |
18 #include "chromeos/components/tether/mock_tether_host_response_recorder.h" | 18 #include "chromeos/components/tether/mock_tether_host_response_recorder.h" |
19 #include "chromeos/components/tether/timer_factory.h" | |
19 #include "chromeos/dbus/dbus_thread_manager.h" | 20 #include "chromeos/dbus/dbus_thread_manager.h" |
20 #include "chromeos/network/network_state.h" | 21 #include "chromeos/network/network_state.h" |
21 #include "chromeos/network/network_state_handler.h" | 22 #include "chromeos/network/network_state_handler.h" |
22 #include "chromeos/network/network_state_test.h" | 23 #include "chromeos/network/network_state_test.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 using testing::NiceMock; | 27 using testing::NiceMock; |
27 using testing::Invoke; | 28 using testing::Invoke; |
28 | 29 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 }; | 72 }; |
72 | 73 |
73 } // namespace | 74 } // namespace |
74 | 75 |
75 // TODO(khorimoto): The test uses a FakeHostScanCache to keep an in-memory | 76 // TODO(khorimoto): The test uses a FakeHostScanCache to keep an in-memory |
76 // cache of expected values. This has the potential to be confusing, since this | 77 // cache of expected values. This has the potential to be confusing, since this |
77 // is the test for HostScanCache. Clean this up to avoid using FakeHostScanCache | 78 // is the test for HostScanCache. Clean this up to avoid using FakeHostScanCache |
78 // if possible. | 79 // if possible. |
79 class HostScanCacheTest : public NetworkStateTest { | 80 class HostScanCacheTest : public NetworkStateTest { |
80 protected: | 81 protected: |
81 class TestTimerFactory : public HostScanCache::TimerFactory { | 82 class TestTimerFactory : public TimerFactory { |
khorimoto
2017/05/31 18:13:28
Move to anonymous namespace.
Ryan Hansberry
2017/05/31 18:24:54
Done.
| |
82 public: | 83 public: |
83 TestTimerFactory() {} | 84 TestTimerFactory() {} |
84 ~TestTimerFactory() {} | 85 ~TestTimerFactory() override {} |
85 | 86 |
86 std::unordered_map<std::string, ExtendedMockTimer*>& | 87 std::unordered_map<std::string, ExtendedMockTimer*>& |
87 tether_network_guid_to_timer_map() { | 88 tether_network_guid_to_timer_map() { |
88 return tether_network_guid_to_timer_map_; | 89 return tether_network_guid_to_timer_map_; |
89 } | 90 } |
90 | 91 |
91 void set_tether_network_guid_for_next_timer( | 92 void set_tether_network_guid_for_next_timer( |
92 const std::string& tether_network_guid_for_next_timer) { | 93 const std::string& tether_network_guid_for_next_timer) { |
93 tether_network_guid_for_next_timer_ = tether_network_guid_for_next_timer; | 94 tether_network_guid_for_next_timer_ = tether_network_guid_for_next_timer; |
94 } | 95 } |
95 | 96 |
96 // HostScanCache::TimerFactory: | 97 // TimerFactory: |
97 std::unique_ptr<base::Timer> CreateOneShotTimer() override { | 98 std::unique_ptr<base::Timer> CreateOneShotTimer() override { |
98 EXPECT_FALSE(tether_network_guid_for_next_timer_.empty()); | 99 EXPECT_FALSE(tether_network_guid_for_next_timer_.empty()); |
99 ExtendedMockTimer* mock_timer = new ExtendedMockTimer(base::Bind( | 100 ExtendedMockTimer* mock_timer = new ExtendedMockTimer(base::Bind( |
100 &TestTimerFactory::OnActiveTimerDestructor, base::Unretained(this), | 101 &TestTimerFactory::OnActiveTimerDestructor, base::Unretained(this), |
101 tether_network_guid_for_next_timer_)); | 102 tether_network_guid_for_next_timer_)); |
102 tether_network_guid_to_timer_map_[tether_network_guid_for_next_timer_] = | 103 tether_network_guid_to_timer_map_[tether_network_guid_for_next_timer_] = |
103 mock_timer; | 104 mock_timer; |
104 return base::WrapUnique(mock_timer); | 105 return base::WrapUnique(mock_timer); |
105 } | 106 } |
106 | 107 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 | 439 |
439 // Simulate a connection to device 1. | 440 // Simulate a connection to device 1. |
440 SetActiveHost(kTetherGuid1); | 441 SetActiveHost(kTetherGuid1); |
441 SetHasConnectedToHost(kTetherGuid1); | 442 SetHasConnectedToHost(kTetherGuid1); |
442 VerifyCacheMatchesNetworkStack(); | 443 VerifyCacheMatchesNetworkStack(); |
443 } | 444 } |
444 | 445 |
445 } // namespace tether | 446 } // namespace tether |
446 | 447 |
447 } // namespace chromeos | 448 } // namespace chromeos |
OLD | NEW |