Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance location detection within utils #2167

Merged
merged 23 commits into from
Mar 26, 2018
Merged

Conversation

rachelrj
Copy link
Contributor

Type of change

  • Feature

Description of change

Check other window objects for location if cannot find.

Copy link
Collaborator

@matthewlane matthewlane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rachelrj Thanks for the PR. Adapter changes look good, a few comments regarding the changes to utils for your review

src/utils.js Outdated

return location;
const parseFullUrl = function(locString) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a parse function in the src/url.js module that parses a url and returns a similar looking object, would reusing that function in place of this one fit this use case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, though I added the href into the return object of that function.

src/utils.js Outdated
@@ -157,17 +157,50 @@ export function parseGPTSingleSizeArray(singleSize) {
}
};

exports.getTopWindowLocation = function () {
let location;
export function getTopWindowLocation() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several modules rely on this function, changing it may introduce subtle differences. Any reason to not keep the existing getTopWindowLocation as is, and create a new function for this case?

Copy link
Contributor Author

@rachelrj rachelrj Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old function getTopWindowLocation either returns window.top.location or returns window.location.

The new getTopWindowLocation returns window.location, window.top.location, window.document.referrer, window.document.location.ancestorOrigins[0], or an object that recreates the values within window.location

The new version attempts to get the same info, just from additional objects.

I checked the modules, and I think this new version should fit all the current use cases.

I am not opposed to creating a new function if you’re worried about it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for the explanation. Changes to core require a second review, assigning that now

src/utils.js Outdated
try {
// force an exception in x-domain enviornments. #1509
window.top.location.toString();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the comment, not sure removing this is the correct thing to do, unless there's an equivalent fix in the new code i'm not seeing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't realize that the exception wasn't thrown when trying to access window.top until I read that 1509 PR. Interesting. Thanks for pointing out. I added back in.

Rachel Joyce and others added 2 commits March 1, 2018 16:48
src/utils.js Outdated
do {
currentWindow = currentWindow ? currentWindow.parent : window;
if (currentWindow.document && currentWindow.document.referrer) {
referrerLoc = currentWindow.document.referrer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this return a string when an object is expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns a string to getIframeParentLoc which then gets sent to parse which turns the string into the expected object.

Copy link
Member

@mkendall07 mkendall07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd feel better if we had unit tests to cover the getTopWindowLocation changes

@rachelrj
Copy link
Contributor Author

rachelrj commented Mar 6, 2018

I'll work on adding some unit tests.

@matthewlane matthewlane removed their assignment Mar 6, 2018
@mkendall07 mkendall07 removed this from the Prebid 1.5.0 milestone Mar 8, 2018
@mkendall07 mkendall07 added this to the 1.6 milestone Mar 8, 2018
@rachelrj
Copy link
Contributor Author

I reorganized the additions to getTopWindowLocation and added unit tests.
To mock the readonly window objects in sinon, I wrapped in accessors.
I couldn't figure out a better way to mock these...

Also to use url.parse for getTopWindowLocation, search needs to be returned as string to mirror window.location object.

@mkendall07
Copy link
Member

There really are not any elegant solutions that I've seen to mock window and the like. The other option is to pass window in the module bootstrap but that's not great either.

Copy link
Member

@mkendall07 mkendall07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for adding tests

@mkendall07
Copy link
Member

@rachelrj
could you fix the merge conflict so I can merge? Thanks

@rachelrj
Copy link
Contributor Author

Fixed merge conflict.

@jaiminpanchal27 jaiminpanchal27 merged commit 63159da into prebid:master Mar 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants