Commit ce459ab3 authored by Kuo Jen Wei's avatar Kuo Jen Wei Committed by Commit Bot

[CCA] Force GA logging off in test run.

Bug: None
Test: Manually check GA event is (not) emitted from network panel for
tast and manual run.

Change-Id: Ia42e8b18378a8a5bf53a31209a34dc7c642ed6b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2060217
Commit-Queue: Kuo Jen Wei <inker@chromium.org>
Auto-Submit: Kuo Jen Wei <inker@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742528}
parent 7b9a8cd1
......@@ -235,6 +235,13 @@ class CCAWindow {
return this.perfLogger_;
}
/**
* @override
*/
isTesting() {
return onAppWindowCreatedForTesting !== null;
}
/**
* Suspends the app window.
*/
......
......@@ -51,6 +51,12 @@ export class BackgroundOps {
*/
getPerfLogger() {}
/**
* @return {boolean} Returns whether window is created for running tests.
* @abstract
*/
isTesting() {}
/**
* Called by foreground window when it's active.
* @abstract
......
......@@ -264,6 +264,9 @@ document.addEventListener('DOMContentLoaded', async () => {
}
assert(window['backgroundOps'] !== undefined);
const /** !BackgroundOps */ bgOps = window['backgroundOps'];
metrics.initMetrics(bgOps.isTesting());
const perfLogger = bgOps.getPerfLogger();
// Setup listener for performance events.
......
......@@ -30,11 +30,18 @@ analytics.EventBuilder.prototype.dimen = function(i, v) {
};
/**
* Promise for Google Analytics tracker.
* @type {Promise<analytics.Tracker>}
* Google Analytics tracker.
* @type {?Promise<analytics.Tracker>}
*/
let ga = null;
/**
* Creates Google Analytics tracker object.
* @param {boolean} isTesting
* @return {!Promise<analytics.Tracker>}
* @suppress {checkTypes}
*/
const ga = (function() {
function createGA(isTesting) {
const id = 'UA-134822711-1';
const service = analytics.getService('chrome-camera-app');
......@@ -51,10 +58,19 @@ const ga = (function() {
return Promise
.all([getConfig(), browserProxy.isCrashReportingEnabled(), initBuilder()])
.then(([config, enabled]) => {
enabled = enabled && !isTesting;
config.setTrackingPermitted(enabled);
return service.getTracker(id);
});
})();
}
/**
* Initializes metrics with parameters.
* @param {boolean} isTesting Whether is collecting logs for running testing.
*/
export function initMetrics(isTesting) {
ga = createGA(isTesting);
}
/**
* Returns event builder for the metrics type: launch.
......@@ -172,5 +188,9 @@ export const Type = {
* @param {...*} args Optional rest parameters for logging metrics.
*/
export function log(type, ...args) {
if (ga === null) {
console.error('log() should not be called before metrics initialization.');
ga = createGA(false);
}
ga.then((tracker) => tracker.send(type(...args)));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment