Skip to content

Commit

Permalink
Fixing UA matching for Safari (ampproject#4378)
Browse files Browse the repository at this point in the history
  • Loading branch information
aghassemi authored and ariangibson committed Sep 7, 2016
1 parent c615674 commit 7eaf8b7
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions test/_init_tests.js
Expand Up @@ -43,36 +43,38 @@ class TestConfig {

constructor(runner) {
this.runner = runner;
this.skippedUserAgents = [];
/**
* List of predicate functions that are called before running each test
* suite to check whether the suite should be skipped or not.
* If any of the functions return 'true', the suite will be skipped.
* @type {!Array<function():boolean>}
*/
this.skipMatchers = [];
/**
* Called for each test suite (things created by `describe`).
* @type {!Array<function(!TestSuite)>}
*/
this.configTasks = [];
}

skipOnTravis() {
this.skippedUserAgents.push('Chromium');
return this;
this.platform_ = platformFor(window);
}

skipChrome() {
this.skippedUserAgents.push('Chrome');
this.skipMatchers.push(this.platform_.isChrome.bind(this.platform_));
return this;
}

skipEdge() {
this.skippedUserAgents.push('Edge');
this.skipMatchers.push(this.platform_.isEdge.bind(this.platform_));
return this;
}

skipFirefox() {
this.skippedUserAgents.push('Firefox');
this.skipMatchers.push(this.platform_.isFirefox.bind(this.platform_));
return this;
}

skipSafari() {
this.skippedUserAgents.push('Safari');
this.skipMatchers.push(this.platform_.isSafari.bind(this.platform_));
return this;
}

Expand All @@ -91,8 +93,8 @@ class TestConfig {
* @param {function()} fn
*/
run(desc, fn) {
for (let i = 0; i < this.skippedUserAgents.length; i++) {
if (navigator.userAgent.indexOf(this.skippedUserAgents[i]) >= 0) {
for (let i = 0; i < this.skipMatchers.length; i++) {
if (this.skipMatchers[i]()) {
this.runner.skip(desc, fn);
return;
}
Expand Down

0 comments on commit 7eaf8b7

Please sign in to comment.