Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(744)

Unified Diff: services/device/vibration/vibration_manager_impl_unittest.cc

Issue 2774783003: [DeviceService] Add service tests for VibrationManager. (Closed)
Patch Set: Address comments from blundell@ Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/device/unittest_manifest.json ('k') | services/service_manager/public/cpp/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/device/vibration/vibration_manager_impl_unittest.cc
diff --git a/services/device/vibration/vibration_manager_impl_unittest.cc b/services/device/vibration/vibration_manager_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d54a771cff3cc1c14eb8cf26d38158c324b301d7
--- /dev/null
+++ b/services/device/vibration/vibration_manager_impl_unittest.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/run_loop.h"
+#include "device/vibration/vibration_manager.mojom.h"
+#include "services/device/device_service_test_base.h"
+#include "services/device/public/interfaces/constants.mojom.h"
+
+#if defined(OS_ANDROID)
+#include "base/android/jni_android.h"
+#include "jni/VibrationManagerImpl_jni.h"
+#else
+#include "device/vibration/vibration_manager_impl.h"
+#endif
+
+namespace device {
+
+namespace {
+
+class VibrationManagerImplTest : public DeviceServiceTestBase {
+ public:
+ VibrationManagerImplTest() = default;
+ ~VibrationManagerImplTest() override = default;
+
+ protected:
+ void SetUp() override {
+ DeviceServiceTestBase::SetUp();
+
+ connector()->BindInterface(mojom::kServiceName, &vibration_manager_);
+ }
+
+ void Vibrate(int64_t milliseconds) {
+ base::RunLoop run_loop;
+ vibration_manager_->Vibrate(milliseconds, run_loop.QuitClosure());
+ run_loop.Run();
+ }
+
+ void Cancel() {
+ base::RunLoop run_loop;
+ vibration_manager_->Cancel(run_loop.QuitClosure());
+ run_loop.Run();
+ }
+
+ int64_t GetVibrationMilliSeconds() {
+#if defined(OS_ANDROID)
+ return Java_VibrationManagerImpl_getVibrateMilliSecondsForTesting(
+ base::android::AttachCurrentThread());
+#else
+ return VibrationManagerImpl::milli_seconds_for_testing_;
+#endif
+ }
+
+ bool GetVibrationCancelled() {
+#if defined(OS_ANDROID)
+ return Java_VibrationManagerImpl_getVibrateCancelledForTesting(
+ base::android::AttachCurrentThread());
+#else
+ return VibrationManagerImpl::cancelled_for_testing_;
+#endif
+ }
+
+ private:
+ mojom::VibrationManagerPtr vibration_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(VibrationManagerImplTest);
+};
+
+TEST_F(VibrationManagerImplTest, VibrateThenCancel) {
+ EXPECT_NE(10000, GetVibrationMilliSeconds());
+ Vibrate(10000);
+ EXPECT_EQ(10000, GetVibrationMilliSeconds());
+
+ EXPECT_FALSE(GetVibrationCancelled());
+ Cancel();
+ EXPECT_TRUE(GetVibrationCancelled());
+}
+
+} // namespace
+
+} // namespace device
« no previous file with comments | « services/device/unittest_manifest.json ('k') | services/service_manager/public/cpp/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698