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

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

Issue 2731953003: [DeviceService] Replace vibration_browsertest.cc with layout tests. (Closed)
Patch Set: 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
« no previous file with comments | « third_party/WebKit/LayoutTests/vibration/mock-vibration.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2882af90a95a55030b40d275e8142f6fb72240c7
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/vibration/resources/vibration-helpers.js
@@ -0,0 +1,65 @@
+'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(milliseconds, '*');
leonhsl(Using Gerrit) 2017/03/07 15:00:41 I'm not sure whether this is the best practice to
+ return Promise.resolve();
+ }
+
+ cancel() {
+ this.cancelled_ = true;
+ }
+
+ 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);
+}
« no previous file with comments | « third_party/WebKit/LayoutTests/vibration/mock-vibration.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698