From 62eed525fdd3b08ba9def5924dcf6e06fa0020ad Mon Sep 17 00:00:00 2001 From: churkin Date: Sun, 3 Jul 2016 13:02:06 +0300 Subject: [PATCH] change hash for the iframe location (#652) --- package.json | 3 ++- .../code-instrumentation/location/wrapper.js | 23 +++++++++++++++-- .../code-instrumentation/location-test.js | 25 ++++++++++++++++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index d29a131a2..5e807e980 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "testcafe-hammerhead", "description": "A powerful web-proxy used as a core for the TestCafe testing framework (https://github.com/DevExpress/testcafe).", - "version": "9.2.2", + "version": "9.2.3", "homepage": "https://github.com/DevExpress/testcafe-hammerhead", "bugs": { "url": "https://github.com/DevExpress/testcafe-hammerhead/issues" @@ -45,6 +45,7 @@ "del": "^0.1.2", "ejs": "0.8.4", "endpoint-utils": "^1.0.1", + "eslint": "2.x", "eslint-plugin-babel": "^3.2.0", "eslint-plugin-hammerhead": "^0.0.5", "eslint-plugin-import": "^1.6.1", diff --git a/src/client/sandbox/code-instrumentation/location/wrapper.js b/src/client/sandbox/code-instrumentation/location/wrapper.js index fbc870686..6ac363ae3 100644 --- a/src/client/sandbox/code-instrumentation/location/wrapper.js +++ b/src/client/sandbox/code-instrumentation/location/wrapper.js @@ -1,11 +1,30 @@ import createPropertyDesc from '../../../utils/create-property-desc'; import { get as getDestLocation, getParsed as getParsedDestLocation } from '../../../utils/destination-location'; -import { getProxyUrl, changeDestUrlPart } from '../../../utils/url'; +import { getProxyUrl, changeDestUrlPart, parseProxyUrl, parseResourceType } from '../../../utils/url'; import { getDomain, stringifyResourceType } from '../../../../utils/url'; export default class LocationWrapper { constructor (window) { - var resourceType = stringifyResourceType(window !== window.top); + var isIframe = window !== window.top; + var isForm = false; + + // NOTE: cross-domain window + try { + var parsedLocation = parseProxyUrl(window.location.toString()); + + if (parsedLocation) { + var locationResType = parseResourceType(parsedLocation.resourceType); + + isIframe |= locationResType.isIframe; + isForm |= locationResType.isForm; + } + } + /*eslint-disable no-empty */ + catch (e) { + } + /*eslint-enable no-empty */ + + var resourceType = stringifyResourceType(isIframe, isForm); var getHref = () => { if (window !== window.top && window.location.href === 'about:blank') return 'about:blank'; diff --git a/test/client/fixtures/sandbox/code-instrumentation/location-test.js b/test/client/fixtures/sandbox/code-instrumentation/location-test.js index e98ac5227..7a777b022 100644 --- a/test/client/fixtures/sandbox/code-instrumentation/location-test.js +++ b/test/client/fixtures/sandbox/code-instrumentation/location-test.js @@ -179,7 +179,7 @@ test('special pages (GH-339)', function () { destLocation.forceLocation(urlUtils.getProxyUrl(specialPageUrl)); var windowMock = { - location: { } + location: {} }; var locationWrapper = new LocationWrapper(windowMock); @@ -225,3 +225,26 @@ if (!browserUtils.isFirefox) { document.body.appendChild(iframe); }); } + +test('change hash for the iframe location', function () { + var proxyUrl = urlUtils.getProxyUrl('http://domain.com/index.html', null, null, null, 'if'); + var windowMock = { + location: { + toString: function () { + return proxyUrl; + } + }, + + top: { + document: document + }, + + document: {} + }; + + var locationWrapper = new LocationWrapper(windowMock); + + locationWrapper.href = 'http://domain.com/index.html#hash'; + + strictEqual(windowMock.location.href, proxyUrl + '#hash'); +});