OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.sync; | 5 package org.chromium.chrome.browser.sync; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.app.Application; | 8 import android.app.Application; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.Intent; | 10 import android.content.Intent; |
11 import android.content.SyncResult; | 11 import android.content.SyncResult; |
12 import android.os.Bundle; | 12 import android.os.Bundle; |
13 import android.test.suitebuilder.annotation.MediumTest; | 13 import android.test.suitebuilder.annotation.MediumTest; |
14 | 14 |
15 import org.chromium.base.ApplicationStatus; | 15 import org.chromium.base.ApplicationStatus; |
16 import org.chromium.base.CommandLine; | 16 import org.chromium.base.CommandLine; |
17 import org.chromium.base.test.util.Feature; | 17 import org.chromium.base.test.util.Feature; |
18 import org.chromium.chrome.browser.ChromeActivity; | 18 import org.chromium.chrome.browser.ChromeActivity; |
19 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 19 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
20 import org.chromium.components.invalidation.PendingInvalidation; | |
20 import org.chromium.content.browser.test.util.Criteria; | 21 import org.chromium.content.browser.test.util.Criteria; |
21 import org.chromium.content.browser.test.util.CriteriaHelper; | 22 import org.chromium.content.browser.test.util.CriteriaHelper; |
22 import org.chromium.sync.AndroidSyncSettings; | 23 import org.chromium.sync.AndroidSyncSettings; |
23 import org.chromium.sync.signin.AccountManagerHelper; | 24 import org.chromium.sync.signin.AccountManagerHelper; |
24 | 25 |
25 /** | 26 /** |
26 * Tests for ChromeBrowserSyncAdapter. | 27 * Tests for ChromeBrowserSyncAdapter. |
27 * | 28 * |
28 * TODO(nyquist) Remove this class when Chrome sync starts up the same way as th e testshell. | 29 * TODO(nyquist) Remove this class when Chrome sync starts up the same way as th e testshell. |
29 */ | 30 */ |
(...skipping 17 matching lines...) Expand all Loading... | |
47 | 48 |
48 assertTrue("Activity should have been sent to background", | 49 assertTrue("Activity should have been sent to background", |
49 CriteriaHelper.pollForCriteria(new Criteria() { | 50 CriteriaHelper.pollForCriteria(new Criteria() { |
50 @Override | 51 @Override |
51 public boolean isSatisfied() { | 52 public boolean isSatisfied() { |
52 return !ApplicationStatus.hasVisibleActivities(); | 53 return !ApplicationStatus.hasVisibleActivities(); |
53 } | 54 } |
54 }, WAIT_FOR_LAUNCHER_MS, POLL_INTERVAL_MS)); | 55 }, WAIT_FOR_LAUNCHER_MS, POLL_INTERVAL_MS)); |
55 } | 56 } |
56 | 57 |
58 private void performSyncWithBundle(Bundle bundle) { | |
59 mSyncAdapter.onPerformSync(TEST_ACCOUNT, bundle, | |
60 AndroidSyncSettings.getContractAuthority(getActivity()), null, n ew SyncResult()); | |
61 } | |
57 | 62 |
58 private static class TestChromeSyncAdapter extends ChromiumSyncAdapter { | 63 private static class TestChromeSyncAdapter extends ChromiumSyncAdapter { |
59 private boolean mSyncRequested; | 64 private boolean mSyncRequested; |
60 private boolean mSyncRequestedForAllTypes; | 65 private boolean mSyncRequestedForAllTypes; |
61 private int mObjectSource; | 66 private int mObjectSource; |
62 private String mObjectId; | 67 private String mObjectId; |
63 private long mVersion; | 68 private long mVersion; |
64 private String mPayload; | 69 private String mPayload; |
65 | 70 |
66 public TestChromeSyncAdapter(Context context, Application application) { | 71 public TestChromeSyncAdapter(Context context, Application application) { |
67 super(context, application); | 72 super(context, application); |
68 } | 73 } |
69 | 74 |
70 @Override | 75 @Override |
71 protected boolean useAsyncStartup() { | 76 protected boolean useAsyncStartup() { |
72 return false; | 77 return false; |
73 } | 78 } |
74 | 79 |
75 @Override | 80 @Override |
76 public void requestSync(int objectSource, String objectId, long version, String payload) { | 81 public void notifyInvalidation( |
82 int objectSource, String objectId, long version, String payload) { | |
77 mObjectSource = objectSource; | 83 mObjectSource = objectSource; |
78 mObjectId = objectId; | 84 mObjectId = objectId; |
79 mVersion = version; | 85 mVersion = version; |
80 mPayload = payload; | 86 mPayload = payload; |
81 mSyncRequested = true; | 87 if (objectId == null) { |
82 } | 88 mSyncRequestedForAllTypes = true; |
83 | 89 } else { |
84 @Override | 90 mSyncRequested = true; |
85 public void requestSyncForAllTypes() { | 91 } |
86 mSyncRequestedForAllTypes = true; | |
87 } | 92 } |
88 } | 93 } |
89 | 94 |
90 @Override | 95 @Override |
91 protected void setUp() throws Exception { | 96 protected void setUp() throws Exception { |
92 super.setUp(); | 97 super.setUp(); |
93 mSyncAdapter = new TestChromeSyncAdapter(getInstrumentation().getTargetC ontext(), | 98 mSyncAdapter = new TestChromeSyncAdapter(getInstrumentation().getTargetC ontext(), |
94 getActivity().getApplication()); | 99 getActivity().getApplication()); |
95 } | 100 } |
96 | 101 |
97 @Override | 102 @Override |
98 public void startMainActivity() throws InterruptedException { | 103 public void startMainActivity() throws InterruptedException { |
99 startMainActivityOnBlankPage(); | 104 startMainActivityOnBlankPage(); |
100 } | 105 } |
101 | 106 |
102 @MediumTest | 107 @MediumTest |
103 @Feature({"Sync"}) | 108 @Feature({"Sync"}) |
104 public void testRequestSyncNoInvalidationData() { | 109 public void testRequestSyncNoInvalidationData() { |
105 SyncResult syncResult = new SyncResult(); | 110 performSyncWithBundle(new Bundle()); |
106 mSyncAdapter.onPerformSync(TEST_ACCOUNT, new Bundle(), | |
107 AndroidSyncSettings.getContractAuthority(getActivity()), null, s yncResult); | |
108 assertTrue(mSyncAdapter.mSyncRequestedForAllTypes); | 111 assertTrue(mSyncAdapter.mSyncRequestedForAllTypes); |
109 assertFalse(mSyncAdapter.mSyncRequested); | 112 assertFalse(mSyncAdapter.mSyncRequested); |
110 assertTrue(CommandLine.isInitialized()); | 113 assertTrue(CommandLine.isInitialized()); |
111 } | 114 } |
112 | 115 |
113 @MediumTest | 116 @MediumTest |
114 @Feature({"Sync"}) | 117 @Feature({"Sync"}) |
115 public void testRequestSyncSpecificDataType() { | 118 public void testRequestSyncSpecificDataType() { |
116 SyncResult syncResult = new SyncResult(); | 119 final String objectId = "objectid_value"; |
nyquist
2015/05/22 20:21:07
Nit: unnecessary final
knn
2015/06/04 18:23:29
Done.
| |
117 Bundle extras = new Bundle(); | 120 final int objectSource = 65; |
118 extras.putInt(ChromiumSyncAdapter.INVALIDATION_OBJECT_SOURCE_KEY, 65); | 121 final long version = 42L; |
119 extras.putString(ChromiumSyncAdapter.INVALIDATION_OBJECT_ID_KEY, "object id_value"); | 122 final String payload = "payload_value"; |
120 extras.putLong(ChromiumSyncAdapter.INVALIDATION_VERSION_KEY, 42); | 123 |
121 extras.putString(ChromiumSyncAdapter.INVALIDATION_PAYLOAD_KEY, "payload_ value"); | 124 performSyncWithBundle( |
122 mSyncAdapter.onPerformSync(TEST_ACCOUNT, extras, | 125 new PendingInvalidation(objectId, objectSource, version, payload ).toBundle()); |
123 AndroidSyncSettings.getContractAuthority(getActivity()), null, s yncResult); | 126 |
124 assertFalse(mSyncAdapter.mSyncRequestedForAllTypes); | 127 assertFalse(mSyncAdapter.mSyncRequestedForAllTypes); |
125 assertTrue(mSyncAdapter.mSyncRequested); | 128 assertTrue(mSyncAdapter.mSyncRequested); |
126 assertEquals(65, mSyncAdapter.mObjectSource); | 129 assertEquals(objectSource, mSyncAdapter.mObjectSource); |
127 assertEquals("objectid_value", mSyncAdapter.mObjectId); | 130 assertEquals(objectId, mSyncAdapter.mObjectId); |
128 assertEquals(42, mSyncAdapter.mVersion); | 131 assertEquals(version, mSyncAdapter.mVersion); |
129 assertEquals("payload_value", mSyncAdapter.mPayload); | 132 assertEquals(payload, mSyncAdapter.mPayload); |
130 assertTrue(CommandLine.isInitialized()); | 133 assertTrue(CommandLine.isInitialized()); |
131 } | 134 } |
132 | 135 |
133 @MediumTest | 136 @MediumTest |
134 @Feature({"Sync"}) | 137 @Feature({"Sync"}) |
135 public void testRequestSyncWhenChromeInBackground() throws InterruptedExcept ion { | 138 public void testRequestSyncWhenChromeInBackground() throws InterruptedExcept ion { |
136 sendChromeToBackground(getActivity()); | 139 sendChromeToBackground(getActivity()); |
137 SyncResult syncResult = new SyncResult(); | 140 performSyncWithBundle(new Bundle()); |
138 mSyncAdapter.onPerformSync(TEST_ACCOUNT, new Bundle(), | |
139 AndroidSyncSettings.getContractAuthority(getActivity()), null, s yncResult); | |
140 assertFalse(mSyncAdapter.mSyncRequestedForAllTypes); | 141 assertFalse(mSyncAdapter.mSyncRequestedForAllTypes); |
141 assertFalse(mSyncAdapter.mSyncRequested); | 142 assertFalse(mSyncAdapter.mSyncRequested); |
142 } | 143 } |
143 } | 144 } |
OLD | NEW |