fix($sniffer): allow history for NW.js apps

Previously `$sniffer` incorrectly detected NW.js apps as Chrome Packaged Apps,
disallowing them to use the history API.

This commit correctly detects NW.js apps and allows them to use the History API.

Fixes #15474

Closes #15633
This commit is contained in:
frederikprijck
2017-01-20 23:04:59 +01:00
committed by Georgios Kalpakas
parent 89f3e3b0af
commit 7019d9f27a
2 changed files with 22 additions and 0 deletions
+3
View File
@@ -25,7 +25,10 @@ function $SnifferProvider() {
// (see https://developer.chrome.com/apps/api_index). If sandboxed, they can be detected by
// the presence of an extension runtime ID and the absence of other Chrome runtime APIs
// (see https://developer.chrome.com/apps/manifest/sandbox).
// (NW.js apps have access to Chrome APIs, but do support `history`.)
isNw = $window.nw && $window.nw.process,
isChromePackagedApp =
!isNw &&
$window.chrome &&
($window.chrome.app && $window.chrome.app.runtime ||
!$window.chrome.app && $window.chrome.runtime && $window.chrome.runtime.id),
+19
View File
@@ -45,6 +45,25 @@ describe('$sniffer', function() {
});
it('should be true on NW.js apps (which look similar to Chrome Packaged Apps)', function() {
var mockWindow = {
history: {
pushState: noop
},
chrome: {
app: {
runtime: {}
}
},
nw: {
process: {}
}
};
expect(sniffer(mockWindow).history).toBe(true);
});
it('should be false on Chrome Packaged Apps', function() {
// Chrome Packaged Apps are not allowed to access `window.history.pushState`.
// In Chrome, `window.app` might be available in "normal" webpages, but `window.app.runtime`