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

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

Issue 2774783003: [DeviceService] Add service tests for VibrationManager. (Closed)
Patch Set: Let service_test app itself register mojo JNIs Created 3 years, 9 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
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 {
timvolodine 2017/04/07 10:39:07 If I understand correctly the idea here is to test
leonhsl(Using Gerrit) 2017/04/08 00:51:01 Yeah we're trying to verify the behavior of Vibrat
+ 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);
timvolodine 2017/04/07 10:39:07 Does this mean the Android device on which the tes
leonhsl(Using Gerrit) 2017/04/08 00:51:01 No, because the test app has no Vibration permissi
+ EXPECT_EQ(10000, GetVibrationMilliSeconds());
+
+ EXPECT_FALSE(GetVibrationCancelled());
+ Cancel();
+ EXPECT_TRUE(GetVibrationCancelled());
+}
+
+} // namespace
+
+} // namespace device

Powered by Google App Engine
This is Rietveld 408576698