summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/sync/browser_fxa_web_channel.html
blob: 927b3523e9913e454029e4b0334ac0daec603d32 (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
153
154
155
156
157
158
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>fxa_web_channel_test</title>
</head>
<body>
<script>
  var webChannelId = "account_updates_test";

  window.onload = function() {
    var testName = window.location.search.replace(/^\?/, "");

    switch (testName) {
      case "profile_change":
        test_profile_change();
        break;
      case "login":
        test_login();
        break;
      case "can_link_account":
        test_can_link_account();
        break;
      case "logout":
        test_logout();
        break;
      case "delete":
        test_delete();
        break;
      case "firefox_view":
        test_firefox_view();
        break;
    }
  };

  function test_profile_change() {
    var event = new window.CustomEvent("WebChannelMessageToChrome", {
      detail: JSON.stringify({
        id: webChannelId,
        message: {
          command: "profile:change",
          data: {
            uid: "abc123",
          },
        },
      }),
    });

    window.dispatchEvent(event);
  }

  function test_login() {
    var event = new window.CustomEvent("WebChannelMessageToChrome", {
      detail: JSON.stringify({
        id: webChannelId,
        message: {
          command: "fxaccounts:login",
          data: {
            authAt: Date.now(),
            email: "testuser@testuser.com",
            keyFetchToken: "key_fetch_token",
            sessionToken: "session_token",
            uid: "uid",
            unwrapBKey: "unwrap_b_key",
            verified: true,
          },
          messageId: 1,
        },
      }),
    });

    window.dispatchEvent(event);
  }

  function test_can_link_account() {
    window.addEventListener("WebChannelMessageToContent", function(e) {
      // echo any responses from the browser back to the tests on the
      // fxaccounts_webchannel_response_echo WebChannel. The tests are
      // listening for events and do the appropriate checks.
      var event = new window.CustomEvent("WebChannelMessageToChrome", {
        detail: JSON.stringify({
          id: "fxaccounts_webchannel_response_echo",
          message: e.detail.message,
        }),
      });

      window.dispatchEvent(event);
    }, true);

    var event = new window.CustomEvent("WebChannelMessageToChrome", {
      detail: JSON.stringify({
        id: webChannelId,
        message: {
          command: "fxaccounts:can_link_account",
          data: {
            email: "testuser@testuser.com",
          },
          messageId: 2,
        },
      }),
    });

    window.dispatchEvent(event);
  }

  function test_logout() {
    var event = new window.CustomEvent("WebChannelMessageToChrome", {
      detail: JSON.stringify({
        id: webChannelId,
        message: {
          command: "fxaccounts:logout",
          data: {
            uid: "uid",
          },
          messageId: 3,
        },
      }),
    });

    window.dispatchEvent(event);
  }

  function test_delete() {
    var event = new window.CustomEvent("WebChannelMessageToChrome", {
      detail: JSON.stringify({
        id: webChannelId,
        message: {
          command: "fxaccounts:delete",
          data: {
            uid: "uid",
          },
          messageId: 4,
        },
      }),
    });

    window.dispatchEvent(event);
  }

  function test_firefox_view() {
    var event = new window.CustomEvent("WebChannelMessageToChrome", {
      detail: JSON.stringify({
        id: webChannelId,
        message: {
          command: "fxaccounts:firefox_view",
          data: {
            uid: "uid",
          },
          messageId: 5,
        },
      }),
    });

    window.dispatchEvent(event);
  }
</script>
</body>
</html>