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

Add check for disabled tap delay #980

Merged
merged 1 commit into from
Dec 12, 2020
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
23 changes: 23 additions & 0 deletions packages/linter/src/rules/ViewportDisablesTapDelay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Context } from "../index";
import { Rule } from "../rule";

export class ViewportDisablesTapDelay extends Rule {
run({ $ }: Context) {
const viewport = $("meta[name=viewport]")[0];
if (!viewport) {
return this.pass();
}
return viewport.attribs.content !== "width=device-width"
? this.fail(`Viewport width not set to device width`)
: this.pass();
}
meta() {
return {
url:
"https://developers.google.com/web/updates/2013/12/300ms-tap-delay-gone-away",
title:
"Set viewport width to the same as the device to disable touch delay causing FID.",
info: "",
};
}
}
32 changes: 31 additions & 1 deletion packages/linter/tests/local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import { HeroImageIsDefined } from "../src/rules/HeroImageIsDefined";
import { FastGoogleFontsDisplay } from "../src/rules/FastGoogleFontsDisplay";
import { GoogleFontPreconnect } from "../src/rules/GoogleFontPreconnect";
import { BoilerplateIsRemoved } from "../src/rules/BoilerplateIsRemoved";
import { AmpImgUsesSrcSet } from '../src/rules/AmpImgUsesSrcSet';
import { AmpImgUsesSrcSet } from "../src/rules/AmpImgUsesSrcSet";
import { ViewportDisablesTapDelay } from "../src/rules/ViewportDisablesTapDelay";

describe(AmpImgAmpPixelPreferred.name, () => {
it(`${AmpImgAmpPixelPreferred.name} - <amp-img height="1" width="1">`, async () => {
Expand Down Expand Up @@ -597,3 +598,32 @@ describe(TitleMeetsLengthCriteria.name, () => {
);
});
});

describe(ViewportDisablesTapDelay.name, () => {
it(`${ViewportDisablesTapDelay.name} - Viewport Disables Tap Delay`, async () => {
return assertPass(
runLocalTest(
ViewportDisablesTapDelay,
`${__dirname}/local/ViewportDisablesTapDelay-1/source.html`
)
);
});

it(`${ViewportDisablesTapDelay.name} - Viewport causes Tap Delay`, async () => {
return assertFail(
runLocalTest(
ViewportDisablesTapDelay,
`${__dirname}/local/ViewportDisablesTapDelay-2/source.html`
)
);
});

it(`${ViewportDisablesTapDelay.name} - no viewport`, async () => {
return assertPass(
runLocalTest(
ViewportDisablesTapDelay,
`${__dirname}/local/ViewportDisablesTapDelay-3/source.html`
)
);
});
});
13 changes: 13 additions & 0 deletions packages/linter/tests/local/ViewportDisablesTapDelay-1/source.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
<noscript>
<style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style>
</noscript>
</head>
<body>
</body>
</html>
14 changes: 14 additions & 0 deletions packages/linter/tests/local/ViewportDisablesTapDelay-2/source.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
<noscript>
<style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style>
</noscript>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
</head>
<body>
</body>
</html>
13 changes: 13 additions & 0 deletions packages/linter/tests/local/ViewportDisablesTapDelay-3/source.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
<noscript>
<style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style>
</noscript>
</head>
<body>
</body>
</html>