Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Client Hints: use fullVersionList in Chromium >=98.
Browse files Browse the repository at this point in the history
RELNOTES[NEW]: Client Hints: use fullVersionList in Chromium >=98.

PiperOrigin-RevId: 469771294
Change-Id: I4a41a9c3a715021ce0cc39de406d71b775d03420
  • Loading branch information
12wrigja authored and copybara-github committed Aug 24, 2022
1 parent da7658d commit 50a2ae0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 40 deletions.
14 changes: 13 additions & 1 deletion closure/goog/labs/useragent/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const googAsserts = goog.require('goog.asserts');
const util = goog.require('goog.labs.userAgent.util');
const {AsyncValue, Version} = goog.require('goog.labs.userAgent.highEntropy.highEntropyValue');
const {compareVersions} = goog.require('goog.string.internal');
const {fullVersionList, hasFullVersionList} = goog.require('goog.labs.userAgent.highEntropy.highEntropyData');
const {fullVersionList} = goog.require('goog.labs.userAgent.highEntropy.highEntropyData');

// TODO(nnaze): Refactor to remove excessive exclusion logic in matching
// functions.
Expand Down Expand Up @@ -96,6 +96,18 @@ function useUserAgentDataBrand() {
return !!userAgentData && userAgentData.brands.length > 0;
}

/**
* @return {boolean} Whether this browser is likely to have the fullVersionList
* high-entropy Client Hint.
*/
function hasFullVersionList() {
// https://chromiumdash.appspot.com/commits?commit=1eb643c3057e64ff4d22468432ad16c4cab12879&platform=Linux
// indicates that for all platforms Chromium 98 shipped this feature.
// See also
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Full-Version-List#browser_compatibility
return isAtLeast(Brand.CHROMIUM, 98);
}

/**
* @return {boolean} Whether the user's browser is Opera. Note: Chromium based
* Opera (Opera 15+) is detected as Chrome to avoid unnecessary special
Expand Down
6 changes: 0 additions & 6 deletions closure/goog/labs/useragent/browser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ testSuite({
util.setUserAgent('');
util.setUserAgentData(null);
highEntropyData.resetAllForTesting();
highEntropyData.setHasFullVersionListForTesting(false);
},

async testOpera10() {
Expand Down Expand Up @@ -990,7 +989,6 @@ testSuite({
]
});
util.setUserAgentData(userAgentDataWithVersion);
highEntropyData.setHasFullVersionListForTesting(true);

assertBrowser(Browser.CHROME);
assertNonChromeChromiumBrowser(NonChromeChromiumBrowser.OPERA_CHROMIUM);
Expand Down Expand Up @@ -1028,7 +1026,6 @@ testSuite({
]
});
util.setUserAgentData(userAgentDataWithVersion);
highEntropyData.setHasFullVersionListForTesting(true);

assertBrowser(Browser.CHROME);
assertNonChromeChromiumBrowser(NonChromeChromiumBrowser.EDGE_CHROMIUM);
Expand Down Expand Up @@ -1100,7 +1097,6 @@ testSuite({
testAgentData.CHROME_USERAGENT_DATA_LINUX,
{fullVersionList: [{brand: 'Chromium', version: '101.0.4472.77'}]});
util.setUserAgentData(userAgentDataWithVersion);
highEntropyData.setHasFullVersionListForTesting(true);

assertBrowser(Browser.CHROME);
assertTrue(userAgentBrowser.isChrome());
Expand Down Expand Up @@ -1151,7 +1147,6 @@ testSuite({

async testChromeUserAgentDataWithRejectedHighEntropyValues() {
util.setUserAgentData(testAgentData.CHROME_USERAGENT_DATA_LINUX);
highEntropyData.setHasFullVersionListForTesting(true);

const fullChromeVersion =
userAgentBrowser.fullVersionOf(userAgentBrowser.Brand.CHROMIUM);
Expand All @@ -1173,7 +1168,6 @@ testSuite({
testAgentData.CHROME_USERAGENT_DATA_LINUX,
{fullVersionList: [{brand: 'Chromium', version: '101.0.4472.77'}]});
util.setUserAgentData(userAgentDataWithVersion);
highEntropyData.setHasFullVersionListForTesting(true);

const fullChromeVersion =
userAgentBrowser.fullVersionOf(userAgentBrowser.Brand.CHROMIUM);
Expand Down
33 changes: 0 additions & 33 deletions closure/goog/labs/useragent/highentropy/highentropydata.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,6 @@ goog.module('goog.labs.userAgent.highEntropy.highEntropyData');

const {HighEntropyValue} = goog.require('goog.labs.userAgent.highEntropy.highEntropyValue');

/**
* fullVersionList is currently not implemented in Chromium.
* TODO(user): When fullVersionList is added, remove this value.
*/
let fullVersionListAvailable = false;

/**
* A helper function to check whether fullVersionList is available in the
* current browser.
* TODO(user): When fullVersionList is added, move hasFullVersionList()
* to browser.js, and inline the browser version check. For example, if it is
* implemented in Chromium 101, have hasFullVersionList simply return
* `browser.isAtLeast(browser.Brand.CHROMIUM, 101)`.
* @return {boolean}
*/
function hasFullVersionList() {
return fullVersionListAvailable;
}
exports.hasFullVersionList = hasFullVersionList;

/**
* A test-only function to set whether it should be assumed fullVersionList is
* available in the browser.
* TODO(user): When fullVersionList is added, remove this function, as
* behavior when fullVersionList is either present or absent would be testable
* by setting the user agent and user agent data accordingly.
* @param {boolean} value
*/
function setHasFullVersionListForTesting(value) {
fullVersionListAvailable = value;
}
exports.setHasFullVersionListForTesting = setHasFullVersionListForTesting;

/**
* @type {!HighEntropyValue<!Array<!NavigatorUABrandVersion>>}
*/
Expand Down

0 comments on commit 50a2ae0

Please sign in to comment.