DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
import json
import pytest
import types

from tests.support.inline import inline
from tests.support.asserts import assert_error, assert_success
from tests.support.wait import wait

alert_doc = inline("<script>window.alert()</script>")
frame_doc = inline("<p>frame")
one_frame_doc = inline("<iframe src='%s'></iframe>" % frame_doc)
two_frames_doc = inline("<iframe src='%s'></iframe>" % one_frame_doc)


# TODO(ato): 7.1 Get


def test_get_current_url_no_browsing_context(session, create_window):
    # 7.2 step 1
    session.window_handle = create_window()
    session.close()

    result = session.transport.send("GET", "session/%s/url" % session.session_id)

    assert_error(result, "no such window")


def test_get_current_url_alert_prompt(session):
    # 7.2 step 2
    session.url = alert_doc

    result = session.transport.send("GET", "session/%s/url" % session.session_id)

    assert_error(result, "unexpected alert open")

def test_get_current_url_matches_location(session):
    # 7.2 step 3
    url = session.execute_script("return window.location.href")
    assert session.url == url

def test_get_current_url_payload(session):
    # 7.2 step 4-5
    session.start()

    result = session.transport.send("GET", "session/%s/url" % session.session_id)

    assert result.status == 200
    assert isinstance(result.body["value"], basestring)

def test_get_current_url_special_pages(session):
    session.url = "about:blank"

    result = session.transport.send("GET", "session/%s/url" % session.session_id)

    assert_success(result, "about:blank")

# TODO(ato): This test requires modification to pass on Windows
def test_get_current_url_file_protocol(session):
    # tests that the browsing context remains the same
    # when navigated privileged documents
    session.url = "file:///"

    result = session.transport.send("GET", "session/%s/url" % session.session_id)

    assert_success(result, "file:///")

# TODO(ato): Test for http:// and https:// protocols.
# We need to expose a fixture for accessing
# documents served by wptserve in order to test this.

def test_set_malformed_url(session):
    result = session.transport.send("POST",
                                    "session/%s/url" % session.session_id,
                                    {"url": "foo"})

    assert_error(result, "invalid argument")

def test_get_current_url_after_modified_location(session):
    start = session.transport.send("GET", "session/%s/url" % session.session_id)
    session.execute_script("window.location.href = 'about:blank#wd_test_modification'")
    wait(session,
         lambda s: s.transport.send("GET", "session/%s/url" % session.session_id) != start.body["value"],
         "URL did not change")
    result = session.transport.send("GET", "session/%s/url" % session.session_id)

    assert_success(result, "about:blank#wd_test_modification")

def test_get_current_url_nested_browsing_context(session, create_frame):
    session.url = "about:blank#wd_from_within_frame"
    session.switch_frame(create_frame())

    result = session.transport.send("GET", "session/%s/url" % session.session_id)

    assert_success(result, "about:blank#wd_from_within_frame")

def test_get_current_url_nested_browsing_contexts(session):
    session.url = two_frames_doc
    top_level_url = session.url

    outer_frame = session.find.css("iframe", all=False)
    session.switch_frame(outer_frame)

    inner_frame = session.find.css("iframe", all=False)
    session.switch_frame(inner_frame)

    assert session.url == top_level_url