summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/the-window-object/open-close/resources/tokenization-noopener-noreferrer.js
blob: a9d42e26dea16afa9743d31aa7b72f3f09e46e68 (plain)
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
function booleanTests(feature) {
  const windowURL = 'resources/close-self.html';
  // Tests for how windows features are tokenized into 'name', 'value'
  // window features separators are ASCII whitespace, '=' and  ','

  const featureUpper = feature.toUpperCase(),
        featureSplitBegin = feature.slice(0, 2),
        featureSplitEnd = feature.slice(2),
        featureMixedCase = featureSplitBegin.toUpperCase() + featureSplitEnd;
        featureMixedCase2 = featureSplitBegin + featureSplitEnd.toUpperCase();

  test (t => {
    // Tokenizing `name`: initial window features separators are ignored
    // Each of these variants should tokenize to (`${feature}`, '')
    [
      ` ${feature}`,
      `=${feature}`,
      `,,${feature}`,
      `,=, ${feature}`,
      `\n=${feature}=`,
      `\t${feature}`,
      `\r,,,=${feature}`,
      `\u000C${feature}`
    ].forEach(variant => {
      const win = window.open(windowURL, "", variant);
      assert_equals(win, null, `"${variant}" should activate feature "${feature}"`);
    });
  }, `Tokenization of "${feature}" should skip window features separators before feature`);

  test (t => {
    // Tokenizing `name`: lowercase conversion
    // Each of these variants should tokenize as feature (`${feature}`, '')
    // except where indicated
    // Note also that `value` is lowercased during tokenization
    [
      `${featureUpper}`,
      `${featureMixedCase}`,
      `  ${featureMixedCase2}`,
      `=${featureUpper}`,
      `${featureUpper}=1`,
      `${featureUpper}=1`,
      `${featureUpper}=yes`,
      `${feature}=YES`,
    ].forEach(variant => {
      const win = window.open(windowURL, '', variant);
      assert_equals(win, null, `"${variant}" should activate feature "${feature}"`);
    });
  }, `Feature "${feature}" should be converted to ASCII lowercase`);

  test (t => {
    // After `name` has been collected, ignore any window features separators until '='
    // except ',' OR a non-window-features-separator — break in those cases
    // i.e. ignore whitespace until '=' unless a ',' is encountered first
    // Each of these variants should tokenize as feature ('noopener', '')
    [
      `${feature}`,
      ` ${feature}\r`,
      `${feature}\n =`,
      `${feature},`,
      `${feature}  =,`,
      `, ${feature}   =`,
      `${feature},=`,
      `${feature} foo`,
      `foo ${feature}=1`,
      `foo=\u000Cbar\u000C${feature}`
    ].forEach(variant => {
      const win = window.open(windowURL, '', variant);
      assert_equals(win, null, `"${variant}" should activate feature "${feature}"`);
    });
  }, `After "${feature}", tokenization should skip window features separators that are not "=" or ","`);

  test (t => {
    // After initial '=', tokenizing should ignore all separators except ','
    // before collecting `value`
    // Each of these variants should tokenize as feature ('noopener', '')
    // Except where indicated
    [
      `${feature}=  yes`,
      `${feature}==,`,
      `${feature}=\n ,`,
      `${feature} = \t ,`,
      `${feature}\n=\r 1,`,
      `${feature}=,yes`,
      `${feature}= yes=,`,
      `${feature} = \u000Cyes`
    ].forEach(variant => {
      const win = window.open(windowURL, '', variant);
      assert_equals(win, null, `"${variant}" should activate feature "${feature}"`);
    });
  }, `Tokenizing "${feature}" should ignore window feature separators except "," after initial "=" and before value`);

  test (t => {
    // Tokenizing `value` should collect any non-separator code points until first separator
    [
      `${feature}=1`,
      `${feature}=yes`,
      `${feature} = yes ,`,
      `${feature}=\nyes  ,`,
      `${feature}=yes yes`,
      `${feature}=yes\ts`,
      `${feature}==`,
      `${feature}=1\n,`,
      `==${feature}===`,
      `${feature}==\u000C`
    ].forEach(variant => {
      const win = window.open(windowURL, '', variant);
      assert_equals(win, null, `"${variant}" should set "${feature}"`);
    });
  }, `Tokenizing "${feature}" should read characters until first window feature separator as \`value\``);

  test (t => {
    [
      `${feature}=1`,
      `${feature}=2`,
      `${feature}=12345`,
      `${feature}=1.5`,
      `${feature}=-1`,
    ].forEach(variant => {
      const win = window.open(windowURL, '', variant);
      assert_equals(win, null, `"${variant}" should activate feature "${feature}"`);
    });
  }, 'Integer values other than 0 should activate the feature');

  test (t => {
    [
      `${feature}=0`,
      `${feature}=0.5`,
      `${feature}=error`,
    ].forEach(variant => {
      const win = window.open(windowURL, '', variant);
      assert_not_equals(win, null, `"${variant}" should NOT activate feature "${feature}"`);
    });
  }, `Integer value of 0 should not activate "${feature}"`);

  test (t => {
    [
      `-${feature}`,
      `${featureUpper}RRR`,
      `${featureMixedCase}R`,
      `${featureSplitBegin}_${featureSplitEnd}`,
      ` ${featureSplitBegin} ${featureSplitEnd}`,
      `${featureSplitBegin}\n${featureSplitEnd}`,
      `${featureSplitBegin},${featureSplitEnd}`,
      `\0${feature}`,
      `${feature}\u0000=yes`,
      `foo=\u000C${feature}`
    ].forEach(variant => {
      const win = window.open(windowURL, '', variant);
      assert_not_equals(win, null, `"${variant}" should NOT activate feature "${feature}"`);
    });
  }, `Invalid feature names should not tokenize as "${feature}"`);
}