This repository has been archived by the owner on Apr 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from GoogleChrome/ff-support-testing
FF Support + Testing
- Loading branch information
Showing
26 changed files
with
1,395 additions
and
864 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
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. | ||
*/ | ||
|
||
// This is a test and we want descriptions to be useful, if this | ||
// breaks the max-length, it's ok. | ||
|
||
/* eslint-disable max-len, no-unused-expressions */ | ||
/* eslint-env browser, mocha */ | ||
|
||
'use strict'; | ||
|
||
describe('Test PushClient Constructor', function() { | ||
if (!window.isPropelClientSupported) { | ||
return; | ||
} | ||
|
||
const EMPTY_SW_PATH = '/test/browser-tests/push-client/empty-sw.js'; | ||
const ERROR_MESSAGES = { | ||
'bad constructor': 'The PushClient constructor expects either service ' + | ||
'worker registration or the path to a service worker file and an ' + | ||
'optional scope string.', | ||
'redundant worker': 'Worker became redundant' | ||
}; | ||
|
||
const getUrlAndScope = function(client) { | ||
return client.getRegistration().then(reg => { | ||
const sw = reg.installing || reg.waiting || reg.active; | ||
return {url: sw.scriptURL, scope: reg.scope}; | ||
}); | ||
}; | ||
|
||
it('should throw an error for no constructor arguments', function() { | ||
window.chai.expect(() => { | ||
/* eslint no-unused-vars: 0 */ | ||
var client = new window.goog.propel.PropelClient(); | ||
}).to.throw(ERROR_MESSAGES['bad constructor']); | ||
}); | ||
|
||
it('should throw an error for Object in the constructor', function() { | ||
window.chai.expect(() => { | ||
/* eslint no-unused-vars: 0 */ | ||
var client = new window.goog.propel.PropelClient({}); | ||
}).to.throw(ERROR_MESSAGES['bad constructor']); | ||
}); | ||
|
||
it('should throw an error for Array in the constructor', function() { | ||
window.chai.expect(() => { | ||
/* eslint no-unused-vars: 0 */ | ||
var client = new window.goog.propel.PropelClient([]); | ||
}).to.throw(ERROR_MESSAGES['bad constructor']); | ||
}); | ||
|
||
it('should throw an error for null in the constructor', function() { | ||
window.chai.expect(() => { | ||
/* eslint no-unused-vars: 0 */ | ||
var client = new window.goog.propel.PropelClient(null); | ||
}).to.throw(ERROR_MESSAGES['bad constructor']); | ||
}); | ||
|
||
it('should throw an error for an empty string in the constructor', function() { | ||
window.chai.expect(() => { | ||
/* eslint no-unused-vars: 0 */ | ||
var client = new window.goog.propel.PropelClient(''); | ||
}).to.throw(ERROR_MESSAGES['bad constructor']); | ||
}); | ||
|
||
it('should be able to create a new push client with just a workerUrl', function() { | ||
window.chai.expect(() => { | ||
/* eslint no-unused-vars: 0 */ | ||
var client = new window.goog.propel.PropelClient('/sw.js', null); | ||
}).not.to.throw(); | ||
}); | ||
|
||
it('should be able to create a new push client with a workerUrl and scope', function(done) { | ||
const pushClient = new window.goog.propel.PropelClient(EMPTY_SW_PATH, './push-service'); | ||
|
||
getUrlAndScope(pushClient).then(result => { | ||
window.chai.expect(result.url).to.contain(EMPTY_SW_PATH); | ||
window.chai.expect(result.scope).to.contain('/test/browser-tests/push-service'); | ||
|
||
done(); | ||
}).catch(done); | ||
}); | ||
|
||
it('should be able to create a new push client with a service worker registration', function(done) { | ||
navigator.serviceWorker.register(EMPTY_SW_PATH) | ||
.then(registration => { | ||
const pushClient = new window.goog.propel.PropelClient(registration); | ||
|
||
return getUrlAndScope(pushClient).then(result => { | ||
window.chai.expect(result.url).to.contain(EMPTY_SW_PATH); | ||
window.chai.expect(result.scope).to.contain('/test/browser-tests/push-client'); | ||
|
||
done(); | ||
}).catch(done); | ||
}) | ||
.catch(done); | ||
}); | ||
}); |
Oops, something went wrong.