|
| 1 | +/* Any copyright is dedicated to the Public Domain. |
| 2 | + * http://creativecommons.org/publicdomain/zero/1.0/ */ |
| 3 | + |
| 4 | +"use strict"; |
| 5 | + |
| 6 | +add_task(async function nimbus_whats_new_page() { |
| 7 | + // The test harness will use the current tab and remove the tab's history. |
| 8 | + // Since the page that is tested is opened prior to the test harness taking |
| 9 | + // over the current tab the active-update.xml specifies two pages to open by |
| 10 | + // having 'https://example.com/|https://example.com/' for the value of openURL |
| 11 | + // and then uses the first tab for the test. |
| 12 | + gBrowser.selectedTab = gBrowser.tabs[0]; |
| 13 | + // The test harness also changes the page to about:blank so go back to the |
| 14 | + // page that was originally opened. |
| 15 | + gBrowser.goBack(); |
| 16 | + // Wait for the page to go back to the original page. |
| 17 | + await TestUtils.waitForCondition( |
| 18 | + () => |
| 19 | + gBrowser.selectedBrowser && |
| 20 | + gBrowser.selectedBrowser.currentURI && |
| 21 | + gBrowser.selectedBrowser.currentURI.spec == |
| 22 | + "https://www.mozilla.org/en-US/projects/firefox/whatsnew/", |
| 23 | + `Waiting for the expected page to reopen, ${gBrowser.selectedBrowser.currentURI.spec}` |
| 24 | + ); |
| 25 | + is( |
| 26 | + gBrowser.selectedBrowser.currentURI.spec, |
| 27 | + "https://www.mozilla.org/en-US/projects/firefox/whatsnew/", |
| 28 | + "The what's new page's url should equal https://www.mozilla.org/en-US/projects/firefox/whatsnew/" |
| 29 | + ); |
| 30 | + gBrowser.removeTab(gBrowser.selectedTab); |
| 31 | + |
| 32 | + let um = Cc["@mozilla.org/updates/update-manager;1"].getService( |
| 33 | + Ci.nsIUpdateManager |
| 34 | + ); |
| 35 | + await TestUtils.waitForCondition( |
| 36 | + () => !um.readyUpdate, |
| 37 | + "Waiting for the ready update to be removed" |
| 38 | + ); |
| 39 | + ok(!um.readyUpdate, "There should not be a ready update"); |
| 40 | + await TestUtils.waitForCondition( |
| 41 | + () => !!um.getUpdateAt(0), |
| 42 | + "Waiting for the ready update to be moved to the update history" |
| 43 | + ); |
| 44 | + ok(!!um.getUpdateAt(0), "There should be an update in the update history"); |
| 45 | + |
| 46 | + // Leave no trace. Since this test modifies its support files put them back in |
| 47 | + // their original state. |
| 48 | + let alternatePath = Services.prefs.getCharPref("app.update.altUpdateDirPath"); |
| 49 | + let testRoot = Services.prefs.getCharPref("mochitest.testRoot"); |
| 50 | + let relativePath = alternatePath.substring("<test-root>".length); |
| 51 | + if (AppConstants.platform == "win") { |
| 52 | + relativePath = relativePath.replace(/\//g, "\\"); |
| 53 | + } |
| 54 | + alternatePath = testRoot + relativePath; |
| 55 | + let updateDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); |
| 56 | + updateDir.initWithPath(alternatePath); |
| 57 | + |
| 58 | + let activeUpdateFile = updateDir.clone(); |
| 59 | + activeUpdateFile.append("active-update.xml"); |
| 60 | + await TestUtils.waitForCondition( |
| 61 | + () => !activeUpdateFile.exists(), |
| 62 | + "Waiting until the active-update.xml file does not exist" |
| 63 | + ); |
| 64 | + |
| 65 | + let updatesFile = updateDir.clone(); |
| 66 | + updatesFile.append("updates.xml"); |
| 67 | + await TestUtils.waitForCondition( |
| 68 | + () => updatesFile.exists(), |
| 69 | + "Waiting until the updates.xml file exists" |
| 70 | + ); |
| 71 | + |
| 72 | + let fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance( |
| 73 | + Ci.nsIFileOutputStream |
| 74 | + ); |
| 75 | + let flags = |
| 76 | + FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE; |
| 77 | + |
| 78 | + let stateSucceeded = "succeeded\n"; |
| 79 | + let updateStatusFile = updateDir.clone(); |
| 80 | + updateStatusFile.append("updates"); |
| 81 | + updateStatusFile.append("0"); |
| 82 | + updateStatusFile.append("update.status"); |
| 83 | + updateStatusFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); |
| 84 | + fos.init(updateStatusFile, flags, FileUtils.PERMS_FILE, 0); |
| 85 | + fos.write(stateSucceeded, stateSucceeded.length); |
| 86 | + fos.close(); |
| 87 | + |
| 88 | + let xmlContents = |
| 89 | + '<?xml version="1.0"?><updates xmlns="http://www.mozilla.org/2005/' + |
| 90 | + 'app-update"><update xmlns="http://www.mozilla.org/2005/app-update" ' + |
| 91 | + 'appVersion="99999999.0" buildID="20990101111111" channel="test" ' + |
| 92 | + 'detailsURL="https://127.0.0.1/" displayVersion="1.0" installDate="' + |
| 93 | + '1555716429454" isCompleteUpdate="true" name="What\'s New Page Test" ' + |
| 94 | + 'previousAppVersion="60.0" serviceURL="https://127.0.0.1/update.xml" ' + |
| 95 | + 'type="minor" platformVersion="99999999.0" actions="showURL" ' + |
| 96 | + 'openURL="https://example.com/|https://example.com/"><patch size="1" ' + |
| 97 | + 'type="complete" URL="https://127.0.0.1/complete.mar" ' + |
| 98 | + 'selected="true" state="pending"/></update></updates>\n'; |
| 99 | + activeUpdateFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); |
| 100 | + fos.init(activeUpdateFile, flags, FileUtils.PERMS_FILE, 0); |
| 101 | + fos.write(xmlContents, xmlContents.length); |
| 102 | + fos.close(); |
| 103 | + |
| 104 | + updatesFile.remove(false); |
| 105 | + Cc["@mozilla.org/updates/update-manager;1"] |
| 106 | + .getService(Ci.nsIUpdateManager) |
| 107 | + .QueryInterface(Ci.nsIObserver) |
| 108 | + .observe(null, "um-reload-update-data", ""); |
| 109 | +}); |
0 commit comments