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 { ...@@ -235,6 +235,13 @@ class CCAWindow {
return this.perfLogger_; return this.perfLogger_;
} }
/**
* @override
*/
isTesting() {
return onAppWindowCreatedForTesting !== null;
}
/** /**
* Suspends the app window. * Suspends the app window.
*/ */
......
...@@ -51,6 +51,12 @@ export class BackgroundOps { ...@@ -51,6 +51,12 @@ export class BackgroundOps {
*/ */
getPerfLogger() {} getPerfLogger() {}
/**
* @return {boolean} Returns whether window is created for running tests.
* @abstract
*/
isTesting() {}
/** /**
* Called by foreground window when it's active. * Called by foreground window when it's active.
* @abstract * @abstract
......
...@@ -264,6 +264,9 @@ document.addEventListener('DOMContentLoaded', async () => { ...@@ -264,6 +264,9 @@ document.addEventListener('DOMContentLoaded', async () => {
} }
assert(window['backgroundOps'] !== undefined); assert(window['backgroundOps'] !== undefined);
const /** !BackgroundOps */ bgOps = window['backgroundOps']; const /** !BackgroundOps */ bgOps = window['backgroundOps'];
metrics.initMetrics(bgOps.isTesting());
const perfLogger = bgOps.getPerfLogger(); const perfLogger = bgOps.getPerfLogger();
// Setup listener for performance events. // Setup listener for performance events.
......
...@@ -30,11 +30,18 @@ analytics.EventBuilder.prototype.dimen = function(i, v) { ...@@ -30,11 +30,18 @@ analytics.EventBuilder.prototype.dimen = function(i, v) {
}; };
/** /**
* Promise for Google Analytics tracker. * Google Analytics tracker.
* @type {Promise<analytics.Tracker>} * @type {?Promise<analytics.Tracker>}
*/
let ga = null;
/**
* Creates Google Analytics tracker object.
* @param {boolean} isTesting
* @return {!Promise<analytics.Tracker>}
* @suppress {checkTypes} * @suppress {checkTypes}
*/ */
const ga = (function() { function createGA(isTesting) {
const id = 'UA-134822711-1'; const id = 'UA-134822711-1';
const service = analytics.getService('chrome-camera-app'); const service = analytics.getService('chrome-camera-app');
...@@ -51,10 +58,19 @@ const ga = (function() { ...@@ -51,10 +58,19 @@ const ga = (function() {
return Promise return Promise
.all([getConfig(), browserProxy.isCrashReportingEnabled(), initBuilder()]) .all([getConfig(), browserProxy.isCrashReportingEnabled(), initBuilder()])
.then(([config, enabled]) => { .then(([config, enabled]) => {
enabled = enabled && !isTesting;
config.setTrackingPermitted(enabled); config.setTrackingPermitted(enabled);
return service.getTracker(id); 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. * Returns event builder for the metrics type: launch.
...@@ -172,5 +188,9 @@ export const Type = { ...@@ -172,5 +188,9 @@ export const Type = {
* @param {...*} args Optional rest parameters for logging metrics. * @param {...*} args Optional rest parameters for logging metrics.
*/ */
export function log(type, ...args) { 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))); 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