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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/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: Make BackgroundSyncLauncher testable 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: chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherServiceTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherServiceTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherServiceTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..7dc29287bb07046aa4260c17ba18ee4bef7deb22
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherServiceTest.java
@@ -0,0 +1,80 @@
+// 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.chrome.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;
+
+ 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());
+ BackgroundSyncLauncher.setGCMEnabled(false);
+ mLauncher = BackgroundSyncLauncher.create(mContext);
+ mLauncherService = new MockLauncherService();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ BackgroundSyncLauncher.setGCMEnabled(true);
+ super.tearDown();
+ }
+
+ 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() {
jkarlin 2015/10/20 17:45:56 s/NotExists/DoesNotExist/
iclelland 2015/10/20 18:56:06 Done.
+ deleteLauncherInstance();
+ startOnRunTaskAndVerify(true);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698