diff --git a/src/helpers/index.js b/src/helpers/index.js index 56700c1c..3a13ce95 100644 --- a/src/helpers/index.js +++ b/src/helpers/index.js @@ -27,3 +27,5 @@ export * from './random-response'; export * from './get-descriptor-addon'; export * from './parse-flags'; export * from './match-request-props'; +export * from './storage-utils'; +export * from './parse-keyword-value'; diff --git a/src/helpers/parse-keyword-value.js b/src/helpers/parse-keyword-value.js new file mode 100644 index 00000000..f2785af6 --- /dev/null +++ b/src/helpers/parse-keyword-value.js @@ -0,0 +1,22 @@ +/** + * Modifies passed keyword value according to its purpose. + * Returns initial value if it's not a keyword. + * @param {string} rawValue + * @returns {string} + */ +export const parseKeywordValue = (rawValue) => { + const NOW_VALUE_KEYWORD = '$now$'; + const CURRENT_DATE_KEYWORD = '$currentDate$'; + + let parsedValue = rawValue; + + if (rawValue === NOW_VALUE_KEYWORD) { + // Set to current time in ms, e.g 1667915146503 + parsedValue = Date.now().toString(); + } else if (rawValue === CURRENT_DATE_KEYWORD) { + // Set to current date e.g 'Tue Nov 08 2022 13:53:19 GMT+0300' + parsedValue = Date(); + } + + return parsedValue; +}; diff --git a/src/helpers/storage-utils.js b/src/helpers/storage-utils.js new file mode 100644 index 00000000..c9c43564 --- /dev/null +++ b/src/helpers/storage-utils.js @@ -0,0 +1,19 @@ +/** + * Sets item to a specified storage, if storage isn't full. + * @param {Storage} storage storage instance to set item into + * @param {string} key + * @param {string} value + * @param {boolean} shouldLog determines if helper should log on a failed set attempt + */ +export const setStorageItem = (storage, key, value, shouldLog) => { + // eslint-disable-next-line no-console + const log = console.log.bind(console); + // setItem() may throw an exception if the storage is full. + try { + storage.setItem(key, value); + } catch (e) { + if (shouldLog) { + log(`Unable to set sessionStorage item due to: ${e.message}`); + } + } +}; diff --git a/src/scriptlets/scriptlets-list.js b/src/scriptlets/scriptlets-list.js index 86f6031b..0a9141f4 100644 --- a/src/scriptlets/scriptlets-list.js +++ b/src/scriptlets/scriptlets-list.js @@ -52,3 +52,4 @@ export * from './trusted-replace-xhr-response'; export * from './xml-prune'; export * from './trusted-set-cookie'; export * from './trusted-replace-fetch-response'; +export * from './trusted-set-local-storage-item'; diff --git a/src/scriptlets/set-local-storage-item.js b/src/scriptlets/set-local-storage-item.js index e04e9eef..9614b5cb 100644 --- a/src/scriptlets/set-local-storage-item.js +++ b/src/scriptlets/set-local-storage-item.js @@ -1,6 +1,7 @@ import { hit, nativeIsNaN, + setStorageItem, } from '../helpers/index'; /* eslint-disable max-len */ @@ -9,6 +10,7 @@ import { * * @description * Adds specified key and its value to localStorage object, or updates the value of the key if it already exists. + * Scriptlet won't set item if storage is full. * * **Syntax** * ``` @@ -39,7 +41,16 @@ import { /* eslint-enable max-len */ export function setLocalStorageItem(source, key, value) { - if (!key || (!value && value !== '')) { + // eslint-disable-next-line no-console + const log = console.log.bind(console); + + if (typeof key === 'undefined') { + log('Item key should be specified.'); + return; + } + + if (typeof value === 'undefined') { + log('Item value should be specified.'); return; } @@ -74,21 +85,9 @@ export function setLocalStorageItem(source, key, value) { return; } - const setItem = (key, value) => { - const { localStorage } = window; - // setItem() may throw an exception if the storage is full. - try { - localStorage.setItem(key, value); - hit(source); - } catch (e) { - if (source.verbose) { - // eslint-disable-next-line no-console - console.log(`Was unable to set localStorage item due to: ${e.message}`); - } - } - }; - - setItem(key, keyValue); + const { localStorage } = window; + setStorageItem(localStorage, key, keyValue, source.verbose); + hit(source); } setLocalStorageItem.names = [ @@ -98,4 +97,5 @@ setLocalStorageItem.names = [ setLocalStorageItem.injections = [ hit, nativeIsNaN, + setStorageItem, ]; diff --git a/src/scriptlets/set-session-storage-item.js b/src/scriptlets/set-session-storage-item.js index 85c707fd..faf5a018 100644 --- a/src/scriptlets/set-session-storage-item.js +++ b/src/scriptlets/set-session-storage-item.js @@ -1,6 +1,7 @@ import { hit, nativeIsNaN, + setStorageItem, } from '../helpers/index'; /* eslint-disable max-len */ @@ -9,6 +10,7 @@ import { * * @description * Adds specified key and its value to sessionStorage object, or updates the value of the key if it already exists. + * Scriptlet won't set item if storage is full. * * **Syntax** * ``` @@ -39,7 +41,16 @@ import { /* eslint-enable max-len */ export function setSessionStorageItem(source, key, value) { - if (!key || (!value && value !== '')) { + // eslint-disable-next-line no-console + const log = console.log.bind(console); + + if (typeof key === 'undefined') { + log('Item key should be specified.'); + return; + } + + if (typeof value === 'undefined') { + log('Item value should be specified.'); return; } @@ -74,21 +85,8 @@ export function setSessionStorageItem(source, key, value) { return; } - const setItem = (key, value) => { - const { sessionStorage } = window; - // setItem() may throw an exception if the storage is full. - try { - sessionStorage.setItem(key, value); - hit(source); - } catch (e) { - if (source.verbose) { - // eslint-disable-next-line no-console - console.log(`Was unable to set sessionStorage item due to: ${e.message}`); - } - } - }; - - setItem(key, keyValue); + const { sessionStorage } = window; + setStorageItem(sessionStorage, key, keyValue, source.verbose); } setSessionStorageItem.names = [ @@ -98,4 +96,5 @@ setSessionStorageItem.names = [ setSessionStorageItem.injections = [ hit, nativeIsNaN, + setStorageItem, ]; diff --git a/src/scriptlets/trusted-set-cookie.js b/src/scriptlets/trusted-set-cookie.js index 9e2f05a8..693640b0 100644 --- a/src/scriptlets/trusted-set-cookie.js +++ b/src/scriptlets/trusted-set-cookie.js @@ -3,6 +3,7 @@ import { nativeIsNaN, isCookieSetWithValue, concatCookieNameValuePath, + parseKeywordValue, // following helpers should be imported and injected // because they are used by helpers above isValidCookieRawPath, @@ -90,21 +91,10 @@ export function trustedSetCookie(source, name, value, offsetExpiresSec = '', rel return; } - const NOW_VALUE_KEYWORD = '$now$'; const ONE_YEAR_EXPIRATION_KEYWORD = '1year'; const ONE_DAY_EXPIRATION_KEYWORD = '1day'; - let parsedValue; - - if (value === NOW_VALUE_KEYWORD) { - // Set cookie value to current time if corresponding keyword was passed - const date = new Date(); - const currentTime = date.getTime(); - - parsedValue = currentTime.toString(); - } else { - parsedValue = value; - } + const parsedValue = parseKeywordValue(value); let cookieToSet = concatCookieNameValuePath(name, parsedValue, path); if (!cookieToSet) { @@ -161,5 +151,6 @@ trustedSetCookie.injections = [ isCookieSetWithValue, concatCookieNameValuePath, isValidCookieRawPath, + parseKeywordValue, getCookiePath, ]; diff --git a/src/scriptlets/trusted-set-local-storage-item.js b/src/scriptlets/trusted-set-local-storage-item.js new file mode 100644 index 00000000..9cd74cd9 --- /dev/null +++ b/src/scriptlets/trusted-set-local-storage-item.js @@ -0,0 +1,87 @@ +import { + hit, + nativeIsNaN, + setStorageItem, + parseKeywordValue, +} from '../helpers/index'; + +/* eslint-disable max-len */ +/** + * @scriptlet trusted-set-local-storage-item + * + * @description + * Adds item with arbitrary key and value to localStorage object, or updates the value of the key if it already exists. + * Scriptlet won't set item if storage is full. + * + * **Syntax** + * ``` + * example.com#%#//scriptlet('trusted-set-local-storage-item', 'key', 'value') + * ``` + * + * - `key` — required, key name to be set. + * - `value` - required, key value; possible values: + * - arbitrary value + * - `$now$` keyword for setting current time in ms, corresponds to `Date.now()` and `(new Date).getTime()` calls + * - `$currentDate$` keyword for setting string representation of the current date and time, corresponds to `Date()` and `(new Date).toString()` calls + * + * **Examples** + * 1. Set local storage item + * ``` + * example.org#%#//scriptlet('trusted-set-local-storage-item', 'player.live.current.mute', 'false') + * + * example.org#%#//scriptlet('trusted-set-local-storage-item', 'COOKIE_CONSENTS', '{"preferences":3,"marketing":false}') + * + * example.org#%#//scriptlet('trusted-set-local-storage-item', 'providers', '[16364,88364]') + * + * example.org#%#//scriptlet('trusted-set-local-storage-item', 'providers', '{"providers":[16364,88364],"consent":"all"}') + * ``` + * + * 2. Set item with current time since unix epoch in ms + * ``` + * example.org#%#//scriptlet('trusted-set-local-storage-item', 'player.live.current.play', '$now$') + * ``` + * + * 3. Set item with current date, e.g 'Tue Nov 08 2022 13:53:19 GMT+0300' + * ``` + * example.org#%#//scriptlet('trusted-set-local-storage-item', 'player.live.current.play', '$currentDate$') + * ``` + * + * 4. Set item without value + * ``` + * example.org#%#//scriptlet('trusted-set-local-storage-item', 'ppu_main_none', '') + * ``` + */ +/* eslint-enable max-len */ + +export function trustedSetLocalStorageItem(source, key, value) { + // eslint-disable-next-line no-console + const log = console.log.bind(console); + + if (typeof key === 'undefined') { + log('Item key should be specified.'); + return; + } + + if (typeof value === 'undefined') { + log('Item value should be specified.'); + return; + } + + const parsedValue = parseKeywordValue(value); + + const { localStorage } = window; + setStorageItem(localStorage, key, parsedValue, source.verbose); + hit(source); +} + +trustedSetLocalStorageItem.names = [ + 'trusted-set-local-storage-item', + // trusted scriptlets support no aliases +]; + +trustedSetLocalStorageItem.injections = [ + hit, + nativeIsNaN, + setStorageItem, + parseKeywordValue, +]; diff --git a/tests/scriptlets/index.test.js b/tests/scriptlets/index.test.js index d45c9f8d..06adf3bb 100644 --- a/tests/scriptlets/index.test.js +++ b/tests/scriptlets/index.test.js @@ -49,3 +49,4 @@ import './xml-prune.test'; import './trusted-click-element.test'; import './trusted-set-cookie.test'; import './trusted-replace-fetch-response.test'; +import './trusted-set-local-storage-item.test'; diff --git a/tests/scriptlets/set-local-storage-item.test.js b/tests/scriptlets/set-local-storage-item.test.js index 1a11244a..3d2b4ab6 100644 --- a/tests/scriptlets/set-local-storage-item.test.js +++ b/tests/scriptlets/set-local-storage-item.test.js @@ -16,8 +16,8 @@ const afterEach = () => { module(name, { beforeEach, afterEach }); -const clearStorageItem = (cName) => { - window.localStorage.removeItem(cName); +const clearStorageItem = (iName) => { + window.localStorage.removeItem(iName); }; if (isSafariBrowser()) { @@ -27,104 +27,104 @@ if (isSafariBrowser()) { }); } else { test('Set localStorage key with valid value', (assert) => { - let cName = '__test-item_true'; - let cValue = 'true'; - runScriptlet(name, [cName, cValue]); + let iName = '__test-item_true'; + let iValue = 'true'; + runScriptlet(name, [iName, iValue]); assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); - assert.strictEqual(window.localStorage.getItem(cName), 'true', 'localStorage item has been set'); - clearStorageItem(cName); + assert.strictEqual(window.localStorage.getItem(iName), 'true', 'localStorage item has been set'); + clearStorageItem(iName); - cName = '__test-item_false'; - cValue = 'false'; - runScriptlet(name, [cName, cValue]); + iName = '__test-item_false'; + iValue = 'false'; + runScriptlet(name, [iName, iValue]); assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); - assert.strictEqual(window.localStorage.getItem(cName), 'false', 'localStorage item has been set'); - clearStorageItem(cName); + assert.strictEqual(window.localStorage.getItem(iName), 'false', 'localStorage item has been set'); + clearStorageItem(iName); - cName = '__test-item_null'; - cValue = 'null'; - runScriptlet(name, [cName, cValue]); + iName = '__test-item_null'; + iValue = 'null'; + runScriptlet(name, [iName, iValue]); assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); - assert.strictEqual(window.localStorage.getItem(cName), 'null', 'localStorage item has been set'); - clearStorageItem(cName); + assert.strictEqual(window.localStorage.getItem(iName), 'null', 'localStorage item has been set'); + clearStorageItem(iName); - cName = '__test-item_undefined'; - cValue = 'undefined'; - runScriptlet(name, [cName, cValue]); + iName = '__test-item_undefined'; + iValue = 'undefined'; + runScriptlet(name, [iName, iValue]); assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); - assert.strictEqual(window.localStorage.getItem(cName), 'undefined', 'localStorage item has been set'); - clearStorageItem(cName); + assert.strictEqual(window.localStorage.getItem(iName), 'undefined', 'localStorage item has been set'); + clearStorageItem(iName); - cName = '__test-item_emptyObj'; - cValue = 'emptyObj'; - runScriptlet(name, [cName, cValue]); + iName = '__test-item_emptyObj'; + iValue = 'emptyObj'; + runScriptlet(name, [iName, iValue]); assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); - assert.strictEqual(window.localStorage.getItem(cName), '{}', 'localStorage item has been set'); - clearStorageItem(cName); + assert.strictEqual(window.localStorage.getItem(iName), '{}', 'localStorage item has been set'); + clearStorageItem(iName); - cName = '__test-item_emptyArr'; - cValue = 'emptyArr'; - runScriptlet(name, [cName, cValue]); + iName = '__test-item_emptyArr'; + iValue = 'emptyArr'; + runScriptlet(name, [iName, iValue]); assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); - assert.strictEqual(window.localStorage.getItem(cName), '[]', 'localStorage item has been set'); - clearStorageItem(cName); + assert.strictEqual(window.localStorage.getItem(iName), '[]', 'localStorage item has been set'); + clearStorageItem(iName); - cName = '__test-item_emptyStr'; - cValue = ''; - runScriptlet(name, [cName, cValue]); + iName = '__test-item_emptyStr'; + iValue = ''; + runScriptlet(name, [iName, iValue]); assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); - assert.strictEqual(window.localStorage.getItem(cName), '', 'localStorage item has been set'); - clearStorageItem(cName); + assert.strictEqual(window.localStorage.getItem(iName), '', 'localStorage item has been set'); + clearStorageItem(iName); - cName = '__test-item_int'; - cValue = '15'; - runScriptlet(name, [cName, cValue]); + iName = '__test-item_int'; + iValue = '15'; + runScriptlet(name, [iName, iValue]); assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); - assert.strictEqual(window.localStorage.getItem(cName), '15', 'localStorage item has been set'); - clearStorageItem(cName); + assert.strictEqual(window.localStorage.getItem(iName), '15', 'localStorage item has been set'); + clearStorageItem(iName); - cName = '__test-item_yes'; - cValue = 'yes'; - runScriptlet(name, [cName, cValue]); + iName = '__test-item_yes'; + iValue = 'yes'; + runScriptlet(name, [iName, iValue]); assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); - assert.strictEqual(window.localStorage.getItem(cName), 'yes', 'localStorage item has been set'); - clearStorageItem(cName); + assert.strictEqual(window.localStorage.getItem(iName), 'yes', 'localStorage item has been set'); + clearStorageItem(iName); - cName = '__test-item_no'; - cValue = 'no'; - runScriptlet(name, [cName, cValue]); + iName = '__test-item_no'; + iValue = 'no'; + runScriptlet(name, [iName, iValue]); assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); - assert.strictEqual(window.localStorage.getItem(cName), 'no', 'localStorage item has been set'); - clearStorageItem(cName); + assert.strictEqual(window.localStorage.getItem(iName), 'no', 'localStorage item has been set'); + clearStorageItem(iName); }); -} -test('Set localStorage key with invalid value', (assert) => { - let cName = '__test-item_arrayItem'; - let cValue = '["item"]'; - runScriptlet(name, [cName, cValue]); - assert.strictEqual(window.hit, undefined, 'Hit was not fired'); - assert.strictEqual(window.localStorage.getItem(cName), null, 'localStorage item has not been set'); - clearStorageItem(cName); - - cName = '__test-item_object'; - cValue = '{"key":value"}'; - runScriptlet(name, [cName, cValue]); - assert.strictEqual(window.hit, undefined, 'Hit was not fired'); - assert.strictEqual(window.localStorage.getItem(cName), null, 'localStorage item has not been set'); - clearStorageItem(cName); - - cName = '__test-item_str'; - cValue = 'test_string'; - runScriptlet(name, [cName, cValue]); - assert.strictEqual(window.hit, undefined, 'Hit was not fired'); - assert.strictEqual(window.localStorage.getItem(cName), null, 'localStorage item has not been set'); - clearStorageItem(cName); - - cName = '__test-item_bigInt'; - cValue = '999999'; - runScriptlet(name, [cName, cValue]); - assert.strictEqual(window.hit, undefined, 'Hit was not fired'); - assert.strictEqual(window.localStorage.getItem(cName), null, 'localStorage item has not been set'); - clearStorageItem(cName); -}); + test('Set localStorage key with invalid value', (assert) => { + let iName = '__test-item_arrayItem'; + let iValue = '["item"]'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, undefined, 'Hit was not fired'); + assert.strictEqual(window.localStorage.getItem(iName), null, 'localStorage item has not been set'); + clearStorageItem(iName); + + iName = '__test-item_object'; + iValue = '{"key":value"}'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, undefined, 'Hit was not fired'); + assert.strictEqual(window.localStorage.getItem(iName), null, 'localStorage item has not been set'); + clearStorageItem(iName); + + iName = '__test-item_str'; + iValue = 'test_string'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, undefined, 'Hit was not fired'); + assert.strictEqual(window.localStorage.getItem(iName), null, 'localStorage item has not been set'); + clearStorageItem(iName); + + iName = '__test-item_bigInt'; + iValue = '999999'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, undefined, 'Hit was not fired'); + assert.strictEqual(window.localStorage.getItem(iName), null, 'localStorage item has not been set'); + clearStorageItem(iName); + }); +} diff --git a/tests/scriptlets/trusted-set-local-storage-item.test.js b/tests/scriptlets/trusted-set-local-storage-item.test.js new file mode 100644 index 00000000..80503eb2 --- /dev/null +++ b/tests/scriptlets/trusted-set-local-storage-item.test.js @@ -0,0 +1,138 @@ +/* eslint-disable no-underscore-dangle */ +import { runScriptlet, clearGlobalProps, isSafariBrowser } from '../helpers'; + +const { test, module } = QUnit; +const name = 'trusted-set-local-storage-item'; + +const beforeEach = () => { + window.__debug = () => { + window.hit = 'FIRED'; + }; +}; + +const afterEach = () => { + clearGlobalProps('hit', '__debug'); +}; + +module(name, { beforeEach, afterEach }); + +const clearStorageItem = (iName) => { + window.localStorage.removeItem(iName); +}; + +if (isSafariBrowser()) { + test('unsupported', (assert) => { + assert.ok(true, 'does not work in Safari 10 while browserstack auto tests run'); + }); +} else { + test('Set localStorage item', (assert) => { + let iName = '__test-item_true'; + let iValue = 'true'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); + assert.strictEqual(window.localStorage.getItem(iName), 'true', 'localStorage item has been set'); + clearStorageItem(iName); + + iName = '__test-item_false'; + iValue = 'false'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); + assert.strictEqual(window.localStorage.getItem(iName), 'false', 'localStorage item has been set'); + clearStorageItem(iName); + + iName = '__test-item_null'; + iValue = 'null'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); + assert.strictEqual(window.localStorage.getItem(iName), 'null', 'localStorage item has been set'); + clearStorageItem(iName); + + iName = '__test-item_undefined'; + iValue = 'undefined'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); + assert.strictEqual(window.localStorage.getItem(iName), 'undefined', 'localStorage item has been set'); + clearStorageItem(iName); + + iName = '__test-item_emptyStr'; + iValue = ''; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); + assert.strictEqual(window.localStorage.getItem(iName), '', 'localStorage item has been set'); + clearStorageItem(iName); + + iName = '__test-item_object'; + iValue = '{"preferences":3,"marketing":false}'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); + assert.strictEqual(window.localStorage.getItem(iName), iValue, 'localStorage item has been set'); + clearStorageItem(iName); + + iName = '__test-item_array'; + iValue = '[1, 2, "test"]'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); + assert.strictEqual(window.localStorage.getItem(iName), iValue, 'localStorage item has been set'); + clearStorageItem(iName); + + iName = '__test-item_string'; + iValue = 'some arbitrary item value 111'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); + assert.strictEqual(window.localStorage.getItem(iName), iValue, 'localStorage item has been set'); + clearStorageItem(iName); + + iName = '__test-item_numbers'; + iValue = '123123'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); + assert.strictEqual(window.localStorage.getItem(iName), iValue, 'localStorage item has been set'); + clearStorageItem(iName); + + iName = '__test-item_mix'; + iValue = '123string_!!:;@#$'; + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); + assert.strictEqual(window.localStorage.getItem(iName), iValue, 'localStorage item has been set'); + clearStorageItem(iName); + }); + + test('Set localStorage item with $now$ keyword value', (assert) => { + const iName = '__test-item_now'; + const iValue = '$now$'; + + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); + + // Some time will pass between calling scriptlet + // and qunit running assertion + const tolerance = 20; + const itemValue = window.localStorage.getItem(iName); + const currentTime = Date.now(); + const timeDiff = currentTime - itemValue; + + assert.ok(timeDiff < tolerance, 'Item value has been set to current time'); + + clearStorageItem(iName); + }); + + test('Set localStorage item with $currentDate$ keyword value', (assert) => { + const iName = '__test-item_current_date'; + const iValue = '$currentDate$'; + + runScriptlet(name, [iName, iValue]); + assert.strictEqual(window.hit, 'FIRED', 'Hit was fired'); + + const value = localStorage.getItem(iName); + const dateObj = new Date(); + const year = dateObj.getFullYear(); + const month = dateObj.getMonth(); + const hours = dateObj.getHours(); + + assert.ok(value.includes(year), 'Years matched'); + assert.ok(value.includes(month), 'Month matched'); + assert.ok(value.includes(hours), 'Hours matched'); + + clearStorageItem(iName); + }); +}