tor-browser

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

test_notification_box_02.html (2326B)


      1 <!-- This Source Code Form is subject to the terms of the Mozilla Public
      2   - License, v. 2.0. If a copy of the MPL was not distributed with this
      3   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
      4 <!DOCTYPE HTML>
      5 <html>
      6 <!--
      7 Test for Notification Box. The test is checking:
      8 * Using custom callback in a notification
      9 -->
     10 <head>
     11  <meta charset="utf-8">
     12  <title>Notification Box</title>
     13  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     14  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
     15 </head>
     16 <body>
     17 <pre id="test">
     18 <script src="head.js" type="application/javascript"></script>
     19 <script type="application/javascript">
     20 
     21 'use strict'
     22 
     23 window.onload = async function () {
     24  try {
     25    const ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom");
     26    const React = browserRequire("devtools/client/shared/vendor/react");
     27    const { NotificationBox, PriorityLevels } = browserRequire("devtools/client/shared/components/NotificationBox");
     28 
     29    // Test rendering
     30    const boxElement = React.createElement(NotificationBox);
     31    const notificationBox = TestUtils.renderIntoDocument(boxElement);
     32    const notificationNode = ReactDOM.findDOMNode(notificationBox);
     33 
     34    let callbackExecuted = false;
     35 
     36    // Append a notification.
     37    notificationBox.appendNotification(
     38      "Info message",
     39      "id1",
     40      null,
     41      PriorityLevels.PRIORITY_INFO_LOW,
     42      undefined,
     43      (reason) => {
     44        callbackExecuted = true;
     45        is(reason, "removed", "The reason must be expected string");
     46      }
     47    );
     48 
     49    is(TestUtils.scryRenderedDOMComponentsWithClass(
     50      notificationBox, "notification").length, 1,
     51      "There must be one notification");
     52 
     53    const closeButton = notificationNode.querySelector(
     54      ".messageCloseButton");
     55 
     56    // Click the close button to close the notification.
     57    TestUtils.Simulate.click(closeButton);
     58 
     59    is(TestUtils.scryRenderedDOMComponentsWithClass(
     60      notificationBox, "notification").length, 0,
     61      "The notification box must be empty now");
     62 
     63    ok(callbackExecuted, "Event callback must be executed.");
     64  } catch(e) {
     65    ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
     66  } finally {
     67    SimpleTest.finish();
     68  }
     69 };
     70 </script>
     71 </pre>
     72 </body>
     73 </html>