Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

Detector Test Tutorial

dmolsen edited this page Feb 16, 2012 · 8 revisions

Modernizr-based tests help create the bulk of the data is available in a browser profile. There are broken down into three types:

  • core tests that come from the included version of Modernizr. The profiles created with core data are stored in user-agents/core/ and include information from ua-parser-php.
  • extended tests are created by individual developers and are meant to be used on an individual install basis. extended tests should be seen as a way to expand on core tests. The information from extended tests are store in profiles in user-agents/extended/. family information is also stored in these same profiles.
  • per-request tests are created by individual developers and are for features that need to be tested on every browser request. They test features that change on a per device basis versus a per request basis. A good example of this is would be device pixel ratio. An iPhone 3G and iPhone 4 can both run the latest version of Mobile Safari but only the iPhone 4 has the Retina display.

Creating Extended Tests

Extended tests are tests that, when sending out the full suite of Modernizr tests, get run along-side Core tests but are instead saved to their own user-agent profile. They're meant to provide developers with a way to add their own Core-like tests but in a way that allows Core to be a standard. To add your own Extended tests simply follow the Modernizr.addTest() format and put them in tests/extended/. The names of the tests should start with extended- so that their values get put into the appropriate user-agent file. The string extended- is stripped from the test name when placing it in session.

Creating Per Request Tests

Per Request tests are tests that get run on every request the browser sends. I'm not sure they'll operate this way in the future. They were designed to capture features that change on a per device basis versus a per browser basis. To add your own Per Request tests simply follow the Modernizr.addTest() format and put them in tests/perrequest/. The names of the tests should start with pr- so that their values are not added to any of the user-agent files. The string pr- is stripped from the test name when placing it in session.

Clone this wiki locally