Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: polymer_1.0.4/bower_components/firebase-element/test/firebase-document.html

Issue 1205703007: Add polymer 1.0 to npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Renamed folder to 1.0.4 Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.g ithub.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/CONTRI BUTORS.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/PATEN TS.txt
10 -->
11 <html>
12 <head>
13 <title>firebase-document</title>
14
15 <script src="../../webcomponentsjs/webcomponents.js"></script>
16 <script src="../../web-component-tester/browser.js"></script>
17 <script src="../../test-fixture/test-fixture-mocha.js"></script>
18
19 <link rel="import" href="../../polymer/polymer.html">
20 <link rel="import" href="../../promise-polyfill/promise-polyfill.html">
21 <link rel="import" href="../../test-fixture/test-fixture.html">
22 <link rel="import" href="test-helpers.html">
23 <link rel="import" href="../firebase-document.html">
24 </head>
25 <body>
26 <test-fixture id="TrivialDocument">
27 <template>
28 <firebase-document
29 location="https://fb-element-demo.firebaseio.com/test/trivial"
30 log>
31 </firebase-document>
32 </template>
33 </test-fixture>
34 <test-fixture id="UpdateableDocument">
35 <template>
36 <firebase-document
37 location="https://fb-element-demo.firebaseio.com/test/updateable_documen t"
38 log>
39 </firebase-document>
40 </template>
41 </test-fixture>
42 <test-fixture id="MalleableDocument">
43 <template>
44 <firebase-document
45 id="local"
46 location="https://fb-element-demo.firebaseio.com/test/document"
47 log>
48 </firebase-document>
49 <firebase-document
50 id="remote"
51 location="https://fb-element-demo.firebaseio.com/test/document"
52 log>
53 </firebase-document>
54 </template>
55 </test-fixture>
56 <script>
57
58 suite('<firebase-document>', function() {
59 var firebase;
60
61 suite('basic usage', function() {
62 setup(function() {
63 firebase = fixture('TrivialDocument');
64 });
65
66 teardown(function() {
67 firebase.disconnect();
68 });
69
70 test('receives data from Firebase location', function(done) {
71 waitForEvent(firebase, 'data-changed').then(function() {
72 expect(firebase.data.passed).to.be.equal(true);
73 done();
74 }).catch(function() {
75 done(e);
76 });
77 });
78 });
79
80 suite('document updating', function() {
81 setup(function(done) {
82 firebase = fixture('UpdateableDocument');
83 waitForEvent(firebase, 'firebase-value').then(function() {
84 done();
85 });
86 });
87
88 test('setting data property updates the document', function(done) {
89 var data = {};
90 var newValue = Math.random().toString().split('.').pop();
91
92 data[newValue] = newValue;
93
94 waitForEvent(firebase, 'firebase-value').then(function() {
95 expect(firebase.data[newValue]).to.be.eql(newValue);
96 done();
97 }).catch(function(e) {
98 done(e);
99 }).then(function() {
100 firebase.set('data.' + newValue, null);
101 });
102
103 firebase.set('data', data);
104 });
105 });
106
107 suite('document manipulation', function() {
108 var localFirebase;
109 var remoteFirebase;
110 var key;
111
112 setup(function(done) {
113 firebase = fixture('MalleableDocument');
114 key = randomKey();
115
116 localFirebase = firebase[0];
117 remoteFirebase = firebase[1];
118
119 Promise.all([
120 localFirebase.data ? null : waitForEvent(localFirebase, 'data-change d'),
121 remoteFirebase.data ? null : waitForEvent(remoteFirebase, 'data-chan ged')
122 ]).then(function() {
123 done();
124 });
125 });
126
127 teardown(function(done) {
128 new Promise(function(resolve, reject) {
129 if (localFirebase.data[key] == null) {
130 resolve();
131 } else {
132 resolve(waitForEvent(localFirebase, 'firebase-value'));
133 localFirebase.set('data.' + key, null);
134 }
135 }).then(function() {
136 localFirebase.disconnect();
137 remoteFirebase.disconnect();
138 done();
139 }).catch(function(e) {
140 done(e);
141 });
142 });
143
144 test('all clients reflect same document', function() {
145 expect(localFirebase.data.permanentValue).to.be.okay;
146 expect(localFirebase.data).to.be.eql(remoteFirebase.data);
147 });
148
149 test('local data-bound child-add reflects remotely', function(done) {
150
151 waitForEvent(remoteFirebase, 'firebase-child-added').then(function() {
152 expect(remoteFirebase.data[key]).to.be.equal(
153 localFirebase.data[key]
154 );
155 }).then(function() {
156 done();
157 }).catch(function(e) {
158 done(e);
159 });
160
161 localFirebase.set('data.' + key, 'foo');
162 });
163
164 test('local data-bound child-remove reflects remotely', function(done) {
165
166 waitForEvent(remoteFirebase, 'firebase-child-added').then(function() {
167 var dataIsRemoved = waitForEvent(remoteFirebase, 'firebase-child-rem oved');
168 localFirebase.set('data.' + key, null);
169 return dataIsRemoved;
170 }).then(function() {
171 expect(localFirebase.data[key]).to.not.be.okay;
172 expect(remoteFirebase.data[key]).to.not.be.okay;
173 done();
174 }).catch(function(e) {
175 done(e);
176 });
177
178 localFirebase.set('data.' + key, 'foo');
179 });
180
181 test('child sub-tree modifications reflect remotely', function(done) {
182
183 waitForEvent(remoteFirebase, 'firebase-child-added').then(function() {
184 expect(localFirebase.data[key].foo).to.be.equal(1);
185 expect(remoteFirebase.data[key]).to.be.eql(localFirebase.data[key]);
186
187 var subtreeKeyIsAdded = waitForEvent(remoteFirebase, 'firebase-child -changed');
188 localFirebase.set('data.' + key + '.bar', 2);
189 return subtreeKeyIsAdded;
190 }).then(function() {
191 expect(localFirebase.data[key].bar).to.be.equal(2);
192 expect(remoteFirebase.data[key]).to.be.eql(localFirebase.data[key]);
193
194 expect(localFirebase.data[key].foo).to.be.okay;
195 expect(remoteFirebase.data[key].foo).to.be.okay;
196
197 var subtreeKeyIsRemoved = waitForEvent(remoteFirebase, 'firebase-chi ld-changed');
198 localFirebase.set('data.' + key + '.foo', null);
199 return subtreeKeyIsRemoved;
200 }).then(function() {
201 expect(localFirebase.data[key].foo).to.not.be.okay;
202 expect(remoteFirebase.data[key].foo).to.not.be.okay;
203
204 expect(localFirebase.data[key].bar).to.be.okay;
205 expect(remoteFirebase.data[key].bar).to.be.okay;
206
207 done();
208 }).catch(function(e) {
209 done(e);
210 });
211
212 localFirebase.set('data.' + key, {
213 foo: 1
214 });
215 });
216 });
217 });
218 </script>
219
220 </body>
221 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698