1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_firstrun_pref.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +let prefsBranch = Cc["@mozilla.org/preferences-service;1"]. 1.8 + getService(Ci.nsIPrefService). 1.9 + getBranch("browser.panorama."); 1.10 +let originalPrefState; 1.11 + 1.12 +function test() { 1.13 + waitForExplicitFinish(); 1.14 + 1.15 + ok(!TabView.isVisible(), "Main window TabView is hidden"); 1.16 + 1.17 + originalPrefState = experienced(); 1.18 + 1.19 + prefsBranch.setBoolPref("experienced_first_run", false); 1.20 + ok(!experienced(), "set to not experienced"); 1.21 + 1.22 + newWindowWithTabView(checkFirstRun, function() { 1.23 + // open tabview doesn't count as first use experience so setting it manually 1.24 + prefsBranch.setBoolPref("experienced_first_run", true); 1.25 + ok(experienced(), "we're now experienced"); 1.26 + 1.27 + newWindowWithTabView(checkNotFirstRun, endGame); 1.28 + }); 1.29 +} 1.30 + 1.31 +function experienced() { 1.32 + return prefsBranch.prefHasUserValue("experienced_first_run") && 1.33 + prefsBranch.getBoolPref("experienced_first_run"); 1.34 +} 1.35 + 1.36 +function checkFirstRun(win) { 1.37 + let contentWindow = win.document.getElementById("tab-view").contentWindow; 1.38 + 1.39 + // Welcome tab disabled by bug 626754. To be fixed via bug 626926. 1.40 + is(win.gBrowser.tabs.length, 1, "There should be one tab"); 1.41 + 1.42 + let groupItems = contentWindow.GroupItems.groupItems; 1.43 + is(groupItems.length, 1, "There should be one group"); 1.44 + is(groupItems[0].getChildren().length, 1, "...with one child"); 1.45 + 1.46 + ok(!experienced(), "we're not experienced"); 1.47 +} 1.48 + 1.49 +function checkNotFirstRun(win) { 1.50 + let contentWindow = win.document.getElementById("tab-view").contentWindow; 1.51 + 1.52 + is(win.gBrowser.tabs.length, 1, "There should be one tab"); 1.53 + 1.54 + let groupItems = contentWindow.GroupItems.groupItems; 1.55 + is(groupItems.length, 1, "There should be one group"); 1.56 + is(groupItems[0].getChildren().length, 1, "...with one child"); 1.57 +} 1.58 + 1.59 +function endGame() { 1.60 + ok(!TabView.isVisible(), "Main window TabView is still hidden"); 1.61 + ok(experienced(), "should finish as experienced"); 1.62 + 1.63 + prefsBranch.setBoolPref("experienced_first_run", originalPrefState); 1.64 + 1.65 + finish(); 1.66 +} 1.67 + 1.68 +function newWindowWithTabView(callback, completeCallback) { 1.69 + let charsetArg = "charset=" + window.content.document.characterSet; 1.70 + let win = window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no,height=800,width=800", 1.71 + "about:blank", charsetArg, null, null, true); 1.72 + let onLoad = function() { 1.73 + win.removeEventListener("load", onLoad, false); 1.74 + let onShown = function() { 1.75 + win.removeEventListener("tabviewshown", onShown, false); 1.76 + callback(win); 1.77 + win.close(); 1.78 + if (typeof completeCallback == "function") 1.79 + completeCallback(); 1.80 + }; 1.81 + win.addEventListener("tabviewshown", onShown, false); 1.82 + win.TabView.toggle(); 1.83 + } 1.84 + win.addEventListener("load", onLoad, false); 1.85 +}