-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wdspec] Add tests for "network.setCacheBypass" command.
Differential Revision: https://phabricator.services.mozilla.com/D215077 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1901032 gecko-commit: 7ee29f7d8432f7f4c9d9452f18ea62d28a566e41 gecko-reviewers: webdriver-reviewers, jdescottes
- Loading branch information
Showing
5 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest_asyncio | ||
|
||
from .. import RESPONSE_COMPLETED_EVENT | ||
|
||
|
||
@pytest_asyncio.fixture | ||
async def is_request_from_cache( | ||
wait_for_event, fetch, wait_for_future_safe, top_context | ||
): | ||
async def is_request_from_cache(url, context=top_context): | ||
on_response_completed = wait_for_event(RESPONSE_COMPLETED_EVENT) | ||
await fetch(url, context=context) | ||
event = await wait_for_future_safe(on_response_completed) | ||
|
||
return event["response"]["fromCache"] | ||
|
||
return is_request_from_cache |
99 changes: 99 additions & 0 deletions
99
webdriver/tests/bidi/network/set_cache_bypass/contexts_tentative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import pytest | ||
import random | ||
|
||
from .. import RESPONSE_COMPLETED_EVENT | ||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
async def test_one_context( | ||
bidi_session, | ||
setup_network_test, | ||
top_context, | ||
new_tab, | ||
url, | ||
inline, | ||
is_request_from_cache, | ||
): | ||
await bidi_session.browsing_context.navigate( | ||
context=new_tab["context"], | ||
url=inline("foo"), | ||
wait="complete", | ||
) | ||
|
||
await setup_network_test( | ||
events=[RESPONSE_COMPLETED_EVENT], | ||
contexts=[top_context["context"], new_tab["context"]], | ||
) | ||
|
||
cached_url = url( | ||
f"/webdriver/tests/support/http_handlers/cached.py?status=200&nocache={random.random()}" | ||
) | ||
|
||
# The first request/response is used to fill the browser cache, | ||
# so we expect fromCache to be False here. | ||
assert await is_request_from_cache(url=cached_url, context=top_context) is False | ||
|
||
# In the second tab it will request from cache. | ||
assert await is_request_from_cache(url=cached_url, context=new_tab) is True | ||
|
||
# Disable cache only in one context. | ||
await bidi_session.network.set_cache_bypass( | ||
bypass=True, contexts=[new_tab["context"]] | ||
) | ||
|
||
assert await is_request_from_cache(url=cached_url, context=top_context) is True | ||
assert await is_request_from_cache(url=cached_url, context=new_tab) is False | ||
|
||
# Reset to default behavior. | ||
await bidi_session.network.set_cache_bypass( | ||
bypass=False, contexts=[new_tab["context"]] | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("type_hint", ["tab", "window"]) | ||
async def test_new_context( | ||
bidi_session, | ||
setup_network_test, | ||
top_context, | ||
url, | ||
inline, | ||
is_request_from_cache, | ||
type_hint, | ||
): | ||
await setup_network_test(events=[RESPONSE_COMPLETED_EVENT]) | ||
|
||
cached_url = url( | ||
f"/webdriver/tests/support/http_handlers/cached.py?status=200&nocache={random.random()}" | ||
) | ||
|
||
# The first request/response is used to fill the browser cache, | ||
# so we expect fromCache to be False here. | ||
assert await is_request_from_cache(url=cached_url) is False | ||
|
||
# In the second tab it will request from cache. | ||
assert await is_request_from_cache(url=cached_url) is True | ||
|
||
# Disable cache only in one context. | ||
await bidi_session.network.set_cache_bypass( | ||
bypass=True, contexts=[top_context["context"]] | ||
) | ||
|
||
assert await is_request_from_cache(url=cached_url, context=top_context) is False | ||
|
||
# Create a new tab. | ||
new_context = await bidi_session.browsing_context.create(type_hint=type_hint) | ||
|
||
await bidi_session.browsing_context.navigate( | ||
context=new_context["context"], | ||
url=inline("<div>foo</div>"), | ||
wait="complete", | ||
) | ||
|
||
# Make sure that the new context still has cache enabled. | ||
assert await is_request_from_cache(cached_url, context=new_context) is True | ||
|
||
# Reset to default behavior. | ||
await bidi_session.network.set_cache_bypass( | ||
bypass=False, contexts=[top_context["context"]] | ||
) |
32 changes: 32 additions & 0 deletions
32
webdriver/tests/bidi/network/set_cache_bypass/invalid_tentative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
import webdriver.bidi.error as error | ||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
@pytest.mark.parametrize("value", [None, "foo", 42, {}, []]) | ||
async def test_params_bypass_invalid_type(bidi_session, value): | ||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.network.set_cache_bypass(bypass=value) | ||
|
||
|
||
@pytest.mark.parametrize("value", ["foo", 42, False, {}]) | ||
async def test_params_contexts_invalid_type(bidi_session, value): | ||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.network.set_cache_bypass(bypass=True, contexts=value) | ||
|
||
|
||
async def test_params_contexts_invalid_value_empty_array(bidi_session): | ||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.network.set_cache_bypass(bypass=True, contexts=[]) | ||
|
||
|
||
@pytest.mark.parametrize("value", [None, 42, False, {}, []]) | ||
async def test_params_contexts_invalid_array_element_type(bidi_session, value): | ||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.network.set_cache_bypass(bypass=True, contexts=[value]) | ||
|
||
|
||
async def test_params_contexts_invalid_array_element_value(bidi_session): | ||
with pytest.raises(error.NoSuchFrameException): | ||
await bidi_session.network.set_cache_bypass(bypass=True, contexts=["foo"]) |
68 changes: 68 additions & 0 deletions
68
webdriver/tests/bidi/network/set_cache_bypass/set_cache_bypass_tentative.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import pytest | ||
import random | ||
|
||
from .. import RESPONSE_COMPLETED_EVENT | ||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
async def test_set_cache_bypass( | ||
bidi_session, setup_network_test, url, is_request_from_cache | ||
): | ||
await setup_network_test(events=[RESPONSE_COMPLETED_EVENT]) | ||
|
||
cached_url = url( | ||
f"/webdriver/tests/support/http_handlers/cached.py?status=200&nocache={random.random()}" | ||
) | ||
|
||
# The first request/response is used to fill the browser cache, | ||
# so we expect fromCache to be False here. | ||
assert await is_request_from_cache(cached_url) is False | ||
|
||
# The second request for the same URL has to be read from the local cache. | ||
assert await is_request_from_cache(cached_url) is True | ||
|
||
await bidi_session.network.set_cache_bypass(bypass=True) | ||
|
||
assert await is_request_from_cache(cached_url) is False | ||
|
||
await bidi_session.network.set_cache_bypass(bypass=False) | ||
|
||
assert await is_request_from_cache(cached_url) is True | ||
|
||
|
||
@pytest.mark.parametrize("type_hint", ["tab", "window"]) | ||
async def test_new_context( | ||
bidi_session, setup_network_test, url, inline, is_request_from_cache, type_hint | ||
): | ||
await setup_network_test(events=[RESPONSE_COMPLETED_EVENT]) | ||
|
||
cached_url = url( | ||
f"/webdriver/tests/support/http_handlers/cached.py?status=200&nocache={random.random()}" | ||
) | ||
|
||
# The first request/response is used to fill the browser cache, | ||
# so we expect fromCache to be False here. | ||
assert await is_request_from_cache(cached_url) is False | ||
|
||
# The second request for the same URL has to be read from the local cache. | ||
assert await is_request_from_cache(cached_url) is True | ||
|
||
await bidi_session.network.set_cache_bypass(bypass=True) | ||
|
||
assert await is_request_from_cache(cached_url) is False | ||
|
||
# Create a new tab. | ||
new_context = await bidi_session.browsing_context.create(type_hint=type_hint) | ||
|
||
await bidi_session.browsing_context.navigate( | ||
context=new_context["context"], | ||
url=inline("<div>foo</div>"), | ||
wait="complete", | ||
) | ||
|
||
# Make sure that the new context still has cache disabled. | ||
assert await is_request_from_cache(cached_url, context=new_context) is False | ||
|
||
# Reset to default behavior. | ||
await bidi_session.network.set_cache_bypass(bypass=False) |