aboutsummaryrefslogtreecommitdiffstats
path: root/test/XSitePostTest.js
blob: 8a3e4d6fb6d7f866d749705ffba9b77c7d3e8dd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
XSitePost = TestCase("XSitePost");

var e = function(text){ return Base64.encode(text); };

XSitePost.prototype.testMessageReceived = function () {
  expectAsserts(4);
  var xPost = new nglr.XSitePost();
  xPost.baseUrl = "http://getangular.test";
  xPost.post = function(url, request, callback){
    assertEquals('http://getangular.test/url', url);
    assertEquals('abc', request.a);
    assertEquals('xyz', request.x);
  };
  xPost.incomingFragment('#id;0;1;'+e('/url')+':a:'+e('abc')+':x:'+e('xyz'));
  assertEquals('{}', nglr.toJson(xPost.inQueue));
};

XSitePost.prototype.testMessageReceivedInParts = function () {
  expectAsserts(5);
  var xPost = new nglr.XSitePost();
  xPost.baseUrl = "http://getangular.test";
  xPost.post = function(url, request, callback){
    assertEquals('http://getangular.test/url', url);
    assertEquals('abc', request.a);
    assertEquals('xyz', request.x);
  };
  xPost.incomingFragment('#id;1;2;:x:'+e('xyz'));
  assertNotSame('{}', nglr.toJson(xPost.inQueue));
  xPost.incomingFragment('#id;0;2;'+e('/url')+':a:'+e('abc'));
  assertEquals('{}', nglr.toJson(xPost.inQueue));
};

XSitePost.prototype.testPostResponsIsEnqueued = function () {
  var xPost = new nglr.XSitePost();
  xPost.maxMsgSize = 11;
  xPost.response("id", "response", "status");

  assertEquals('["id:0:2:cmVzcG9uc2U","id:1:2:="]',
      nglr.toJson(xPost.outQueue));
};

XSitePost.prototype.testPush = function () {
  var window = {};
  var xPost = new nglr.XSitePost(window);
  xPost.response("id", "response", "status");
  assertEquals('id:0:1:cmVzcG9uc2U=', xPost.outQueue[0]);
};