Skip to content

Commit

Permalink
[WebDriver BiDi] Fix issue with memory cache in Chrome (#49904)
Browse files Browse the repository at this point in the history
* [WebDriver BiDi] Fix issue with cached JS

* Update comments

* Apply suggestions from code review

Co-authored-by: Alex Rudenko <OrKoN@users.noreply.github.com>

---------

Co-authored-by: Alex Rudenko <OrKoN@users.noreply.github.com>
  • Loading branch information
2 people authored and sadym-chromium committed Jan 14, 2025
1 parent 6229098 commit d3c99ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,12 @@ async def test_page_with_cached_script_javascript(
wait="complete",
)

# Expect three events, one for the document and two for script javascript files.
# Expect two or three events, one for the document and the rest for javascript files.
# If the browser uses memory caching there may be only single request for the javascript files,
# see issue https://github.com/whatwg/html/issues/6110.
wait = AsyncPoll(bidi_session, timeout=2)
await wait.until(lambda _: len(events) >= 7)
assert len(events) == 7
await wait.until(lambda _: len(events) >= 6)
assert len(events) >= 6

# Assert only cached events after reload.
cached_events = events[4:]
Expand All @@ -386,10 +388,11 @@ async def test_page_with_cached_script_javascript(
cached_events[1],
expected_request={"method": "GET", "url": cached_script_js_url},
)
assert_before_request_sent_event(
cached_events[2],
expected_request={"method": "GET", "url": cached_script_js_url},
)
if len(events) > 6:
assert_before_request_sent_event(
cached_events[2],
expected_request={"method": "GET", "url": cached_script_js_url},
)


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,12 @@ async def test_page_with_cached_script_javascript(
wait="complete",
)

# Expect three events, one for the document and two for script javascript files.
# Expect two or three events, one for the document and the rest for javascript files.
# If the browser uses memory caching there may be only single request for the javascript files,
# see issue https://github.com/whatwg/html/issues/6110.
wait = AsyncPoll(bidi_session, timeout=2)
await wait.until(lambda _: len(events) >= 7)
assert len(events) == 7
await wait.until(lambda _: len(events) >= 6)
assert len(events) >= 6

# Assert only cached events after reload.
cached_events = events[4:]
Expand All @@ -548,11 +550,12 @@ async def test_page_with_cached_script_javascript(
expected_request={"method": "GET", "url": cached_script_js_url},
expected_response={"url": cached_script_js_url, "fromCache": True},
)
assert_response_event(
cached_events[2],
expected_request={"method": "GET", "url": cached_script_js_url},
expected_response={"url": cached_script_js_url, "fromCache": True},
)
if len(events) > 6:
assert_response_event(
cached_events[2],
expected_request={"method": "GET", "url": cached_script_js_url},
expected_response={"url": cached_script_js_url, "fromCache": True},
)


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ async def test_cached_revalidate(
)




@pytest.mark.asyncio
async def test_page_with_cached_link_stylesheet(
bidi_session,
Expand Down Expand Up @@ -542,10 +540,12 @@ async def test_page_with_cached_script_javascript(
wait="complete",
)

# Expect three events, one for the document and two for script javascript files.
# Expect two or three events, one for the document and the rest for javascript files.
# If the browser uses memory caching there may be only single request for the javascript files,
# see issue https://github.com/whatwg/html/issues/6110.
wait = AsyncPoll(bidi_session, timeout=2)
await wait.until(lambda _: len(events) >= 7)
assert len(events) == 7
await wait.until(lambda _: len(events) >= 6)
assert len(events) >= 6

# Assert only cached events after reload.
cached_events = events[4:]
Expand All @@ -560,11 +560,12 @@ async def test_page_with_cached_script_javascript(
expected_request={"method": "GET", "url": cached_script_js_url},
expected_response={"url": cached_script_js_url, "fromCache": True},
)
assert_response_event(
cached_events[2],
expected_request={"method": "GET", "url": cached_script_js_url},
expected_response={"url": cached_script_js_url, "fromCache": True},
)
if len(events) > 6:
assert_response_event(
cached_events[2],
expected_request={"method": "GET", "url": cached_script_js_url},
expected_response={"url": cached_script_js_url, "fromCache": True},
)


@pytest.mark.asyncio
Expand Down

0 comments on commit d3c99ae

Please sign in to comment.