~didrocks/+junk/face-detection-15.04

« back to all changes in this revision

Viewing changes to facedetection/www/bower_components/iron-location/test/iron-location.html

  • Committer: Didier Roche
  • Date: 2016-05-10 23:09:11 UTC
  • Revision ID: didier.roche@canonical.com-20160510230911-c7xr490zrj3yrzxd
New version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!doctype html>
 
2
<!--
 
3
@license
 
4
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
 
5
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
 
6
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
 
7
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
 
8
Code distributed by Google as part of the polymer project is also
 
9
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
 
10
-->
 
11
<html>
 
12
<head>
 
13
  <title>iron-location</title>
 
14
 
 
15
  <script src="../../webcomponentsjs/webcomponents.js"></script>
 
16
  <script src="../../web-component-tester/browser.js"></script>
 
17
 
 
18
  <link rel="import" href="../../polymer/polymer.html">
 
19
  <link rel="import" href="../../promise-polyfill/promise-polyfill.html">
 
20
  <link rel="import" href="../iron-location.html">
 
21
</head>
 
22
<body>
 
23
<test-fixture id='Solo'>
 
24
  <template>
 
25
    <iron-location></iron-location>
 
26
  </template>
 
27
</test-fixture>
 
28
<test-fixture id='Together'>
 
29
  <template>
 
30
    <div>
 
31
      <iron-location id='one'></iron-location>
 
32
      <iron-location id='two'></iron-location>
 
33
    </div>
 
34
  </template>
 
35
</test-fixture>
 
36
 
 
37
 
 
38
<script>
 
39
  'use strict';
 
40
 
 
41
  function timePasses(ms) {
 
42
    return new Promise(function(resolve) {
 
43
      window.setTimeout(function() {
 
44
        resolve();
 
45
      }, ms);
 
46
    });
 
47
  }
 
48
 
 
49
  suite('<iron-location>', function () {
 
50
    var initialUrl;
 
51
    setup(function() {
 
52
      initialUrl = window.location.href;
 
53
    });
 
54
    teardown(function(){
 
55
      window.history.replaceState({}, '', initialUrl);
 
56
    });
 
57
 
 
58
    suite('when used solo', function() {
 
59
      var urlElem;
 
60
      setup(function() {
 
61
        urlElem = fixture('Solo');
 
62
      });
 
63
      test('basic functionality with #hash urls', function() {
 
64
        // Initialized to the window location's hash.
 
65
        expect(window.location.hash).to.be.equal(urlElem.hash);
 
66
 
 
67
        // Changing the urlElem's hash changes the URL
 
68
        urlElem.hash = '/lol/ok';
 
69
        expect(window.location.hash).to.be.equal('#/lol/ok');
 
70
 
 
71
        // Changing the hash via normal means changes the urlElem.
 
72
        var anchor = document.createElement('a');
 
73
        anchor.href = '#/wat';
 
74
        document.body.appendChild(anchor);
 
75
        anchor.click();
 
76
        // In IE10 it appears that the hashchange event is asynchronous.
 
77
        return timePasses(10).then(function() {
 
78
          expect(urlElem.hash).to.be.equal('/wat');
 
79
        });
 
80
      });
 
81
      test('basic functionality with paths', function() {
 
82
        // Initialized to the window location's path.
 
83
        expect(window.location.pathname).to.be.equal(urlElem.path);
 
84
 
 
85
        // Changing the urlElem's path changes the URL
 
86
        urlElem.path = '/foo/bar';
 
87
        expect(window.location.pathname).to.be.equal('/foo/bar');
 
88
 
 
89
        // Changing the path and sending a custom event on the window changes
 
90
        // the urlElem.
 
91
        window.history.replaceState({}, '', '/baz')
 
92
        window.dispatchEvent(new CustomEvent('location-changed'));
 
93
        expect(urlElem.path).to.be.equal('/baz');
 
94
      });
 
95
      test('basic functionality with ?key=value params', function() {
 
96
        // Initialized to the window location's params.
 
97
        expect(urlElem.query).to.be.eq('');
 
98
 
 
99
        // Changing location.search and sending a custom event on the window
 
100
        // changes the urlElem.
 
101
        window.history.replaceState({}, '', '/?greeting=hello&target=world');
 
102
        window.dispatchEvent(new CustomEvent('location-changed'));
 
103
        expect(urlElem.query).to.be.equal('greeting=hello&target=world');
 
104
 
 
105
        // Changing the urlElem's query changes the URL.
 
106
        urlElem.query = 'greeting=hello&target=world&another=key';
 
107
        expect(window.location.search).to.be.equal(
 
108
            '?greeting=hello&target=world&another=key');
 
109
      });
 
110
    });
 
111
    suite('when used with other iron-location elements', function() {
 
112
      var otherUrlElem;
 
113
      var urlElem;
 
114
      setup(function() {
 
115
        var elems = fixture('Together');
 
116
        urlElem = elems.querySelector('#one');
 
117
        otherUrlElem = elems.querySelector('#two');
 
118
      });
 
119
      function assertHaveSameUrls(urlElemOne, urlElemTwo) {
 
120
        expect(urlElemOne.path).to.be.equal(urlElemTwo.path);
 
121
        expect(urlElemOne.hash).to.be.equal(urlElemTwo.hash);
 
122
        expect(urlElemOne.query).to.be.equal(urlElemTwo.query);
 
123
      }
 
124
      test('coordinate their changes (by firing events on window)', function() {
 
125
        assertHaveSameUrls(urlElem, otherUrlElem);
 
126
 
 
127
        urlElem.path = '/a/b/c';
 
128
        assertHaveSameUrls(urlElem, otherUrlElem);
 
129
 
 
130
        otherUrlElem.query = 'alsdkjflaksjfd=alksjfdlkajsdfl';
 
131
        assertHaveSameUrls(urlElem, otherUrlElem);
 
132
 
 
133
        urlElem.hash = 'lkjljifosjkldfjlksjfldsjf';
 
134
        assertHaveSameUrls(urlElem, otherUrlElem);
 
135
      });
 
136
    });
 
137
  });
 
138
 
 
139
</script>
 
140
</body>