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.

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

mercurial