Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Treat everything other than FxOS and desktop as android (bug 1180296)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstriemer committed Jul 6, 2015
1 parent 14bdc95 commit 49ead0d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
21 changes: 11 additions & 10 deletions core/capabilities.js
Expand Up @@ -101,23 +101,24 @@ define('core/capabilities', ['core/settings'], function(settings) {
caps = caps || static_caps;
if (caps.firefoxOS) {
return 'firefoxos';
} else if (caps.firefoxAndroid) {
} else if (caps.os.type === 'desktop') {
return 'desktop';
} else {
// Make everything else android so we can treat iPhone, iPad,
// Windows Phone, etc as mobile instead of desktop.
return 'android';
}
return 'desktop';
};

/* Returns device form factor alone, i.e. 'tablet' or 'mobile' ('device' API parameter).
* Only supported for Android currently. */
/* Returns device form factor alone, i.e. 'tablet' or 'mobile' ('device'
* API parameter). Unsupported on FxOS and desktop. */
static_caps.device_formfactor = function(caps) {
caps = caps || static_caps;
if (caps.firefoxAndroid) {
if (caps.widescreen()) {
return 'tablet';
}
return 'mobile';
if (caps.firefoxOS || caps.os.type === 'desktop') {
return '';
} else {
return caps.widescreen() ? 'tablet' : 'mobile';
}
return '';
};

/* Returns full device type information, e.g. 'android-mobile' or 'firefoxos' as exposed by the API. */
Expand Down
40 changes: 29 additions & 11 deletions tests/capabilities.js
Expand Up @@ -4,17 +4,21 @@ define('tests/capabilities',

describe('capabilities.device_platform', function() {
it('can be firefoxos', function() {
var caps = {firefoxOS: true};
var caps = {firefoxOS: true, os: {type: ''}};
assert.equal(capabilities.device_platform(caps), 'firefoxos');
});

it('can be android', function() {
var caps = {firefoxOS: false, firefoxAndroid: true};
var caps = {
firefoxOS: false,
firefoxAndroid: true,
os: {type: 'mobile'},
};
assert.equal(capabilities.device_platform(caps), 'android');
});

it('can be desktop', function() {
var caps = {firefoxAndroid: false};
var caps = {firefoxAndroid: false, os: {type: 'desktop'}};
assert.equal(capabilities.device_platform(caps), 'desktop');
});
});
Expand All @@ -25,6 +29,7 @@ define('tests/capabilities',
firefoxOS: true,
firefoxAndroid: false,
widescreen: function() { return false; },
os: {type: ''},
};
assert.equal(capabilities.device_formfactor(caps), '');
});
Expand All @@ -34,6 +39,7 @@ define('tests/capabilities',
firefoxOS: true,
firefoxAndroid: false,
widescreen: function() { return true; },
os: {type: ''},
};
assert.equal(capabilities.device_formfactor(caps), '');
});
Expand All @@ -43,6 +49,7 @@ define('tests/capabilities',
firefoxOS: false,
firefoxAndroid: true,
widescreen: function() { return false; },
os: {type: 'mobile'},
};
assert.equal(capabilities.device_formfactor(caps), 'mobile');
});
Expand All @@ -52,26 +59,31 @@ define('tests/capabilities',
firefoxOS: false,
firefoxAndroid: true,
widescreen: function() { return true; },
os: {type: 'mobile'},
};
// This becomes tablet because it is widescreen. The Android OS
// type is always set to `mobile`.
assert.equal(capabilities.device_formfactor(caps), 'tablet');
});

it('is nothing for other mobile', function() {
it('is mobile for other mobile', function() {
var caps = {
firefoxOS: false,
firefoxAndroid: false,
widescreen: function() { return false; },
os: {type: ''},
};
assert.equal(capabilities.device_formfactor(caps), '');
assert.equal(capabilities.device_formfactor(caps), 'mobile');
});

it('is nothing for other tablet', function() {
it('is tablet for other tablet', function() {
var caps = {
firefoxOS: false,
firefoxAndroid: false,
widescreen: function() { return true; },
os: {type: ''},
};
assert.equal(capabilities.device_formfactor(caps), '');
assert.equal(capabilities.device_formfactor(caps), 'tablet');
});
});

Expand All @@ -81,6 +93,7 @@ define('tests/capabilities',
firefoxOS: true,
firefoxAndroid: false,
widescreen: function() { return false; },
os: {type: ''},
};
assert.equal(capabilities.device_type(caps), 'firefoxos');
});
Expand All @@ -90,6 +103,7 @@ define('tests/capabilities',
firefoxOS: true,
firefoxAndroid: false,
widescreen: function() { return true; },
os: {type: ''},
};
assert.equal(capabilities.device_type(caps), 'firefoxos');
});
Expand All @@ -99,6 +113,7 @@ define('tests/capabilities',
firefoxOS: false,
firefoxAndroid: true,
widescreen: function() { return false; },
os: {type: 'mobile'},
};
assert.equal(capabilities.device_type(caps), 'android-mobile');
});
Expand All @@ -108,26 +123,29 @@ define('tests/capabilities',
firefoxOS: false,
firefoxAndroid: true,
widescreen: function() { return true; },
os: {type: 'mobile'},
};
assert.equal(capabilities.device_type(caps), 'android-tablet');
});

it('is desktop on other mobile', function() {
it('is android-mobile on other mobile', function() {
var caps = {
firefoxOS: false,
firefoxAndroid: false,
widescreen: function() { return false; },
os: {type: ''},
};
assert.equal(capabilities.device_type(caps), 'desktop');
assert.equal(capabilities.device_type(caps), 'android-mobile');
});

it('is desktop on other tablet', function() {
it('is android-tablet on other tablet', function() {
var caps = {
firefoxOS: false,
firefoxAndroid: false,
widescreen: function() { return true; },
os: {type: ''},
};
assert.equal(capabilities.device_type(caps), 'desktop');
assert.equal(capabilities.device_type(caps), 'android-tablet');
});
});

Expand Down

0 comments on commit 49ead0d

Please sign in to comment.