1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug656778.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,157 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +function test() { 1.8 + waitForExplicitFinish(); 1.9 + 1.10 + registerCleanupFunction(function () { 1.11 + Services.prefs.clearUserPref(TabView.PREF_FIRST_RUN); 1.12 + Services.prefs.clearUserPref(TabView.PREF_STARTUP_PAGE); 1.13 + Services.prefs.clearUserPref(TabView.PREF_RESTORE_ENABLED_ONCE); 1.14 + }); 1.15 + 1.16 + let assertBoolPref = function (pref, value) { 1.17 + is(Services.prefs.getBoolPref(pref), value, pref + " is " + value); 1.18 + }; 1.19 + 1.20 + let assertIntPref = function (pref, value) { 1.21 + is(Services.prefs.getIntPref(pref), value, pref + " is " + value); 1.22 + }; 1.23 + 1.24 + let setPreferences = function (startupPage, firstRun, enabledOnce) { 1.25 + Services.prefs.setIntPref(TabView.PREF_STARTUP_PAGE, startupPage); 1.26 + Services.prefs.setBoolPref(TabView.PREF_FIRST_RUN, firstRun); 1.27 + Services.prefs.setBoolPref(TabView.PREF_RESTORE_ENABLED_ONCE, enabledOnce); 1.28 + }; 1.29 + 1.30 + let assertPreferences = function (startupPage, firstRun, enabledOnce) { 1.31 + assertIntPref(TabView.PREF_STARTUP_PAGE, startupPage); 1.32 + assertBoolPref(TabView.PREF_FIRST_RUN, firstRun); 1.33 + assertBoolPref(TabView.PREF_RESTORE_ENABLED_ONCE, enabledOnce); 1.34 + }; 1.35 + 1.36 + let assertNotificationBannerVisible = function (win) { 1.37 + let cw = win.TabView.getContentWindow(); 1.38 + is(cw.iQ(".banner").length, 1, "notification banner is visible"); 1.39 + }; 1.40 + 1.41 + let assertNotificationBannerNotVisible = function (win) { 1.42 + let cw = win.TabView.getContentWindow(); 1.43 + is(cw.iQ(".banner").length, 0, "notification banner is not visible"); 1.44 + }; 1.45 + 1.46 + let next = function () { 1.47 + if (tests.length == 0) { 1.48 + waitForFocus(finish); 1.49 + return; 1.50 + } 1.51 + 1.52 + let test = tests.shift(); 1.53 + info("running " + test.name + "..."); 1.54 + test(); 1.55 + }; 1.56 + 1.57 + // State: 1.58 + // Panorama was already used before (firstUseExperienced = true) but session 1.59 + // restore is deactivated. We did not automatically enable SR, yet. 1.60 + // 1.61 + // Expected result: 1.62 + // When entering Panorma session restore will be enabled and a notification 1.63 + // banner is shown. 1.64 + let test1 = function test1() { 1.65 + setPreferences(1, true, false); 1.66 + 1.67 + newWindowWithTabView(function (win) { 1.68 + assertNotificationBannerVisible(win); 1.69 + assertPreferences(3, true, true); 1.70 + 1.71 + win.close(); 1.72 + next(); 1.73 + }); 1.74 + }; 1.75 + 1.76 + // State: 1.77 + // Panorama has not been used before (firstUseExperienced = false) and session 1.78 + // restore is deactivated. We did not automatically enable SR, yet. That state 1.79 + // is equal to starting the browser the first time. 1.80 + // 1.81 + // Expected result: 1.82 + // When entering Panorma nothing happens. When we detect that Panorama is 1.83 + // really used (firstUseExperienced = true) we notify that session restore 1.84 + // is now enabled. 1.85 + let test2 = function test2() { 1.86 + setPreferences(1, false, false); 1.87 + 1.88 + newWindowWithTabView(function (win) { 1.89 + assertNotificationBannerNotVisible(win); 1.90 + assertPreferences(1, false, false); 1.91 + 1.92 + win.TabView.firstUseExperienced = true; 1.93 + 1.94 + assertNotificationBannerVisible(win); 1.95 + assertPreferences(3, true, true); 1.96 + 1.97 + win.close(); 1.98 + next(); 1.99 + }); 1.100 + }; 1.101 + 1.102 + // State: 1.103 + // Panorama was already used before (firstUseExperienced = true) and session 1.104 + // restore is activated. We did not automatically enable SR, yet. 1.105 + // 1.106 + // Expected result: 1.107 + // When entering Panorama nothing happens because session store is already 1.108 + // enabled so there's no reason to notify. 1.109 + let test3 = function test3() { 1.110 + setPreferences(3, true, false); 1.111 + 1.112 + newWindowWithTabView(function (win) { 1.113 + assertNotificationBannerNotVisible(win); 1.114 + assertPreferences(3, true, true); 1.115 + 1.116 + win.close(); 1.117 + next(); 1.118 + }); 1.119 + }; 1.120 + 1.121 + // State: 1.122 + // Panorama was already used before (firstUseExperienced = true) and session 1.123 + // restore has been automatically activated. 1.124 + // 1.125 + // Expected result: 1.126 + // When entering Panorama nothing happens. 1.127 + let test4 = function test4() { 1.128 + setPreferences(3, true, true); 1.129 + 1.130 + newWindowWithTabView(function (win) { 1.131 + assertNotificationBannerNotVisible(win); 1.132 + assertPreferences(3, true, true); 1.133 + 1.134 + win.close(); 1.135 + next(); 1.136 + }); 1.137 + }; 1.138 + 1.139 + // State: 1.140 + // Panorama was already used before (firstUseExperienced = true) and session 1.141 + // restore has been automatically activated. Session store was afterwards 1.142 + // disabled by the user so we won't touch that again. 1.143 + // 1.144 + // Expected result: 1.145 + // When entering Panorama nothing happens and we didn't enable session restore. 1.146 + let test5 = function test5() { 1.147 + setPreferences(1, true, true); 1.148 + 1.149 + newWindowWithTabView(function (win) { 1.150 + assertNotificationBannerNotVisible(win); 1.151 + assertPreferences(1, true, true); 1.152 + 1.153 + win.close(); 1.154 + next(); 1.155 + }); 1.156 + }; 1.157 + 1.158 + let tests = [test1, test2, test3, test4, test5]; 1.159 + next(); 1.160 +}