Adapt SyncTestRule to allow AndroidSyncSettings to depend on PSS
Problem: AndroidSyncSettings (ASS) will soon depend on ProfileSyncService (PSS), particularly in its constructor. Although this is is fine in production code, SyncTestRule poses two issues for this setup on test code. - ASS is created before a fake PSS provided by tests can be injected. This is a problem because the initial state of PSS will be relevant to the constructor logic of ASS, so we need to be able to fake this initial state to write good tests. - ASS is created before the JNI loads in startMainActivityForSyncTest(). For tests that don't provide a fake PSS, ASS will then attempt to talk to the real PSS before JNI is loaded, causing an error. Solution: When SyncTestRule creates an ASS, the goal is actually just to fake one of its internal dependencies, SyncContentResolverDelegate. In this CL, we convert SyncContentResolverDelegate into a singleton. In this way, a fake for this object can be injected without needing to early construct ASS*. Furthermore, JNI is loaded earlier so that the rule can safely use tools like FakeServer and FakeProfileSyncService. * Note that constructing after startMainActivityForSyncTest() is not an option because there's already code talking to ASS when this function is running. Bug: 1125622 Change-Id: I9dd938fd5d8211d58a97adb6d484c1a21a3b67db Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424150 Commit-Queue: Victor Vianna <victorvianna@google.com> Reviewed-by:Marc Treib <treib@chromium.org> Cr-Commit-Position: refs/heads/master@{#810116}
Showing
Please register or sign in to comment