browser_advanced_update.js (4958B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const Cm = Components.manager; 7 8 const uuidGenerator = Services.uuid; 9 10 const mockUpdateManager = { 11 contractId: "@mozilla.org/updates/update-manager;1", 12 13 _mockClassId: uuidGenerator.generateUUID(), 14 15 _originalClassId: "", 16 17 QueryInterface: ChromeUtils.generateQI(["nsIUpdateManager"]), 18 19 createInstance(iiD) { 20 return this.QueryInterface(iiD); 21 }, 22 23 register() { 24 let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); 25 if (!registrar.isCIDRegistered(this._mockClassId)) { 26 this._originalClassId = registrar.contractIDToCID(this.contractId); 27 registrar.registerFactory( 28 this._mockClassId, 29 "Unregister after testing", 30 this.contractId, 31 this 32 ); 33 } 34 }, 35 36 unregister() { 37 let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); 38 registrar.unregisterFactory(this._mockClassId, this); 39 registrar.registerFactory(this._originalClassId, "", this.contractId, null); 40 }, 41 42 async getHistory() { 43 return [...this._updates]; 44 }, 45 46 _updates: [ 47 { 48 name: "Firefox Developer Edition 49.0a2", 49 statusText: "The Update was successfully installed", 50 buildID: "20160728004010", 51 installDate: 1469763105156, 52 detailsURL: "https://www.mozilla.org/firefox/aurora/", 53 }, 54 { 55 name: "Firefox Developer Edition 43.0a2", 56 statusText: "The Update was successfully installed", 57 buildID: "20150929004011", 58 installDate: 1443585886224, 59 detailsURL: "https://www.mozilla.org/firefox/aurora/", 60 }, 61 { 62 name: "Firefox Developer Edition 42.0a2", 63 statusText: "The Update was successfully installed", 64 buildID: "20150920004018", 65 installDate: 1442818147544, 66 detailsURL: "https://www.mozilla.org/firefox/aurora/", 67 }, 68 ], 69 }; 70 71 function formatInstallDate(sec) { 72 var date = new Date(sec); 73 const dtOptions = { 74 year: "numeric", 75 month: "long", 76 day: "numeric", 77 hour: "numeric", 78 minute: "numeric", 79 second: "numeric", 80 }; 81 return date.toLocaleString(undefined, dtOptions); 82 } 83 84 add_task(async function () { 85 await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true }); 86 let doc = gBrowser.selectedBrowser.contentDocument; 87 88 let showBtn = doc.getElementById("showUpdateHistory"); 89 let dialogOverlay = content.gSubDialog._preloadDialog._overlay; 90 91 // XXX: For unknown reasons, this mock cannot be loaded by 92 // XPCOMUtils.defineLazyServiceGetter() called in aboutDialog-appUpdater.js. 93 // It is registered here so that we could assert update history subdialog 94 // without stopping the preferences advanced pane from loading. 95 // See bug 1361929. 96 mockUpdateManager.register(); 97 98 // Test the dialog window opens 99 ok( 100 BrowserTestUtils.isHidden(dialogOverlay), 101 "The dialog should be invisible" 102 ); 103 let promiseSubDialogLoaded = promiseLoadSubDialog( 104 "chrome://mozapps/content/update/history.xhtml" 105 ); 106 showBtn.doCommand(); 107 await promiseSubDialogLoaded; 108 ok(!BrowserTestUtils.isHidden(dialogOverlay), "The dialog should be visible"); 109 110 let dialogFrame = dialogOverlay.querySelector(".dialogFrame"); 111 let frameDoc = dialogFrame.contentDocument; 112 let updates = frameDoc.querySelectorAll("richlistitem.update"); 113 const history = await mockUpdateManager.getHistory(); 114 115 // Test the update history numbers are correct 116 is(updates.length, history.length, "The update count is incorrect."); 117 118 // Test the updates are displayed correctly 119 let update = null; 120 let updateData = null; 121 for (let i = 0; i < updates.length; ++i) { 122 update = updates[i]; 123 updateData = history[i]; 124 125 let testcases = [ 126 { 127 selector: ".update-name", 128 id: "update-full-build-name", 129 args: { name: updateData.name, buildID: updateData.buildID }, 130 }, 131 { 132 selector: ".update-installedOn-label", 133 id: "update-installed-on", 134 args: { date: formatInstallDate(updateData.installDate) }, 135 }, 136 { 137 selector: ".update-status-label", 138 id: "update-status", 139 args: { status: updateData.statusText }, 140 }, 141 ]; 142 143 for (let { selector, id, args } of testcases) { 144 const element = update.querySelector(selector); 145 const l10nAttrs = frameDoc.l10n.getAttributes(element); 146 Assert.deepEqual( 147 l10nAttrs, 148 { 149 id, 150 args, 151 }, 152 "Wrong " + id 153 ); 154 } 155 156 if (update.detailsURL) { 157 is( 158 update.detailsURL, 159 update.querySelector(".text-link").href, 160 "Wrong detailsURL" 161 ); 162 } 163 } 164 165 // Test the dialog window closes 166 let closeBtn = dialogOverlay.querySelector(".dialogClose"); 167 closeBtn.doCommand(); 168 ok( 169 BrowserTestUtils.isHidden(dialogOverlay), 170 "The dialog should be invisible" 171 ); 172 173 mockUpdateManager.unregister(); 174 gBrowser.removeCurrentTab(); 175 });