diff options
Diffstat (limited to 'apps/system/test/unit/mock_navigator_wake_lock.js')
-rw-r--r-- | apps/system/test/unit/mock_navigator_wake_lock.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/apps/system/test/unit/mock_navigator_wake_lock.js b/apps/system/test/unit/mock_navigator_wake_lock.js new file mode 100644 index 0000000..c9ff845 --- /dev/null +++ b/apps/system/test/unit/mock_navigator_wake_lock.js @@ -0,0 +1,41 @@ +'use strict'; + +(function() { + var lastWakeLock, + throwAtNextUnlock; + + function mnwl_requestWakeLock(lock) { + lastWakeLock = { + released: false, + topic: lock, + unlock: function() { + if (throwAtNextUnlock) { + throwAtNextUnlock = false; + throw "NS_ERROR_DOM_INVALID_STATE_ERR"; + } + + this.released = true; + } + }; + return lastWakeLock; + } + + function mnwl_teardown() { + lastWakeLock = undefined; + throwAtNextUnlock = undefined; + } + + function mnwl_throwAtNextUnlock() { + throwAtNextUnlock = true; + } + + window.MockNavigatorWakeLock = { + requestWakeLock: mnwl_requestWakeLock, + mTeardown: mnwl_teardown, + mThrowAtNextUnlock: mnwl_throwAtNextUnlock, + get mLastWakeLock() { + return lastWakeLock; + } + }; + +})(); |