scratch – Blame information for rev 63
?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 () { |
||
34 | it("has default value", function (){ |
||
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(); |
||
56 | fp2.get(function(result){ |
||
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"); |
||
65 | fp2.get(function(result) { |
||
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"); |
||
76 | fp2.get(function(result) { |
||
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"); |
||
85 | fp2.get(function(result) { |
||
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"); |
||
94 | fp2.get(function(result) { |
||
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"); |
||
103 | fp2.get(function(result) { |
||
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"); |
||
112 | fp2.get(function(result) { |
||
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"); |
||
121 | fp2.get(function(result) { |
||
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(); |
||
132 | fp2.get(function(result, components) { |
||
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(); |
||
140 | fp2.get(function(result, components) { |
||
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(); |
||
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(); |
||
152 | } |
||
153 | } |
||
154 | done(); |
||
155 | }); |
||
156 | }); |
||
157 | |||
158 | it("returns user_agent as the first element", function (done) { |
||
159 | var fp2 = new Fingerprint2(); |
||
160 | fp2.get(function(result, components) { |
||
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 = [ |
||
200 | "Andale Mono", "Arial", "Arial Black", "Arial Hebrew", "Arial MT", "Arial Narrow", "Arial Rounded MT Bold", "Arial Unicode MS", |
||
201 | "Bitstream Vera Sans Mono", "Book Antiqua", "Bookman Old Style", |
||
202 | "Calibri", "Cambria", "Cambria Math", "Century", "Century Gothic", "Century Schoolbook", "Comic Sans", "Comic Sans MS", "Consolas", "Courier", "Courier New", |
||
203 | "Garamond", "Geneva", "Georgia", |
||
204 | "Helvetica", "Helvetica Neue", |
||
205 | "Impact", |
||
206 | "Lucida Bright", "Lucida Calligraphy", "Lucida Console", "Lucida Fax", "LUCIDA GRANDE", "Lucida Handwriting", "Lucida Sans", "Lucida Sans Typewriter", "Lucida Sans Unicode", |
||
207 | "Microsoft Sans Serif", "Monaco", "Monotype Corsiva", "MS Gothic", "MS Outlook", "MS PGothic", "MS Reference Sans Serif", "MS Sans Serif", "MS Serif", "MYRIAD", "MYRIAD PRO", |
||
208 | "Palatino", "Palatino Linotype", |
||
209 | "Segoe Print", "Segoe Script", "Segoe UI", "Segoe UI Light", "Segoe UI Semibold", "Segoe UI Symbol", |
||
210 | "Tahoma", "Times", "Times New Roman", "Times New Roman PS", "Trebuchet MS", |
||
211 | "Verdana", "Wingdings", "Wingdings 2", "Wingdings 3" |
||
212 | ]; |
||
213 | |||
214 | expect(fontList.length).toEqual(65); |
||
215 | var userDefinedFonts = []; |
||
216 | fontList.concat(userDefinedFonts); |
||
217 | expect(fontList.length).toEqual(65); |
||
218 | |||
219 | |||
220 | userDefinedFonts = ["Adria Grotesk", "Butler", "Nimbus Mono"]; |
||
221 | expect(userDefinedFonts.length).toEqual(3); |
||
222 | fontList = fontList.concat(userDefinedFonts); |
||
223 | expect(fontList.length).toEqual(65 + 3); |
||
224 | done(); |
||
225 | }); |
||
226 | }); |
||
227 | }); |
||
228 | }); |