Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added short-name-length check #145

Merged
merged 1 commit into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions aggregators/will-get-add-to-homescreen-prompt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const manifestIconsMin144 = require('../../audits/manifest/icons-min-144').name;
/** @type {string} */
const manifestShortName = require('../../audits/manifest/short-name').name;

/** @type {string} */
const manifestShortNameLength = require('../../audits/manifest/short-name-length').name;

class AddToHomescreen extends Aggregate {

/**
Expand All @@ -52,6 +55,7 @@ class AddToHomescreen extends Aggregate {
* - valid start_url
* - valid name
* - valid short_name
* - short_name of reasonable length
* - icon of size >= 144x144 and png (either type `image/png` or filename ending in `.png`
* @see https://github.com/GoogleChrome/lighthouse/issues/23
*
Expand Down Expand Up @@ -86,6 +90,11 @@ class AddToHomescreen extends Aggregate {
weight: 0
};

criteria[manifestShortNameLength] = {
value: true,
weight: 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the 0 weight mean this is just advisory?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like it. I think it's appropriate for this test. 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I think that's great. I was actually all ready to say that I didn't think your score shouldn't be docked just because your name was a little long

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

};

return criteria;
}
}
Expand Down
71 changes: 71 additions & 0 deletions audits/manifest/short-name-length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @license
* Copyright 2016 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const Audit = require('../audit');

class ManifestShortNameLength extends Audit {
/**
* @override
*/
static get tags() {
return ['Manifest'];
}

/**
* @override
*/
static get name() {
return 'manifest-short-name-length';
}

/**
* @override
*/
static get description() {
return 'App short_name won\'t be truncated on the homescreen';
}

/**
* @param {!Artifacts} artifacts
* @return {!AuditResult}
*/
static audit(artifacts) {
let isShortNameShortEnough = false;
let debugString;
const manifest = artifacts.manifest.value;
const suggestedLength = 12;

if (manifest && manifest.short_name && manifest.short_name.value) {
// Historically, Chrome recommended 12 chars as the maximum length to prevent truncation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe put in a mention of #69 to track while we figure out the answer there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 lets link the issue as theres some valuable discussion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// See #69 for more discussion.
isShortNameShortEnough = (manifest.short_name.value.length <= suggestedLength);
if (!isShortNameShortEnough) {
debugString = `${suggestedLength} chars is the suggested maximum length`;
}
}

return ManifestShortNameLength.generateAuditResult(
isShortNameShortEnough,
undefined,
debugString
);
}
}

module.exports = ManifestShortNameLength;
1 change: 1 addition & 0 deletions extension/app/scripts.babel/pwa-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const audits = [
require('../../../audits/manifest/icons-min-144'),
require('../../../audits/manifest/name'),
require('../../../audits/manifest/short-name'),
require('../../../audits/manifest/short-name-length'),
require('../../../audits/manifest/start-url'),
require('../../../audits/html/meta-theme-color')
];
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const audits = [
require('./audits/manifest/icons-min-144'),
require('./audits/manifest/name'),
require('./audits/manifest/short-name'),
require('./audits/manifest/short-name-length'),
require('./audits/manifest/start-url'),
require('./audits/html/meta-theme-color')
];
Expand Down
57 changes: 57 additions & 0 deletions test/audits/manifest/short-name-length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright 2016 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const Audit = require('../../../audits/manifest/short-name-length.js');
const assert = require('assert');
const manifestParser = require('../../../helpers/manifest-parser');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now you're not using this manifestParser...

but you should. It's not worth it to handcraft the post-parser objects to pass in: https://github.com/GoogleChrome/lighthouse/blob/master/test/helpers/icons.js#L57-L76

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/* global describe, it*/

describe('Manifest: short_name_length audit', () => {
it('fails when an empty manifest is present', () => {
const manifest = manifestParser('{}');
console.info('got empty manifest', manifest);
return assert.equal(Audit.audit({manifest}).value, false);
});

// Need to disable camelcase check for dealing with short_name.
/* eslint-disable camelcase */
it('fails when a manifest contains no short_name', () => {
const manifestSrc = JSON.stringify({
short_name: undefined
});
const manifest = manifestParser(manifestSrc);
return assert.equal(Audit.audit({manifest}).value, false);
});

it('fails when a manifest contains a long short_name', () => {
const manifestSrc = JSON.stringify({
short_name: 'i\'m much longer than the recommended size'
});
const manifest = manifestParser(manifestSrc);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also verify the Debug string is attached here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const out = Audit.audit({manifest});
assert.equal(out.value, false);
assert.notEqual(out.debugString, undefined);
});

it('succeeds when a manifest contains a short_name', () => {
const manifestSrc = JSON.stringify({
short_name: 'Lighthouse'
});
const manifest = manifestParser(manifestSrc);
return assert.equal(Audit.audit({manifest}).value, true);
});
/* eslint-enable camelcase */
});