bv-ui-core 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +40 -0
- package/.travis.yml +5 -0
- package/CONTRIBUTING.md +98 -0
- package/LICENSE.md +13 -0
- package/OWNERS +2 -0
- package/README.md +63 -0
- package/catalog-info.yaml +30 -0
- package/karma.conf.js +130 -0
- package/lib/README.md +61 -0
- package/lib/api/.babelrc +3 -0
- package/lib/api/.eslintrc +9 -0
- package/lib/api/README.md +134 -0
- package/lib/api/index.js +15 -0
- package/lib/api/statistics.js +148 -0
- package/lib/application/README.md +96 -0
- package/lib/application/index.js +171 -0
- package/lib/body/README.md +13 -0
- package/lib/body/index.js +19 -0
- package/lib/bvFetch/README.md +101 -0
- package/lib/bvFetch/index.js +383 -0
- package/lib/checkHighContrast/README.md +26 -0
- package/lib/checkHighContrast/index.js +36 -0
- package/lib/cookie/README.md +29 -0
- package/lib/cookie/index.js +111 -0
- package/lib/cookieConsent/README.md +41 -0
- package/lib/cookieConsent/index.js +227 -0
- package/lib/cssLoadChecker/README.md +19 -0
- package/lib/cssLoadChecker/index.js +72 -0
- package/lib/date.now/README.md +11 -0
- package/lib/date.now/index.js +40 -0
- package/lib/domainPolice/README.md +66 -0
- package/lib/domainPolice/index.js +95 -0
- package/lib/evented/README.md +42 -0
- package/lib/evented/index.js +135 -0
- package/lib/getOriginalConstructor/README.md +16 -0
- package/lib/getOriginalConstructor/index.js +52 -0
- package/lib/global/README.md +10 -0
- package/lib/global/index.js +48 -0
- package/lib/ie/README.md +13 -0
- package/lib/ie/index.js +25 -0
- package/lib/loader/README.md +73 -0
- package/lib/loader/index.js +358 -0
- package/lib/logger/README.md +82 -0
- package/lib/logger/index.js +180 -0
- package/lib/messageFormat/README.md +10 -0
- package/lib/messageFormat/index.js +42 -0
- package/lib/namespacer/README.md +57 -0
- package/lib/namespacer/index.js +98 -0
- package/lib/performance/README.md +35 -0
- package/lib/performance/entries.js +5 -0
- package/lib/performance/getEntries.js +42 -0
- package/lib/performance/getEntriesByName.js +61 -0
- package/lib/performance/getEntriesByType.js +55 -0
- package/lib/performance/index.js +11 -0
- package/lib/performance/mark.js +97 -0
- package/lib/performance/measure.js +106 -0
- package/lib/performance/now.js +63 -0
- package/lib/pixelsDisplayed/README.md +19 -0
- package/lib/pixelsDisplayed/index.js +113 -0
- package/lib/polyfills/README.md +39 -0
- package/lib/polyfills/fetch/Headers.js +3 -0
- package/lib/polyfills/fetch/Request.js +3 -0
- package/lib/polyfills/fetch/Response.js +3 -0
- package/lib/polyfills/fetch/fetch.js +3 -0
- package/lib/polyfills/fetch/index.js +57 -0
- package/lib/polyfills/promise.js +265 -0
- package/lib/queryShadowDom/README.md +50 -0
- package/lib/queryShadowDom/index.js +93 -0
- package/lib/region/README.md +64 -0
- package/lib/region/europe/index.js +94 -0
- package/lib/region/europe/territories.js +40 -0
- package/lib/region/index.js +123 -0
- package/lib/staticAssetLoader/README.md +116 -0
- package/lib/staticAssetLoader/index.js +248 -0
- package/lib/waitForBody/README.md +21 -0
- package/lib/waitForBody/index.js +36 -0
- package/mkdocs.yaml +5 -0
- package/package.json +55 -0
- package/test/.eslintrc +5 -0
- package/test/fixtures/lib.loader.document-is-wrong-in-ie8.js +5 -0
- package/test/fixtures/lib.loader.loadscript-attribute.js +3 -0
- package/test/fixtures/lib.loader.loadscript.js +3 -0
- package/test/fixtures/lib.loader.loadstylesheet.css +3 -0
- package/test/unit/api/.eslintrc +6 -0
- package/test/unit/api/index.spec.js +37 -0
- package/test/unit/api/response.json +67 -0
- package/test/unit/api/statistics.spec.js +218 -0
- package/test/unit/application/index.spec.js +313 -0
- package/test/unit/body/index.spec.js +15 -0
- package/test/unit/bvFetch/index.spec.js +246 -0
- package/test/unit/checkHighContrast/index.spec.js +16 -0
- package/test/unit/cookie/index.spec.js +191 -0
- package/test/unit/cookieConsent/index.spec.js +119 -0
- package/test/unit/cssLoadChecker/index.spec.js +75 -0
- package/test/unit/date.now/index.spec.js +21 -0
- package/test/unit/domainPolice/index.spec.js +141 -0
- package/test/unit/evented/index.spec.js +59 -0
- package/test/unit/getOriginalConstructor/index.spec.js +60 -0
- package/test/unit/global/index.spec.js +84 -0
- package/test/unit/ie/index.spec.js +14 -0
- package/test/unit/loader/index.spec.js +644 -0
- package/test/unit/logger/index.spec.js +141 -0
- package/test/unit/messageFormat/index.spec.js +31 -0
- package/test/unit/mochaInit.js +8 -0
- package/test/unit/namespacer/index.spec.js +100 -0
- package/test/unit/performance/getEntries.spec.js +30 -0
- package/test/unit/performance/getEntriesByName.spec.js +88 -0
- package/test/unit/performance/getEntriesByType.spec.js +48 -0
- package/test/unit/performance/index.spec.js +35 -0
- package/test/unit/performance/mark.spec.js +40 -0
- package/test/unit/performance/measure.spec.js +50 -0
- package/test/unit/performance/now.spec.js +21 -0
- package/test/unit/pixelsDisplayed/index.spec.js +271 -0
- package/test/unit/polyfills/fetch/Headers.js +12 -0
- package/test/unit/polyfills/fetch/Request.js +12 -0
- package/test/unit/polyfills/fetch/Response.js +12 -0
- package/test/unit/polyfills/fetch/fetch.js +12 -0
- package/test/unit/polyfills/fetch/index.js +61 -0
- package/test/unit/polyfills/promise.spec.js +48 -0
- package/test/unit/region/europe/index.spec.js +70 -0
- package/test/unit/region/index.spec.js +113 -0
- package/test/unit/staticAssetLoader/index.spec.js +215 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the cookie module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Imports.
|
|
7
|
+
var cookie = require('../../../lib/cookie');
|
|
8
|
+
var global = require('../../../lib/global');
|
|
9
|
+
var cookieConsent = require('../../../lib/cookieConsent');
|
|
10
|
+
|
|
11
|
+
function deleteCookie (name) {
|
|
12
|
+
global.document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('lib/cookie', function () {
|
|
16
|
+
|
|
17
|
+
it('cookie.create', function () {
|
|
18
|
+
cookieConsent.initConsent({
|
|
19
|
+
'test create': true
|
|
20
|
+
});
|
|
21
|
+
cookie.create('test create', 'cookie monster', 3);
|
|
22
|
+
expect(global.document.cookie).to.have.string('test%20create=cookie%20monster');
|
|
23
|
+
|
|
24
|
+
// Clean up.
|
|
25
|
+
deleteCookie('test%20create');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('cookie.read', function () {
|
|
29
|
+
global.document.cookie = 'test%20read=Hello%20World';
|
|
30
|
+
expect(cookie.read('test read')).to.equal('Hello World');
|
|
31
|
+
|
|
32
|
+
// Clean up.
|
|
33
|
+
deleteCookie('test%20read');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('cookie.remove', function () {
|
|
37
|
+
global.document.cookie = 'test%20delete=1';
|
|
38
|
+
cookie.remove('test delete');
|
|
39
|
+
expect(global.document.cookie).to.not.have.string('test%20delete');
|
|
40
|
+
|
|
41
|
+
// Clean up.
|
|
42
|
+
deleteCookie('test%20delete');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('lib/cookie secure flag behavior', function () {
|
|
48
|
+
var originalProtocol;
|
|
49
|
+
|
|
50
|
+
beforeEach(function () {
|
|
51
|
+
// Store original protocol to restore after each test
|
|
52
|
+
originalProtocol = global.location && global.location.protocol;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterEach(function () {
|
|
56
|
+
// Restore original protocol
|
|
57
|
+
if (global.location) {
|
|
58
|
+
// Some browsers don't allow direct assignment to location.protocol
|
|
59
|
+
// so we use Object.defineProperty where possible
|
|
60
|
+
try {
|
|
61
|
+
Object.defineProperty(global.location, 'protocol', {
|
|
62
|
+
value: originalProtocol,
|
|
63
|
+
writable: true,
|
|
64
|
+
configurable: true
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
// If we can't restore, tests may need to run in isolation
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Clean up test cookies
|
|
72
|
+
deleteCookie('test%20secure');
|
|
73
|
+
deleteCookie('test%20https');
|
|
74
|
+
deleteCookie('test%20http');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should set secure flag when secure=true is explicitly passed', function () {
|
|
78
|
+
cookieConsent.initConsent({
|
|
79
|
+
'test secure': true
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Create cookie with explicit secure=true
|
|
83
|
+
cookie.create('test secure', 'securevalue', 1, null, true);
|
|
84
|
+
|
|
85
|
+
// Note: We can't directly check if secure flag was set via document.cookie
|
|
86
|
+
// because secure cookies are not visible in document.cookie on http pages.
|
|
87
|
+
// This test verifies the function doesn't throw when secure=true is passed.
|
|
88
|
+
expect(true).to.equal(true);
|
|
89
|
+
|
|
90
|
+
// Clean up
|
|
91
|
+
deleteCookie('test%20secure');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should automatically set secure flag on HTTPS pages', function () {
|
|
95
|
+
// Skip if we can't modify location.protocol
|
|
96
|
+
if (!global.location) {
|
|
97
|
+
this.skip();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
Object.defineProperty(global.location, 'protocol', {
|
|
103
|
+
value: 'https:',
|
|
104
|
+
writable: true,
|
|
105
|
+
configurable: true
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
// Browser doesn't allow protocol modification, skip test
|
|
110
|
+
this.skip();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
cookieConsent.initConsent({
|
|
115
|
+
'test https': true
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Create cookie without explicit secure flag - should auto-secure on HTTPS
|
|
119
|
+
cookie.create('test https', 'httpsvalue', 1);
|
|
120
|
+
|
|
121
|
+
// The cookie creation should succeed without errors
|
|
122
|
+
// On actual HTTPS, the secure flag would be set automatically
|
|
123
|
+
expect(true).to.equal(true);
|
|
124
|
+
|
|
125
|
+
// Clean up
|
|
126
|
+
deleteCookie('test%20https');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should NOT set secure flag on HTTP pages when secure param is not passed', function () {
|
|
130
|
+
// Skip if we can't modify location.protocol
|
|
131
|
+
if (!global.location) {
|
|
132
|
+
this.skip();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
Object.defineProperty(global.location, 'protocol', {
|
|
138
|
+
value: 'http:',
|
|
139
|
+
writable: true,
|
|
140
|
+
configurable: true
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
// Browser doesn't allow protocol modification, skip test
|
|
145
|
+
this.skip();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
cookieConsent.initConsent({
|
|
150
|
+
'test http': true
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Create cookie without secure flag on HTTP
|
|
154
|
+
cookie.create('test http', 'httpvalue', 1);
|
|
155
|
+
|
|
156
|
+
// Cookie should be readable (not secure, so visible on HTTP)
|
|
157
|
+
expect(global.document.cookie).to.have.string('test%20http=httpvalue');
|
|
158
|
+
|
|
159
|
+
// Clean up
|
|
160
|
+
deleteCookie('test%20http');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('should handle missing global.location gracefully', function () {
|
|
164
|
+
var originalLocation = global.location;
|
|
165
|
+
|
|
166
|
+
// Temporarily remove location
|
|
167
|
+
try {
|
|
168
|
+
delete global.location;
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
// Can't delete location in some environments, skip
|
|
172
|
+
this.skip();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
cookieConsent.initConsent({
|
|
177
|
+
'test nolocation': true
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Should not throw when global.location is undefined
|
|
181
|
+
expect(function () {
|
|
182
|
+
cookie.create('test nolocation', 'value', 1);
|
|
183
|
+
}).to.not.throw();
|
|
184
|
+
|
|
185
|
+
// Restore location
|
|
186
|
+
global.location = originalLocation;
|
|
187
|
+
|
|
188
|
+
// Clean up
|
|
189
|
+
deleteCookie('test%20nolocation');
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the cookieConsent module.
|
|
4
|
+
*/
|
|
5
|
+
var cookieConsent = require('../../../lib/cookieConsent');
|
|
6
|
+
|
|
7
|
+
describe('lib/cookieConsent', function () {
|
|
8
|
+
it('cookieConsent.initConsent', function () {
|
|
9
|
+
function test1 () {
|
|
10
|
+
cookieConsent.initConsent(true);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
expect(test1).to.throw(TypeError, 'cookieConsent (init): consent should be an object.');
|
|
14
|
+
|
|
15
|
+
function test2 () {
|
|
16
|
+
cookieConsent.initConsent({
|
|
17
|
+
key1: 1
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
expect(test2).to.throw(TypeError, 'cookieConsent (init): consent values for key1 should be of type boolean.');
|
|
22
|
+
|
|
23
|
+
function test3 () {
|
|
24
|
+
return cookieConsent.initConsent({
|
|
25
|
+
key1: false
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
expect(test3()).to.be.true;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('cookieConsent.getConsent', function () {
|
|
33
|
+
expect(cookieConsent.getConsent('key1')).to.be.false;
|
|
34
|
+
cookieConsent.setConsent({ key1: true });
|
|
35
|
+
expect(cookieConsent.getConsent('key1')).to.be.true;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('cookieConsent.setConsent', function () {
|
|
39
|
+
function test1 () {
|
|
40
|
+
cookieConsent.setConsent(null);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
expect(test1).to.throw(TypeError, 'cookieConsent (setConsent): consent should be an object.');
|
|
44
|
+
|
|
45
|
+
function test2 () {
|
|
46
|
+
cookieConsent.setConsent({ key2: 1 });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
expect(test2).to.throw(TypeError, 'cookieConsent (setConsent): consent values should be of type boolean. Check value for key2.');
|
|
50
|
+
|
|
51
|
+
function test3 () {
|
|
52
|
+
return cookieConsent.setConsent({ key2: false });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
expect(test3()).to.be.true;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('cookieConsent.subscribe', function () {
|
|
59
|
+
function test1 () {
|
|
60
|
+
cookieConsent.subscribe(1, 2, null);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
expect(test1).to.throw(TypeError, 'cookieConsent (subscribe): consent key should be of type string.');
|
|
64
|
+
|
|
65
|
+
function test2 () {
|
|
66
|
+
cookieConsent.subscribe('key1', 2, null);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
expect(test2).to.throw(TypeError, 'cookieConsent (subscribe): event name should be of type string.');
|
|
70
|
+
|
|
71
|
+
function test3 () {
|
|
72
|
+
cookieConsent.subscribe('key1', 'delete', null);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
var events = ['add', 'enable', 'disable', 'change'];
|
|
76
|
+
expect(test3).to.throw(TypeError, 'cookieConsent (subscribe): event name should be one of ' + events.join(', ') + '.');
|
|
77
|
+
|
|
78
|
+
function test4 () {
|
|
79
|
+
cookieConsent.subscribe('key1', 'enable', null);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
expect(test4).to.throw(TypeError, 'cookieConsent (subscribe): callback should be a function.');
|
|
83
|
+
|
|
84
|
+
function test5 () {
|
|
85
|
+
return cookieConsent.subscribe('key1', 'enable', function () {});
|
|
86
|
+
}
|
|
87
|
+
expect(test5()).to.be.an('object');
|
|
88
|
+
});
|
|
89
|
+
it('cookieConsent.subscribeToConsentStore', function () {
|
|
90
|
+
// Error checks - Correct errors are thrown
|
|
91
|
+
function test6 () {
|
|
92
|
+
cookieConsent.subscribeToConsentStore('Callback')
|
|
93
|
+
}
|
|
94
|
+
expect(test6).to.throw(TypeError,'cookieConsent (subscribeToConsentStore): callback should be a function.');
|
|
95
|
+
// Subscriber creation test - The subscription gets created correctly
|
|
96
|
+
function test7 () {
|
|
97
|
+
return cookieConsent.subscribeToConsentStore(function () {});
|
|
98
|
+
}
|
|
99
|
+
expect(test7()).to.be.an('object');
|
|
100
|
+
|
|
101
|
+
// Event listener test - The subscriber callback fires on store change
|
|
102
|
+
var fn = sinon.spy()
|
|
103
|
+
function test8 () {
|
|
104
|
+
cookieConsent.subscribeToConsentStore(fn)
|
|
105
|
+
cookieConsent.setConsent({ cookie4: true })
|
|
106
|
+
}
|
|
107
|
+
test8 ()
|
|
108
|
+
sinon.assert.calledOnce(fn)
|
|
109
|
+
// Unsubscribe test - Should be able to unsubscribe successfully (Should not fire the callback after unsubscription)
|
|
110
|
+
var fn2 = sinon.spy()
|
|
111
|
+
function test9 () {
|
|
112
|
+
var event = cookieConsent.subscribeToConsentStore(fn2)
|
|
113
|
+
event.unsubscribe()
|
|
114
|
+
cookieConsent.setConsent({ cookie5: true })
|
|
115
|
+
}
|
|
116
|
+
test9()
|
|
117
|
+
sinon.assert.notCalled(fn2)
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the cssLoadChecker module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Imports.
|
|
7
|
+
var global = require('../../../lib/global');
|
|
8
|
+
var cssLoadChecker = require('../../../lib/cssLoadChecker');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to add a test style sheet to the page
|
|
12
|
+
*
|
|
13
|
+
* @param {string} className - The class name used to check if the css file has loaded yet.
|
|
14
|
+
* @return {object} The style element that was added to the page.
|
|
15
|
+
*/
|
|
16
|
+
var addCss = function (className) {
|
|
17
|
+
var cssStyles = global.document.createElement('style');
|
|
18
|
+
cssStyles.type = 'text/css';
|
|
19
|
+
cssStyles.innerHTML = '.' + className + ' { display: none; }';
|
|
20
|
+
global.document.getElementsByTagName('head')[0].appendChild(cssStyles);
|
|
21
|
+
return cssStyles;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Helper function to remove a test style sheet from the page
|
|
26
|
+
*
|
|
27
|
+
* @param {object} cssStyles - the style element that was added to the page.
|
|
28
|
+
*/
|
|
29
|
+
var removeCss = function (cssStyles) {
|
|
30
|
+
if (cssStyles) {
|
|
31
|
+
cssStyles.parentNode.removeChild(cssStyles);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
describe('lib/cssLoadChecker', function () {
|
|
37
|
+
|
|
38
|
+
var sandbox;
|
|
39
|
+
var cssStyles;
|
|
40
|
+
var className = 'bv-verify-css-loaded';
|
|
41
|
+
|
|
42
|
+
beforeEach(function () {
|
|
43
|
+
sandbox = sinon.sandbox.create();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
afterEach(function () {
|
|
47
|
+
sandbox.restore();
|
|
48
|
+
removeCss(cssStyles);
|
|
49
|
+
cssStyles = undefined;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
describe('isCssLoaded', function () {
|
|
54
|
+
|
|
55
|
+
it('CSS is not loaded', function () {
|
|
56
|
+
var test = cssLoadChecker.isCssLoaded(className);
|
|
57
|
+
expect(test).to.equal(false);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('CSS is loaded', function () {
|
|
61
|
+
cssStyles = addCss(className);
|
|
62
|
+
var test = cssLoadChecker.isCssLoaded(className);
|
|
63
|
+
expect(test).to.equal(true);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('After checking for CSS, test div should be removed', function () {
|
|
67
|
+
cssLoadChecker.isCssLoaded(className);
|
|
68
|
+
|
|
69
|
+
var allTestDivs = global.document.getElementsByClassName(className);
|
|
70
|
+
expect(allTestDivs.length).to.equal(0);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the date.now module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Imports.
|
|
7
|
+
var dateNow = require('../../../lib/date.now');
|
|
8
|
+
|
|
9
|
+
describe('lib/date.now', function () {
|
|
10
|
+
|
|
11
|
+
it('returns a non-negative number', function () {
|
|
12
|
+
var result = dateNow.now();
|
|
13
|
+
|
|
14
|
+
// Test 1: it returns a number.
|
|
15
|
+
expect(result).to.be.a('number');
|
|
16
|
+
|
|
17
|
+
// Test 2: the number is non-negative.
|
|
18
|
+
expect(result).to.be.above(0);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the Domain Police module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Includes.
|
|
7
|
+
var domainPolice = require('../../../lib/domainPolice');
|
|
8
|
+
|
|
9
|
+
describe('lib/domainPolice', function () {
|
|
10
|
+
|
|
11
|
+
// For each of these domains:
|
|
12
|
+
// - domain: The domain to test against.
|
|
13
|
+
// - matchedDomain: The expected return value of 'domain'
|
|
14
|
+
// - isValid: The expected return value from domainPolice.
|
|
15
|
+
var domainsToTest = [
|
|
16
|
+
{
|
|
17
|
+
domain: 'localhost.bazaarvoice.com',
|
|
18
|
+
matchedDomain: '.bazaarvoice.com',
|
|
19
|
+
isValid: true,
|
|
20
|
+
thirdPartyCookieEnabled: true,
|
|
21
|
+
commentsEnabled: true
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
domain: 'foo.localhost.bazaarvoice.com',
|
|
25
|
+
matchedDomain: '.bazaarvoice.com',
|
|
26
|
+
isValid: true,
|
|
27
|
+
thirdPartyCookieEnabled: true,
|
|
28
|
+
commentsEnabled: true
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
domain: 'no-prefixing-dot.foo.com',
|
|
32
|
+
matchedDomain: 'no-prefixing-dot.foo.com',
|
|
33
|
+
isValid: true,
|
|
34
|
+
thirdPartyCookieEnabled: true
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
domain: 'www.no-prefixing-dot.foo.com',
|
|
38
|
+
matchedDomain: 'no-prefixing-dot.foo.com',
|
|
39
|
+
isValid: true,
|
|
40
|
+
thirdPartyCookieEnabled: true
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
domain: 'foo.com',
|
|
44
|
+
matchedDomain: undefined,
|
|
45
|
+
isValid: false
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
domain: 'bar.com',
|
|
49
|
+
matchedDomain: undefined,
|
|
50
|
+
isValid: false
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
domain: 'ec2-54-234-131-1.compute-1.amazonaws.com',
|
|
54
|
+
matchedDomain: '.ec2-54-234-131-1.compute-1.amazonaws.com',
|
|
55
|
+
isValid: true,
|
|
56
|
+
thirdPartyCookieEnabled: false,
|
|
57
|
+
commentsEnabled: true
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
domain: 'www.ec2-54-234-131-1.compute-1.amazonaws.com',
|
|
61
|
+
matchedDomain: '.ec2-54-234-131-1.compute-1.amazonaws.com',
|
|
62
|
+
isValid: true,
|
|
63
|
+
thirdPartyCookieEnabled: false,
|
|
64
|
+
commentsEnabled: true
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
domain: 'compute-1.amazonaws.com',
|
|
68
|
+
matchedDomain: undefined,
|
|
69
|
+
isValid: false
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
domain: 'localhost',
|
|
73
|
+
matchedDomain: '.localhost',
|
|
74
|
+
isValid: true,
|
|
75
|
+
thirdPartyCookieEnabled: false
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
domain: '172.16.0.5',
|
|
79
|
+
matchedDomain: '172.16.0.5',
|
|
80
|
+
isValid: true,
|
|
81
|
+
thirdPartyCookieEnabled: true,
|
|
82
|
+
commentsEnabled: false
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
domain: '192.168.10.10',
|
|
86
|
+
matchedDomain: undefined,
|
|
87
|
+
isValid: false
|
|
88
|
+
}
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
// There is very intentional variation on what each domain in the allowedDomains set includes,
|
|
92
|
+
// in order to make testing more interesting
|
|
93
|
+
var allowedDomains = [
|
|
94
|
+
{
|
|
95
|
+
domain: '.bazaarvoice.com',
|
|
96
|
+
thirdPartyCookieEnabled: true,
|
|
97
|
+
commentsEnabled: true
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
domain: '.ec2-54-234-131-1.compute-1.amazonaws.com',
|
|
101
|
+
thirdPartyCookieEnabled: false,
|
|
102
|
+
commentsEnabled: true
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
domain: '.172.16.0.5',
|
|
106
|
+
thirdPartyCookieEnabled: true,
|
|
107
|
+
commentsEnabled: false
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
domain: '.localhost',
|
|
111
|
+
thirdPartyCookieEnabled: false
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
domain: 'no-prefixing-dot.foo.com',
|
|
115
|
+
thirdPartyCookieEnabled: true
|
|
116
|
+
}
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
it('produces correct results for all test domains', function () {
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A utility function used to test a domain.
|
|
123
|
+
*/
|
|
124
|
+
function testDomain (domainUnderTest) {
|
|
125
|
+
var domain = domainUnderTest.domain;
|
|
126
|
+
|
|
127
|
+
var dp = domainPolice(allowedDomains.slice(0), domain);
|
|
128
|
+
|
|
129
|
+
expect(dp.isValid).to.equal(domainUnderTest.isValid);
|
|
130
|
+
expect(dp.get('domain')).to.equal(domainUnderTest.matchedDomain);
|
|
131
|
+
expect(dp.get('thirdPartyCookieEnabled')).to.equal(domainUnderTest.thirdPartyCookieEnabled);
|
|
132
|
+
expect(dp.get('commentsEnabled')).to.equal(domainUnderTest.commentsEnabled);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Run the tests on each domain
|
|
136
|
+
for (var i = 0, l = domainsToTest.length; i < l; i++) {
|
|
137
|
+
testDomain(domainsToTest[i]);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the evented module.
|
|
4
|
+
*
|
|
5
|
+
* The tests in this file are minimal because the module is covered by the tests
|
|
6
|
+
* in the original asEvented repo (https://github.com/mkuklis/asEvented). With
|
|
7
|
+
* that in mind, this file just aims to test that we expose the interface we
|
|
8
|
+
* promise to expose.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// Imports.
|
|
12
|
+
var evented = require('../../../lib/evented');
|
|
13
|
+
|
|
14
|
+
describe('lib/import', function () {
|
|
15
|
+
|
|
16
|
+
it('exports a function that creates an event emitter', function () {
|
|
17
|
+
function M () {}
|
|
18
|
+
|
|
19
|
+
evented.call(M.prototype);
|
|
20
|
+
var m = new M();
|
|
21
|
+
|
|
22
|
+
expect(m.on).to.be.a('function');
|
|
23
|
+
expect(m.off).to.be.a('function');
|
|
24
|
+
expect(m.trigger).to.be.a('function');
|
|
25
|
+
expect(m.one).to.be.a('function');
|
|
26
|
+
expect(m.once).to.be.a('function');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('invokes an errorHandler function correctly', function () {
|
|
30
|
+
function M () {}
|
|
31
|
+
|
|
32
|
+
evented.call(M.prototype);
|
|
33
|
+
var m = new M();
|
|
34
|
+
|
|
35
|
+
// Ensure that errors escaping from listeners are caught
|
|
36
|
+
var error = new Error('test error 1');
|
|
37
|
+
m.on('test_event', function () {
|
|
38
|
+
throw error;
|
|
39
|
+
});
|
|
40
|
+
m.trigger('test_event'); // should NOT throw
|
|
41
|
+
|
|
42
|
+
// Ensure that errors are provided to custom error handler
|
|
43
|
+
error = new Error('test error 2');
|
|
44
|
+
var spy = sinon.spy();
|
|
45
|
+
m.setErrorHandler(spy);
|
|
46
|
+
m.trigger('test_event');
|
|
47
|
+
expect(spy).to.have.been.calledWith(error, sinon.match.has('event', 'test_event'));
|
|
48
|
+
|
|
49
|
+
// Ensure that errors can be rethrown from custom error handler
|
|
50
|
+
error = new Error('test error 3');
|
|
51
|
+
m.setErrorHandler(function (theError) {
|
|
52
|
+
throw theError;
|
|
53
|
+
});
|
|
54
|
+
expect(function () {
|
|
55
|
+
m.trigger('test_event');
|
|
56
|
+
}).to.throw(error);
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the getOriginalConstructor module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Imports.
|
|
7
|
+
var getOriginalConstructor = require('../../../lib/getOriginalConstructor');
|
|
8
|
+
|
|
9
|
+
describe('lib/getOriginalConstructor', function () {
|
|
10
|
+
var originalPush = Array.prototype.push;
|
|
11
|
+
var push = function push () {
|
|
12
|
+
originalPush.apply(this, arguments);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Array.prototype.push = push;
|
|
16
|
+
|
|
17
|
+
getOriginalConstructor(Array).then(function (originalArray) {
|
|
18
|
+
it('Should return an unaltered constructor', function () {
|
|
19
|
+
// Verify that the original push function matches '[native code]'
|
|
20
|
+
expect(!!originalPush.toString().match(/\[native code]/)).to.equal(true);
|
|
21
|
+
// Verify that the overridden push function doesn't match '[native code]'
|
|
22
|
+
expect(!!Array.prototype.push.toString().match(/\[native code]/)).to.equal(false);
|
|
23
|
+
|
|
24
|
+
// Verify that the getOriginalConstructor function returns a reset
|
|
25
|
+
// constructor and that its prototype push function matches '[native code]'
|
|
26
|
+
expect(!!originalArray.prototype.push.toString().match(/\[native code]/)).to.equal(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('Should cache the returned constructor for future lookups', function (done) {
|
|
30
|
+
getOriginalConstructor(Array).then(function (newArray) {
|
|
31
|
+
expect(newArray).to.equal(originalArray);
|
|
32
|
+
done();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('Should return the definition for constructor.name when constructor.name exists', function (done) {
|
|
37
|
+
var constructor = function Array () {};
|
|
38
|
+
|
|
39
|
+
Object.defineProperty(constructor, 'name', {
|
|
40
|
+
value: 'Array'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// We should pull the Array constructor, with prototype, if this is working properly
|
|
44
|
+
getOriginalConstructor(constructor).then(function (newArray) {
|
|
45
|
+
expect(newArray).to.have.property('prototype');
|
|
46
|
+
done();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('Should return the definition for the function name where constructor.name doesn\'t exist', function (done) {
|
|
51
|
+
var constructor = function Array () {};
|
|
52
|
+
|
|
53
|
+
// We should pull the Array constructor, with prototype, if this is working properly
|
|
54
|
+
getOriginalConstructor(constructor).then(function (newArray) {
|
|
55
|
+
expect(newArray).to.have.property('prototype');
|
|
56
|
+
done();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|