2021-02-04 19:15:23 +01:00
|
|
|
import { strict as assert } from 'assert';
|
2021-11-06 01:28:44 +01:00
|
|
|
import sinon from 'sinon';
|
2021-02-12 16:25:58 +01:00
|
|
|
import { isPrefixedFormattedHexString } from '../../../shared/modules/network.utils';
|
2020-01-09 04:34:58 +01:00
|
|
|
import {
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
ENVIRONMENT_TYPE_POPUP,
|
|
|
|
ENVIRONMENT_TYPE_NOTIFICATION,
|
|
|
|
ENVIRONMENT_TYPE_FULLSCREEN,
|
|
|
|
ENVIRONMENT_TYPE_BACKGROUND,
|
2021-11-06 01:28:44 +01:00
|
|
|
PLATFORM_FIREFOX,
|
|
|
|
PLATFORM_OPERA,
|
|
|
|
PLATFORM_CHROME,
|
|
|
|
PLATFORM_EDGE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../shared/constants/app';
|
2021-11-06 01:28:44 +01:00
|
|
|
import { getEnvironmentType, getPlatform } from './util';
|
2017-08-04 20:36:27 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('app utils', function () {
|
|
|
|
describe('getEnvironmentType', function () {
|
|
|
|
it('should return popup type', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/popup.html',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.equal(environmentType, ENVIRONMENT_TYPE_POPUP);
|
|
|
|
});
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should return notification type', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/notification.html',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.equal(environmentType, ENVIRONMENT_TYPE_NOTIFICATION);
|
|
|
|
});
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should return fullscreen type for home.html', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/home.html',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.equal(environmentType, ENVIRONMENT_TYPE_FULLSCREEN);
|
|
|
|
});
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should return fullscreen type for phishing.html', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/phishing.html',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.equal(environmentType, ENVIRONMENT_TYPE_FULLSCREEN);
|
|
|
|
});
|
2019-10-18 18:05:32 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should return background type', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/_generated_background_page.html',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.equal(environmentType, ENVIRONMENT_TYPE_BACKGROUND);
|
|
|
|
});
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should return the correct type for a URL with a hash fragment', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/popup.html#hash',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.equal(environmentType, ENVIRONMENT_TYPE_POPUP);
|
|
|
|
});
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should return the correct type for a URL with query parameters', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/popup.html?param=foo',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.equal(environmentType, ENVIRONMENT_TYPE_POPUP);
|
|
|
|
});
|
Close window after opening fullscreen (#6966)
* Add background environment type
The `getEnvironmentType` method now checks for the background
environment as well, instead of returning 'notification' for that case.
Instead of adding another regex for the background path, the regexes
for each environment have been replaced with the URL constructor[0].
This is the standard method of parsing URLs, and is available in all
supported browsers.
[0]: https://developer.mozilla.org/en-US/docs/Web/API/URL
* Add note regarding a missing manifest permission
The `url` parameter to `tabs.query(...)` requires the `tabs` permission,
and will be ignored otherwise. We are missing this permission, so that
call does not work.
* Close window after opening full screen
The browser behaviour when opening a new tab differs between Chrome and
Firefox. In the case of a popup, Chrome will close the popup whereas
Firefox will leave it open. In the case of the notification window,
Chrome will move the new tab to the foreground, whereas Firefox will
leave the notification window in the foreground when opening a new tab.
We always want to close the current UI (popup or notification) when
switching to a full-screen view. The only exception to this is when the
switch is triggered from the background, which has no UI.
Closes #6513, #6685
2019-08-08 16:50:32 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should return the correct type for a URL with query parameters and a hash fragment', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/popup.html?param=foo#hash',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.equal(environmentType, ENVIRONMENT_TYPE_POPUP);
|
|
|
|
});
|
|
|
|
});
|
2017-08-04 20:36:27 +02:00
|
|
|
|
2020-10-06 19:57:02 +02:00
|
|
|
describe('isPrefixedFormattedHexString', function () {
|
|
|
|
it('should return true for valid hex strings', function () {
|
|
|
|
assert.equal(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString('0x1'),
|
|
|
|
true,
|
2020-10-06 19:57:02 +02:00
|
|
|
'should return true',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
assert.equal(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString('0xa'),
|
|
|
|
true,
|
2020-10-06 19:57:02 +02:00
|
|
|
'should return true',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
assert.equal(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString('0xabcd1123fae909aad87452'),
|
|
|
|
true,
|
2020-10-06 19:57:02 +02:00
|
|
|
'should return true',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
it('should return false for invalid hex strings', function () {
|
|
|
|
assert.equal(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString('0x'),
|
|
|
|
false,
|
2020-10-06 19:57:02 +02:00
|
|
|
'should return false',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
assert.equal(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString('0x0'),
|
|
|
|
false,
|
2020-10-06 19:57:02 +02:00
|
|
|
'should return false',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
assert.equal(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString('0x01'),
|
|
|
|
false,
|
2020-10-06 19:57:02 +02:00
|
|
|
'should return false',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
assert.equal(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString(' 0x1'),
|
|
|
|
false,
|
2020-10-06 19:57:02 +02:00
|
|
|
'should return false',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
assert.equal(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString('0x1 '),
|
|
|
|
false,
|
2020-10-06 19:57:02 +02:00
|
|
|
'should return false',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
assert.equal(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString('0x1afz'),
|
|
|
|
false,
|
2020-10-06 19:57:02 +02:00
|
|
|
'should return false',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
assert.equal(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString('z'),
|
|
|
|
false,
|
2020-10-06 19:57:02 +02:00
|
|
|
'should return false',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
assert.equal(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString(2),
|
|
|
|
false,
|
2020-10-06 19:57:02 +02:00
|
|
|
'should return false',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
|
|
|
assert.equal(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString(['0x1']),
|
|
|
|
false,
|
2020-10-06 19:57:02 +02:00
|
|
|
'should return false',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.equal(
|
|
|
|
isPrefixedFormattedHexString(),
|
|
|
|
false,
|
|
|
|
'should return false',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2021-11-06 01:28:44 +01:00
|
|
|
|
|
|
|
describe('getPlatform', function () {
|
|
|
|
const setBrowserSpecificWindow = (browser) => {
|
|
|
|
switch (browser) {
|
|
|
|
case 'firefox': {
|
|
|
|
sinon.stub(window, 'navigator').value({
|
|
|
|
userAgent:
|
|
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0',
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'edge': {
|
|
|
|
sinon.stub(window, 'navigator').value({
|
|
|
|
userAgent:
|
|
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Edg/95.0.1020.30',
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'opera': {
|
|
|
|
sinon.stub(window, 'navigator').value({
|
|
|
|
userAgent:
|
|
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36 OPR/80.0.4170.63',
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
sinon.stub(window, 'navigator').value({
|
|
|
|
userAgent:
|
|
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36',
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should detect Firefox', function () {
|
|
|
|
setBrowserSpecificWindow('firefox');
|
|
|
|
assert.equal(getPlatform(), PLATFORM_FIREFOX);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should detect Edge', function () {
|
|
|
|
setBrowserSpecificWindow('edge');
|
|
|
|
assert.equal(getPlatform(), PLATFORM_EDGE);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should detect Opera', function () {
|
|
|
|
setBrowserSpecificWindow('opera');
|
|
|
|
assert.equal(getPlatform(), PLATFORM_OPERA);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should detect Chrome', function () {
|
|
|
|
setBrowserSpecificWindow('chrome');
|
|
|
|
assert.equal(getPlatform(), PLATFORM_CHROME);
|
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|