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

Unified Diff: third_party/WebKit/LayoutTests/vibration/resources/vibration-helpers.js

Issue 2731953003: [DeviceService] Replace vibration_browsertest.cc with layout tests. (Closed)
Patch Set: 'git cl format --js' for js/html 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: third_party/WebKit/LayoutTests/vibration/resources/vibration-helpers.js
diff --git a/third_party/WebKit/LayoutTests/vibration/resources/vibration-helpers.js b/third_party/WebKit/LayoutTests/vibration/resources/vibration-helpers.js
new file mode 100644
index 0000000000000000000000000000000000000000..6baf62b49f5d8fd8a2a252303fc38e112b035c43
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/vibration/resources/vibration-helpers.js
@@ -0,0 +1,72 @@
+'use strict';
+
+function vibration_mocks(mojo) {
+ return define(
+ 'VibrationManager mocks',
+ [
+ 'mojo/public/js/bindings',
+ 'device/vibration/vibration_manager.mojom',
+ ],
+ (bindings, vibrationManager) => {
+ class MockVibrationManager {
+ constructor() {
+ this.bindingSet =
+ new bindings.BindingSet(vibrationManager.VibrationManager);
+
+ this.vibrate_milliseconds_ = -1;
+ this.cancelled_ = false;
+ }
+
+ vibrate(milliseconds) {
+ this.vibrate_milliseconds_ = milliseconds;
+ window.postMessage('Vibrate', '*');
+ return Promise.resolve();
+ }
+
+ cancel() {
+ this.cancelled_ = true;
+ window.postMessage('Cancel', '*');
+ }
+
+ getDuration() {
+ return this.vibrate_milliseconds_;
+ }
+
+ isCancelled() {
+ return this.cancelled_;
+ }
+
+ reset() {
+ this.vibrate_milliseconds_ = -1;
+ this.cancelled_ = false;
+ }
+ }
+
+ let mockVibrationManager = new MockVibrationManager;
+ mojo.frameInterfaces.addInterfaceOverrideForTesting(
+ vibrationManager.VibrationManager.name, handle => {
+ mockVibrationManager.bindingSet.addBinding(
+ mockVibrationManager, handle);
+ });
+
+ return Promise.resolve({
+ // Interface instance bound to main frame.
+ mockVibrationManager: mockVibrationManager,
+ // Constructor for mock VibrationManager class.
+ MockVibrationManager: MockVibrationManager,
+ // Loaded mojom interface.
+ VibrationManager: vibrationManager.VibrationManager,
+ });
+ });
+}
+
+function vibration_test(func, name, properties) {
+ mojo_test(
+ mojo => vibration_mocks(mojo).then(vibration => {
+ let result = Promise.resolve(func(vibration));
+ let cleanUp = () => vibration.mockVibrationManager.reset();
+ result.then(cleanUp, cleanUp);
+ return result;
+ }),
+ name, properties);
+}

Powered by Google App Engine
This is Rietveld 408576698