File: navigation.sub.html

package info (click to toggle)
firefox 145.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,528 kB
  • sloc: cpp: 7,594,999; javascript: 6,459,658; ansic: 3,752,909; python: 1,403,455; xml: 629,809; asm: 438,679; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (162 lines) | stat: -rw-r--r-- 5,286 bytes parent folder | download | duplicates (25)
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
<!doctype html>
<meta charset={{GET[encoding]}}> <!-- ends up as <meta charset> by default which is windows-1252 -->
<meta name=variant content="?encoding=windows-1252">
<meta name=variant content="?encoding=x-cp1251">
<meta name=variant content="?encoding=utf8">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/utils.js"></script>
<link rel=help href=https://html.spec.whatwg.org/multipage/#following-hyperlinks>
<link rel=help href=https://html.spec.whatwg.org/multipage/#hyperlink-auditing>
<link rel=help href=https://html.spec.whatwg.org/multipage/#attr-meta-http-equiv-refresh>
<div id=log></div>
<script>
function expected(encoding) {
  return {
    "UTF-8": "%C3%BF",
    "windows-1251": "%26%23255%3B",
    "windows-1252": "%FF"
  }[encoding];
}
var encoding = document.characterSet;
var blank = 'resources/blank.py?encoding=' + encoding;
var stash_put = 'resources/stash.py?q=\u00FF&action=put&id=';
var stash_take = 'resources/stash.py?action=take&id=';
var input_url_html = 'resources/resource.py?q=\u00FF&encoding=' + encoding + '&type=html';
var expected_current = expected(encoding);
var expected_utf8 = expected('UTF-8');

function assert_ends_with(input, endsWith) {
  assert_true(input.endsWith(endsWith), input + " did not end with " + endsWith);
}


function poll_for_stash(test_obj, uuid, expected) {
  var start = new Date();
  var poll = test_obj.step_func(function () {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', stash_take + uuid);
    xhr.onload = test_obj.step_func(function(e) {
      if (xhr.response == "") {
        if (new Date() - start > 10000) {
          // If we set the status to TIMEOUT here we avoid a race between the
          // page and the test timing out
          test_obj.force_timeout();
        }
        test_obj.step_timeout(poll, 200);
      } else {
        assert_equals(xhr.response, expected);
        test_obj.done();
      }
    });
    xhr.send();
  })
  test_obj.step_timeout(poll, 200);
}

function setup_navigation(elm, iframe, id, test_obj) {
  iframe.name = id;
  elm.target = id;
  elm.setAttribute('href', input_url_html);
  document.body.appendChild(iframe);
  document.body.appendChild(elm);
  test_obj.add_cleanup(function() {
    document.body.removeChild(iframe);
    document.body.removeChild(elm);
  });
}

// follow hyperlink
function test_follow_link(tag) {
  async_test(function() {
    var elm = document.createElement(tag);
    var iframe = document.createElement('iframe');
    setup_navigation(elm, iframe, 'test_follow_link_'+tag, this);
    iframe.onload = this.step_func_done(function() { // when the page navigated to has loaded
      assert_equals(iframe.contentDocument.body.textContent, expected_current);
    });
    // follow the hyperlink
    elm.click();
    // check that navigation succeeded by ...??? XXX
  }, 'follow hyperlink <'+tag+' href>');
}

'a, area'.split(', ').forEach(function(str) {
  test_follow_link(str);
});

async_test(function() {
  const iframe = document.createElement('iframe');
  iframe.name = 'test_dont_follow_link';
  document.body.appendChild(iframe);

  const link = document.createElement('link');
  link.target = iframe.name;
  link.setAttribute('href', input_url_html);
  document.body.appendChild(link);

  const anchor = document.createElement('a');
  anchor.target = iframe.name;
  anchor.setAttribute('href', blank);
  document.body.appendChild(anchor);

  this.add_cleanup(function() {
    iframe.remove();
    link.remove();
    anchor.remove();
  });

  iframe.onload = this.step_func_done(() => {
    assert_equals(
      iframe.contentDocument.location.pathname,
      '/html/infrastructure/urls/resolving-urls/query-encoding/resources/blank.py',
      'The <a> navigation should occur instead of the <link> navigation.');
  });

  anchor.click();
  link.click();
}, `don't follow hyperlink <link href>`);

// follow hyperlink with ping attribute
function test_follow_link_ping(tag) {
  async_test(function() {
    var uuid = token();
    var elm = document.createElement(tag);
    // check if ping is supported
    assert_true('ping' in elm, 'ping not supported');
    elm.setAttribute('ping', stash_put + uuid);
    var iframe = document.createElement('iframe');
    setup_navigation(elm, iframe, 'test_follow_link_ping_'+tag, this);
    // follow the hyperlink
    elm.click();
    // check that navigation succeeded by ...??? XXX
    // check that the right URL was requested for the ping
    poll_for_stash(this, uuid, expected_current);
  }, 'hyperlink auditing <'+tag+' ping>');
}

'a, area'.split(', ').forEach(function(str) {
  test_follow_link_ping(str);
});

// navigating with meta refresh
async_test(function() {
  var iframe = document.createElement('iframe');
  iframe.src = blank;
  document.body.appendChild(iframe);
  this.add_cleanup(function() {
    document.body.removeChild(iframe);
  });
  iframe.onload = this.step_func_done(function() {
    var doc = iframe.contentDocument;
    var got = doc.body.textContent;
    if (got == '') {
      doc.write('<meta http-equiv=refresh content="0; URL='+input_url_html+'">REFRESH');
      doc.close();
      return;
    }
    assert_equals(got, expected_current);
  });
}, 'meta refresh');

</script>