michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: registerCleanupFunction(function () { michael@0: Services.prefs.clearUserPref(TabView.PREF_FIRST_RUN); michael@0: Services.prefs.clearUserPref(TabView.PREF_STARTUP_PAGE); michael@0: Services.prefs.clearUserPref(TabView.PREF_RESTORE_ENABLED_ONCE); michael@0: }); michael@0: michael@0: let assertBoolPref = function (pref, value) { michael@0: is(Services.prefs.getBoolPref(pref), value, pref + " is " + value); michael@0: }; michael@0: michael@0: let assertIntPref = function (pref, value) { michael@0: is(Services.prefs.getIntPref(pref), value, pref + " is " + value); michael@0: }; michael@0: michael@0: let setPreferences = function (startupPage, firstRun, enabledOnce) { michael@0: Services.prefs.setIntPref(TabView.PREF_STARTUP_PAGE, startupPage); michael@0: Services.prefs.setBoolPref(TabView.PREF_FIRST_RUN, firstRun); michael@0: Services.prefs.setBoolPref(TabView.PREF_RESTORE_ENABLED_ONCE, enabledOnce); michael@0: }; michael@0: michael@0: let assertPreferences = function (startupPage, firstRun, enabledOnce) { michael@0: assertIntPref(TabView.PREF_STARTUP_PAGE, startupPage); michael@0: assertBoolPref(TabView.PREF_FIRST_RUN, firstRun); michael@0: assertBoolPref(TabView.PREF_RESTORE_ENABLED_ONCE, enabledOnce); michael@0: }; michael@0: michael@0: let assertNotificationBannerVisible = function (win) { michael@0: let cw = win.TabView.getContentWindow(); michael@0: is(cw.iQ(".banner").length, 1, "notification banner is visible"); michael@0: }; michael@0: michael@0: let assertNotificationBannerNotVisible = function (win) { michael@0: let cw = win.TabView.getContentWindow(); michael@0: is(cw.iQ(".banner").length, 0, "notification banner is not visible"); michael@0: }; michael@0: michael@0: let next = function () { michael@0: if (tests.length == 0) { michael@0: waitForFocus(finish); michael@0: return; michael@0: } michael@0: michael@0: let test = tests.shift(); michael@0: info("running " + test.name + "..."); michael@0: test(); michael@0: }; michael@0: michael@0: // State: michael@0: // Panorama was already used before (firstUseExperienced = true) but session michael@0: // restore is deactivated. We did not automatically enable SR, yet. michael@0: // michael@0: // Expected result: michael@0: // When entering Panorma session restore will be enabled and a notification michael@0: // banner is shown. michael@0: let test1 = function test1() { michael@0: setPreferences(1, true, false); michael@0: michael@0: newWindowWithTabView(function (win) { michael@0: assertNotificationBannerVisible(win); michael@0: assertPreferences(3, true, true); michael@0: michael@0: win.close(); michael@0: next(); michael@0: }); michael@0: }; michael@0: michael@0: // State: michael@0: // Panorama has not been used before (firstUseExperienced = false) and session michael@0: // restore is deactivated. We did not automatically enable SR, yet. That state michael@0: // is equal to starting the browser the first time. michael@0: // michael@0: // Expected result: michael@0: // When entering Panorma nothing happens. When we detect that Panorama is michael@0: // really used (firstUseExperienced = true) we notify that session restore michael@0: // is now enabled. michael@0: let test2 = function test2() { michael@0: setPreferences(1, false, false); michael@0: michael@0: newWindowWithTabView(function (win) { michael@0: assertNotificationBannerNotVisible(win); michael@0: assertPreferences(1, false, false); michael@0: michael@0: win.TabView.firstUseExperienced = true; michael@0: michael@0: assertNotificationBannerVisible(win); michael@0: assertPreferences(3, true, true); michael@0: michael@0: win.close(); michael@0: next(); michael@0: }); michael@0: }; michael@0: michael@0: // State: michael@0: // Panorama was already used before (firstUseExperienced = true) and session michael@0: // restore is activated. We did not automatically enable SR, yet. michael@0: // michael@0: // Expected result: michael@0: // When entering Panorama nothing happens because session store is already michael@0: // enabled so there's no reason to notify. michael@0: let test3 = function test3() { michael@0: setPreferences(3, true, false); michael@0: michael@0: newWindowWithTabView(function (win) { michael@0: assertNotificationBannerNotVisible(win); michael@0: assertPreferences(3, true, true); michael@0: michael@0: win.close(); michael@0: next(); michael@0: }); michael@0: }; michael@0: michael@0: // State: michael@0: // Panorama was already used before (firstUseExperienced = true) and session michael@0: // restore has been automatically activated. michael@0: // michael@0: // Expected result: michael@0: // When entering Panorama nothing happens. michael@0: let test4 = function test4() { michael@0: setPreferences(3, true, true); michael@0: michael@0: newWindowWithTabView(function (win) { michael@0: assertNotificationBannerNotVisible(win); michael@0: assertPreferences(3, true, true); michael@0: michael@0: win.close(); michael@0: next(); michael@0: }); michael@0: }; michael@0: michael@0: // State: michael@0: // Panorama was already used before (firstUseExperienced = true) and session michael@0: // restore has been automatically activated. Session store was afterwards michael@0: // disabled by the user so we won't touch that again. michael@0: // michael@0: // Expected result: michael@0: // When entering Panorama nothing happens and we didn't enable session restore. michael@0: let test5 = function test5() { michael@0: setPreferences(1, true, true); michael@0: michael@0: newWindowWithTabView(function (win) { michael@0: assertNotificationBannerNotVisible(win); michael@0: assertPreferences(1, true, true); michael@0: michael@0: win.close(); michael@0: next(); michael@0: }); michael@0: }; michael@0: michael@0: let tests = [test1, test2, test3, test4, test5]; michael@0: next(); michael@0: }