Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/RestoreHistogramTest.java

Issue 2750323002: [Android] Histogram for Android restore (Closed)
Patch Set: fix bauerb@s nits Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/RestoreHistogramTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/RestoreHistogramTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/RestoreHistogramTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..1b14c02a922fee0eafbeb1d9facc1225d2dbd42c
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/RestoreHistogramTest.java
@@ -0,0 +1,92 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser;
+
+import android.support.test.filters.SmallTest;
+
+import org.chromium.base.ContextUtils;
+import org.chromium.base.library_loader.LibraryLoader;
+import org.chromium.base.library_loader.LibraryProcessType;
+import org.chromium.base.library_loader.ProcessInitException;
+import org.chromium.base.metrics.RecordHistogram;
+import org.chromium.base.test.util.MetricsUtils;
+import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
+
+/**
+ * This test tests the logic for writing the restore histogram at two different levels
+ */
+public class RestoreHistogramTest extends ChromeTabbedActivityTestBase {
+ @Override
+ public void startMainActivity() {
+ // Do nothing, these tests need to control when they start the activity.
+ }
+
+ private void clearPrefs() {
+ ContextUtils.getAppSharedPreferences().edit().clear().apply();
+ }
+
+ /**
+ * Test that the fundamental method for writing the histogram
+ * {@link ChromeBackupAgent#recordRestoreHistogram()} works correctly
+ *
+ * @throws ProcessInitException
+ * @Note This can't be tested in the ChromeBackupAgent Junit test, since the histograms are
+ * written in the C++ code, and because all the functions are static there is no easy way
+ * of mocking them in Mockito (one can disable them, but that would spoil the point of the
+ * test).
+ */
+ @SmallTest
+ public void testHistogramWriter() throws ProcessInitException {
+ LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized();
+ RecordHistogram.initialize();
+ MetricsUtils.HistogramDelta noRestoreDelta = new MetricsUtils.HistogramDelta(
+ ChromeBackupAgent.HISTOGRAM_ANDROID_RESTORE_RESULT, ChromeBackupAgent.NO_RESTORE);
+ MetricsUtils.HistogramDelta restoreCompletedDelta =
+ new MetricsUtils.HistogramDelta(ChromeBackupAgent.HISTOGRAM_ANDROID_RESTORE_RESULT,
+ ChromeBackupAgent.RESTORE_COMPLETED);
+ MetricsUtils.HistogramDelta restoreStatusRecorded =
+ new MetricsUtils.HistogramDelta(ChromeBackupAgent.HISTOGRAM_ANDROID_RESTORE_RESULT,
+ ChromeBackupAgent.RESTORE_STATUS_RECORDED);
+
+ // Check behavior with no preference set
+ clearPrefs();
+ ChromeBackupAgent.recordRestoreHistogram();
+ assertEquals(1, noRestoreDelta.getDelta());
+ assertEquals(0, restoreCompletedDelta.getDelta());
+ assertEquals(
+ ChromeBackupAgent.RESTORE_STATUS_RECORDED, ChromeBackupAgent.getRestoreStatus());
+
+ // Check behavior with a restore status
+ ChromeBackupAgent.setRestoreStatus(ChromeBackupAgent.RESTORE_COMPLETED);
+ ChromeBackupAgent.recordRestoreHistogram();
+ assertEquals(1, noRestoreDelta.getDelta());
+ assertEquals(1, restoreCompletedDelta.getDelta());
+ assertEquals(
+ ChromeBackupAgent.RESTORE_STATUS_RECORDED, ChromeBackupAgent.getRestoreStatus());
+
+ // Second call should record nothing (note this assumes it doesn't record something totally
+ // random)
+ ChromeBackupAgent.recordRestoreHistogram();
+ assertEquals(0, restoreStatusRecorded.getDelta());
+ }
+
+ /**
+ * Test that the histogram is written during Chrome first run.
+ *
+ * @throws InterruptedException
+ * @throws ProcessInitException
+ */
+ @SmallTest
+ public void testWritingHistogramAtStartup() throws InterruptedException, ProcessInitException {
+ LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized();
+ RecordHistogram.initialize();
+ MetricsUtils.HistogramDelta noRestoreDelta = new MetricsUtils.HistogramDelta(
+ ChromeBackupAgent.HISTOGRAM_ANDROID_RESTORE_RESULT, ChromeBackupAgent.NO_RESTORE);
+
+ // Histogram should be written the first time the activity is started.
+ startMainActivityOnBlankPage();
+ assertEquals(1, noRestoreDelta.getDelta());
+ }
+}
« no previous file with comments | « chrome/android/java_sources.gni ('k') | chrome/android/junit/src/org/chromium/chrome/browser/ChromeBackupAgentTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698