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

mercurial