From e8ac1fbbda9ccad8b0b4e52ee7b8c4f0b3914bac Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Mon, 15 Nov 2021 10:28:46 -0800 Subject: [PATCH] test: Fix test failure due to unconditional extension API usage This test failure was introduced in 8d09fea6. Change-Id: Ibdce76e43fda310c699070e0355b0b6bb7b6e01a --- log-window.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/log-window.js b/log-window.js index 84c2230..61821f4 100644 --- a/log-window.js +++ b/log-window.js @@ -264,19 +264,23 @@ function prettyPrint(obj, indentation = '') { return obj.toString(); } -/** - * Listens for messages from the content script to append a log item to the - * current frame and log file. - */ -chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { - const log = request.log; - EmeLogWindow.instance.appendLog(log); -}); +// NOTE: These APIs are not defined in our test environment, but should always +// be present when this is run as a Chrome extension. +if (chrome.runtime !== undefined) { + /** + * Listens for messages from the content script to append a log item to the + * current frame and log file. + */ + chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { + const log = request.log; + EmeLogWindow.instance.appendLog(log); + }); -/** - * When the extension icon is clicked, open the log window if it doesn't exist, - * and bring it to the front otherwise. - */ -chrome.browserAction.onClicked.addListener((tab) => { - EmeLogWindow.instance.open(); -}); + /** + * When the extension icon is clicked, open the log window if it doesn't exist, + * and bring it to the front otherwise. + */ + chrome.browserAction.onClicked.addListener((tab) => { + EmeLogWindow.instance.open(); + }); +}