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

Side by Side Diff: js/tests/stateReflector.js

Issue 1204793003: Add tests for sk.object functions and sk.stateReflector. (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « js/tests/object.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 describe('sk.stateReflector',
2 function() {
3 var clock;
4
5 afterEach(function () { if (clock) { clock.restore(); } });
6
7 function testStateReflector() {
8 clock = sinon.useFakeTimers();
9 var page = {
10 state: {
11 height: 2.0,
12 name: "Fritz",
13 alive: true,
14 labels: "foo bar baz",
15 }
16 };
17
18 var initHistoryLength = window.history.length;
19 var spy = sinon.spy();
20 var nextResolveCallback;
21 var pending = new Promise(function(resolve, reject) {
22 nextResolveCallback = resolve;
23 var callback = function() {
24 spy();
25 nextResolveCallback();
26 };
27 sk.stateReflector(page, callback);
28 // Fake the polymer-ready event.
29 window.dispatchEvent(new Event('polymer-ready'));
30 }).then(function() {
31 assert.equal(spy.callCount, 1);
32 page.state.height = 1.5;
33 page.state.name = "Lucy";
34 clock.tick(200); // Causes timers to be called.
35 assert.equal(window.history.length - initHistoryLength, 1);
36 page.state.alive = false;
37 page.state.labels = "foo bar";
38 clock.tick(200); // Causes timers to be called.
39 assert.equal(window.history.length - initHistoryLength, 2);
40 assert.deepEqual(page.state,
41 { height: 1.5,
42 name: "Lucy",
43 alive: false,
44 labels: "foo bar" });
45 // Trigger popstate due to history.back() and wait for callback.
46 return new Promise(function (resolve, reject) {
47 nextResolveCallback = resolve;
48 window.history.back();
49 });
50 }).then(function() {
51 assert.equal(spy.callCount, 2);
52 assert.deepEqual(page.state,
53 { height: 1.5,
54 name: "Lucy",
55 alive: true,
56 labels: "foo bar baz" });
57 // Trigger popstate due to history.back() and wait for callback.
58 return new Promise(function (resolve, reject) {
59 nextResolveCallback = resolve;
60 window.history.back();
61 });
62 }).then(function() {
63 assert.equal(spy.callCount, 3);
64 assert.deepEqual(page.state,
65 { height: 2.0,
66 name: "Fritz",
67 alive: true,
68 labels: "foo bar baz" });
69 // Trigger popstate due to history.forward() and wait for callback.
70 return new Promise(function (resolve, reject) {
71 nextResolveCallback = resolve;
72 window.history.forward();
73 });
74 }).then(function() {
75 assert.equal(spy.callCount, 4);
76 assert.deepEqual(page.state,
77 { height: 1.5,
78 name: "Lucy",
79 alive: true,
80 labels: "foo bar baz" });
81 });
82 return pending;
83 }
84
85 it("should link browser history with a JS object's state",
86 testStateReflector);
87 }
88 );
OLDNEW
« no previous file with comments | « js/tests/object.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698