|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
|
6 Cu.import("resource://services-sync/main.js"); |
|
7 |
|
8 let gTests = [ { |
|
9 desc: "Makes sure the progress bar appears if firstSync pref is set", |
|
10 setup: function () { |
|
11 Services.prefs.setCharPref("services.sync.firstSync", "newAccount"); |
|
12 }, |
|
13 run: function () { |
|
14 let doc = gBrowser.selectedTab.linkedBrowser.contentDocument; |
|
15 let progressBar = doc.getElementById("uploadProgressBar"); |
|
16 |
|
17 let win = doc.defaultView; |
|
18 isnot(win.getComputedStyle(progressBar).display, "none", "progress bar should be visible"); |
|
19 executeSoon(runNextTest); |
|
20 } |
|
21 }, |
|
22 |
|
23 { |
|
24 desc: "Makes sure the progress bar is hidden if firstSync pref is not set", |
|
25 setup: function () { |
|
26 Services.prefs.clearUserPref("services.sync.firstSync"); |
|
27 is(Services.prefs.getPrefType("services.sync.firstSync"), |
|
28 Ci.nsIPrefBranch.PREF_INVALID, "pref DNE" ); |
|
29 }, |
|
30 run: function () { |
|
31 let doc = gBrowser.selectedTab.linkedBrowser.contentDocument; |
|
32 let progressBar = doc.getElementById("uploadProgressBar"); |
|
33 |
|
34 let win = doc.defaultView; |
|
35 is(win.getComputedStyle(progressBar).display, "none", |
|
36 "progress bar should not be visible"); |
|
37 executeSoon(runNextTest); |
|
38 } |
|
39 }, |
|
40 { |
|
41 desc: "Makes sure the observer updates are reflected in the progress bar", |
|
42 setup: function () { |
|
43 }, |
|
44 run: function () { |
|
45 let doc = gBrowser.selectedTab.linkedBrowser.contentDocument; |
|
46 let progressBar = doc.getElementById("uploadProgressBar"); |
|
47 |
|
48 Services.obs.notifyObservers(null, "weave:engine:sync:finish", null); |
|
49 Services.obs.notifyObservers(null, "weave:engine:sync:error", null); |
|
50 |
|
51 let received = progressBar.getAttribute("value"); |
|
52 |
|
53 is(received, 2, "progress bar received correct notifications"); |
|
54 executeSoon(runNextTest); |
|
55 } |
|
56 }, |
|
57 { |
|
58 desc: "Close button should close tab", |
|
59 setup: function (){ |
|
60 }, |
|
61 run: function () { |
|
62 function onTabClosed() { |
|
63 ok(true, "received TabClose notification"); |
|
64 gBrowser.tabContainer.removeEventListener("TabClose", onTabClosed, false); |
|
65 executeSoon(runNextTest); |
|
66 } |
|
67 let doc = gBrowser.selectedTab.linkedBrowser.contentDocument; |
|
68 let button = doc.getElementById('closeButton'); |
|
69 let window = doc.defaultView; |
|
70 gBrowser.tabContainer.addEventListener("TabClose", onTabClosed, false); |
|
71 EventUtils.sendMouseEvent({type: "click"}, button, window); |
|
72 } |
|
73 }, |
|
74 ]; |
|
75 |
|
76 function test () { |
|
77 waitForExplicitFinish(); |
|
78 executeSoon(runNextTest); |
|
79 } |
|
80 |
|
81 function runNextTest() |
|
82 { |
|
83 while (gBrowser.tabs.length > 1) { |
|
84 gBrowser.removeCurrentTab(); |
|
85 } |
|
86 |
|
87 if (gTests.length) { |
|
88 let test = gTests.shift(); |
|
89 info(test.desc); |
|
90 test.setup(); |
|
91 let tab = gBrowser.selectedTab = gBrowser.addTab("about:sync-progress"); |
|
92 tab.linkedBrowser.addEventListener("load", function (event) { |
|
93 tab.linkedBrowser.removeEventListener("load", arguments.callee, true); |
|
94 // Some part of the page is populated on load, so enqueue on it. |
|
95 executeSoon(test.run); |
|
96 }, true); |
|
97 } |
|
98 else { |
|
99 finish(); |
|
100 } |
|
101 } |
|
102 |