Bug 1243585 - Add UploadAllPingsImmediatelyScheduler and tests. r=sebastian
Note: still does not compile.
MozReview-Commit-ID: 7NuLecUSTVa
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/schedulers/TelemetryUploadAllPingsImmediatelyScheduler.java
@@ -0,0 +1,32 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+package org.mozilla.gecko.telemetry.schedulers;
+
+import android.content.Context;
+import android.content.Intent;
+import org.mozilla.gecko.telemetry.stores.TelemetryPingStore;
+import org.mozilla.gecko.telemetry.TelemetryUploadService;
+
+/**
+ * Schedules an upload with all pings to be sent immediately.
+ */
+public class TelemetryUploadAllPingsImmediatelyScheduler implements TelemetryUploadScheduler {
+
+ @Override
+ public boolean isReadyToUpload(final TelemetryPingStore store) {
+ // We're ready since we don't have any conditions to wait on (e.g. on wifi, accumulated X pings).
+ return true;
+ }
+
+ @Override
+ public void scheduleUpload(final Context context, final TelemetryPingStore store) {
+ final Intent i = new Intent(TelemetryUploadService.ACTION_UPLOAD);
+ i.setClass(context, TelemetryUploadService.class);
+ i.putExtra(TelemetryUploadService.EXTRA_STORE, store);
+ context.startService(i);
+ }
+}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -567,16 +567,17 @@ gbjar.sources += ['java/org/mozilla/geck
'tabs/TabsGridLayout.java',
'tabs/TabsLayoutAdapter.java',
'tabs/TabsLayoutItemView.java',
'tabs/TabsListLayout.java',
'tabs/TabsPanel.java',
'tabs/TabsPanelThumbnailView.java',
'Telemetry.java',
'telemetry/core/TelemetryCorePingBuilder.java',
+ 'telemetry/schedulers/TelemetryUploadAllPingsImmediatelyScheduler.java',
'telemetry/schedulers/TelemetryUploadScheduler.java',
'telemetry/stores/TelemetryPingStore.java',
'telemetry/TelemetryConstants.java',
'telemetry/TelemetryDispatcher.java',
'telemetry/TelemetryPing.java',
'telemetry/TelemetryPingBuilder.java',
'telemetry/TelemetryPingFromStore.java',
'telemetry/TelemetryUploadService.java',
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/schedulers/TestTelemetryUploadAllPingsImmediatelyScheduler.java
@@ -0,0 +1,59 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+package org.mozilla.gecko.telemetry.schedulers;
+
+import android.content.Context;
+import android.content.Intent;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mozilla.gecko.background.testhelpers.TestRunner;
+import org.mozilla.gecko.telemetry.TelemetryUploadService;
+import org.mozilla.gecko.telemetry.stores.TelemetryPingStore;
+
+import static junit.framework.Assert.*;
+import static org.mockito.Mockito.*;
+
+/**
+ * Unit tests for the upload immediately scheduler.
+ *
+ * When we add more schedulers, we'll likely change the interface
+ * (e.g. pass in current time) and these tests will be more useful.
+ */
+@RunWith(TestRunner.class)
+public class TestTelemetryUploadAllPingsImmediatelyScheduler {
+
+ private TelemetryUploadAllPingsImmediatelyScheduler testScheduler;
+ private TelemetryPingStore testStore;
+
+ @Before
+ public void setUp() {
+ testScheduler = new TelemetryUploadAllPingsImmediatelyScheduler();
+ testStore = mock(TelemetryPingStore.class);
+ }
+
+ @Test
+ public void testReadyToUpload() {
+ assertTrue("Scheduler is always ready to upload", testScheduler.isReadyToUpload(testStore));
+ }
+
+ @Test
+ public void testScheduleUpload() {
+ final Context context = mock(Context.class);
+
+ testScheduler.scheduleUpload(context, testStore);
+
+ final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ verify(context).startService(intentCaptor.capture());
+ final Intent actualIntent = intentCaptor.getValue();
+ assertEquals("Intent action is upload", TelemetryUploadService.ACTION_UPLOAD, actualIntent.getAction());
+ assertTrue("Intent contains store", actualIntent.hasExtra(TelemetryUploadService.EXTRA_STORE));
+ assertEquals("Intent class target is upload service",
+ TelemetryUploadService.class.getName(), actualIntent.getComponent().getClassName());
+ }
+}