summaryrefslogtreecommitdiffstats
path: root/netwerk/test/browser/browser_test_offline_tab.js
blob: bf60b4f46247d2b98cc3990cfb2117e89deff004 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_set_tab_offline() {
  await BrowserTestUtils.withNewTab("https://example.com", async browser => {
    // Set the tab to offline
    gBrowser.selectedBrowser.browsingContext.forceOffline = true;

    await SpecialPowers.spawn(browser, [], async () => {
      try {
        await content.fetch("https://example.com/empty.html");
        ok(false, "Should not load since tab is offline");
      } catch (err) {
        is(err.name, "TypeError", "Should fail since tab is offline");
      }
    });
  });
});

add_task(async function test_set_tab_online() {
  await BrowserTestUtils.withNewTab("https://example.com", async browser => {
    // Set the tab to online
    gBrowser.selectedBrowser.browsingContext.forceOffline = false;

    await SpecialPowers.spawn(browser, [], async () => {
      try {
        await content.fetch("https://example.com/empty.html");
        ok(true, "Should load since tab is online");
      } catch (err) {
        ok(false, "Should not fail since tab is online");
      }
    });
  });
});