Skip to content

Commit

Permalink
Replace goog.global with globalThis in closure unit test as a first s…
Browse files Browse the repository at this point in the history
…tep of deprecating goog.global.

RELNOTES:n/a

PiperOrigin-RevId: 341682972
  • Loading branch information
concavelenz authored and kjin committed Nov 13, 2020
1 parent 690b713 commit a1577b0
Show file tree
Hide file tree
Showing 45 changed files with 182 additions and 185 deletions.
4 changes: 2 additions & 2 deletions closure/goog/async/nexttick_test.js
Expand Up @@ -145,7 +145,7 @@ testSuite({
errorHandlerCallbackCalled = true;
});

// MS Edge will always use goog.global.setImmediate, so ensure we get
// MS Edge will always use globalThis.setImmediate, so ensure we get
// to setImmediate_ here. See useSetImmediate_ implementation for details
// on Edge special casing.
propertyReplacer.set(nextTick, 'useSetImmediate_', () => false);
Expand Down Expand Up @@ -233,7 +233,7 @@ testSuite({
},

testBehaviorOnPagesWithOverriddenWindowConstructor() {
propertyReplacer.set(goog.global, 'Window', {});
propertyReplacer.set(globalThis, 'Window', {});
this.testNextTick();
this.testNextTickSetImmediate();
this.testNextTickMockClock();
Expand Down
6 changes: 3 additions & 3 deletions closure/goog/collections/iters_test.js
Expand Up @@ -46,9 +46,9 @@ function createRangeIterator(start, stop) {
function createRangeIterable(start, stop) {
const obj = {};

// Refer to goog.global['Symbol'] because otherwise this
// Refer to globalThis['Symbol'] because otherwise this
// is a parse error in earlier IEs.
obj[goog.global['Symbol'].iterator] = () => createRangeIterator(start, stop);
obj[globalThis['Symbol'].iterator] = () => createRangeIterator(start, stop);
return /** @type {!Iterable<number>} */ (obj);
}

Expand All @@ -68,7 +68,7 @@ function* rangeGeneratorWithReturn(start, stop) {

/** @return {boolean} */
function isSymbolDefined() {
return !!goog.global['Symbol'];
return !!globalThis['Symbol'];
}

testSuite({
Expand Down
2 changes: 1 addition & 1 deletion closure/goog/crypt/blobhasher_test.js
Expand Up @@ -117,7 +117,7 @@ function readFromBlob(blobHasher, maxReads) {

testSuite({
setUp() {
stubs.set(goog.global, 'FileReader', FileReaderMock);
stubs.set(globalThis, 'FileReader', FileReaderMock);
stubs.set(fs, 'sliceBlob', fsSliceBlobMock);
},

Expand Down
6 changes: 3 additions & 3 deletions closure/goog/crypt/crypt_test.js
Expand Up @@ -88,7 +88,7 @@ testSuite({
* Array<number>.
*/
testUint8ArrayToString() {
if (!goog.global.Uint8Array) {
if (!globalThis.Uint8Array) {
// Uint8Array not supported.
return;
}
Expand Down Expand Up @@ -139,7 +139,7 @@ testSuite({
Same as testByteArrayToHex but with Uint8Array instead of Array<number>.
*/
testUint8ArrayToHex() {
if (goog.global.Uint8Array === undefined) {
if (globalThis.Uint8Array === undefined) {
// Uint8Array not supported.
return;
}
Expand All @@ -164,7 +164,7 @@ testSuite({

/** Same as testXorByteArray but with Uint8Array instead of Array<number>. */
testXorUint8Array() {
if (goog.global.Uint8Array === undefined) {
if (globalThis.Uint8Array === undefined) {
// Uint8Array not supported.
return;
}
Expand Down
4 changes: 2 additions & 2 deletions closure/goog/crypt/hash32_test.js
Expand Up @@ -161,10 +161,10 @@ const byteArrays = {
};

let testCase;
if (goog.global.G_testRunner) {
if (globalThis.G_testRunner) {
testCase = new TestCase(document.title);
testCase.autoDiscoverTests();
goog.global.G_testRunner.initialize(testCase);
globalThis.G_testRunner.initialize(testCase);
}
testSuite({
testEncodeInteger() {
Expand Down
6 changes: 3 additions & 3 deletions closure/goog/debug/errorhandler_test.js
Expand Up @@ -189,7 +189,7 @@ testSuite({
},

testDisposal() {
fakeWin = goog.global['window'];
fakeWin = globalThis['window'];
const originalSetTimeout = fakeWin.setTimeout;
const originalSetInterval = fakeWin.setInterval;

Expand Down Expand Up @@ -257,7 +257,7 @@ testSuite({
testGetProtectedFunction_withoutWrappedErrors() {
const shouldCallErrorLog = !!Error.captureStackTrace;
if (shouldCallErrorLog) {
mockControl.createMethodMock(goog.global.console, 'error');
mockControl.createMethodMock(globalThis.console, 'error');
}
errorHandler.setWrapErrors(false);
const fn = () => {
Expand All @@ -267,7 +267,7 @@ testSuite({
};
const protectedFn = errorHandler.getProtectedFunction(fn);
if (shouldCallErrorLog) {
goog.global.console.error('Foo', 'STACK');
globalThis.console.error('Foo', 'STACK');
}
mockControl.$replayAll();
const e = assertThrows(protectedFn);
Expand Down
24 changes: 12 additions & 12 deletions closure/goog/debug/errorreporter_test.js
Expand Up @@ -139,7 +139,7 @@ testSuite({
}

stubs.set(userAgent, 'IE', false);
stubs.set(goog.global, 'setTimeout', (fcn, time) => {
stubs.set(globalThis, 'setTimeout', (fcn, time) => {
fcn.call();
});

Expand All @@ -148,7 +148,7 @@ testSuite({
const errorFunction = goog.partial(throwAnErrorWith, url, 5, 'Hello :)');

try {
goog.global.setTimeout(errorFunction, 0);
globalThis.setTimeout(errorFunction, 0);
} catch (e) {
// Expected. The error is rethrown after sending.
}
Expand All @@ -164,10 +164,10 @@ testSuite({
stubs.set(userAgent, 'isVersionOrHigher', functions.FALSE);

// Remove test runner's onerror handler so the test doesn't fail.
stubs.set(goog.global, 'onerror', null);
stubs.set(globalThis, 'onerror', null);

errorReporter = ErrorReporter.install('/errorreporter');
goog.global.onerror('Goodbye :(', url, 22);
globalThis.onerror('Goodbye :(', url, 22);
assertEquals(
`/errorreporter?script=${encodedUrl}` +
'&error=Goodbye%20%3A(&line=22',
Expand All @@ -179,17 +179,17 @@ testSuite({
stubs.set(userAgent, 'IE', true);
stubs.set(userAgent, 'isVersionOrHigher', functions.FALSE);
// Remove test runner's onerror handler so the test doesn't fail.
stubs.set(goog.global, 'onerror', null);
stubs.set(globalThis, 'onerror', null);

errorReporter = ErrorReporter.install('/errorreporter');
errorReporter.setLoggingHeaders('header!');
goog.global.onerror('Goodbye :(', 'http://www.your.tst/more/bogus.js', 22);
globalThis.onerror('Goodbye :(', 'http://www.your.tst/more/bogus.js', 22);
assertEquals('header!', MockXhrIo.lastHeaders);
},

test_nonInternetExplorerSendErrorReportWithTrace() {
stubs.set(userAgent, 'IE', false);
stubs.set(goog.global, 'setTimeout', (fcn, time) => {
stubs.set(globalThis, 'setTimeout', (fcn, time) => {
fcn.call();
});

Expand All @@ -203,7 +203,7 @@ testSuite({
goog.partial(throwAnErrorWith, url, 5, 'Hello :)', trace);

try {
goog.global.setTimeout(errorFunction, 0);
globalThis.setTimeout(errorFunction, 0);
} catch (e) {
// Expected. The error is rethrown after sending.
}
Expand All @@ -222,7 +222,7 @@ testSuite({

test_nonInternetExplorerSendErrorReportWithTraceAndCauses() {
stubs.set(userAgent, 'IE', false);
stubs.set(goog.global, 'setTimeout', (fcn, time) => {
stubs.set(globalThis, 'setTimeout', (fcn, time) => {
fcn.call();
});

Expand Down Expand Up @@ -260,7 +260,7 @@ testSuite({
goog.partial(throwAnErrorWith, url, 5, 'MainError', maintrace, cause1);

try {
goog.global.setTimeout(errorFunction, 0);
globalThis.setTimeout(errorFunction, 0);
} catch (e) {
// Expected. The error is rethrown after sending.
}
Expand All @@ -274,7 +274,7 @@ testSuite({

test_nonInternetExplorerSendErrorReportWithCyclicCauses() {
stubs.set(userAgent, 'IE', false);
stubs.set(goog.global, 'setTimeout', (fcn, time) => {
stubs.set(globalThis, 'setTimeout', (fcn, time) => {
fcn.call();
});

Expand Down Expand Up @@ -312,7 +312,7 @@ testSuite({
goog.partial(throwAnErrorWith, url, 5, 'MainError', maintrace, cause1);

try {
goog.global.setTimeout(errorFunction, 0);
globalThis.setTimeout(errorFunction, 0);
} catch (e) {
// Expected. The error is rethrown after sending.
}
Expand Down
6 changes: 3 additions & 3 deletions closure/goog/dom/dom_test.js
Expand Up @@ -873,10 +873,10 @@ testSuite({
},

testIsWindow() {
const global = goog.global;
const global = globalThis;
const frame = window.frames['frame'];
const otherWindow = window.open('', 'blank');
const object = {window: goog.global};
const object = {window: globalThis};
const nullVar = null;
let notDefined;

Expand All @@ -885,7 +885,7 @@ testSuite({
// an assertion fails or something else goes wrong.
assertTrue(
'global object in HTML context should be a window',
googDom.isWindow(goog.global));
googDom.isWindow(globalThis));
assertTrue('iframe window should be a window', googDom.isWindow(frame));
if (otherWindow) {
assertTrue(
Expand Down
2 changes: 1 addition & 1 deletion closure/goog/editor/contenteditablefield_test.js
Expand Up @@ -15,7 +15,7 @@ const testSuite = goog.require('goog.testing.testSuite');

const HTML = '<div id="testField">I am text.</div>';

goog.global.FieldConstructor = ContentEditableField;
globalThis.FieldConstructor = ContentEditableField;

testSuite({
setUp() {
Expand Down
4 changes: 2 additions & 2 deletions closure/goog/format/format_test.js
Expand Up @@ -318,8 +318,8 @@ testSuite({
const wbrEl = dom.createDom(
TagName.DIV,
{'style': 'width: 100px; overflow: hidden; margin-top: 15px'});
dom.appendChild(goog.global.document.body, overflowEl);
dom.appendChild(goog.global.document.body, wbrEl);
dom.appendChild(globalThis.document.body, overflowEl);
dom.appendChild(globalThis.document.body, wbrEl);

overflowEl.innerHTML = text;
wbrEl.innerHTML = textWbr;
Expand Down
28 changes: 14 additions & 14 deletions closure/goog/fs/fs_test.js
Expand Up @@ -24,8 +24,8 @@ const testSuite = goog.require('goog.testing.testSuite');

const TEST_DIR = 'goog-fs-test-dir';

const fsExists = (goog.global.requestFileSystem !== undefined) ||
goog.global.webkitRequestFileSystem !== undefined;
const fsExists = (globalThis.requestFileSystem !== undefined) ||
globalThis.webkitRequestFileSystem !== undefined;
/** @suppress {checkTypes} suppression added to enable type checking */
const deferredFs = fsExists ? googFs.getTemporary() : null;
const stubs = new PropertyReplacer();
Expand Down Expand Up @@ -145,8 +145,8 @@ testSuite({
},

testUnavailableTemporaryFilesystem() {
stubs.set(goog.global, 'requestFileSystem', null);
stubs.set(goog.global, 'webkitRequestFileSystem', null);
stubs.set(globalThis, 'requestFileSystem', null);
stubs.set(globalThis, 'webkitRequestFileSystem', null);

return googFs.getTemporary(1024).then(
fail, /**
Expand All @@ -159,8 +159,8 @@ testSuite({
},

testUnavailablePersistentFilesystem() {
stubs.set(goog.global, 'requestFileSystem', null);
stubs.set(goog.global, 'webkitRequestFileSystem', null);
stubs.set(globalThis, 'requestFileSystem', null);
stubs.set(globalThis, 'webkitRequestFileSystem', null);

return googFs.getPersistent(2048).then(
fail, /**
Expand Down Expand Up @@ -598,9 +598,9 @@ testSuite({

/** @suppress {checkTypes} suppression added to enable type checking */
testGetBlobThrowsError() {
stubs.remove(goog.global, 'BlobBuilder');
stubs.remove(goog.global, 'WebKitBlobBuilder');
stubs.remove(goog.global, 'Blob');
stubs.remove(globalThis, 'BlobBuilder');
stubs.remove(globalThis, 'WebKitBlobBuilder');
stubs.remove(globalThis, 'Blob');

try {
googFsBlob.getBlob();
Expand All @@ -615,7 +615,7 @@ testSuite({

testGetBlobWithProperties() {
// Skip test if browser doesn't support Blob API.
if (typeof (goog.global.Blob) != 'function') {
if (typeof (globalThis.Blob) != 'function') {
return;
}

Expand All @@ -626,9 +626,9 @@ testSuite({

/** @suppress {checkTypes} suppression added to enable type checking */
testGetBlobWithPropertiesThrowsError() {
stubs.remove(goog.global, 'BlobBuilder');
stubs.remove(goog.global, 'WebKitBlobBuilder');
stubs.remove(goog.global, 'Blob');
stubs.remove(globalThis, 'BlobBuilder');
stubs.remove(globalThis, 'WebKitBlobBuilder');
stubs.remove(globalThis, 'Blob');

try {
googFsBlob.getBlobWithProperties();
Expand All @@ -652,7 +652,7 @@ testSuite({
return {type: type, builder: this};
};
}
stubs.set(goog.global, 'BlobBuilder', BlobBuilder);
stubs.set(globalThis, 'BlobBuilder', BlobBuilder);

const blob =
googFsBlob.getBlobWithProperties(['test'], 'text/test', 'native');
Expand Down
8 changes: 4 additions & 4 deletions closure/goog/fs/url_test.js
Expand Up @@ -16,9 +16,9 @@ const stubs = new PropertyReplacer();
testSuite({
/** @suppress {checkTypes} suppression added to enable type checking */
testBrowserSupportsObjectUrls() {
stubs.remove(goog.global, 'URL');
stubs.remove(goog.global, 'webkitURL');
stubs.remove(goog.global, 'createObjectURL');
stubs.remove(globalThis, 'URL');
stubs.remove(globalThis, 'webkitURL');
stubs.remove(globalThis, 'createObjectURL');

assertFalse(url.browserSupportsObjectUrls());
try {
Expand All @@ -33,7 +33,7 @@ testSuite({
function createObjectURL() {
return objectUrl;
}
stubs.set(goog.global, 'createObjectURL', createObjectURL);
stubs.set(globalThis, 'createObjectURL', createObjectURL);

assertTrue(url.browserSupportsObjectUrls());
assertEquals(objectUrl, url.createObjectUrl());
Expand Down
4 changes: 2 additions & 2 deletions closure/goog/html/safehtml_test.js
Expand Up @@ -91,8 +91,8 @@ testSuite({
const trustedValue = SafeHtml.unwrapTrustedHTML(safeValue);
assertEquals(safeValue.getTypedStringValue(), trustedValue.toString());
assertTrue(
goog.global.TrustedHTML ? trustedValue instanceof TrustedHTML :
typeof trustedValue === 'string');
globalThis.TrustedHTML ? trustedValue instanceof TrustedHTML :
typeof trustedValue === 'string');
},

testHtmlEscape() {
Expand Down
4 changes: 2 additions & 2 deletions closure/goog/html/safescript_test.js
Expand Up @@ -69,8 +69,8 @@ testSuite({
const trustedValue = SafeScript.unwrapTrustedScript(safeValue);
assertEquals(safeValue.getTypedStringValue(), trustedValue.toString());
assertTrue(
goog.global.TrustedScript ? trustedValue instanceof TrustedScript :
typeof trustedValue === 'string');
globalThis.TrustedScript ? trustedValue instanceof TrustedScript :
typeof trustedValue === 'string');
},

testFromConstant_allowsEmptyString() {
Expand Down
4 changes: 2 additions & 2 deletions closure/goog/html/safeurl_test.js
Expand Up @@ -161,7 +161,7 @@ testSuite({
},

testSafeUrlFromMediaSource_createsBlob() {
if (!('MediaSource' in goog.global)) {
if (!('MediaSource' in globalThis)) {
return;
}
const safeUrl = SafeUrl.fromMediaSource(new MediaSource());
Expand All @@ -170,7 +170,7 @@ testSuite({
},

testSafeUrlFromMediaSource_rejectsBlobs() {
if (!('MediaSource' in goog.global)) {
if (!('MediaSource' in globalThis)) {
return;
}
const safeUrl =
Expand Down

0 comments on commit a1577b0

Please sign in to comment.