tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_1914327_media_qdnd_vn.py (1751B)


      1 import pytest
      2 from webdriver.bidi.error import UnknownErrorException
      3 
      4 URL = "https://media.qdnd.vn/phim-truyen-thong-tai-lieu/nhung-hinh-anh-dau-tien-trong-du-an-phim-ve-bo-doi-cu-ho-nam-2024-59811"
      5 PLAY_BUTTON_CSS = "#hpcplayer .media-icon-play"
      6 ERROR_MSG_CSS = ".jw-error-msg.jw-reset"
      7 EXPECTED_TYPE = "application/vnd.apple.mpegurl"
      8 
      9 
     10 async def calls_canPlayType(client, type):
     11    await client.make_preload_script(
     12        """
     13      const proto = HTMLMediaElement.prototype;
     14      const def = Object.getOwnPropertyDescriptor(proto, "canPlayType");
     15      const orig = def.value;
     16      window.__cpts = [];
     17      def.value = function(type) {
     18        window.__cpts.push(type);
     19        return orig.apply(this, arguments);
     20      }
     21      Object.defineProperty(proto, "canPlayType", def);
     22    """
     23    )
     24    try:
     25        await client.navigate(URL, no_skip=True)
     26    except UnknownErrorException:
     27        pass
     28    play, err = client.await_first_element_of(
     29        [
     30            client.css(PLAY_BUTTON_CSS),
     31            client.css(ERROR_MSG_CSS),
     32        ],
     33        is_displayed=True,
     34    )
     35    await client.stall(2)
     36    if play:
     37        play.click()
     38    await client.stall(2)
     39    return client.execute_script(
     40        """
     41      return window.__cpts.includes(arguments[0]);
     42      """,
     43        type,
     44    )
     45 
     46 
     47 @pytest.mark.only_platforms("android")
     48 @pytest.mark.actual_platform_required
     49 @pytest.mark.asyncio
     50 @pytest.mark.with_interventions
     51 async def test_enabled(client):
     52    assert await calls_canPlayType(client, EXPECTED_TYPE)
     53 
     54 
     55 @pytest.mark.only_platforms("android")
     56 @pytest.mark.actual_platform_required
     57 @pytest.mark.asyncio
     58 @pytest.mark.without_interventions
     59 async def test_disabled(client):
     60    assert not await calls_canPlayType(client, EXPECTED_TYPE)