Skip to content

Commit

Permalink
Merge b3db9ba into a2b4619
Browse files Browse the repository at this point in the history
  • Loading branch information
vrunoa committed Jan 3, 2019
2 parents a2b4619 + b3db9ba commit 1970fda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/unlock-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ helpers.isValidKey = function (type, key) {
throw new Error(`Invalid unlock type ${type}`);
};

helpers.wakeUp = async function (adb) {
logger.info("Waking up the device to unlock it");
await adb.keyevent('224');
};

helpers.dismissKeyguard = async function (driver, adb) {
await this.wakeUp(adb);
let isKeyboardShown = await driver.isKeyboardShown();
if (isKeyboardShown) {
await driver.hideKeyboard();
Expand Down
10 changes: 10 additions & 0 deletions test/unit/unlock-helper-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,17 @@ describe('Unlock Helpers', function () {
.to.throw('Invalid unlock type');
});
});
describe('wakeUp', withMocks({adb, helpers}, (mocks) => {
it('should call shell input to wake up device', async function () {
mocks.adb.expects('keyevent').withExactArgs('224').once();
await helpers.wakeUp(adb);
mocks.adb.verify();
});
}));
describe('dismissKeyguard', withMocks({driver, adb, asyncbox, helpers}, (mocks) => {
it('should hide keyboard if keyboard is snown', async function () {
mocks.driver.expects('isKeyboardShown').returns(true);
mocks.helpers.expects('wakeUp').once();
mocks.driver.expects('hideKeyboard').once();
mocks.asyncbox.expects('sleep').withExactArgs(HIDE_KEYBOARD_WAIT_TIME).once();
mocks.adb.expects('shell').once();
Expand All @@ -76,6 +84,7 @@ describe('Unlock Helpers', function () {
});
it('should dismiss notifications and dissmiss keyguard via swipping up', async function () {
mocks.driver.expects('isKeyboardShown').returns(false);
mocks.helpers.expects('wakeUp').once();
mocks.adb.expects('shell')
.withExactArgs(["service", "call", "notification", "1"]).once();
mocks.adb.expects('back').once();
Expand All @@ -88,6 +97,7 @@ describe('Unlock Helpers', function () {
});
it('should dissmiss keyguard via dismiss-keyguard shell command if API level > 21', async function () {
mocks.driver.expects('isKeyboardShown').returns(false);
mocks.helpers.expects('wakeUp').once();
mocks.adb.expects('shell').onCall(0).returns('');
mocks.adb.expects('back').once();
mocks.adb.expects('getApiLevel').returns(22);
Expand Down

0 comments on commit 1970fda

Please sign in to comment.