Skip to content

Commit

Permalink
change hash for the iframe location (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
churkin authored and AlexanderMoskovkin committed Jul 3, 2016
1 parent 4731fd2 commit 62eed52
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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",
Expand Down
23 changes: 21 additions & 2 deletions src/client/sandbox/code-instrumentation/location/wrapper.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ test('special pages (GH-339)', function () {
destLocation.forceLocation(urlUtils.getProxyUrl(specialPageUrl));

var windowMock = {
location: { }
location: {}
};

var locationWrapper = new LocationWrapper(windowMock);
Expand Down Expand Up @@ -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');
});

0 comments on commit 62eed52

Please sign in to comment.