This repository has been archived by the owner on Dec 9, 2021. It is now read-only.
Adds a new controlledBySW method #54
Merged
gauntface
merged 6 commits into
GoogleChromeLabs:master
from
jeffposnick:controlled-by-sw
Mar 28, 2017
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2e2c01d
Adds a new controlledBySW method
jeffposnick f4544a8
Added a comment.
jeffposnick a9af2b3
Added an additional comment.
jeffposnick 1be827c
Linting fixes
jeffposnick 5de0a82
Disable the no-var linting rule.
jeffposnick 80ba3ab
var => let
jeffposnick File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
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 swUtils.controlledBySW()', function() { | ||
const SERVICE_WORKER_PATH = '/test/browser-tests/window-utils/serviceworkers'; | ||
|
||
it('should reject when called with no arguments', function(done) { | ||
return window.goog.swUtils.controlledBySW() | ||
.then(() => done(new Error('Should have rejected'))) | ||
.catch(() => done()); | ||
}); | ||
|
||
it('should reject when called with an array argument', function(done) { | ||
return window.goog.swUtils.controlledBySW([]) | ||
.then(() => done(new Error('Should have rejected'))) | ||
.catch(() => done()); | ||
}); | ||
|
||
it('should reject called with an object argument', function(done) { | ||
return window.goog.swUtils.controlledBySW({}) | ||
.then(() => done(new Error('Should have rejected'))) | ||
.catch(() => done()); | ||
}); | ||
|
||
it('should reject when used with an invalid service worker path', function(done) { | ||
return window.goog.swUtils.controlledBySW(SERVICE_WORKER_PATH + '/sw-doesnt-exist.js') | ||
.then(() => done(new Error('Should have rejected'))) | ||
.catch(() => done()); | ||
}); | ||
|
||
it('should reject when used with a service worker that fails to install', function(done) { | ||
return window.goog.swUtils.controlledBySW(SERVICE_WORKER_PATH + '/sw-broken-install.js') | ||
.then(() => done(new Error('Should have rejected'))) | ||
.catch(() => done()); | ||
}); | ||
|
||
it('should resolve once the service worker controls the iframe', function() { | ||
return window.goog.swUtils.controlledBySW(SERVICE_WORKER_PATH + '/immediate-control.js') | ||
.then(iframe => { | ||
chai.expect(iframe.contentWindow.navigator.serviceWorker.controller).to.exist; | ||
}); | ||
}); | ||
}); |
2 changes: 2 additions & 0 deletions
2
test/browser-tests/window-utils/serviceworkers/immediate-control.js
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,2 @@ | ||
self.addEventListener('install', () => self.skipWaiting()); | ||
self.addEventListener('activate', () => self.clients.claim()); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment here just along the lines of:
"This service worker does not use event.waitUntil() on purpose. This has ambiguity over implementation across browsers (i.e. whether it's needed to be used with skipWaiting and clients.claim()). This service worker is used to test controlledBySw() - PLEASE DO NOT CHANGE."
Without this I can see someone eventually sneaking in event.waitUntil() (i.e. myself) and then it's undermines the purpose of this new method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the ambiguity is, though? AFAIK there are no browsers that ever required an
event.waitUntil()
wrapper aroundself.skipWaiting()
orself.clients.claim()
.There are old examples that used
event.waitUntil()
(including many I wrote), but it turns out it was never actually necessary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I added a comment anyway!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we've seen the difference in behavior - so it's not "required" it does affect the end behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL at the revised comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that works.