| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/net/wake_on_wifi_connection_observer.h" |
| 6 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" |
| 7 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 8 #include "chrome/test/base/testing_profile.h" |
| 9 #include "chromeos/network/mock_network_device_handler.h" |
| 10 #include "content/public/test/test_browser_thread_bundle.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 using testing::_; |
| 15 using testing::Return; |
| 16 using testing::StrictMock; |
| 17 |
| 18 namespace chromeos { |
| 19 namespace { |
| 20 |
| 21 scoped_ptr<KeyedService> BuildFakeGCMProfileService( |
| 22 content::BrowserContext* context) { |
| 23 return gcm::FakeGCMProfileService::Build(static_cast<Profile*>(context)); |
| 24 } |
| 25 |
| 26 class WakeOnWifiObserverTest : public ::testing::Test { |
| 27 public: |
| 28 WakeOnWifiObserverTest() { |
| 29 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory( |
| 30 &profile_, &BuildFakeGCMProfileService); |
| 31 } |
| 32 ~WakeOnWifiObserverTest() override {} |
| 33 |
| 34 protected: |
| 35 StrictMock<MockNetworkDeviceHandler::MockNetworkDeviceHandler> |
| 36 mock_network_device_handler_; |
| 37 TestingProfile profile_; |
| 38 |
| 39 private: |
| 40 content::TestBrowserThreadBundle thread_bundle_; |
| 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(WakeOnWifiObserverTest); |
| 43 }; |
| 44 |
| 45 } // namespace |
| 46 |
| 47 TEST_F(WakeOnWifiObserverTest, TestWakeOnWifiPacketAdd) { |
| 48 WakeOnWifiConnectionObserver observer( |
| 49 &profile_, false, WakeOnWifiManager::WAKE_ON_WIFI_PACKET, |
| 50 &mock_network_device_handler_); |
| 51 |
| 52 EXPECT_CALL(mock_network_device_handler_, |
| 53 AddWifiWakeOnPacketConnection(_, _, _)) |
| 54 .Times(1); |
| 55 |
| 56 observer.AddWakeOnPacketConnection(); |
| 57 } |
| 58 |
| 59 TEST_F(WakeOnWifiObserverTest, TestWakeOnWifiPacketRemove) { |
| 60 WakeOnWifiConnectionObserver observer( |
| 61 &profile_, false, WakeOnWifiManager::WAKE_ON_WIFI_PACKET, |
| 62 &mock_network_device_handler_); |
| 63 |
| 64 EXPECT_CALL(mock_network_device_handler_, |
| 65 RemoveWifiWakeOnPacketConnection(_, _, _)) |
| 66 .Times(1); |
| 67 |
| 68 observer.RemoveWakeOnPacketConnection(); |
| 69 } |
| 70 |
| 71 TEST_F(WakeOnWifiObserverTest, TestWakeOnWifiNoneAdd) { |
| 72 WakeOnWifiConnectionObserver observer( |
| 73 &profile_, false, WakeOnWifiManager::WAKE_ON_WIFI_NONE, |
| 74 &mock_network_device_handler_); |
| 75 |
| 76 EXPECT_CALL(mock_network_device_handler_, |
| 77 AddWifiWakeOnPacketConnection(_, _, _)) |
| 78 .Times(0); |
| 79 |
| 80 observer.AddWakeOnPacketConnection(); |
| 81 } |
| 82 |
| 83 TEST_F(WakeOnWifiObserverTest, TestWakeOnWifiNoneRemove) { |
| 84 WakeOnWifiConnectionObserver observer( |
| 85 &profile_, false, WakeOnWifiManager::WAKE_ON_WIFI_NONE, |
| 86 &mock_network_device_handler_); |
| 87 |
| 88 EXPECT_CALL(mock_network_device_handler_, |
| 89 RemoveWifiWakeOnPacketConnection(_, _, _)) |
| 90 .Times(0); |
| 91 |
| 92 observer.RemoveWakeOnPacketConnection(); |
| 93 } |
| 94 |
| 95 } // namespace chromeos |
| OLD | NEW |