OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.invalidation; | 5 package org.chromium.chrome.browser.invalidation; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.content.ComponentName; | 9 import android.content.ComponentName; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 assertEquals(1, intent.getExtras().size()); | 72 assertEquals(1, intent.getExtras().size()); |
73 assertTrue(intent.hasExtra(InvalidationIntentProtocol.EXTRA_STOP)); | 73 assertTrue(intent.hasExtra(InvalidationIntentProtocol.EXTRA_STOP)); |
74 assertTrue(intent.getBooleanExtra(InvalidationIntentProtocol.EXTRA_STOP,
false)); | 74 assertTrue(intent.getBooleanExtra(InvalidationIntentProtocol.EXTRA_STOP,
false)); |
75 } | 75 } |
76 | 76 |
77 @SmallTest | 77 @SmallTest |
78 @Feature({"Sync"}) | 78 @Feature({"Sync"}) |
79 public void testResumingMainActivity() throws Exception { | 79 public void testResumingMainActivity() throws Exception { |
80 // Resuming main activity should trigger a start if sync is enabled. | 80 // Resuming main activity should trigger a start if sync is enabled. |
81 setupSync(true); | 81 setupSync(true); |
82 mController.onActivityStateChange(ActivityStatus.RESUMED); | 82 mController.onApplicationStateChange(ActivityStatus.HAS_RUNNING_ACTIVITI
ES); |
83 assertEquals(1, mContext.getNumStartedIntents()); | 83 assertEquals(1, mContext.getNumStartedIntents()); |
84 Intent intent = mContext.getStartedIntent(0); | 84 Intent intent = mContext.getStartedIntent(0); |
85 validateIntentComponent(intent); | 85 validateIntentComponent(intent); |
86 } | 86 } |
87 | 87 |
88 @SmallTest | 88 @SmallTest |
89 @Feature({"Sync"}) | 89 @Feature({"Sync"}) |
90 public void testResumingMainActivityWithSyncDisabled() throws Exception { | 90 public void testResumingMainActivityWithSyncDisabled() throws Exception { |
91 // Resuming main activity should NOT trigger a start if sync is disabled
. | 91 // Resuming main activity should NOT trigger a start if sync is disabled
. |
92 setupSync(false); | 92 setupSync(false); |
93 mController.onActivityStateChange(ActivityStatus.RESUMED); | 93 mController.onApplicationStateChange(ActivityStatus.HAS_RUNNING_ACTIVITI
ES); |
94 assertEquals(0, mContext.getNumStartedIntents()); | 94 assertEquals(0, mContext.getNumStartedIntents()); |
95 } | 95 } |
96 | 96 |
97 @SmallTest | 97 @SmallTest |
98 @Feature({"Sync"}) | 98 @Feature({"Sync"}) |
99 public void testPausingMainActivity() throws Exception { | 99 public void testPausingMainActivity() throws Exception { |
100 // Resuming main activity should trigger a stop if sync is enabled. | 100 // Resuming main activity should trigger a stop if sync is enabled. |
101 setupSync(true); | 101 setupSync(true); |
102 mController.onActivityStateChange(ActivityStatus.PAUSED); | 102 mController.onApplicationStateChange(ActivityStatus.HAS_ONLY_PAUSED_ACTI
VITIES); |
103 assertEquals(1, mContext.getNumStartedIntents()); | 103 assertEquals(1, mContext.getNumStartedIntents()); |
104 Intent intent = mContext.getStartedIntent(0); | 104 Intent intent = mContext.getStartedIntent(0); |
105 validateIntentComponent(intent); | 105 validateIntentComponent(intent); |
106 assertEquals(1, intent.getExtras().size()); | 106 assertEquals(1, intent.getExtras().size()); |
107 assertTrue(intent.hasExtra(InvalidationIntentProtocol.EXTRA_STOP)); | 107 assertTrue(intent.hasExtra(InvalidationIntentProtocol.EXTRA_STOP)); |
108 assertTrue(intent.getBooleanExtra(InvalidationIntentProtocol.EXTRA_STOP,
false)); | 108 assertTrue(intent.getBooleanExtra(InvalidationIntentProtocol.EXTRA_STOP,
false)); |
109 } | 109 } |
110 | 110 |
111 @SmallTest | 111 @SmallTest |
112 @Feature({"Sync"}) | 112 @Feature({"Sync"}) |
113 public void testPausingMainActivityWithSyncDisabled() throws Exception { | 113 public void testPausingMainActivityWithSyncDisabled() throws Exception { |
114 // Resuming main activity should NOT trigger a stop if sync is disabled. | 114 // Resuming main activity should NOT trigger a stop if sync is disabled. |
115 setupSync(false); | 115 setupSync(false); |
116 mController.onActivityStateChange(ActivityStatus.PAUSED); | 116 mController.onApplicationStateChange(ActivityStatus.HAS_ONLY_PAUSED_ACTI
VITIES); |
117 assertEquals(0, mContext.getNumStartedIntents()); | 117 assertEquals(0, mContext.getNumStartedIntents()); |
118 } | 118 } |
119 | 119 |
120 private void setupSync(boolean syncEnabled) { | 120 private void setupSync(boolean syncEnabled) { |
121 Account account = AccountManagerHelper.createAccountFromName("test@gmail
.com"); | 121 Account account = AccountManagerHelper.createAccountFromName("test@gmail
.com"); |
122 ChromeSigninController chromeSigninController = ChromeSigninController.g
et(mContext); | 122 ChromeSigninController chromeSigninController = ChromeSigninController.g
et(mContext); |
123 chromeSigninController.setSignedInAccountName(account.name); | 123 chromeSigninController.setSignedInAccountName(account.name); |
124 SyncStatusHelper syncStatusHelper = SyncStatusHelper.get(mContext); | 124 SyncStatusHelper syncStatusHelper = SyncStatusHelper.get(mContext); |
125 if (syncEnabled) { | 125 if (syncEnabled) { |
126 syncStatusHelper.enableAndroidSync(account); | 126 syncStatusHelper.enableAndroidSync(account); |
127 } else { | 127 } else { |
128 syncStatusHelper.disableAndroidSync(account); | 128 syncStatusHelper.disableAndroidSync(account); |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 @SmallTest | 132 @SmallTest |
133 @Feature({"Sync"}) | 133 @Feature({"Sync"}) |
134 public void testEnsureConstructorRegistersListener() throws Exception { | 134 public void testEnsureConstructorRegistersListener() throws Exception { |
135 final AtomicBoolean listenerCallbackCalled = new AtomicBoolean(); | 135 final AtomicBoolean listenerCallbackCalled = new AtomicBoolean(); |
136 | 136 |
137 // Create instance. | 137 // Create instance. |
138 new InvalidationController(mContext) { | 138 new InvalidationController(mContext) { |
139 @Override | 139 @Override |
140 public void onActivityStateChange(int newState) { | 140 public void onApplicationStateChange(int newState) { |
141 listenerCallbackCalled.set(true); | 141 listenerCallbackCalled.set(true); |
142 } | 142 } |
143 }; | 143 }; |
144 | 144 |
145 // Ensure initial state is correct. | 145 // Ensure initial state is correct. |
146 assertFalse(listenerCallbackCalled.get()); | 146 assertFalse(listenerCallbackCalled.get()); |
147 | 147 |
148 // Ensure we get a callback, which means we have registered for them. | 148 // Ensure we get a callback, which means we have registered for them. |
149 ActivityStatus.onStateChangeForTesting(new Activity(), ActivityStatus.RE
SUMED); | 149 ActivityStatus.onStateChangeForTesting(new Activity(), ActivityStatus.RE
SUMED); |
150 assertTrue(listenerCallbackCalled.get()); | 150 assertTrue(listenerCallbackCalled.get()); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 return startedIntents.get(idx); | 343 return startedIntents.get(idx); |
344 } | 344 } |
345 | 345 |
346 @Override | 346 @Override |
347 public PackageManager getPackageManager() { | 347 public PackageManager getPackageManager() { |
348 return getBaseContext().getPackageManager(); | 348 return getBaseContext().getPackageManager(); |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 } | 352 } |
OLD | NEW |