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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/BackgroundSyncLauncherServiceTest.java

Issue 1324173002: [Background Sync] Use GcmNetworkManager to start the browser for sync events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@bgsync-fix-background5
Patch Set: Move the BackgroundSyncLauncher into /chrome Created 5 years, 2 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: content/public/android/javatests/src/org/chromium/content/browser/BackgroundSyncLauncherServiceTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/BackgroundSyncLauncherServiceTest.java b/content/public/android/javatests/src/org/chromium/content/browser/BackgroundSyncLauncherServiceTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..e1a29aa1643552ef4cbbc3d2f1a3d1503d881fee
--- /dev/null
+++ b/content/public/android/javatests/src/org/chromium/content/browser/BackgroundSyncLauncherServiceTest.java
@@ -0,0 +1,74 @@
+// Copyright 2015 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.content.browser;
+
+import android.content.Context;
+import android.test.InstrumentationTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.test.util.AdvancedMockContext;
+import org.chromium.base.test.util.Feature;
+
+/**
+ * Tests {@link BackgroundSyncLauncherService}.
+ */
+public class BackgroundSyncLauncherServiceTest extends InstrumentationTestCase {
+ private Context mContext;
+ private BackgroundSyncLauncher mLauncher;
+ private MockLauncherService mLauncherService;
+ private Boolean mShouldLaunchResult;
+
+ static class MockLauncherService extends BackgroundSyncLauncherService {
+ private boolean mDidStartService = false;
+
+ @Override
+ protected void launchBrowser(Context context) {
+ mDidStartService = true;
+ }
+
+ // Posts an assertion task to the UI thread. Since this is only called after the call
+ // to onRunTask, it will be enqueued after any possible call to launchBrowser, and we
+ // can reliably check whether launchBrowser was called.
+ protected void checkExpectations(final boolean expectedStartService) {
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ assertEquals("StartedService", expectedStartService, mDidStartService);
+ }
+ });
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ mContext = new AdvancedMockContext(getInstrumentation().getTargetContext());
+ mLauncher = BackgroundSyncLauncher.create(mContext);
+ mLauncherService = new MockLauncherService();
+ }
+
+ private void deleteLauncherInstance() {
+ mLauncher.destroy();
+ mLauncher = null;
+ }
+
+ private void startOnRunTaskAndVerify(boolean shouldStart) {
+ mLauncherService.onRunTask(null);
+ mLauncherService.checkExpectations(shouldStart);
+ }
+
+ @SmallTest
+ @Feature({"BackgroundSync"})
+ public void testNoFireWhenInstanceExists() {
+ startOnRunTaskAndVerify(false);
+ }
+
+ @SmallTest
+ @Feature({"BackgroundSync"})
+ public void testFiresWhenInstanceNotExists() {
+ deleteLauncherInstance();
+ startOnRunTaskAndVerify(true);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698