Skip to content

Fix unintended behaviors of Location.reload() - #781

Closed
yamamoto-kanoko wants to merge 4 commits into
HtmlUnit:masterfrom
yamamoto-kanoko:kay_location_reload
Closed

Fix unintended behaviors of Location.reload()#781
yamamoto-kanoko wants to merge 4 commits into
HtmlUnit:masterfrom
yamamoto-kanoko:kay_location_reload

Conversation

@yamamoto-kanoko

Copy link
Copy Markdown

This PR does the following

  • Make Location.reload() behave like real browsers by
    • Fix an issue where calling reload() will not actually reload the page if the current href contains a hash, as showed in LocationTest.reloadWithHash()
    • Fix an issue where the updated hash value is not preserved after calling reload(), as showed in LocationTest.reloadNoHash()

final WebRequest request = htmlPage.getWebResponse().getWebRequest();

// update request url with location.href in case hash was changed
request.setUrl(new URL(getHref()));

@rbri rbri May 2, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i fear setting this here will change the getUrl() response because the getUrl() method reads from the request
Can you please include the checking of the pageUrl in your test cases

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rbri added 1 more commit to update the tests. Could you take a look at it ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do you see a chance to add the tests to Location2Test - then we can really compare with the browser behaviour

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What test cases do you want to put in Location2Test ? Same as this one ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What test cases do you want to put in Location2Test ? Same as this one ?

Sorry...

Usually it is easier to maintain the tests if they are WebDriverTest cases, because i can run them with real browsers and proof the expected results more or less automatically. Otherwise we have to recheck (in theory) manually with every browser update.
So what i like to say is to prefer writing WebDriverTest cases over the others. But in some cases it is not possible...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see... I will try to add it tomorrow

@duonglaiquang
duonglaiquang force-pushed the kay_location_reload branch from b35d2a8 to 94c8787 Compare May 2, 2024 12:31
rbri added a commit that referenced this pull request May 2, 2024
@rbri

rbri commented May 2, 2024

Copy link
Copy Markdown
Member

Have added two tests (validated with real browsers but failing in HtmlUnit). Maybe you can take this as sample....

Btw this shows that there is a difference between FF and Chrome

@duonglaiquang
duonglaiquang force-pushed the kay_location_reload branch 2 times, most recently from 033bbbe to fadcfdf Compare May 3, 2024 00:14
@rbri

rbri commented May 3, 2024

Copy link
Copy Markdown
Member

@yamamoto-kanoko @duonglaiquang @atnak first of all thanks for all the work on this (and all the other stuff) and sorry for being that picky this time...

When running the new Location2Test with real browsers (i guess you know how to setup this (see WebDriverTestCase class javadoc)) i got exactly the result i wrote into the expectations.
image
Therefor i see reason to change the expectations - do you get other results with the real browsers?

If you think the test produces different results for the real browsers than doing the same with the real browser manually then we have to use the @BuggyWebDriver annotation.

Suggestion - please have a look at the new tests in Location2Test

  • is there any test case missing?
  • do we have to check more in the test cases?
  • can you reproduce my results when using real browsers?

rbri added a commit that referenced this pull request May 3, 2024
@rbri

rbri commented May 3, 2024

Copy link
Copy Markdown
Member

OK, have adjusted the tests, and now i can reproduce your results.

@duonglaiquang

Copy link
Copy Markdown
Contributor

@rbri Thanks for all the tests 😁. But regarding this one


shouldn't FF & FF_ESR have null referer ?

@duonglaiquang
duonglaiquang force-pushed the kay_location_reload branch from fadcfdf to 4552c3d Compare May 3, 2024 07:21
@duonglaiquang

duonglaiquang commented May 3, 2024

Copy link
Copy Markdown
Contributor

And for this one, your previous test have FF & FF_ESR both produce no additional request when calling reload() but that's not what i saw when testing with the real FF browser. It still sends another request, just like Chrome (not sure about FF_ESR thought but probably same).

If you think the test produces different results for the real browsers than doing the same with the real browser manually then we have to use the @BuggyWebDriver annotation.

@rbri

rbri commented May 3, 2024

Copy link
Copy Markdown
Member

And for this one, your previous test have FF & FF_ESR both produce no additional request

Yes; something strage is going on here with FF - just trying to write test that make clear what secret is hidden there.
Maybe i can commit some more tests later today (or in the night at your location :-)

@rbri

rbri commented May 3, 2024

Copy link
Copy Markdown
Member

@yamamoto-kanoko @duonglaiquang @atnak

have commited my updated tests and your fixes (without merging this). Looks like your fixes are fixing my tests - always a good sign :-)
Please have a look, if there is something missing from my tests - otherwise i like to close this and wait for your next PR ;-)

Thanks a lot and have a nice weekend....

@duonglaiquang
duonglaiquang deleted the kay_location_reload branch May 3, 2024 13:57
@yamamoto-kanoko

Copy link
Copy Markdown
Author

@rbri @duonglaiquang @atnak
Thank you for checking from various perspectives !
This was my first time creating a PR as a contributor, and it was a very valuable experience!
Thank you so much! Have a great weekend :-)

@rbri

rbri commented May 3, 2024

Copy link
Copy Markdown
Member

made a first 4.2.0-SNAPSHOT available - have fun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants