1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_aboutSyncProgress.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; 1.9 +Cu.import("resource://services-sync/main.js"); 1.10 + 1.11 +let gTests = [ { 1.12 + desc: "Makes sure the progress bar appears if firstSync pref is set", 1.13 + setup: function () { 1.14 + Services.prefs.setCharPref("services.sync.firstSync", "newAccount"); 1.15 + }, 1.16 + run: function () { 1.17 + let doc = gBrowser.selectedTab.linkedBrowser.contentDocument; 1.18 + let progressBar = doc.getElementById("uploadProgressBar"); 1.19 + 1.20 + let win = doc.defaultView; 1.21 + isnot(win.getComputedStyle(progressBar).display, "none", "progress bar should be visible"); 1.22 + executeSoon(runNextTest); 1.23 + } 1.24 +}, 1.25 + 1.26 +{ 1.27 + desc: "Makes sure the progress bar is hidden if firstSync pref is not set", 1.28 + setup: function () { 1.29 + Services.prefs.clearUserPref("services.sync.firstSync"); 1.30 + is(Services.prefs.getPrefType("services.sync.firstSync"), 1.31 + Ci.nsIPrefBranch.PREF_INVALID, "pref DNE" ); 1.32 + }, 1.33 + run: function () { 1.34 + let doc = gBrowser.selectedTab.linkedBrowser.contentDocument; 1.35 + let progressBar = doc.getElementById("uploadProgressBar"); 1.36 + 1.37 + let win = doc.defaultView; 1.38 + is(win.getComputedStyle(progressBar).display, "none", 1.39 + "progress bar should not be visible"); 1.40 + executeSoon(runNextTest); 1.41 + } 1.42 +}, 1.43 +{ 1.44 + desc: "Makes sure the observer updates are reflected in the progress bar", 1.45 + setup: function () { 1.46 + }, 1.47 + run: function () { 1.48 + let doc = gBrowser.selectedTab.linkedBrowser.contentDocument; 1.49 + let progressBar = doc.getElementById("uploadProgressBar"); 1.50 + 1.51 + Services.obs.notifyObservers(null, "weave:engine:sync:finish", null); 1.52 + Services.obs.notifyObservers(null, "weave:engine:sync:error", null); 1.53 + 1.54 + let received = progressBar.getAttribute("value"); 1.55 + 1.56 + is(received, 2, "progress bar received correct notifications"); 1.57 + executeSoon(runNextTest); 1.58 + } 1.59 +}, 1.60 +{ 1.61 + desc: "Close button should close tab", 1.62 + setup: function (){ 1.63 + }, 1.64 + run: function () { 1.65 + function onTabClosed() { 1.66 + ok(true, "received TabClose notification"); 1.67 + gBrowser.tabContainer.removeEventListener("TabClose", onTabClosed, false); 1.68 + executeSoon(runNextTest); 1.69 + } 1.70 + let doc = gBrowser.selectedTab.linkedBrowser.contentDocument; 1.71 + let button = doc.getElementById('closeButton'); 1.72 + let window = doc.defaultView; 1.73 + gBrowser.tabContainer.addEventListener("TabClose", onTabClosed, false); 1.74 + EventUtils.sendMouseEvent({type: "click"}, button, window); 1.75 + } 1.76 +}, 1.77 +]; 1.78 + 1.79 +function test () { 1.80 + waitForExplicitFinish(); 1.81 + executeSoon(runNextTest); 1.82 +} 1.83 + 1.84 +function runNextTest() 1.85 +{ 1.86 + while (gBrowser.tabs.length > 1) { 1.87 + gBrowser.removeCurrentTab(); 1.88 + } 1.89 + 1.90 + if (gTests.length) { 1.91 + let test = gTests.shift(); 1.92 + info(test.desc); 1.93 + test.setup(); 1.94 + let tab = gBrowser.selectedTab = gBrowser.addTab("about:sync-progress"); 1.95 + tab.linkedBrowser.addEventListener("load", function (event) { 1.96 + tab.linkedBrowser.removeEventListener("load", arguments.callee, true); 1.97 + // Some part of the page is populated on load, so enqueue on it. 1.98 + executeSoon(test.run); 1.99 + }, true); 1.100 + } 1.101 + else { 1.102 + finish(); 1.103 + } 1.104 +} 1.105 +