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 "chrome/browser/chromeos/mobile/mobile_activator.h" | 5 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/cros/mock_network_library.h" | 7 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
8 #include "chrome/browser/chromeos/cros/network_library.h" | 8 #include "chrome/browser/chromeos/cros/network_library.h" |
9 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" | |
10 #include "chrome/browser/chromeos/net/mock_connectivity_state_helper.h" | |
9 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 using std::string; | 15 using std::string; |
14 | 16 |
15 using content::BrowserThread; | 17 using content::BrowserThread; |
16 using testing::_; | 18 using testing::_; |
17 using testing::Eq; | 19 using testing::Eq; |
18 using testing::Return; | 20 using testing::Return; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 | 59 |
58 void InvokeChangeState(CellularNetwork* network, | 60 void InvokeChangeState(CellularNetwork* network, |
59 MobileActivator::PlanActivationState new_state, | 61 MobileActivator::PlanActivationState new_state, |
60 const std::string& error_description) { | 62 const std::string& error_description) { |
61 MobileActivator::ChangeState(network, new_state, error_description); | 63 MobileActivator::ChangeState(network, new_state, error_description); |
62 } | 64 } |
63 | 65 |
64 private: | 66 private: |
65 MOCK_CONST_METHOD0(GetNetworkLibrary, NetworkLibrary*(void)); | 67 MOCK_CONST_METHOD0(GetNetworkLibrary, NetworkLibrary*(void)); |
66 MOCK_CONST_METHOD1(DCheckOnThread, void(const BrowserThread::ID id)); | 68 MOCK_CONST_METHOD1(DCheckOnThread, void(const BrowserThread::ID id)); |
67 | |
68 MockNetworkLibrary* mock_network_library_; | 69 MockNetworkLibrary* mock_network_library_; |
69 CellularNetwork* cellular_network_; | 70 CellularNetwork* cellular_network_; |
70 | 71 |
71 DISALLOW_COPY_AND_ASSIGN(TestMobileActivator); | 72 DISALLOW_COPY_AND_ASSIGN(TestMobileActivator); |
72 }; | 73 }; |
73 | 74 |
74 class MobileActivatorTest : public testing::Test { | 75 class MobileActivatorTest : public testing::Test { |
75 public: | 76 public: |
76 MobileActivatorTest() | 77 MobileActivatorTest() |
77 : network_library_(), | 78 : network_library_(), |
78 cellular_network_(string(kTestServicePath)), | 79 cellular_network_(string(kTestServicePath)), |
79 mobile_activator_(&network_library_, &cellular_network_) {} | 80 mobile_activator_(&network_library_, &cellular_network_) {} |
80 virtual ~MobileActivatorTest() {} | 81 virtual ~MobileActivatorTest() {} |
81 | 82 |
82 protected: | 83 protected: |
83 virtual void SetUp() {} | 84 virtual void SetUp() { |
84 virtual void TearDown() {} | 85 mock_connectivity_state_helper_ = new MockConnectivityStateHelper(); |
86 ConnectivityStateHelper::InitializeForTesting( | |
87 mock_connectivity_state_helper_); | |
88 } | |
89 virtual void TearDown() { | |
90 ConnectivityStateHelper::Shutdown(); | |
91 } | |
85 | 92 |
86 void set_activator_state(const MobileActivator::PlanActivationState state) { | 93 void set_activator_state(const MobileActivator::PlanActivationState state) { |
87 mobile_activator_.state_ = state; | 94 mobile_activator_.state_ = state; |
88 } | 95 } |
89 void set_network_activation_state(ActivationState state) { | 96 void set_network_activation_state(ActivationState state) { |
90 cellular_network_.activation_state_ = state; | 97 cellular_network_.activation_state_ = state; |
91 } | 98 } |
92 void set_connection_state(ConnectionState state) { | 99 void set_connection_state(ConnectionState state) { |
93 cellular_network_.state_ = state; | 100 cellular_network_.state_ = state; |
94 } | 101 } |
95 | 102 |
96 MockNetworkLibrary network_library_; | 103 MockNetworkLibrary network_library_; |
stevenjb
2013/03/11 23:11:05
Here too - I'd prefer to convert this all at once.
stevenjb
2013/03/12 15:53:34
And this.
| |
97 MockCellularNetwork cellular_network_; | 104 MockCellularNetwork cellular_network_; |
98 TestMobileActivator mobile_activator_; | 105 TestMobileActivator mobile_activator_; |
106 MockConnectivityStateHelper* mock_connectivity_state_helper_; | |
107 | |
99 private: | 108 private: |
100 DISALLOW_COPY_AND_ASSIGN(MobileActivatorTest); | 109 DISALLOW_COPY_AND_ASSIGN(MobileActivatorTest); |
101 }; | 110 }; |
102 | 111 |
103 TEST_F(MobileActivatorTest, BasicFlowForNewDevices) { | 112 TEST_F(MobileActivatorTest, BasicFlowForNewDevices) { |
104 // In a new device, we aren't connected to Verizon, we start at START | 113 // In a new device, we aren't connected to Verizon, we start at START |
105 // because we haven't paid Verizon (ever), and the modem isn't even partially | 114 // because we haven't paid Verizon (ever), and the modem isn't even partially |
106 // activated. | 115 // activated. |
107 std::string error_description; | 116 std::string error_description; |
108 set_activator_state(MobileActivator::PLAN_ACTIVATION_START); | 117 set_activator_state(MobileActivator::PLAN_ACTIVATION_START); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 EXPECT_EQ(MobileActivator::PLAN_ACTIVATION_RECONNECTING, | 236 EXPECT_EQ(MobileActivator::PLAN_ACTIVATION_RECONNECTING, |
228 mobile_activator_.PickNextState(&cellular_network_, | 237 mobile_activator_.PickNextState(&cellular_network_, |
229 &error_description)); | 238 &error_description)); |
230 set_activator_state(MobileActivator::PLAN_ACTIVATION_SHOWING_PAYMENT); | 239 set_activator_state(MobileActivator::PLAN_ACTIVATION_SHOWING_PAYMENT); |
231 EXPECT_EQ(MobileActivator::PLAN_ACTIVATION_RECONNECTING, | 240 EXPECT_EQ(MobileActivator::PLAN_ACTIVATION_RECONNECTING, |
232 mobile_activator_.PickNextState(&cellular_network_, | 241 mobile_activator_.PickNextState(&cellular_network_, |
233 &error_description)); | 242 &error_description)); |
234 } | 243 } |
235 | 244 |
236 TEST_F(MobileActivatorTest, StartAtStart) { | 245 TEST_F(MobileActivatorTest, StartAtStart) { |
237 EXPECT_CALL(network_library_, | 246 EXPECT_CALL(*mock_connectivity_state_helper_, |
238 AddNetworkManagerObserver(Eq(&mobile_activator_))); | 247 AddNetworkManagerObserver(Eq(&mobile_activator_))); |
239 EXPECT_CALL(network_library_, HasRecentCellularPlanPayment()). | 248 EXPECT_CALL(network_library_, HasRecentCellularPlanPayment()). |
240 WillOnce(Return(false)); | 249 WillOnce(Return(false)); |
241 EXPECT_CALL(mobile_activator_, | 250 EXPECT_CALL(mobile_activator_, |
242 EvaluateCellularNetwork(Eq(&cellular_network_))); | 251 EvaluateCellularNetwork(Eq(&cellular_network_))); |
243 mobile_activator_.StartActivation(); | 252 mobile_activator_.StartActivation(); |
244 EXPECT_EQ(mobile_activator_.state(), MobileActivator::PLAN_ACTIVATION_START); | 253 EXPECT_EQ(mobile_activator_.state(), MobileActivator::PLAN_ACTIVATION_START); |
245 } | 254 } |
246 | 255 |
247 } // namespace chromeos | 256 } // namespace chromeos |
OLD | NEW |