From 0fa80ae53408709f91ef0f9dfd32193029d27b15 Mon Sep 17 00:00:00 2001 From: Isaac Murchie Date: Wed, 5 Nov 2014 10:24:52 -0800 Subject: [PATCH] Add unit test for starting app --- test/unit/adb-specs.js | 68 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/unit/adb-specs.js b/test/unit/adb-specs.js index b85fdce3e..28a52b34a 100644 --- a/test/unit/adb-specs.js +++ b/test/unit/adb-specs.js @@ -80,5 +80,73 @@ describe('adb', function () { ).nodeify(done); }); }); + + describe('startApp', function () { + var getStartAppMock = function (apiLevel, stdout, startApp) { + return { + getApiLevel: function (cb) { cb(null, apiLevel); }, + shell: function (cmd, cb) { cb(null, stdout); }, + startApp: startApp + }; + }; + + it('should fail when there is no permission', function (done) { + var stdout = + 'Stopping: com.android.contacts\n' + + 'Starting: Intent { cmp=com.android.contacts/.ContactsListActivity }\n' + + 'java.lang.SecurityException: Permission Denial: ' + + 'starting Intent { flg=0x10000000 cmp=com.android.contacts/.ContactsListActivity } ' + + 'from null (pid=13312, uid=2000) not exported from uid 10013\n' + + ' at android.os.Parcel.readException(Parcel.java:1431)\n' + + ' ...'; + + ADB.prototype.startApp.call(getStartAppMock(19, stdout, null), {pkg: 'com.android.contacts'}, function (err) { + err.should.not.be.null; + err.message.should.include('Permission to start activity denied'); + done(); + }); + }); + + it('should fail when no activity is specified', function (done) { + var stdout = + 'Error: Activity class ... does not exist'; + + ADB.prototype.startApp.call(getStartAppMock(19, stdout, null), {pkg: 'com.android.contacts'}, function (err) { + err.should.not.be.null; + err.message.should.include('Parameter \'appActivity\' is required for launching application'); + done(); + }); + }); + + it('should fail when activity does not exist', function (done) { + var stdout = + 'Error: Activity class ... does not exist'; + + ADB.prototype.startApp.call(getStartAppMock(19, stdout, null), { + pkg: 'com.android.contacts', + activity: '.ContactsListActivity' + }, function (err) { + err.should.not.be.null; + err.message.should.include('Activity used to start app doesn\'t exist or cannot be ' + + 'launched! Make sure it exists and is a launchable activity'); + done(); + }); + }); + + it('should retry non-existent activity preceded by a `.`', function (done) { + var stdout = + 'Error: Activity class ... does not exist'; + + ADB.prototype.startApp.call(getStartAppMock(19, stdout, function (startAppOptions, cb) { + startAppOptions.activity.should.equal('.ContactsListActivity'); + cb(); + }), { + pkg: 'com.android.contacts', + activity: 'ContactsListActivity' + }, function () { + done(); + }); + }); + }); });