summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html
diff options
context:
space:
mode:
Diffstat (limited to 'polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html')
-rw-r--r--polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html243
1 files changed, 191 insertions, 52 deletions
diff --git a/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html b/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html
index e88096b25e..8b8507433e 100644
--- a/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html
+++ b/polygerrit-ui/app/elements/core/gr-reporting/gr-reporting_test.html
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<!--
+@license
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
@@ -44,6 +45,7 @@ limitations under the License.
sandbox = sinon.sandbox.create();
clock = sinon.useFakeTimers(NOW_TIME);
element = fixture('basic');
+ element._baselines = Object.assign({}, GrReporting.STARTUP_TIMERS);
fakePerformance = {
navigationStart: 1,
loadEventEnd: 2,
@@ -52,18 +54,31 @@ limitations under the License.
{get() { return fakePerformance; }});
sandbox.stub(element, 'reporter');
});
+
teardown(() => {
sandbox.restore();
clock.restore();
});
test('appStarted', () => {
- element.appStarted();
+ element.appStarted(true);
assert.isTrue(
element.reporter.calledWithExactly(
'timing-report', 'UI Latency', 'App Started',
NOW_TIME - fakePerformance.navigationStart
));
+ assert.isTrue(
+ element.reporter.calledWithExactly(
+ 'lifecycle', 'Page Visibility', 'hidden'
+ ));
+ });
+
+ test('WebComponentsReady', () => {
+ sandbox.stub(element, 'now').returns(42);
+ element.timeEnd('WebComponentsReady');
+ assert.isTrue(element.reporter.calledWithExactly(
+ 'timing-report', 'UI Latency', 'WebComponentsReady', 42
+ ));
});
test('pageLoaded', () => {
@@ -75,20 +90,167 @@ limitations under the License.
);
});
+ test('beforeLocationChanged', () => {
+ element._baselines['garbage'] = 'monster';
+ sandbox.stub(element, 'time');
+ GrJankDetector.jank = 42;
+ element.beforeLocationChanged();
+ assert.equal(GrJankDetector.jank, 0);
+ assert.isTrue(element.reporter.calledWithExactly(
+ 'lifecycle', 'UI Latency', 'Jank count', 42));
+ assert.isTrue(element.time.calledWithExactly('DashboardDisplayed'));
+ assert.isTrue(element.time.calledWithExactly('ChangeDisplayed'));
+ assert.isTrue(element.time.calledWithExactly('ChangeFullyLoaded'));
+ assert.isTrue(element.time.calledWithExactly('DiffViewDisplayed'));
+ assert.isTrue(element.time.calledWithExactly('FileListDisplayed'));
+ assert.isFalse(element._baselines.hasOwnProperty('garbage'));
+ });
+
+ test('changeDisplayed', () => {
+ sandbox.spy(element, 'timeEnd');
+ element.changeDisplayed();
+ assert.isFalse(
+ element.timeEnd.calledWithExactly('ChangeDisplayed'));
+ assert.isTrue(
+ element.timeEnd.calledWithExactly('StartupChangeDisplayed'));
+ element.changeDisplayed();
+ assert.isTrue(element.timeEnd.calledWithExactly('ChangeDisplayed'));
+ });
+
+ test('changeFullyLoaded', () => {
+ sandbox.spy(element, 'timeEnd');
+ element.changeFullyLoaded();
+ assert.isFalse(
+ element.timeEnd.calledWithExactly('ChangeFullyLoaded'));
+ assert.isTrue(
+ element.timeEnd.calledWithExactly('StartupChangeFullyLoaded'));
+ element.changeFullyLoaded();
+ assert.isTrue(element.timeEnd.calledWithExactly('ChangeFullyLoaded'));
+ });
+
+ test('diffViewDisplayed', () => {
+ sandbox.spy(element, 'timeEnd');
+ element.diffViewDisplayed();
+ assert.isFalse(
+ element.timeEnd.calledWithExactly('DiffViewDisplayed'));
+ assert.isTrue(
+ element.timeEnd.calledWithExactly('StartupDiffViewDisplayed'));
+ element.diffViewDisplayed();
+ assert.isTrue(element.timeEnd.calledWithExactly('DiffViewDisplayed'));
+ });
+
+ test('fileListDisplayed', () => {
+ sandbox.spy(element, 'timeEnd');
+ element.fileListDisplayed();
+ assert.isFalse(
+ element.timeEnd.calledWithExactly('FileListDisplayed'));
+ assert.isTrue(
+ element.timeEnd.calledWithExactly('StartupFileListDisplayed'));
+ element.fileListDisplayed();
+ assert.isTrue(element.timeEnd.calledWithExactly('FileListDisplayed'));
+ });
+
+ test('dashboardDisplayed', () => {
+ sandbox.spy(element, 'timeEnd');
+ element.dashboardDisplayed();
+ assert.isFalse(
+ element.timeEnd.calledWithExactly('DashboardDisplayed'));
+ assert.isTrue(
+ element.timeEnd.calledWithExactly('StartupDashboardDisplayed'));
+ element.dashboardDisplayed();
+ assert.isTrue(element.timeEnd.calledWithExactly('DashboardDisplayed'));
+ });
+
test('time and timeEnd', () => {
const nowStub = sandbox.stub(element, 'now').returns(0);
element.time('foo');
- nowStub.returns(1);
+ nowStub.returns(1.1);
element.time('bar');
nowStub.returns(2);
element.timeEnd('bar');
- nowStub.returns(3.123);
+ nowStub.returns(3.511);
element.timeEnd('foo');
assert.isTrue(element.reporter.calledWithExactly(
- 'timing-report', 'UI Latency', 'foo', '3ms'
+ 'timing-report', 'UI Latency', 'foo', 4
));
assert.isTrue(element.reporter.calledWithExactly(
- 'timing-report', 'UI Latency', 'bar', '1ms'
+ 'timing-report', 'UI Latency', 'bar', 1
+ ));
+ });
+
+ test('timer object', () => {
+ const nowStub = sandbox.stub(element, 'now').returns(100);
+ const timer = element.getTimer('foo-bar');
+ nowStub.returns(150);
+ timer.end();
+ assert.isTrue(element.reporter.calledWithExactly(
+ 'timing-report', 'UI Latency', 'foo-bar', 50));
+ });
+
+ test('timer object double call', () => {
+ const timer = element.getTimer('foo-bar');
+ timer.end();
+ assert.isTrue(element.reporter.calledOnce);
+ assert.throws(() => {
+ timer.end();
+ done();
+ }, 'Timer for "foo-bar" already ended.');
+ });
+
+ test('timer object maximum', () => {
+ const nowStub = sandbox.stub(element, 'now').returns(100);
+ const timer = element.getTimer('foo-bar').withMaximum(100);
+ nowStub.returns(150);
+ timer.end();
+ assert.isTrue(element.reporter.calledOnce);
+
+ timer.reset();
+ nowStub.returns(260);
+ timer.end();
+ assert.isTrue(element.reporter.calledOnce);
+ });
+
+ test('recordDraftInteraction', () => {
+ const key = 'TimeBetweenDraftActions';
+ const nowStub = sandbox.stub(element, 'now').returns(100);
+ const timingStub = sandbox.stub(element, '_reportTiming');
+ element.recordDraftInteraction();
+ assert.isFalse(timingStub.called);
+
+ nowStub.returns(200);
+ element.recordDraftInteraction();
+ assert.isTrue(timingStub.calledOnce);
+ assert.equal(timingStub.lastCall.args[0], key);
+ assert.equal(timingStub.lastCall.args[1], 100);
+
+ nowStub.returns(350);
+ element.recordDraftInteraction();
+ assert.isTrue(timingStub.calledTwice);
+ assert.equal(timingStub.lastCall.args[0], key);
+ assert.equal(timingStub.lastCall.args[1], 150);
+
+ nowStub.returns(370 + 2 * 60 * 1000);
+ element.recordDraftInteraction();
+ assert.isFalse(timingStub.calledThrice);
+ });
+
+ test('timeEndWithAverage', () => {
+ const nowStub = sandbox.stub(element, 'now').returns(0);
+ nowStub.returns(1000);
+ element.time('foo');
+ nowStub.returns(1100);
+ element.timeEndWithAverage('foo', 'bar', 10);
+ assert.isTrue(element.reporter.calledTwice);
+ assert.isTrue(element.reporter.calledWithExactly(
+ 'timing-report', 'UI Latency', 'foo', 100));
+ assert.isTrue(element.reporter.calledWithExactly(
+ 'timing-report', 'UI Latency', 'bar', 10));
+ });
+
+ test('reportExtension', () => {
+ element.reportExtension('foo');
+ assert.isTrue(element.reporter.calledWithExactly(
+ 'lifecycle', 'Extension detected', 'foo'
));
});
@@ -96,81 +258,58 @@ limitations under the License.
setup(() => {
element.reporter.restore();
sandbox.stub(element, 'defaultReporter');
- sandbox.stub(Gerrit, '_arePluginsLoaded');
});
test('pluginsLoaded reports time', () => {
- Gerrit._arePluginsLoaded.returns(true);
sandbox.stub(element, 'now').returns(42);
element.pluginsLoaded();
assert.isTrue(element.defaultReporter.calledWithExactly(
- 'timing-report', 'UI Latency', 'PluginsLoaded', '42ms'
+ 'timing-report', 'UI Latency', 'PluginsLoaded', 42, undefined
+ ));
+ });
+
+ test('pluginsLoaded reports plugins', () => {
+ element.pluginsLoaded(['foo', 'bar']);
+ assert.isTrue(element.defaultReporter.calledWith(
+ 'lifecycle', 'Plugins installed', 'foo,bar'
));
});
test('caches reports if plugins are not loaded', () => {
- Gerrit._arePluginsLoaded.returns(false);
element.timeEnd('foo');
assert.isFalse(element.defaultReporter.called);
});
test('reports if plugins are loaded', () => {
- Gerrit._arePluginsLoaded.returns(true);
- element.timeEnd('foo');
+ element.pluginsLoaded();
assert.isTrue(element.defaultReporter.called);
});
test('reports cached events preserving order', () => {
- Gerrit._arePluginsLoaded.returns(false);
+ element.time('foo');
+ element.time('bar');
element.timeEnd('foo');
- Gerrit._arePluginsLoaded.returns(true);
+ element.pluginsLoaded();
element.timeEnd('bar');
- assert.isTrue(element.defaultReporter.firstCall.calledWith(
+ assert.isTrue(element.defaultReporter.getCall(0).calledWith(
'timing-report', 'UI Latency', 'foo'
));
- assert.isTrue(element.defaultReporter.secondCall.calledWith(
+ assert.isTrue(element.defaultReporter.getCall(1).calledWith(
+ 'timing-report', 'UI Latency', 'PluginsLoaded'
+ ));
+ assert.isTrue(element.defaultReporter.getCall(2).calledWith(
+ 'lifecycle', 'Plugins installed'
+ ));
+ assert.isTrue(element.defaultReporter.getCall(3).calledWith(
'timing-report', 'UI Latency', 'bar'
));
});
});
- suite('location changed', () => {
- let pathnameStub;
- setup(() => {
- pathnameStub = sinon.stub(element, '_getPathname');
- });
-
- teardown(() => {
- pathnameStub.restore();
- });
-
- test('search', () => {
- pathnameStub.returns('/q/foo');
- element.locationChanged();
- assert.isTrue(element.reporter.calledWithExactly(
- 'nav-report', 'Location Changed', 'Page', '/q/'));
- });
-
- test('change view', () => {
- pathnameStub.returns('/c/42/');
- element.locationChanged();
- assert.isTrue(element.reporter.calledWithExactly(
- 'nav-report', 'Location Changed', 'Page', '/c/'));
- });
-
- test('change view', () => {
- pathnameStub.returns('/c/41/2');
- element.locationChanged();
- assert.isTrue(element.reporter.calledWithExactly(
- 'nav-report', 'Location Changed', 'Page', '/c/'));
- });
-
- test('diff view', () => {
- pathnameStub.returns('/c/41/2/file.txt');
- element.locationChanged();
- assert.isTrue(element.reporter.calledWithExactly(
- 'nav-report', 'Location Changed', 'Page', '/c//COMMIT_MSG'));
- });
+ test('search', () => {
+ element.locationChanged('_handleSomeRoute');
+ assert.isTrue(element.reporter.calledWithExactly(
+ 'nav-report', 'Location Changed', 'Page', '_handleSomeRoute'));
});
suite('exception logging', () => {