Skip to content

Commit

Permalink
merge latest manifest/display tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Aug 20, 2016
1 parent 23fd592 commit af716df
Showing 1 changed file with 79 additions and 14 deletions.
93 changes: 79 additions & 14 deletions lighthouse-core/test/manifest-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Manifest Parser', function() {
assert.equal(parsedManifest.value.name.value, undefined);
assert.equal(parsedManifest.value.short_name.value, undefined);
assert.equal(parsedManifest.value.start_url.value, undefined);
assert.equal(parsedManifest.value.display.value, undefined);
assert.equal(parsedManifest.value.display.value, 'browser');
assert.equal(parsedManifest.value.orientation.value, undefined);
assert.equal(parsedManifest.value.theme_color.value, undefined);
assert.equal(parsedManifest.value.background_color.value, undefined);
Expand All @@ -43,19 +43,6 @@ describe('Manifest Parser', function() {
// prefer_related_applications
});

it('accepts unknown values', function() {
// TODO(bckenny): this is the same exact test as above
let parsedManifest = manifestParser('{}');
assert(!parsedManifest.debugString);
assert.equal(parsedManifest.value.name.value, undefined);
assert.equal(parsedManifest.value.short_name.value, undefined);
assert.equal(parsedManifest.value.start_url.value, undefined);
assert.equal(parsedManifest.value.display.value, undefined);
assert.equal(parsedManifest.value.orientation.value, undefined);
assert.equal(parsedManifest.value.theme_color.value, undefined);
assert.equal(parsedManifest.value.background_color.value, undefined);
});

describe('icon parsing', function() {
it('parses basic string', function() {
let parsedManifest = manifestParser('{"icons": [{"src": "192.png", "sizes": "192x192"}]}');
Expand Down Expand Up @@ -131,4 +118,82 @@ describe('Manifest Parser', function() {
assert.equal(parsedManifest.value.short_name.value, undefined);
});
});

/**
* @see https://w3c.github.io/manifest/#display-member
*/
describe('display parsing', () => {
it('falls back to \'browser\' and issues a warning for an invalid value', () => {
const parsedManifest = manifestParser('{"display": {} }');
const display = parsedManifest.value.display;
assert.ok(display.debugString);
assert.equal(display.value, 'browser');
});

it('falls back to \'browser\' and issues a warning for an invalid value', () => {
const parsedManifest = manifestParser('{"display": 5 }');
const display = parsedManifest.value.display;
assert.ok(display.debugString);
assert.equal(display.value, 'browser');
});

it('falls back to \'browser\' and issues no warning when undefined', () => {
const parsedManifest = manifestParser('{}');
const display = parsedManifest.value.display;
assert.ok(!display.debugString);
assert.equal(display.value, 'browser');
assert.equal(display.rawValue, undefined);
});

it('trims whitespace', () => {
const displayValue = ' fullscreen ';
const parsedManifest = manifestParser(`{"display": "${displayValue}" }`);
const display = parsedManifest.value.display;
assert.ok(!display.debugString);
assert.equal(display.value, 'fullscreen');
});

it('converts to lowercase', () => {
const displayValue = 'fUlLScrEEn';
const parsedManifest = manifestParser(`{"display": "${displayValue}" }`);
const display = parsedManifest.value.display;
assert.ok(!display.debugString);
assert.equal(display.value, 'fullscreen');
});

it('falls back to \'browser\' and issues a warning when a non-existent mode', () => {
const parsedManifest = manifestParser('{"display": "fullestscreen" }');
const display = parsedManifest.value.display;
assert.ok(display.debugString);
assert.equal(display.value, 'browser');
});

it('correctly parses `fullscreen` display mode', () => {
const parsedManifest = manifestParser('{"display": "fullscreen" }');
const display = parsedManifest.value.display;
assert.ok(!display.debugString);
assert.equal(display.value, 'fullscreen');
});

it('correctly parses `standalone` display mode', () => {
const parsedManifest = manifestParser('{"display": "standalone" }');
const display = parsedManifest.value.display;
assert.ok(!display.debugString);
assert.equal(display.value, 'standalone');
});

it('correctly parses `minimal-ui` display mode', () => {
const parsedManifest = manifestParser('{"display": "minimal-ui" }');
const display = parsedManifest.value.display;
assert.ok(!display.debugString);
assert.equal(display.value, 'minimal-ui');
});

it('correctly parses `browser` display mode', () => {
const parsedManifest = manifestParser('{"display": "browser" }');
const display = parsedManifest.value.display;
assert.ok(!display.debugString);
assert.equal(display.value, 'browser');
});
});
});

0 comments on commit af716df

Please sign in to comment.