File size: 4,650 Bytes
065fee7 |
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
"""Test default selectors."""
from .. import util
class TestDefault(util.TestCase):
"""Test default selectors."""
def test_default(self):
"""Test default."""
markup = """
<form>
<input type="radio" name="season" id="spring">
<label for="spring">Spring</label>
<input type="radio" name="season" id="summer" checked>
<label for="summer">Summer</label>
<input type="radio" name="season" id="fall">
<label for="fall">Fall</label>
<input type="radio" name="season" id="winter">
<label for="winter">Winter</label>
<select id="pet-select">
<option value="">--Please choose an option--</option>
<option id="dog" value="dog">Dog</option>
<option id="cat" value="cat">Cat</option>
<option id="hamster" value="hamster" selected>Hamster</option>
<option id="parrot" value="parrot">Parrot</option>
<option id="spider" value="spider">Spider</option>
<option id="goldfish" value="goldfish">Goldfish</option>
</select>
<input type="checkbox" name="enable" id="enable" checked>
<label for="enable">Enable</label>
<button type="button">
not default
</button>
<button id="d1" type="submit">
default1
</button>
<button id="d2" type="submit">
default2
</button>
</form>
<form>
<div>
<button id="d3" type="submit">
default3
</button>
</div>
<button id="d4" type="submit">
default4
</button>
</form>
<button id="d5" type="submit">
default4
</button>
"""
self.assert_selector(
markup,
":default",
['summer', 'd1', 'd3', 'hamster', 'enable'],
flags=util.HTML
)
def test_iframe(self):
"""Test with `iframe`."""
markup = """
<html>
<body>
<form>
<button id="d1" type="submit">default1</button>
</form>
<form>
<iframe>
<html>
<body>
<button id="d2" type="submit">default2</button>
</body>
</html>
</iframe>
<button id="d3" type="submit">default3</button>
</form>
<iframe>
<html>
<body>
<form>
<button id="d4" type="submit">default4</button>
</form>
</body>
</html>
</iframe>
</body>
</html>
"""
self.assert_selector(
markup,
":default",
['d1', 'd3', 'd4'],
flags=util.PYHTML
)
def test_nested_form(self):
"""
Test nested form.
This is technically invalid use of forms, but browsers will generally evaluate first in the nested forms.
"""
markup = """
<form>
<form>
<button id="d1" type="submit">
button1
</button>
</form>
<button id="d2" type="submit">
button2
</button>
</form>
"""
self.assert_selector(
markup,
":default",
['d1'],
flags=util.HTML
)
def test_default_cached(self):
"""
Test that we use the cached "default".
For the sake of coverage, we will do this impractical select
to ensure we reuse the cached default.
"""
markup = """
<form>
<form>
<button id="d1" type="submit">
button1
</button>
</form>
<button id="d2" type="submit">
button2
</button>
</form>
"""
self.assert_selector(
markup,
":default:default",
['d1'],
flags=util.HTML
)
def test_nested_form_fail(self):
"""
Test that the search for elements will bail after the first nested form.
You shouldn't nest forms, but if you do, when a parent form encounters a nested form,
we will bail evaluation like browsers do. We should see button 1 getting found for nested
form, but button 2 will not be found for parent form.
"""
markup = """
<form>
<form>
<span>what</span>
</form>
<button id="d2" type="submit">
button2
</button>
</form>
"""
self.assert_selector(
markup,
":default",
[],
flags=util.HTML
)
|