tor-browser

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

browser_UITour_observe.js (2589B)


      1 "use strict";
      2 
      3 var gTestTab;
      4 var gContentAPI;
      5 
      6 function test() {
      7  requestLongerTimeout(2);
      8  UITourTest();
      9 }
     10 
     11 var tests = [
     12  function test_no_params(done) {
     13    function listener(event, params) {
     14      is(event, "test-event-1", "Correct event name");
     15      ok(!params, "No param object");
     16      gContentAPI.observe(null);
     17      done();
     18    }
     19 
     20    gContentAPI.observe(listener, () => {
     21      UITour.notify("test-event-1");
     22    });
     23  },
     24  function test_param_string(done) {
     25    function listener(event, params) {
     26      is(event, "test-event-2", "Correct event name");
     27      is(params, "a param", "Correct param string");
     28      gContentAPI.observe(null);
     29      done();
     30    }
     31 
     32    gContentAPI.observe(listener, () => {
     33      UITour.notify("test-event-2", "a param");
     34    });
     35  },
     36  function test_param_object(done) {
     37    function listener(event, params) {
     38      is(event, "test-event-3", "Correct event name");
     39      is(
     40        JSON.stringify(params),
     41        JSON.stringify({ key: "something" }),
     42        "Correct param object"
     43      );
     44      gContentAPI.observe(null);
     45      done();
     46    }
     47 
     48    gContentAPI.observe(listener, () => {
     49      UITour.notify("test-event-3", { key: "something" });
     50    });
     51  },
     52  function test_background_tab(done) {
     53    function listener(event, params) {
     54      is(event, "test-event-background-1", "Correct event name");
     55      ok(!params, "No param object");
     56      gContentAPI.observe(null);
     57      gBrowser.removeCurrentTab();
     58      done();
     59    }
     60 
     61    gContentAPI.observe(listener, () => {
     62      gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:blank");
     63      isnot(
     64        gBrowser.selectedTab,
     65        gTestTab,
     66        "Make sure the selected tab changed"
     67      );
     68 
     69      UITour.notify("test-event-background-1");
     70    });
     71  },
     72  // Make sure the tab isn't torn down when switching back to the tour one.
     73  function test_background_then_foreground_tab(done) {
     74    let blankTab = null;
     75    function listener(event, params) {
     76      is(event, "test-event-4", "Correct event name");
     77      ok(!params, "No param object");
     78      gContentAPI.observe(null);
     79      gBrowser.removeTab(blankTab);
     80      done();
     81    }
     82 
     83    gContentAPI.observe(listener, () => {
     84      blankTab = gBrowser.selectedTab = BrowserTestUtils.addTab(
     85        gBrowser,
     86        "about:blank"
     87      );
     88      isnot(
     89        gBrowser.selectedTab,
     90        gTestTab,
     91        "Make sure the selected tab changed"
     92      );
     93      gBrowser.selectedTab = gTestTab;
     94      is(gBrowser.selectedTab, gTestTab, "Switch back to the test tab");
     95 
     96      UITour.notify("test-event-4");
     97    });
     98  },
     99 ];