fune/toolkit/xre/test/gtest/TestCompatVersionCompare.cpp
Dave Townsend d9a9041a7c Bug 1556832: Comparing compatibility versions goes on to check the build IDs when the version is newer. r=froydnj
When comparing compatibility versions we first compare the version part. If that
shows us to be a downgrade then we stop checking at that point. But we must also
stop checking if it shows us to be an upgrade since we don't need to check the
build IDs at that point. This also applies to the check for the app build ID.

This means that a newer version with an older build id will appear to be a
downgrade.

This is problematic for safe mode because when safe mode runs it sets the
compatibility version to "Safe Mode" (bug 1556831) to ensure that caches are
invalidated on next startup. On the next run the Firefox version is considered
as newer than "Safe Mode" so we would move on to comparing the build IDs. But
the Firefox build ID gets version compared to "" (since there isn't a build ID
part in "Safe Mode"). Since build ID's are larger than 32-bit numbers we trigger
bug 1556829 and the actual comparison depends on the value of the build ID
truncated to 32-bits. This seems to often be negative and so lower than the
apparent previous build ID causing us to think this is a downgrade.

Cue nfroydnj saying I told you so because if I'd written this as a more
traditional compare function as he suggested I probably would have caught this.

Differential Revision: https://phabricator.services.mozilla.com/D33702

--HG--
extra : rebase_source : bb506c4ba4d75a68976bb114015d53cd41b4d4c3
2019-06-04 10:44:16 -07:00

155 lines
5.1 KiB
C++

/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
#include "gtest/gtest.h"
#include "nsAppRunner.h"
#include "nsString.h"
void CheckCompatVersionCompare(const nsCString& aOldCompatVersion,
const nsCString& aNewCompatVersion,
bool aExpectedSame, bool aExpectedDowngrade) {
printf("Comparing '%s' to '%s'.\n", aOldCompatVersion.get(), aNewCompatVersion.get());
int32_t result = CompareCompatVersions(aOldCompatVersion, aNewCompatVersion);
ASSERT_EQ(aExpectedSame, result == 0) << "Version sameness check should match.";
ASSERT_EQ(aExpectedDowngrade, result > 0) << "Version downgrade check should match.";
}
void CheckExpectedResult(
const char* aOldAppVersion, const char* aOldAppID, const char* aOldToolkitID,
const char* aNewAppVersion, const char* aNewAppID, const char* aNewToolkitID,
bool aExpectedSame, bool aExpectedDowngrade) {
nsCString oldCompatVersion;
BuildCompatVersion(aOldAppVersion, aOldAppID, aOldToolkitID, oldCompatVersion);
nsCString newCompatVersion;
BuildCompatVersion(aNewAppVersion, aNewAppID, aNewToolkitID, newCompatVersion);
CheckCompatVersionCompare(oldCompatVersion, newCompatVersion,
aExpectedSame, aExpectedDowngrade);
}
// clang-format off
TEST(CompatVersionCompare, CompareVersionChange) {
// Identical
CheckExpectedResult(
"67.0", "20000000000000", "20000000000000",
"67.0", "20000000000000", "20000000000000",
true, false);
// Build ID changes
CheckExpectedResult(
"67.0", "20000000000000", "20000000000001",
"67.0", "20000000000000", "20000000000000",
false, true);
CheckExpectedResult(
"67.0", "20000000000001", "20000000000000",
"67.0", "20000000000000", "20000000000000",
false, true);
CheckExpectedResult(
"67.0", "20000000000000", "20000000000000",
"67.0", "20000000000000", "20000000000001",
false, false);
CheckExpectedResult(
"67.0", "20000000000000", "20000000000000",
"67.0", "20000000000001", "20000000000000",
false, false);
// Version changes
CheckExpectedResult(
"67.0", "20000000000000", "20000000000000",
"68.0", "20000000000000", "20000000000000",
false, false);
CheckExpectedResult(
"68.0", "20000000000000", "20000000000000",
"67.0", "20000000000000", "20000000000000",
false, true);
CheckExpectedResult(
"67.0", "20000000000000", "20000000000000",
"67.0.1", "20000000000000", "20000000000000",
false, false);
CheckExpectedResult(
"67.0.1", "20000000000000", "20000000000000",
"67.0", "20000000000000", "20000000000000",
false, true);
CheckExpectedResult(
"67.0.1", "20000000000000", "20000000000000",
"67.0.1", "20000000000000", "20000000000000",
true, false);
CheckExpectedResult(
"67.0.1", "20000000000000", "20000000000000",
"67.0.2", "20000000000000", "20000000000000",
false, false);
CheckExpectedResult(
"67.0.2", "20000000000000", "20000000000000",
"67.0.1", "20000000000000", "20000000000000",
false, true);
// Unexpected ID formats
CheckExpectedResult(
"67.0.1", "build1", "build1",
"67.0.1", "build2", "build2",
false, false);
CheckExpectedResult(
"67.0.1", "build10", "build10",
"67.0.1", "build2", "build2",
false, true);
CheckExpectedResult(
"67.0.1", "1", "1",
"67.0.1", "10", "10",
false, false);
CheckExpectedResult(
"67.0.1", "10", "10",
"67.0.1", "1", "1",
false, true);
// These support an upgrade case from a normal-style build ID to the one
// we're suggesting Ubuntu use.
CheckExpectedResult(
"67.0.1", "20000000000000", "20000000000000",
"67.0.1", "1build1", "1build1",
false, false);
CheckExpectedResult(
"67.0.1", "1build1", "1build1",
"67.0.1", "20000000000000", "20000000000000",
false, true);
// The actual case from bug 1554029:
CheckExpectedResult(
"67.0", "20190516215225", "20190516215225",
"67.0.5", "20190523030228","20190523030228",
false, false);
CheckExpectedResult(
"67.0.5", "20190523030228", "20190523030228",
"67.0", "20190516215225", "20190516215225",
false, true);
// A newer or equal version should not go on to test the build IDs (bug 1556612).
CheckExpectedResult(
"65.0", "30000000000000", "20000000000000",
"66.0", "20000000000000", "20000000000000",
false, false);
CheckExpectedResult(
"65.0", "20000000000000", "30000000000000",
"66.0", "20000000000000", "20000000000000",
false, false);
CheckExpectedResult(
"66.0", "30000000000000", "20000000000000",
"65.0", "20000000000000", "20000000000000",
false, true);
CheckExpectedResult(
"66.0", "20000000000000", "30000000000000",
"65.0", "20000000000000", "20000000000000",
false, true);
// Check that if the last run was safe mode then we consider this an upgrade.
CheckCompatVersionCompare(
NS_LITERAL_CSTRING("Safe Mode"),
NS_LITERAL_CSTRING("67.0.1_20000000000000/20000000000000"),
false, false);
}
// clang-format on