mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
update components
This commit is contained in:
parent
9254ff721d
commit
3197c48232
162 changed files with 902 additions and 9728 deletions
|
@ -1,26 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--
|
||||
@license
|
||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
|
||||
<script src="../../web-component-tester/browser.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
WCT.loadSuites([
|
||||
'iron-location.html',
|
||||
'iron-query-params.html',
|
||||
'initialization-tests.html'
|
||||
]);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,277 +0,0 @@
|
|||
<!--
|
||||
@license
|
||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
|
||||
<link rel='import' href='../iron-location.html'>
|
||||
<link rel='import' href='../../polymer/polymer.html'>
|
||||
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'default-value',
|
||||
properties: {
|
||||
val: {
|
||||
type: String,
|
||||
notify: true,
|
||||
value: 'default-value'
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Polymer({
|
||||
is: 'on-attached',
|
||||
properties: {
|
||||
val: {
|
||||
type: String,
|
||||
notify: true,
|
||||
value: 'on-attached-default-value'
|
||||
}
|
||||
},
|
||||
attached: function() {
|
||||
if (this.val === 'on-attached-default-value') {
|
||||
this.val = 'on-attached';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Polymer({
|
||||
is: 'on-ready',
|
||||
properties: {
|
||||
val: {
|
||||
type: String,
|
||||
notify: true,
|
||||
value: 'on-ready-default-value'
|
||||
}
|
||||
},
|
||||
ready: function() {
|
||||
this.val = 'on-ready';
|
||||
}
|
||||
});
|
||||
|
||||
Polymer({
|
||||
is: 'on-timeout',
|
||||
properties: {
|
||||
val: {
|
||||
type: String,
|
||||
notify: true,
|
||||
value: 'on-timeout-default-value'
|
||||
}
|
||||
},
|
||||
attached: function() {
|
||||
setTimeout(function() {
|
||||
this.val = 'on-timeout';
|
||||
}.bind(this), 10);
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<dom-module id='default-before'>
|
||||
<template>
|
||||
<default-value value='{{val}}'></default-value>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
|
||||
</template>
|
||||
<script>Polymer({is: 'default-before', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='attached-before'>
|
||||
<template>
|
||||
<on-attached val='{{val}}'></on-attached>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
</template>
|
||||
<script>Polymer({is: 'attached-before', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='ready-before'>
|
||||
<template>
|
||||
<on-ready val='{{val}}'></on-ready>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
</template>
|
||||
<script>Polymer({is: 'ready-before', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='timeout-before'>
|
||||
<template>
|
||||
<on-timeout val='{{val}}'></on-timeout>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
</template>
|
||||
<script>Polymer({is: 'timeout-before', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
|
||||
<dom-module id='default-after'>
|
||||
<template>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
<default-value value='{{val}}'></default-value>
|
||||
</template>
|
||||
<script>Polymer({is: 'default-after', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='attached-after'>
|
||||
<template>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
<on-attached val='{{val}}'></on-attached>
|
||||
</template>
|
||||
<script>Polymer({is: 'attached-after', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='ready-after'>
|
||||
<template>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
<on-ready val='{{val}}'></on-ready>
|
||||
</template>
|
||||
<script>Polymer({is: 'ready-after', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='timeout-after'>
|
||||
<template>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
<on-timeout val='{{val}}'></on-timeout>
|
||||
</template>
|
||||
<script>Polymer({is: 'timeout-after', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
|
||||
<dom-module id='default-below'>
|
||||
<template>
|
||||
<iron-location query='{{val}}'>
|
||||
<default-value value='{{val}}'></default-value>
|
||||
</iron-location>
|
||||
</template>
|
||||
<script>Polymer({is: 'default-below', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='attached-below'>
|
||||
<template>
|
||||
<iron-location query='{{val}}'>
|
||||
<on-attached val='{{val}}'></on-attached>
|
||||
</iron-location>
|
||||
</template>
|
||||
<script>Polymer({is: 'attached-below', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='ready-below'>
|
||||
<template>
|
||||
<iron-location query='{{val}}'>
|
||||
<on-ready val='{{val}}'></on-ready>
|
||||
</iron-location>
|
||||
</template>
|
||||
<script>Polymer({is: 'ready-below', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='timeout-below'>
|
||||
<template>
|
||||
<iron-location query='{{val}}'>
|
||||
<on-timeout val='{{val}}'></on-timeout>
|
||||
</iron-location>
|
||||
</template>
|
||||
<script>Polymer({is: 'timeout-below', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
|
||||
<dom-module id='default-above'>
|
||||
<template>
|
||||
<default-value value='{{val}}'>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
</default-value>
|
||||
</template>
|
||||
<script>Polymer({is: 'default-above', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='attached-above'>
|
||||
<template>
|
||||
<on-attached val='{{val}}'>
|
||||
<iron-location query='{{val}}'>
|
||||
</iron-location>
|
||||
</on-attached>
|
||||
</template>
|
||||
<script>Polymer({is: 'attached-above', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='ready-above'>
|
||||
<template>
|
||||
<on-ready val='{{val}}'>
|
||||
<iron-location query='{{val}}'>
|
||||
</iron-location>
|
||||
</on-ready>
|
||||
</template>
|
||||
<script>Polymer({is: 'ready-above', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='timeout-above'>
|
||||
<template>
|
||||
<on-timeout val='{{val}}'>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
</on-timeout>
|
||||
</template>
|
||||
<script>Polymer({is: 'timeout-above', properties: {val: {type: String}}});</script>
|
||||
</dom-module>
|
||||
|
||||
|
||||
<dom-module id='default-container'>
|
||||
<template>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
</template>
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'default-container',
|
||||
properties: {val: {type: String, value: 'default-container-val'}}
|
||||
});
|
||||
</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='attached-container'>
|
||||
<template>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
</template>
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'attached-container',
|
||||
properties: {val: {type: String, value: 'container-attached-default-val'}},
|
||||
attached: function() {
|
||||
if (this.val === 'container-attached-default-val') {
|
||||
this.val = 'attached-container-val';
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='ready-container'>
|
||||
<template>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
</template>
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'ready-container', properties: {val: {type: String}},
|
||||
ready: function() {
|
||||
this.val = 'ready-container-val';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='timeout-container'>
|
||||
<template>
|
||||
<iron-location query='{{val}}'></iron-location>
|
||||
</template>
|
||||
<script>Polymer({
|
||||
is: 'timeout-container',
|
||||
properties: {
|
||||
val: {
|
||||
type: String,
|
||||
notify: true
|
||||
}
|
||||
},
|
||||
attached: function() {
|
||||
setTimeout(function() {
|
||||
this.val = 'on-timeout';
|
||||
}.bind(this), 10);
|
||||
}
|
||||
});</script>
|
||||
</dom-module>
|
|
@ -1,61 +0,0 @@
|
|||
<!--
|
||||
@license
|
||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Base source for injecting into an iframe for tests</title>
|
||||
<script src="../../webcomponentsjs/webcomponents.js"></script>
|
||||
<link rel='import' href='./initialization-cases.html'>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
window.addEventListener("message", messageReceived, false);
|
||||
|
||||
window.addEventListener('WebComponentsReady', function() {
|
||||
window.parent.postMessage({
|
||||
'type': 'ready'
|
||||
}, '*');
|
||||
});
|
||||
|
||||
var appendBodyReceived = false;
|
||||
function messageReceived(msg) {
|
||||
if (!msg.data) {
|
||||
console.error('got invalid msg?');
|
||||
}
|
||||
// the parent can (at any time) ask for our URL.
|
||||
if (msg.data.type === 'urlQuery') {
|
||||
msg.source.postMessage({
|
||||
'type': 'urlQueryResponse',
|
||||
'href': window.location.href,
|
||||
'pathname': window.location.pathname,
|
||||
'hash': window.location.hash,
|
||||
'search': window.location.search
|
||||
}, '*');
|
||||
} else if (msg.data.type === 'appendBody') {
|
||||
if (appendBodyReceived) {
|
||||
throw new Error('should only receive at most one appendBody call');
|
||||
}
|
||||
var element = document.createElement(msg.data.tagName);
|
||||
document.body.appendChild(element);
|
||||
appendBodyReceived = true;
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('error', function(e) {
|
||||
window.parent.postMessage({
|
||||
'type': 'error',
|
||||
'error': e.message
|
||||
}, '*');
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,145 +0,0 @@
|
|||
<!--
|
||||
@license
|
||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<script src="../../webcomponentsjs/webcomponents.js"></script>
|
||||
<script src="../../web-component-tester/browser.js"></script>
|
||||
<script src="../../test-fixture/test-fixture-mocha.js"></script>
|
||||
|
||||
<link rel="import" href="../../polymer/polymer.html">
|
||||
<link rel="import" href="../../promise-polyfill/promise-polyfill.html">
|
||||
<link rel="import" href="../../test-fixture/test-fixture.html">
|
||||
<link rel="import" href="../iron-location.html">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
function getIframe() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var iframe = document.createElement('iframe');
|
||||
var result = getMessageMatching(iframe, function(message) {
|
||||
return message.type === 'ready';
|
||||
});
|
||||
iframe.src = './initialization-iframe.html';
|
||||
document.body.appendChild(iframe);
|
||||
iframe.addEventListener('error', reject);
|
||||
result.then(function() {resolve(iframe)}, reject);
|
||||
});
|
||||
}
|
||||
|
||||
function onMessage(iframe, callback) {
|
||||
var f = function(event) {
|
||||
if (event.source === iframe.contentWindow) {
|
||||
callback(event.data);
|
||||
}
|
||||
};
|
||||
window.addEventListener('message', f, false);
|
||||
return function() {
|
||||
window.removeEventListener('message', f);
|
||||
}
|
||||
}
|
||||
|
||||
function getMessageMatching(iframe, predicate) {
|
||||
var revoke = function() {};
|
||||
var result = new Promise(function(resolve, reject) {
|
||||
revoke = onMessage(iframe, function(message) {
|
||||
if (predicate(message)) {
|
||||
resolve(message);
|
||||
}
|
||||
});
|
||||
});
|
||||
result.then(revoke, revoke);
|
||||
return result;
|
||||
}
|
||||
|
||||
function getUrl(iframe) {
|
||||
var result = getMessageMatching(iframe, function(message) {
|
||||
return message.type === 'urlQueryResponse';
|
||||
})
|
||||
var revoke = function() {};
|
||||
var result = new Promise(function(resolve, reject) {
|
||||
revoke = onMessage(iframe, resolve);
|
||||
});
|
||||
result.then(revoke, revoke);
|
||||
iframe.contentWindow.postMessage({type: 'urlQuery'}, '*');
|
||||
return result;
|
||||
}
|
||||
|
||||
function timePasses(ms) {
|
||||
return new Promise(function(resolve) {
|
||||
window.setTimeout(function() {
|
||||
resolve();
|
||||
}, ms);
|
||||
});
|
||||
}
|
||||
|
||||
suite('<iron-location>\'s initialization', function() {
|
||||
var iframe;
|
||||
var error;
|
||||
setup(function() {
|
||||
return getIframe().then(function(i) {
|
||||
iframe = i;
|
||||
function isError(m) {return m.type === 'error'}
|
||||
getMessageMatching(iframe, isError).then(function(m) {
|
||||
error = m.error;
|
||||
});
|
||||
});
|
||||
});
|
||||
teardown(function() {
|
||||
if (iframe) {
|
||||
document.body.removeChild(iframe);
|
||||
}
|
||||
var e = error;
|
||||
iframe = null;
|
||||
error = null;
|
||||
if (e) {
|
||||
throw new Error('Error message from contained iframe: ' + e);
|
||||
}
|
||||
});
|
||||
var cases = [
|
||||
'default-before', 'attached-before', 'ready-before',
|
||||
'default-after', 'attached-after', 'ready-after',
|
||||
'default-below', 'attached-below', 'ready-below',
|
||||
'default-above', 'attached-above', 'ready-above',
|
||||
'default-container', 'attached-container', 'ready-container'
|
||||
];
|
||||
cases.forEach(function(caseName) {
|
||||
test('the url takes priority in ' + caseName + ' initialization', function() {
|
||||
return getUrl(iframe).then(function(url) {
|
||||
expect(url.search).to.be.eq('');
|
||||
iframe.contentWindow.postMessage({type: 'appendBody', tagName: caseName}, '*');
|
||||
return timePasses(10).then(function() {return getUrl(iframe)});
|
||||
}).then(function(url) {
|
||||
expect(url.search).to.be.eq('');
|
||||
});
|
||||
});
|
||||
});
|
||||
var expectedFailureCases = ['timeout-before', 'timeout-after', 'timeout-below', 'timeout-above', 'timeout-container'];
|
||||
expectedFailureCases.forEach(function(caseName) {
|
||||
test('the url does not take priority in ' + caseName + ' initialization', function() {
|
||||
return getUrl(iframe).then(function(url) {
|
||||
expect(url.search).to.be.eq('');
|
||||
iframe.contentWindow.postMessage({type: 'appendBody', tagName: caseName}, '*');
|
||||
return timePasses(60).then(function() {return getUrl(iframe)});
|
||||
}).then(function(url) {
|
||||
expect(url.search).to.be.eq('?on-timeout');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,369 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--
|
||||
@license
|
||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>iron-location</title>
|
||||
|
||||
<script src="../../webcomponentsjs/webcomponents.js"></script>
|
||||
<script src="../../web-component-tester/browser.js"></script>
|
||||
|
||||
<link rel="import" href="../../polymer/polymer.html">
|
||||
<link rel="import" href="../../promise-polyfill/promise-polyfill.html">
|
||||
<link rel="import" href="../iron-location.html">
|
||||
<link rel="import" href="./redirection.html">
|
||||
</head>
|
||||
<body>
|
||||
<test-fixture id='Solo'>
|
||||
<template>
|
||||
<iron-location></iron-location>
|
||||
</template>
|
||||
</test-fixture>
|
||||
<test-fixture id='Together'>
|
||||
<template>
|
||||
<div>
|
||||
<iron-location id='one'></iron-location>
|
||||
<iron-location id='two'></iron-location>
|
||||
</div>
|
||||
</template>
|
||||
</test-fixture>
|
||||
<test-fixture id='RedirectHash'>
|
||||
<template>
|
||||
<redirect-hash></redirect-hash>
|
||||
</template>
|
||||
</test-fixture>
|
||||
<test-fixture id='RedirectPath'>
|
||||
<template>
|
||||
<redirect-path></redirect-path>
|
||||
</template>
|
||||
</test-fixture>
|
||||
<test-fixture id='RedirectQuery'>
|
||||
<template>
|
||||
<redirect-query></redirect-query>
|
||||
</template>
|
||||
</test-fixture>
|
||||
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
function timePasses(ms) {
|
||||
return new Promise(function(resolve) {
|
||||
window.setTimeout(function() {
|
||||
resolve();
|
||||
}, ms);
|
||||
});
|
||||
}
|
||||
|
||||
function makeAbsoluteUrl(path) {
|
||||
return window.location.protocol + '//' + window.location.host + path;
|
||||
}
|
||||
|
||||
// A window.history.replaceState wrapper that's smart about baseURI.
|
||||
function replaceState(path) {
|
||||
window.history.replaceState({}, '', makeAbsoluteUrl(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* We run the iron location tests with a couple different page configurations
|
||||
* (e.g. with and withoug a base URI), so we define the test set as a function
|
||||
* that we call in each of these configurations.
|
||||
*/
|
||||
function ironLocationTests() {
|
||||
suite('when used solo', function() {
|
||||
var urlElem;
|
||||
setup(function() {
|
||||
urlElem = fixture('Solo');
|
||||
});
|
||||
test('basic functionality with #hash urls', function() {
|
||||
// Initialized to the window location's hash.
|
||||
expect(window.location.hash).to.be.equal(urlElem.hash);
|
||||
|
||||
// Changing the urlElem's hash changes the URL
|
||||
urlElem.hash = '/lol/ok';
|
||||
expect(window.location.hash).to.be.equal('#/lol/ok');
|
||||
|
||||
// Changing the hash via normal means changes the urlElem.
|
||||
var anchor = document.createElement('a');
|
||||
var base =
|
||||
window.location.protocol + '//' + window.location.host +
|
||||
window.location.pathname;
|
||||
anchor.href = base + '#/wat';
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
// In IE10 it appears that the hashchange event is asynchronous.
|
||||
return timePasses(10).then(function() {
|
||||
expect(urlElem.hash).to.be.equal('/wat');
|
||||
});
|
||||
});
|
||||
test('basic functionality with paths', function() {
|
||||
// Initialized to the window location's path.
|
||||
expect(window.location.pathname).to.be.equal(urlElem.path);
|
||||
|
||||
// Changing the urlElem's path changes the URL
|
||||
urlElem.path = '/foo/bar';
|
||||
expect(window.location.pathname).to.be.equal('/foo/bar');
|
||||
|
||||
// Changing the path and sending a custom event on the window changes
|
||||
// the urlElem.
|
||||
replaceState('/baz');
|
||||
window.dispatchEvent(new CustomEvent('location-changed'));
|
||||
expect(urlElem.path).to.be.equal('/baz');
|
||||
});
|
||||
test('assigning to a relative path URL', function() {
|
||||
urlElem.path = '/foo/bar';
|
||||
expect(window.location.pathname).to.be.equal('/foo/bar');
|
||||
|
||||
// A relative path is treated as an absolute one, just with a
|
||||
// missing leading slash.
|
||||
urlElem.path = 'baz';
|
||||
expect(window.location.pathname).to.be.equal('/baz');
|
||||
});
|
||||
test('basic functionality with ?key=value params', function() {
|
||||
// Initialized to the window location's params.
|
||||
expect(urlElem.query).to.be.eq('');
|
||||
|
||||
// Changing location.search and sending a custom event on the window
|
||||
// changes the urlElem.
|
||||
replaceState('/?greeting=hello&target=world');
|
||||
window.dispatchEvent(new CustomEvent('location-changed'));
|
||||
expect(urlElem.query).to.be.equal('greeting=hello&target=world');
|
||||
|
||||
// Changing the urlElem's query changes the URL.
|
||||
urlElem.query = 'greeting=hello&target=world&another=key';
|
||||
expect(window.location.search).to.be.equal(
|
||||
'?greeting=hello&target=world&another=key');
|
||||
});
|
||||
});
|
||||
suite('does not spam the user\'s history', function() {
|
||||
var replaceStateCalls, pushStateCalls;
|
||||
var nativeReplaceState, nativePushState;
|
||||
setup(function() {
|
||||
replaceStateCalls = pushStateCalls = 0;
|
||||
nativeReplaceState = window.history.replaceState;
|
||||
nativePushState = window.history.pushState;
|
||||
window.history.replaceState = function() {
|
||||
replaceStateCalls++;
|
||||
};
|
||||
window.history.pushState = function() {
|
||||
pushStateCalls++;
|
||||
};
|
||||
});
|
||||
teardown(function() {
|
||||
window.history.replaceState = nativeReplaceState;
|
||||
window.history.pushState = nativePushState;
|
||||
});
|
||||
test('when a change happens immediately after ' +
|
||||
'the iron-location is attached', function() {
|
||||
var ironLocation = fixture('Solo');
|
||||
expect(pushStateCalls).to.be.equal(0);
|
||||
expect(replaceStateCalls).to.be.equal(0);
|
||||
ironLocation.path = '/foo';
|
||||
expect(replaceStateCalls).to.be.equal(1);
|
||||
expect(pushStateCalls).to.be.equal(0);
|
||||
});
|
||||
|
||||
suite('when intercepting links', function() {
|
||||
/**
|
||||
* Clicks the given link while an iron-location element with the given
|
||||
* urlSpaceRegex is in the same document. Returns whether the
|
||||
* iron-location prevented the default behavior of the click.
|
||||
*
|
||||
* No matter what, it prevents the default behavior of the click itself
|
||||
* to ensure that no navigation occurs (as that would interrupt
|
||||
* running and reporting these tests!)
|
||||
*/
|
||||
function isClickCaptured(anchor, urlSpaceRegex) {
|
||||
var defaultWasPrevented;
|
||||
function handler(event) {
|
||||
expect(event.target).to.be.eq(anchor);
|
||||
defaultWasPrevented = event.defaultPrevented;
|
||||
event.preventDefault();
|
||||
expect(event.defaultPrevented).to.be.eq(true);
|
||||
}
|
||||
window.addEventListener('click', handler);
|
||||
var ironLocation = fixture('Solo');
|
||||
if (urlSpaceRegex != null) {
|
||||
ironLocation.urlSpaceRegex = urlSpaceRegex;
|
||||
}
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
document.body.removeChild(anchor);
|
||||
window.removeEventListener('click', handler);
|
||||
return defaultWasPrevented;
|
||||
}
|
||||
|
||||
test('simple link to / is intercepted', function() {
|
||||
var anchor = document.createElement('a');
|
||||
if (document.baseURI !== window.location.href) {
|
||||
anchor.href = makeAbsoluteUrl('/');
|
||||
} else {
|
||||
anchor.href = '/';
|
||||
}
|
||||
|
||||
expect(isClickCaptured(anchor)).to.be.eq(true);
|
||||
expect(pushStateCalls).to.be.equal(1);
|
||||
});
|
||||
|
||||
test('link that matches url space is intercepted', function() {
|
||||
var anchor = document.createElement('a');
|
||||
anchor.href = makeAbsoluteUrl('/foo');
|
||||
|
||||
expect(isClickCaptured(anchor, '/fo+')).to.be.eq(true);
|
||||
expect(pushStateCalls).to.be.equal(1);
|
||||
});
|
||||
|
||||
test('link that doesn\'t match url space isn\'t intercepted', function() {
|
||||
var anchor = document.createElement('a');
|
||||
anchor.href = makeAbsoluteUrl('/bar');
|
||||
|
||||
expect(isClickCaptured(anchor, '/fo+')).to.be.eq(false);
|
||||
expect(pushStateCalls).to.be.equal(0);
|
||||
});
|
||||
|
||||
test('link to another domain isn\'t intercepted', function() {
|
||||
var anchor = document.createElement('a');
|
||||
anchor.href = 'http://example.com/';
|
||||
|
||||
expect(isClickCaptured(anchor)).to.be.eq(false);
|
||||
expect(pushStateCalls).to.be.equal(0);
|
||||
});
|
||||
|
||||
test('a link with target=_blank isn\'t intercepted', function() {
|
||||
var anchor = document.createElement('a');
|
||||
anchor.href = makeAbsoluteUrl('/');
|
||||
anchor.target = '_blank';
|
||||
|
||||
expect(isClickCaptured(anchor)).to.be.eq(false);
|
||||
expect(pushStateCalls).to.be.equal(0);
|
||||
});
|
||||
|
||||
test('a link with an href to the ' +
|
||||
'current page shouldn\'t add to history.', function() {
|
||||
var anchor = document.createElement('a');
|
||||
anchor.href = window.location.href;
|
||||
|
||||
// The click is captured, but it doesn't add to history.
|
||||
expect(isClickCaptured(anchor)).to.be.equal(true);
|
||||
expect(pushStateCalls).to.be.equal(0);
|
||||
});
|
||||
|
||||
test('a click that has already been defaultPrevented ' +
|
||||
'shouldn\'t result in a navigation', function() {
|
||||
fixture('Solo');
|
||||
var anchor = document.createElement('a');
|
||||
anchor.href = makeAbsoluteUrl('/');
|
||||
anchor.addEventListener('click', function(event) {
|
||||
event.preventDefault();
|
||||
});
|
||||
document.body.appendChild(anchor);
|
||||
|
||||
var originalPushState = window.history.pushState;
|
||||
var count = 0;
|
||||
window.history.pushState = function() {
|
||||
count++;
|
||||
}
|
||||
anchor.click();
|
||||
window.history.pushState = originalPushState;
|
||||
|
||||
expect(count).to.be.equal(0);
|
||||
})
|
||||
});
|
||||
});
|
||||
suite('when used with other iron-location elements', function() {
|
||||
var otherUrlElem;
|
||||
var urlElem;
|
||||
setup(function() {
|
||||
var elems = fixture('Together');
|
||||
urlElem = elems.querySelector('#one');
|
||||
otherUrlElem = elems.querySelector('#two');
|
||||
});
|
||||
function assertHaveSameUrls(urlElemOne, urlElemTwo) {
|
||||
expect(urlElemOne.path).to.be.equal(urlElemTwo.path);
|
||||
expect(urlElemOne.hash).to.be.equal(urlElemTwo.hash);
|
||||
expect(urlElemOne.query).to.be.equal(urlElemTwo.query);
|
||||
}
|
||||
test('coordinate their changes (by firing events on window)', function() {
|
||||
assertHaveSameUrls(urlElem, otherUrlElem);
|
||||
|
||||
urlElem.path = '/a/b/c';
|
||||
assertHaveSameUrls(urlElem, otherUrlElem);
|
||||
|
||||
otherUrlElem.query = 'alsdkjflaksjfd=alksjfdlkajsdfl';
|
||||
assertHaveSameUrls(urlElem, otherUrlElem);
|
||||
|
||||
urlElem.hash = 'lkjljifosjkldfjlksjfldsjf';
|
||||
assertHaveSameUrls(urlElem, otherUrlElem);
|
||||
});
|
||||
});
|
||||
|
||||
suite('supports doing synchronous redirection', function() {
|
||||
test('of the hash portion of the URL', function() {
|
||||
expect(window.location.hash).to.be.equal('');
|
||||
var redirector = fixture('RedirectHash');
|
||||
expect(window.location.hash).to.be.equal('#redirectedTo');
|
||||
expect(redirector.hash).to.be.equal('redirectedTo');
|
||||
redirector.hash = 'newHash';
|
||||
expect(window.location.hash).to.be.equal('#redirectedTo');
|
||||
expect(redirector.hash).to.be.equal('redirectedTo');
|
||||
});
|
||||
|
||||
test('of the path portion of the URL', function() {
|
||||
expect(window.location.pathname).to.not.be.equal('/redirectedTo');
|
||||
var redirector = fixture('RedirectPath');
|
||||
expect(window.location.pathname).to.be.equal('/redirectedTo');
|
||||
expect(redirector.path).to.be.equal('/redirectedTo');
|
||||
redirector.path = '/newPath';
|
||||
expect(window.location.pathname).to.be.equal('/redirectedTo');
|
||||
expect(redirector.path).to.be.equal('/redirectedTo');
|
||||
});
|
||||
|
||||
test('of the query portion of the URL', function() {
|
||||
expect(window.location.search).to.be.equal('');
|
||||
var redirector = fixture('RedirectQuery');
|
||||
expect(window.location.search).to.be.equal('?redirectedTo');
|
||||
expect(redirector.query).to.be.equal('redirectedTo');
|
||||
redirector.query = 'newQuery';
|
||||
expect(window.location.search).to.be.equal('?redirectedTo');
|
||||
expect(redirector.query).to.be.equal('redirectedTo');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
suite('<iron-location>', function () {
|
||||
var initialUrl;
|
||||
setup(function() {
|
||||
initialUrl = window.location.href;
|
||||
});
|
||||
teardown(function(){
|
||||
window.history.replaceState({}, '', initialUrl);
|
||||
});
|
||||
|
||||
ironLocationTests();
|
||||
|
||||
suite('with a base URI', function() {
|
||||
var baseElem;
|
||||
setup(function() {
|
||||
expect(document.baseURI).to.be.equal(window.location.href);
|
||||
baseElem = document.createElement('base');
|
||||
var href = 'https://example.com/i/dont/exist/obviously'
|
||||
baseElem.href = href;
|
||||
document.head.appendChild(baseElem);
|
||||
expect(document.baseURI).to.be.equal(href);
|
||||
});
|
||||
teardown(function() {
|
||||
document.head.removeChild(baseElem);
|
||||
});
|
||||
|
||||
ironLocationTests();
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
|
@ -1,96 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--
|
||||
@license
|
||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>iron-location</title>
|
||||
|
||||
<script src="../../webcomponentsjs/webcomponents.js"></script>
|
||||
<script src="../../web-component-tester/browser.js"></script>
|
||||
|
||||
<link rel="import" href="../../polymer/polymer.html">
|
||||
<link rel="import" href="../../promise-polyfill/promise-polyfill.html">
|
||||
<link rel="import" href="../iron-query-params.html">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<test-fixture id="BasicQueryParams">
|
||||
<template>
|
||||
<iron-query-params></iron-query-params>
|
||||
</template>
|
||||
</test-fixture>
|
||||
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
suite('<iron-query-params>', function () {
|
||||
|
||||
var paramsElem;
|
||||
setup(function() {
|
||||
paramsElem = fixture('BasicQueryParams');
|
||||
});
|
||||
|
||||
test('basic functionality with ?key=value params', function() {
|
||||
// Check initialization
|
||||
expect(paramsElem.paramsString).to.be.eq('');
|
||||
expect(paramsElem.paramsObject).to.deep.eq({});
|
||||
|
||||
// Check the mapping from paramsString to paramsObject.
|
||||
paramsElem.paramsString = 'greeting=hello&target=world';
|
||||
expect(paramsElem.paramsObject).to.deep.equal(
|
||||
{greeting: 'hello', target: 'world'});
|
||||
|
||||
// Check the mapping from paramsObject back to paramsString.
|
||||
paramsElem.set('paramsObject.another', 'key');
|
||||
expect(paramsElem.paramsString).to.be.equal(
|
||||
'greeting=hello&target=world&another=key');
|
||||
});
|
||||
test('encoding of params', function() {
|
||||
var mappings = [
|
||||
{
|
||||
string: 'a=b',
|
||||
object: {'a': 'b'}
|
||||
},
|
||||
{
|
||||
string: 'debug&ok',
|
||||
object: {'debug': '', 'ok': ''}
|
||||
},
|
||||
{
|
||||
string: 'monster%20kid%3A=%F0%9F%98%BF',
|
||||
object: {'monster kid:': '😿'}
|
||||
},
|
||||
{
|
||||
string: 'yes%2C%20ok%3F%20what%20is%20up%20with%20%CB%9Athiiis%CB%9A=%E2%98%83',
|
||||
object: {'yes, ok? what is up with ˚thiiis˚': '☃'}
|
||||
},
|
||||
];
|
||||
|
||||
mappings.forEach(function(mapping) {
|
||||
// Clear
|
||||
paramsElem.paramsObject = {};
|
||||
expect(paramsElem.paramsString).to.be.equal('');
|
||||
|
||||
// Test going from string to object
|
||||
paramsElem.paramsString = mapping.string;
|
||||
expect(paramsElem.paramsObject).to.deep.equal(mapping.object);
|
||||
|
||||
// Clear again.
|
||||
paramsElem.paramsObject = {};
|
||||
expect(paramsElem.paramsString).to.be.equal('');
|
||||
|
||||
// Test going from object to string
|
||||
paramsElem.paramsObject = mapping.object;
|
||||
expect(paramsElem.paramsString).to.be.equal(mapping.string);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
|
@ -1,68 +0,0 @@
|
|||
<!--
|
||||
@license
|
||||
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
|
||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
||||
Code distributed by Google as part of the polymer project is also
|
||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
||||
-->
|
||||
<dom-module id='redirect-hash'>
|
||||
<template>
|
||||
<iron-location hash='{{hash}}'></iron-location>
|
||||
</template>
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'redirect-hash',
|
||||
properties: {
|
||||
hash: {
|
||||
value: '',
|
||||
observer: 'hashChanged'
|
||||
}
|
||||
},
|
||||
hashChanged: function(hash) {
|
||||
this.hash = 'redirectedTo';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='redirect-path'>
|
||||
<template>
|
||||
<iron-location path='{{path}}'></iron-location>
|
||||
</template>
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'redirect-path',
|
||||
properties: {
|
||||
path: {
|
||||
value: '',
|
||||
observer: 'pathChanged'
|
||||
}
|
||||
},
|
||||
pathChanged: function(path) {
|
||||
this.path = '/redirectedTo';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id='redirect-query'>
|
||||
<template>
|
||||
<iron-location query='{{query}}'></iron-location>
|
||||
</template>
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'redirect-query',
|
||||
properties: {
|
||||
query: {
|
||||
value: '',
|
||||
observer: 'queryChanged'
|
||||
}
|
||||
},
|
||||
queryChanged: function(query) {
|
||||
this.query = 'redirectedTo';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</dom-module>
|
Loading…
Add table
Add a link
Reference in a new issue