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

Side by Side Diff: test/firebase_test_helpers.dart

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: update pubspec/changelog Created 5 years, 1 month 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 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 library iron_elements.test.firebase_test_helpers;
5
6 import 'dart:js';
7 import 'dart:math';
8 import 'common.dart';
9 import 'package:polymer_elements/firebase_collection.dart';
10
11 var _rand = new Random();
12
13 String firebaseTestProject = 'fb-element-demo';
14
15 randomKey() {
16 return (0 | (_rand.nextDouble() * 999999999)).toString();
17 }
18
19 randomInt([min = 0, max = 10000]) {
20 return _rand.nextInt(max - min) + min;
21 }
22
23 randomObject([min = 0, max = 10000]) {
24 return {'value': randomInt(min, max)};
25 }
26
27 firebaseUrl(project, [path]) {
28 return 'https://$project.firebaseio.com${path != null ? '/$path' : ''}';
29 }
30
31 fixtureLocation([data = const {}]) {
32 var firebase =
33 new JsObject(context['Firebase'], [firebaseUrl(firebaseTestProject)]);
34 return firebaseUrl(firebaseTestProject,
35 firebase.callMethod('push', [new JsObject.jsify(data)]).callMethod('key')) ;
36 }
37
38 removeLocation(location) {
39 new JsObject(context['Firebase'], [location]).callMethod('remove');
40 }
41
42 fixtureFirebase(fixtureName, [data = const {}]) {
43 FirebaseCollection firebase = fixture(fixtureName);
44 firebase.location = fixtureLocation(data);
45 return firebase;
46 }
47
48 removeFirebase(firebase) {
49 removeLocation(firebase.location);
50 firebase.disconnect();
51 }
52
53 arrayOfPrimitives(length) {
54 var array = [];
55
56 for (var i = 0; i < length; ++i) {
57 array.add(randomInt());
58 }
59
60 return array;
61 }
62
63 arrayOfObjects(length) {
64 var array = [];
65
66 for (var i = 0; i < length; ++i) {
67 array.add(randomObject());
68 }
69
70 return array;
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698