| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "net/base/network_change_notifier.h" | 6 #include "net/base/network_change_notifier.h" |
| 7 #include "net/base/network_change_notifier_factory.h" | 7 #include "net/base/network_change_notifier_factory.h" |
| 8 #include "net/base/network_change_notifier_win.h" | 8 #include "net/base/network_change_notifier_win.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 public: | 24 public: |
| 25 TestNetworkChangeNotifierWin() {} | 25 TestNetworkChangeNotifierWin() {} |
| 26 | 26 |
| 27 virtual ~TestNetworkChangeNotifierWin() { | 27 virtual ~TestNetworkChangeNotifierWin() { |
| 28 // This is needed so we don't try to stop watching for IP address changes, | 28 // This is needed so we don't try to stop watching for IP address changes, |
| 29 // as we never actually started. | 29 // as we never actually started. |
| 30 set_is_watching(false); | 30 set_is_watching(false); |
| 31 } | 31 } |
| 32 | 32 |
| 33 // From NetworkChangeNotifierWin. | 33 // From NetworkChangeNotifierWin. |
| 34 virtual NetworkChangeNotifier::ConnectionType | 34 virtual NetworkChangeNotifier::ConnectionType RecomputeCurrentConnectionType() |
| 35 RecomputeCurrentConnectionType() const override { | 35 const override { |
| 36 return NetworkChangeNotifier::CONNECTION_UNKNOWN; | 36 return NetworkChangeNotifier::CONNECTION_UNKNOWN; |
| 37 } | 37 } |
| 38 | 38 |
| 39 // From NetworkChangeNotifierWin. | 39 // From NetworkChangeNotifierWin. |
| 40 MOCK_METHOD0(WatchForAddressChangeInternal, bool()); | 40 MOCK_METHOD0(WatchForAddressChangeInternal, bool()); |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 DISALLOW_COPY_AND_ASSIGN(TestNetworkChangeNotifierWin); | 43 DISALLOW_COPY_AND_ASSIGN(TestNetworkChangeNotifierWin); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class TestIPAddressObserver | 46 class TestIPAddressObserver |
| 47 : public net::NetworkChangeNotifier::IPAddressObserver { | 47 : public net::NetworkChangeNotifier::IPAddressObserver { |
| 48 public: | 48 public: |
| 49 TestIPAddressObserver() { | 49 TestIPAddressObserver() { NetworkChangeNotifier::AddIPAddressObserver(this); } |
| 50 NetworkChangeNotifier::AddIPAddressObserver(this); | |
| 51 } | |
| 52 | 50 |
| 53 ~TestIPAddressObserver() { | 51 ~TestIPAddressObserver() { |
| 54 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 52 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 55 } | 53 } |
| 56 | 54 |
| 57 MOCK_METHOD0(OnIPAddressChanged, void()); | 55 MOCK_METHOD0(OnIPAddressChanged, void()); |
| 58 | 56 |
| 59 private: | 57 private: |
| 60 DISALLOW_COPY_AND_ASSIGN(TestIPAddressObserver); | 58 DISALLOW_COPY_AND_ASSIGN(TestIPAddressObserver); |
| 61 }; | 59 }; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 156 } |
| 159 | 157 |
| 160 // Runs the message loop until WatchForAddressChange is called again, as a | 158 // Runs the message loop until WatchForAddressChange is called again, as a |
| 161 // result of the already posted task after a WatchForAddressChangeInternal | 159 // result of the already posted task after a WatchForAddressChangeInternal |
| 162 // failure. Simulates a success on the resulting call to | 160 // failure. Simulates a success on the resulting call to |
| 163 // WatchForAddressChangeInternal. | 161 // WatchForAddressChangeInternal. |
| 164 void RetryAndSucceed() { | 162 void RetryAndSucceed() { |
| 165 EXPECT_FALSE(network_change_notifier_.is_watching()); | 163 EXPECT_FALSE(network_change_notifier_.is_watching()); |
| 166 EXPECT_LT(0, network_change_notifier_.sequential_failures()); | 164 EXPECT_LT(0, network_change_notifier_.sequential_failures()); |
| 167 | 165 |
| 168 EXPECT_CALL(test_ip_address_observer_, OnIPAddressChanged()).Times(1) | 166 EXPECT_CALL(test_ip_address_observer_, OnIPAddressChanged()) |
| 167 .Times(1) |
| 169 .WillOnce( | 168 .WillOnce( |
| 170 Invoke(base::MessageLoop::current(), &base::MessageLoop::Quit)); | 169 Invoke(base::MessageLoop::current(), &base::MessageLoop::Quit)); |
| 171 EXPECT_CALL(network_change_notifier_, WatchForAddressChangeInternal()) | 170 EXPECT_CALL(network_change_notifier_, WatchForAddressChangeInternal()) |
| 172 .Times(1).WillOnce(Return(true)); | 171 .Times(1) |
| 172 .WillOnce(Return(true)); |
| 173 | 173 |
| 174 base::MessageLoop::current()->Run(); | 174 base::MessageLoop::current()->Run(); |
| 175 | 175 |
| 176 EXPECT_TRUE(network_change_notifier_.is_watching()); | 176 EXPECT_TRUE(network_change_notifier_.is_watching()); |
| 177 EXPECT_EQ(0, network_change_notifier_.sequential_failures()); | 177 EXPECT_EQ(0, network_change_notifier_.sequential_failures()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Runs the message loop until WatchForAddressChange is called again, as a | 180 // Runs the message loop until WatchForAddressChange is called again, as a |
| 181 // result of the already posted task after a WatchForAddressChangeInternal | 181 // result of the already posted task after a WatchForAddressChangeInternal |
| 182 // failure. Simulates a failure on the resulting call to | 182 // failure. Simulates a failure on the resulting call to |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 251 } |
| 252 | 252 |
| 253 TEST_F(NetworkChangeNotifierWinTest, NetChangeWinFailSignalTwice) { | 253 TEST_F(NetworkChangeNotifierWinTest, NetChangeWinFailSignalTwice) { |
| 254 StartWatchingAndSucceed(); | 254 StartWatchingAndSucceed(); |
| 255 SignalAndFail(); | 255 SignalAndFail(); |
| 256 RetryAndFail(); | 256 RetryAndFail(); |
| 257 RetryAndSucceed(); | 257 RetryAndSucceed(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 } // namespace net | 260 } // namespace net |
| OLD | NEW |