OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017 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 "base/run_loop.h" |
| 6 #include "device/vibration/vibration_manager.mojom.h" |
| 7 #include "services/device/device_service_test_base.h" |
| 8 #include "services/device/public/interfaces/constants.mojom.h" |
| 9 |
| 10 #if defined(OS_ANDROID) |
| 11 #include "base/android/jni_android.h" |
| 12 #include "jni/VibrationManagerImpl_jni.h" |
| 13 #else |
| 14 #include "device/vibration/vibration_manager_impl.h" |
| 15 #endif |
| 16 |
| 17 namespace device { |
| 18 |
| 19 namespace { |
| 20 |
| 21 class VibrationManagerImplTest : public DeviceServiceTestBase { |
| 22 public: |
| 23 VibrationManagerImplTest() = default; |
| 24 ~VibrationManagerImplTest() override = default; |
| 25 |
| 26 protected: |
| 27 void SetUp() override { |
| 28 DeviceServiceTestBase::SetUp(); |
| 29 |
| 30 connector()->BindInterface(mojom::kServiceName, &vibration_manager_); |
| 31 } |
| 32 |
| 33 void Vibrate(int64_t milliseconds) { |
| 34 base::RunLoop run_loop; |
| 35 vibration_manager_->Vibrate(milliseconds, run_loop.QuitClosure()); |
| 36 run_loop.Run(); |
| 37 } |
| 38 |
| 39 void Cancel() { |
| 40 base::RunLoop run_loop; |
| 41 vibration_manager_->Cancel(run_loop.QuitClosure()); |
| 42 run_loop.Run(); |
| 43 } |
| 44 |
| 45 int64_t GetVibrationMilliSeconds() { |
| 46 #if defined(OS_ANDROID) |
| 47 return Java_VibrationManagerImpl_getVibrateMilliSecondsForTesting( |
| 48 base::android::AttachCurrentThread()); |
| 49 #else |
| 50 return VibrationManagerImpl::milli_seconds_for_testing_; |
| 51 #endif |
| 52 } |
| 53 |
| 54 bool GetVibrationCancelled() { |
| 55 #if defined(OS_ANDROID) |
| 56 return Java_VibrationManagerImpl_getVibrateCancelledForTesting( |
| 57 base::android::AttachCurrentThread()); |
| 58 #else |
| 59 return VibrationManagerImpl::cancelled_for_testing_; |
| 60 #endif |
| 61 } |
| 62 |
| 63 private: |
| 64 mojom::VibrationManagerPtr vibration_manager_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(VibrationManagerImplTest); |
| 67 }; |
| 68 |
| 69 TEST_F(VibrationManagerImplTest, VibrateThenCancel) { |
| 70 EXPECT_NE(10000, GetVibrationMilliSeconds()); |
| 71 Vibrate(10000); |
| 72 EXPECT_EQ(10000, GetVibrationMilliSeconds()); |
| 73 |
| 74 EXPECT_FALSE(GetVibrationCancelled()); |
| 75 Cancel(); |
| 76 EXPECT_TRUE(GetVibrationCancelled()); |
| 77 } |
| 78 |
| 79 } // namespace |
| 80 |
| 81 } // namespace device |
OLD | NEW |