tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_user_suggestion_box.html (3271B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4    <title>Bug 1665057 - Add www button on https-only error page</title>
      5    <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 <script class="testbody" type="text/javascript">
     10 "use strict";
     11 
     12 /*
     13 * Description of the test:
     14 * We send a top-level request to a http-page in https-only mode
     15 * The page has a bad certificate and can't be updated so the error page appears
     16 * If there is a secure connection possible to www the suggestion-box on the error page
     17 * should appear and have a link to that secure www-page
     18 * if the original-pagerequest already has a www or there is no secure www connection
     19 * the suggestion box should not appear
     20 */
     21 
     22 SimpleTest.requestFlakyTimeout("We need to wait for the HTTPS-Only error page to appear and for the additional 'www' request to provide a suggestion.");
     23 SimpleTest.requestLongerTimeout(10);
     24 
     25 // urls of server locations with bad cert -> https-only should display error page
     26 const KICK_OFF_REQUEST_WITH_SUGGESTION = "http://suggestion-example.com";
     27 const KICK_OFF_REQUEST_WITHOUT_SUGGESTION = "http://no-suggestion-example.com";
     28 
     29 // l10n ids to compare html to
     30 const ERROR_PAGE_L10N_ID = "about-httpsonly-title-alert";
     31 const SUGGESTION_BOX_L10N_ID = "about-httpsonly-suggestion-box-www-text";
     32 
     33 // the error page needs to be build and a background https://www request needs to happen
     34 // we use 4 seconds to make sure these requests did happen.
     35 function resolveAfter4Seconds() {
     36  return new Promise(resolve => {
     37    setTimeout(() => {
     38      resolve();
     39    }, 4000);
     40  });
     41 }
     42 
     43 async function runTests(aMessage) {
     44  let errorPageL10nId = "about-httpsonly-title-alert";
     45  let suggestionBoxL10nId = "about-httpsonly-suggestion-box-www-text";
     46 
     47  let innerHTML = content.document.body.innerHTML;
     48 
     49  if (aMessage === "with_suggestion") {
     50    // test if the page with suggestion shows the error page and the suggestion box
     51    ok(innerHTML.includes(errorPageL10nId), "the error page should be shown.");
     52    ok(innerHTML.includes(suggestionBoxL10nId), "the suggestion box should be shown.");
     53  } else if (aMessage === "without_suggestion") {
     54    // test if the page without suggestion shows the error page but not the suggestion box
     55    ok(innerHTML.includes(errorPageL10nId), "the error page should be shown.");
     56    ok(!innerHTML.includes(suggestionBoxL10nId), "the suggestion box should not be shown.");
     57  } else {
     58    ok(false, "we should never get here");
     59  }
     60 }
     61 
     62 add_task(async function() {
     63  await SpecialPowers.pushPrefEnv({ set: [
     64    ["dom.security.https_only_mode", true],
     65    ["dom.security.https_only_mode_send_http_background_request", false],
     66    ["dom.security.https_only_mode_error_page_user_suggestions", true],
     67  ]});
     68  let testWinSuggestion = window.open(KICK_OFF_REQUEST_WITH_SUGGESTION, "_blank");
     69  let testWinWithoutSuggestion = window.open(KICK_OFF_REQUEST_WITHOUT_SUGGESTION, "_blank");
     70 
     71  await resolveAfter4Seconds();
     72 
     73  await SpecialPowers.spawn(testWinSuggestion, ["with_suggestion"], runTests);
     74  await SpecialPowers.spawn(testWinWithoutSuggestion, ["without_suggestion"], runTests);
     75 
     76  testWinSuggestion.close();
     77  testWinWithoutSuggestion.close();
     78 });
     79 </script>
     80 </body>
     81 </html>