browser/components/tabview/test/browser_tabview_bug656778.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 function test() {
     5   waitForExplicitFinish();
     7   registerCleanupFunction(function () {
     8     Services.prefs.clearUserPref(TabView.PREF_FIRST_RUN);
     9     Services.prefs.clearUserPref(TabView.PREF_STARTUP_PAGE);
    10     Services.prefs.clearUserPref(TabView.PREF_RESTORE_ENABLED_ONCE);
    11   });
    13   let assertBoolPref = function (pref, value) {
    14     is(Services.prefs.getBoolPref(pref), value, pref + " is " + value);
    15   };
    17   let assertIntPref = function (pref, value) {
    18     is(Services.prefs.getIntPref(pref), value, pref + " is " + value);
    19   };
    21   let setPreferences = function (startupPage, firstRun, enabledOnce) {
    22     Services.prefs.setIntPref(TabView.PREF_STARTUP_PAGE, startupPage);
    23     Services.prefs.setBoolPref(TabView.PREF_FIRST_RUN, firstRun);
    24     Services.prefs.setBoolPref(TabView.PREF_RESTORE_ENABLED_ONCE, enabledOnce);
    25   };
    27   let assertPreferences = function (startupPage, firstRun, enabledOnce) {
    28     assertIntPref(TabView.PREF_STARTUP_PAGE, startupPage);
    29     assertBoolPref(TabView.PREF_FIRST_RUN, firstRun);
    30     assertBoolPref(TabView.PREF_RESTORE_ENABLED_ONCE, enabledOnce);
    31   };
    33   let assertNotificationBannerVisible = function (win) {
    34     let cw = win.TabView.getContentWindow();
    35     is(cw.iQ(".banner").length, 1, "notification banner is visible");
    36   };
    38   let assertNotificationBannerNotVisible = function (win) {
    39     let cw = win.TabView.getContentWindow();
    40     is(cw.iQ(".banner").length, 0, "notification banner is not visible");
    41   };
    43   let next = function () {
    44     if (tests.length == 0) {
    45       waitForFocus(finish);
    46       return;
    47     }
    49     let test = tests.shift();
    50     info("running " + test.name + "...");
    51     test();
    52   };
    54   // State:
    55   // Panorama was already used before (firstUseExperienced = true) but session
    56   // restore is deactivated. We did not automatically enable SR, yet.
    57   //
    58   // Expected result:
    59   // When entering Panorma session restore will be enabled and a notification
    60   // banner is shown.
    61   let test1 = function test1() {
    62     setPreferences(1, true, false);
    64     newWindowWithTabView(function (win) {
    65       assertNotificationBannerVisible(win);
    66       assertPreferences(3, true, true);
    68       win.close();
    69       next();
    70     });
    71   };
    73   // State:
    74   // Panorama has not been used before (firstUseExperienced = false) and session
    75   // restore is deactivated. We did not automatically enable SR, yet. That state
    76   // is equal to starting the browser the first time.
    77   //
    78   // Expected result:
    79   // When entering Panorma nothing happens. When we detect that Panorama is
    80   // really used (firstUseExperienced = true) we notify that session restore
    81   // is now enabled.
    82   let test2 = function test2() {
    83     setPreferences(1, false, false);
    85     newWindowWithTabView(function (win) {
    86       assertNotificationBannerNotVisible(win);
    87       assertPreferences(1, false, false);
    89       win.TabView.firstUseExperienced = true;
    91       assertNotificationBannerVisible(win);
    92       assertPreferences(3, true, true);
    94       win.close();
    95       next();
    96     });
    97   };
    99   // State:
   100   // Panorama was already used before (firstUseExperienced = true) and session
   101   // restore is activated. We did not automatically enable SR, yet.
   102   //
   103   // Expected result:
   104   // When entering Panorama nothing happens because session store is already
   105   // enabled so there's no reason to notify.
   106   let test3 = function test3() {
   107     setPreferences(3, true, false);
   109     newWindowWithTabView(function (win) {
   110       assertNotificationBannerNotVisible(win);
   111       assertPreferences(3, true, true);
   113       win.close();
   114       next();
   115     });
   116   };
   118   // State:
   119   // Panorama was already used before (firstUseExperienced = true) and session
   120   // restore has been automatically activated.
   121   //
   122   // Expected result:
   123   // When entering Panorama nothing happens.
   124   let test4 = function test4() {
   125     setPreferences(3, true, true);
   127     newWindowWithTabView(function (win) {
   128       assertNotificationBannerNotVisible(win);
   129       assertPreferences(3, true, true);
   131       win.close();
   132       next();
   133     });
   134   };
   136   // State:
   137   // Panorama was already used before (firstUseExperienced = true) and session
   138   // restore has been automatically activated. Session store was afterwards
   139   // disabled by the user so we won't touch that again.
   140   //
   141   // Expected result:
   142   // When entering Panorama nothing happens and we didn't enable session restore.
   143   let test5 = function test5() {
   144     setPreferences(1, true, true);
   146     newWindowWithTabView(function (win) {
   147       assertNotificationBannerNotVisible(win);
   148       assertPreferences(1, true, true);
   150       win.close();
   151       next();
   152     });
   153   };
   155   let tests = [test1, test2, test3, test4, test5];
   156   next();
   157 }

mercurial