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
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
describe('app utils', () => {
|
|
|
|
describe('getEnvironmentType', () => {
|
|
|
|
it('should return popup type', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/popup.html',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_POPUP);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
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
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return notification type', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/notification.html',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_NOTIFICATION);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
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
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return fullscreen type for home.html', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const environmentType = getEnvironmentType(
|
|
|
|
'http://extension-id/home.html',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_FULLSCREEN);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
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
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return background type', () => {
|
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
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_BACKGROUND);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
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
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return the correct type for a URL with a hash fragment', () => {
|
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
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_POPUP);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
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
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return the correct type for a URL with query parameters', () => {
|
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
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_POPUP);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
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
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return the correct type for a URL with query parameters and a hash fragment', () => {
|
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
|
|
|
);
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(environmentType).toStrictEqual(ENVIRONMENT_TYPE_POPUP);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2017-08-04 20:36:27 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
describe('isPrefixedFormattedHexString', () => {
|
|
|
|
it('should return true for valid hex strings', () => {
|
|
|
|
expect(isPrefixedFormattedHexString('0x1')).toStrictEqual(true);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString('0xa')).toStrictEqual(true);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
isPrefixedFormattedHexString('0xabcd1123fae909aad87452'),
|
2021-12-06 17:40:39 +01:00
|
|
|
).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should return false for invalid hex strings', () => {
|
|
|
|
expect(isPrefixedFormattedHexString('0x')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString('0x0')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString('0x01')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString(' 0x1')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString('0x1 ')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString('0x1afz')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString('z')).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString(2)).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString(['0x1'])).toStrictEqual(false);
|
2020-10-06 19:57:02 +02:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(isPrefixedFormattedHexString()).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2021-11-06 01:28:44 +01:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
describe('getPlatform', () => {
|
|
|
|
let userAgent, setBrowserSpecificWindow;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
userAgent = jest.spyOn(window.navigator, 'userAgent', 'get');
|
|
|
|
|
|
|
|
setBrowserSpecificWindow = (browser) => {
|
|
|
|
switch (browser) {
|
|
|
|
case 'firefox': {
|
|
|
|
userAgent.mockReturnValue(
|
2021-11-06 01:28:44 +01:00
|
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0',
|
2021-12-06 17:40:39 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'edge': {
|
|
|
|
userAgent.mockReturnValue(
|
2021-11-06 01:28:44 +01:00
|
|
|
'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',
|
2021-12-06 17:40:39 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'opera': {
|
|
|
|
userAgent.mockReturnValue(
|
2021-11-06 01:28:44 +01:00
|
|
|
'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',
|
2021-12-06 17:40:39 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
userAgent.mockReturnValue(
|
2021-11-06 01:28:44 +01:00
|
|
|
'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',
|
2021-12-06 17:40:39 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2021-11-06 01:28:44 +01:00
|
|
|
}
|
2021-12-06 17:40:39 +01:00
|
|
|
};
|
|
|
|
});
|
2021-11-06 01:28:44 +01:00
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should detect Firefox', () => {
|
2021-11-06 01:28:44 +01:00
|
|
|
setBrowserSpecificWindow('firefox');
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(getPlatform()).toStrictEqual(PLATFORM_FIREFOX);
|
2021-11-06 01:28:44 +01:00
|
|
|
});
|
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should detect Edge', () => {
|
2021-11-06 01:28:44 +01:00
|
|
|
setBrowserSpecificWindow('edge');
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(getPlatform()).toStrictEqual(PLATFORM_EDGE);
|
2021-11-06 01:28:44 +01:00
|
|
|
});
|
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should detect Opera', () => {
|
2021-11-06 01:28:44 +01:00
|
|
|
setBrowserSpecificWindow('opera');
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(getPlatform()).toStrictEqual(PLATFORM_OPERA);
|
2021-11-06 01:28:44 +01:00
|
|
|
});
|
|
|
|
|
2021-12-06 17:40:39 +01:00
|
|
|
it('should detect Chrome', () => {
|
2021-11-06 01:28:44 +01:00
|
|
|
setBrowserSpecificWindow('chrome');
|
2021-12-06 17:40:39 +01:00
|
|
|
expect(getPlatform()).toStrictEqual(PLATFORM_CHROME);
|
2021-11-06 01:28:44 +01:00
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|