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