summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/webdriver/support/context.py
blob: 910b202075e3c9a46b3fcf085ad43f0b0c9f653e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import contextlib


def set_context(session, context):
    session.send_session_command("POST", "moz/context", {"context": context})


@contextlib.contextmanager
def using_context(session, context):
    orig_context = session.send_session_command("GET", "moz/context")
    needs_change = context != orig_context

    if needs_change:
        set_context(session, context)

    try:
        yield
    finally:
        if needs_change:
            set_context(session, orig_context)