scratch – Blame information for rev 125
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
58 | office | 1 | "use strict"; |
2 | describe("Fingerprint2", function () { |
||
3 | describe("new", function () { |
||
4 | it("creates a new instance of FP2", function () { |
||
5 | expect(new Fingerprint2()).not.toBeNull(); |
||
6 | }); |
||
7 | |||
8 | it("accepts an empty options object", function () { |
||
9 | expect(new Fingerprint2({})).not.toBeNull(); |
||
10 | }); |
||
11 | |||
12 | it("uses default options", function () { |
||
13 | var fp2 = new Fingerprint2(); |
||
14 | expect(fp2.options.swfContainerId).toEqual("fingerprintjs2"); |
||
15 | expect(fp2.options.swfPath).toEqual("flash/compiled/FontList.swf"); |
||
16 | expect(fp2.options.userDefinedFonts).toEqual([]); |
||
17 | }); |
||
18 | |||
19 | it("allows to override default options", function () { |
||
20 | var fp2 = new Fingerprint2({swfPath: "newpath", userDefinedFonts: ["Ethos", "Quenda"]}); |
||
21 | expect(fp2.options.swfContainerId).toEqual("fingerprintjs2"); |
||
22 | expect(fp2.options.swfPath).toEqual("newpath"); |
||
23 | expect(fp2.options.userDefinedFonts).toEqual(["Ethos", "Quenda"]); |
||
24 | }); |
||
25 | |||
26 | it("allows to add new options", function () { |
||
27 | var fp2 = new Fingerprint2({excludeUserAgent: true}); |
||
28 | expect(fp2.options.swfContainerId).toEqual("fingerprintjs2"); |
||
29 | expect(fp2.options.swfPath).toEqual("flash/compiled/FontList.swf"); |
||
30 | expect(fp2.options.excludeUserAgent).toBe(true); |
||
31 | }); |
||
32 | |||
33 | describe("sortPluginsFor", function () { |
||
125 | office | 34 | it("has default value", function () { |
58 | office | 35 | var fp2 = new Fingerprint2(); |
36 | expect(fp2.options.sortPluginsFor).toEqual([/palemoon/i]); |
||
37 | }); |
||
38 | |||
39 | it("allows to set new array of regexes", function () { |
||
40 | var fp2 = new Fingerprint2({sortPluginsFor: [/firefox/i, /chrome/i]}); |
||
41 | expect(fp2.options.sortPluginsFor).toEqual([/firefox/i, /chrome/i]); |
||
42 | }); |
||
43 | }); |
||
44 | }); |
||
45 | |||
46 | describe("without new keyword", function () { |
||
47 | it("creates a new instance of FP2", function () { |
||
48 | expect(Fingerprint2()).not.toBeNull(); |
||
49 | }); |
||
50 | }) |
||
51 | |||
52 | describe("get", function () { |
||
53 | describe("default options", function () { |
||
54 | it("calculates fingerprint", function (done) { |
||
55 | var fp2 = new Fingerprint2(); |
||
125 | office | 56 | fp2.get(function (result) { |
58 | office | 57 | expect(result).toMatch(/^[0-9a-f]{32}$/i); |
58 | done(); |
||
59 | }); |
||
60 | }); |
||
61 | |||
62 | it("does not try calling flash font detection", function (done) { |
||
63 | var fp2 = new Fingerprint2(); |
||
64 | spyOn(fp2, "flashFontsKey"); |
||
125 | office | 65 | fp2.get(function (result) { |
58 | office | 66 | expect(fp2.flashFontsKey).not.toHaveBeenCalled(); |
67 | done(); |
||
68 | }); |
||
69 | }); |
||
70 | }); |
||
71 | |||
72 | describe("non-default options", function () { |
||
73 | it("does not use userAgent when excluded", function (done) { |
||
74 | var fp2 = new Fingerprint2({excludeUserAgent: true}); |
||
75 | spyOn(fp2, "getUserAgent"); |
||
125 | office | 76 | fp2.get(function (result) { |
58 | office | 77 | expect(fp2.getUserAgent).not.toHaveBeenCalled(); |
78 | done(); |
||
79 | }); |
||
80 | }); |
||
81 | |||
82 | it("does not use pixelRatio when excluded", function (done) { |
||
83 | var fp2 = new Fingerprint2({excludePixelRatio: true}); |
||
84 | spyOn(fp2, "getPixelRatio"); |
||
125 | office | 85 | fp2.get(function (result) { |
58 | office | 86 | expect(fp2.getPixelRatio).not.toHaveBeenCalled(); |
87 | done(); |
||
88 | }); |
||
89 | }); |
||
90 | |||
91 | it("does not use screen resolution when excluded", function (done) { |
||
92 | var fp2 = new Fingerprint2({excludeScreenResolution: true}); |
||
93 | spyOn(fp2, "getScreenResolution"); |
||
125 | office | 94 | fp2.get(function (result) { |
58 | office | 95 | expect(fp2.getScreenResolution).not.toHaveBeenCalled(); |
96 | done(); |
||
97 | }); |
||
98 | }); |
||
99 | |||
100 | it("does not use available screen resolution when excluded", function (done) { |
||
101 | var fp2 = new Fingerprint2({excludeAvailableScreenResolution: true}); |
||
102 | spyOn(fp2, "getAvailableScreenResolution"); |
||
125 | office | 103 | fp2.get(function (result) { |
58 | office | 104 | expect(fp2.getAvailableScreenResolution).not.toHaveBeenCalled(); |
105 | done(); |
||
106 | }); |
||
107 | }); |
||
108 | |||
109 | it("does not use plugins info when excluded", function (done) { |
||
110 | var fp2 = new Fingerprint2({excludePlugins: true}); |
||
111 | spyOn(fp2, "getRegularPlugins"); |
||
125 | office | 112 | fp2.get(function (result) { |
58 | office | 113 | expect(fp2.getRegularPlugins).not.toHaveBeenCalled(); |
114 | done(); |
||
115 | }); |
||
116 | }); |
||
117 | |||
118 | it("does not use IE plugins info when excluded", function (done) { |
||
119 | var fp2 = new Fingerprint2({excludeIEPlugins: true}); |
||
120 | spyOn(fp2, "getIEPlugins"); |
||
125 | office | 121 | fp2.get(function (result) { |
58 | office | 122 | expect(fp2.getIEPlugins).not.toHaveBeenCalled(); |
123 | done(); |
||
124 | }); |
||
125 | }); |
||
126 | |||
127 | }); |
||
128 | |||
129 | describe("returns components", function () { |
||
130 | it("does it return components as a second argument to callback", function (done) { |
||
131 | var fp2 = new Fingerprint2(); |
||
125 | office | 132 | fp2.get(function (result, components) { |
58 | office | 133 | expect(components).not.toBeNull(); |
134 | done(); |
||
135 | }); |
||
136 | }); |
||
137 | |||
138 | it("checks if returned components is array", function (done) { |
||
139 | var fp2 = new Fingerprint2(); |
||
125 | office | 140 | fp2.get(function (result, components) { |
58 | office | 141 | expect(components).toBeArrayOfObjects(); |
142 | done(); |
||
143 | }); |
||
144 | }); |
||
145 | |||
146 | it("checks if js_fonts component is array", function (done) { |
||
147 | var fp2 = new Fingerprint2(); |
||
125 | office | 148 | fp2.get(function (result, components) { |
149 | for (var x = 0; x < components.length; x++) { |
||
150 | if (components[x].key == "js_fonts") { |
||
151 | expect(components[x].value).toBeArray(); |
||
58 | office | 152 | } |
153 | } |
||
154 | done(); |
||
155 | }); |
||
156 | }); |
||
157 | |||
158 | it("returns user_agent as the first element", function (done) { |
||
159 | var fp2 = new Fingerprint2(); |
||
125 | office | 160 | fp2.get(function (result, components) { |
58 | office | 161 | expect(components[0].key).toEqual("user_agent"); |
162 | done(); |
||
163 | }); |
||
164 | }); |
||
165 | }); |
||
166 | |||
167 | describe("baseFontArray iteration", function () { |
||
168 | it("only iterates specified items", function (done) { |
||
169 | var baseFonts = ["monospace", "sans-serif", "serif"]; |
||
170 | var ctr = 0; |
||
171 | for (var x in baseFonts) { |
||
172 | ctr++; |
||
173 | } |
||
174 | |||
175 | expect(baseFonts.length).toEqual(3); |
||
176 | expect(ctr).toEqual(baseFonts.length); |
||
177 | |||
178 | // Somewhere deep in your JavaScript library... |
||
179 | Array.prototype.foo = 1; |
||
180 | Array.prototype.bar = 2; |
||
181 | ctr = 0; |
||
182 | for (var x in baseFonts) { |
||
183 | console.log(x); |
||
184 | ctr++; |
||
185 | // Now foo & bar is a part of EVERY array and |
||
186 | // will show up here as a value of 'x'. |
||
187 | } |
||
188 | |||
189 | expect(baseFonts.length).toEqual(3); |
||
190 | // sadface |
||
191 | expect(ctr).not.toEqual(baseFonts.length); |
||
192 | expect(ctr).toEqual(5); |
||
193 | done(); |
||
194 | }); |
||
195 | }); |
||
196 | |||
197 | describe("userDefinedFonts option", function () { |
||
198 | it("concatinates existing fonts with user-defined", function (done) { |
||
199 | var fontList = [ |
||
125 | office | 200 | "Andale Mono", "Arial", "Arial Black", "Arial Hebrew", "Arial MT", "Arial Narrow", "Arial Rounded MT Bold", |
201 | "Arial Unicode MS", |
||
202 | "Bitstream Vera Sans Mono", "Book Antiqua", "Bookman Old Style", |
||
203 | "Calibri", "Cambria", "Cambria Math", "Century", "Century Gothic", "Century Schoolbook", "Comic Sans", |
||
204 | "Comic Sans MS", "Consolas", "Courier", "Courier New", |
||
205 | "Garamond", "Geneva", "Georgia", |
||
206 | "Helvetica", "Helvetica Neue", |
||
207 | "Impact", |
||
208 | "Lucida Bright", "Lucida Calligraphy", "Lucida Console", "Lucida Fax", "LUCIDA GRANDE", "Lucida Handwriting", |
||
209 | "Lucida Sans", "Lucida Sans Typewriter", "Lucida Sans Unicode", |
||
210 | "Microsoft Sans Serif", "Monaco", "Monotype Corsiva", "MS Gothic", "MS Outlook", "MS PGothic", |
||
211 | "MS Reference Sans Serif", "MS Sans Serif", "MS Serif", "MYRIAD", "MYRIAD PRO", |
||
212 | "Palatino", "Palatino Linotype", |
||
213 | "Segoe Print", "Segoe Script", "Segoe UI", "Segoe UI Light", "Segoe UI Semibold", "Segoe UI Symbol", |
||
214 | "Tahoma", "Times", "Times New Roman", "Times New Roman PS", "Trebuchet MS", |
||
215 | "Verdana", "Wingdings", "Wingdings 2", "Wingdings 3" |
||
216 | ]; |
||
58 | office | 217 | |
218 | expect(fontList.length).toEqual(65); |
||
219 | var userDefinedFonts = []; |
||
220 | fontList.concat(userDefinedFonts); |
||
221 | expect(fontList.length).toEqual(65); |
||
222 | |||
223 | userDefinedFonts = ["Adria Grotesk", "Butler", "Nimbus Mono"]; |
||
224 | expect(userDefinedFonts.length).toEqual(3); |
||
225 | fontList = fontList.concat(userDefinedFonts); |
||
226 | expect(fontList.length).toEqual(65 + 3); |
||
227 | done(); |
||
228 | }); |
||
229 | }); |
||
125 | office | 230 | describe("customFunction option", function () { |
231 | |||
232 | it("concatinates the current keys with the customFunction output", function (done) { |
||
233 | function customFunction () { |
||
234 | return "RANDOM_STRING"; |
||
235 | } |
||
236 | var spy = jasmine.createSpy('customFunction', customFunction).and.callThrough(); |
||
237 | var fp = new Fingerprint2({ |
||
238 | "customFunction": spy |
||
239 | }); |
||
240 | fp.get(function (result, keys) { |
||
241 | expect(spy).toHaveBeenCalled(); |
||
242 | done() |
||
243 | }); |
||
244 | }); |
||
245 | }); |
||
58 | office | 246 | }); |
247 | }); |