Debian Codegraph @

closure-library/closure/goog/ui/ac/remotearraymatcher_test.js

raw
1 // Copyright 2009 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.ui.ac.RemoteArrayMatcherTest');
16 goog.setTestOnly('goog.ui.ac.RemoteArrayMatcherTest');
17
18 goog.require('goog.net.XhrIo');
19 goog.require('goog.testing.MockControl');
20 goog.require('goog.testing.jsunit');
21 goog.require('goog.testing.net.XhrIo');
22 goog.require('goog.ui.ac.RemoteArrayMatcher');
23 var url = 'http://www.google.com';
24 var token = 'goog';
25 var maxMatches = 5;
26 var fullToken = 'google';
27
28 var responseJsonText = '["eric", "larry", "sergey", "marissa", "pupius"]';
29 var responseJson = JSON.parse(responseJsonText);
30
31 var mockControl;
32 var mockMatchHandler;
33
34
35 function setUp() {
36 goog.net.XhrIo = goog.testing.net.XhrIo;
37 mockControl = new goog.testing.MockControl();
38 mockMatchHandler = mockControl.createFunctionMock();
39 }
40
41 function testRequestMatchingRows_noSimilarTrue() {
42 var matcher = new goog.ui.ac.RemoteArrayMatcher(url);
43 mockMatchHandler(token, responseJson);
44 mockControl.$replayAll();
45 matcher.requestMatchingRows(token, maxMatches, mockMatchHandler, fullToken);
46 matcher.xhr_.simulateResponse(200, responseJsonText);
47 mockControl.$verifyAll();
48 mockControl.$resetAll();
49 }
50
51 function testRequestMatchingRows_twoCalls() {
52 var matcher = new goog.ui.ac.RemoteArrayMatcher(url);
53
54 var dummyMatchHandler = mockControl.createFunctionMock();
55
56 mockMatchHandler(token, responseJson);
57 mockControl.$replayAll();
58
59 matcher.requestMatchingRows(token, maxMatches, dummyMatchHandler, fullToken);
60
61 matcher.requestMatchingRows(token, maxMatches, mockMatchHandler, fullToken);
62 matcher.xhr_.simulateResponse(200, responseJsonText);
63 mockControl.$verifyAll();
64 mockControl.$resetAll();
65 }