|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 waitForExplicitFinish(); |
|
6 |
|
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 }); |
|
12 |
|
13 let assertBoolPref = function (pref, value) { |
|
14 is(Services.prefs.getBoolPref(pref), value, pref + " is " + value); |
|
15 }; |
|
16 |
|
17 let assertIntPref = function (pref, value) { |
|
18 is(Services.prefs.getIntPref(pref), value, pref + " is " + value); |
|
19 }; |
|
20 |
|
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 }; |
|
26 |
|
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 }; |
|
32 |
|
33 let assertNotificationBannerVisible = function (win) { |
|
34 let cw = win.TabView.getContentWindow(); |
|
35 is(cw.iQ(".banner").length, 1, "notification banner is visible"); |
|
36 }; |
|
37 |
|
38 let assertNotificationBannerNotVisible = function (win) { |
|
39 let cw = win.TabView.getContentWindow(); |
|
40 is(cw.iQ(".banner").length, 0, "notification banner is not visible"); |
|
41 }; |
|
42 |
|
43 let next = function () { |
|
44 if (tests.length == 0) { |
|
45 waitForFocus(finish); |
|
46 return; |
|
47 } |
|
48 |
|
49 let test = tests.shift(); |
|
50 info("running " + test.name + "..."); |
|
51 test(); |
|
52 }; |
|
53 |
|
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); |
|
63 |
|
64 newWindowWithTabView(function (win) { |
|
65 assertNotificationBannerVisible(win); |
|
66 assertPreferences(3, true, true); |
|
67 |
|
68 win.close(); |
|
69 next(); |
|
70 }); |
|
71 }; |
|
72 |
|
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); |
|
84 |
|
85 newWindowWithTabView(function (win) { |
|
86 assertNotificationBannerNotVisible(win); |
|
87 assertPreferences(1, false, false); |
|
88 |
|
89 win.TabView.firstUseExperienced = true; |
|
90 |
|
91 assertNotificationBannerVisible(win); |
|
92 assertPreferences(3, true, true); |
|
93 |
|
94 win.close(); |
|
95 next(); |
|
96 }); |
|
97 }; |
|
98 |
|
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); |
|
108 |
|
109 newWindowWithTabView(function (win) { |
|
110 assertNotificationBannerNotVisible(win); |
|
111 assertPreferences(3, true, true); |
|
112 |
|
113 win.close(); |
|
114 next(); |
|
115 }); |
|
116 }; |
|
117 |
|
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); |
|
126 |
|
127 newWindowWithTabView(function (win) { |
|
128 assertNotificationBannerNotVisible(win); |
|
129 assertPreferences(3, true, true); |
|
130 |
|
131 win.close(); |
|
132 next(); |
|
133 }); |
|
134 }; |
|
135 |
|
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); |
|
145 |
|
146 newWindowWithTabView(function (win) { |
|
147 assertNotificationBannerNotVisible(win); |
|
148 assertPreferences(1, true, true); |
|
149 |
|
150 win.close(); |
|
151 next(); |
|
152 }); |
|
153 }; |
|
154 |
|
155 let tests = [test1, test2, test3, test4, test5]; |
|
156 next(); |
|
157 } |