tor-browser

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

browser_fxa_web_channel.html (3711B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>fxa_web_channel_test</title>
      6 </head>
      7 <body>
      8 <script>
      9  var webChannelId = "account_updates_test";
     10 
     11  window.onload = function() {
     12    var testName = window.location.search.replace(/^\?/, "");
     13 
     14    switch (testName) {
     15      case "profile_change":
     16        test_profile_change();
     17        break;
     18      case "login":
     19        test_login();
     20        break;
     21      case "can_link_account":
     22        test_can_link_account();
     23        break;
     24      case "logout":
     25        test_logout();
     26        break;
     27      case "delete":
     28        test_delete();
     29        break;
     30      case "firefox_view":
     31        test_firefox_view();
     32        break;
     33    }
     34  };
     35 
     36  function test_profile_change() {
     37    var event = new window.CustomEvent("WebChannelMessageToChrome", {
     38      detail: JSON.stringify({
     39        id: webChannelId,
     40        message: {
     41          command: "profile:change",
     42          data: {
     43            uid: "abc123",
     44          },
     45        },
     46      }),
     47    });
     48 
     49    window.dispatchEvent(event);
     50  }
     51 
     52  function test_login() {
     53    var event = new window.CustomEvent("WebChannelMessageToChrome", {
     54      detail: JSON.stringify({
     55        id: webChannelId,
     56        message: {
     57          command: "fxaccounts:login",
     58          data: {
     59            authAt: Date.now(),
     60            email: "testuser@testuser.com",
     61            keyFetchToken: "key_fetch_token",
     62            sessionToken: "session_token",
     63            uid: "uid",
     64            unwrapBKey: "unwrap_b_key",
     65            verified: true,
     66          },
     67          messageId: 1,
     68        },
     69      }),
     70    });
     71 
     72    window.dispatchEvent(event);
     73  }
     74 
     75  function test_can_link_account() {
     76    window.addEventListener("WebChannelMessageToContent", function(e) {
     77      // echo any responses from the browser back to the tests on the
     78      // fxaccounts_webchannel_response_echo WebChannel. The tests are
     79      // listening for events and do the appropriate checks.
     80      var event = new window.CustomEvent("WebChannelMessageToChrome", {
     81        detail: JSON.stringify({
     82          id: "fxaccounts_webchannel_response_echo",
     83          message: e.detail.message,
     84        }),
     85      });
     86 
     87      window.dispatchEvent(event);
     88    }, true);
     89 
     90    var event = new window.CustomEvent("WebChannelMessageToChrome", {
     91      detail: JSON.stringify({
     92        id: webChannelId,
     93        message: {
     94          command: "fxaccounts:can_link_account",
     95          data: {
     96            uid: "uid",
     97            email: "testuser@testuser.com",
     98          },
     99          messageId: 2,
    100        },
    101      }),
    102    });
    103 
    104    window.dispatchEvent(event);
    105  }
    106 
    107  function test_logout() {
    108    var event = new window.CustomEvent("WebChannelMessageToChrome", {
    109      detail: JSON.stringify({
    110        id: webChannelId,
    111        message: {
    112          command: "fxaccounts:logout",
    113          data: {
    114            uid: "uid",
    115          },
    116          messageId: 3,
    117        },
    118      }),
    119    });
    120 
    121    window.dispatchEvent(event);
    122  }
    123 
    124  function test_delete() {
    125    var event = new window.CustomEvent("WebChannelMessageToChrome", {
    126      detail: JSON.stringify({
    127        id: webChannelId,
    128        message: {
    129          command: "fxaccounts:delete",
    130          data: {
    131            uid: "uid",
    132          },
    133          messageId: 4,
    134        },
    135      }),
    136    });
    137 
    138    window.dispatchEvent(event);
    139  }
    140 
    141  function test_firefox_view() {
    142    var event = new window.CustomEvent("WebChannelMessageToChrome", {
    143      detail: JSON.stringify({
    144        id: webChannelId,
    145        message: {
    146          command: "fxaccounts:firefox_view",
    147          data: {
    148            uid: "uid",
    149          },
    150          messageId: 5,
    151        },
    152      }),
    153    });
    154 
    155    window.dispatchEvent(event);
    156  }
    157 </script>
    158 </body>
    159 </html>