Chromium Code Reviews| Index: components/web_restrictions/browser/javatest/src/org/chromium/components/webrestrictions/MockWebRestrictionsClient.java |
| diff --git a/components/web_restrictions/browser/javatest/src/org/chromium/components/webrestrictions/MockWebRestrictionsClient.java b/components/web_restrictions/browser/javatest/src/org/chromium/components/webrestrictions/MockWebRestrictionsClient.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e7547815dc290d3a68de038d5c54c554b18f0ec8 |
| --- /dev/null |
| +++ b/components/web_restrictions/browser/javatest/src/org/chromium/components/webrestrictions/MockWebRestrictionsClient.java |
| @@ -0,0 +1,78 @@ |
| +// 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.components.webrestrictions; |
| + |
| +import org.chromium.base.annotations.CalledByNative; |
| + |
| +/** |
| + * This is a dummy version of the real WebRestrictionsClient, to allow unit testing of the C++ |
| + * code. |
| + */ |
| +public class MockWebRestrictionsClient extends WebRestrictionsClient { |
| + |
| + private String mAuthority; |
| + |
| + @CalledByNative |
| + static void registerAsMockForTesting() { |
| + WebRestrictionsClient.registerMockForTesting(new MockWebRestrictionsClient()); |
| + } |
| + |
| + @CalledByNative |
| + static void unregisterAsMockForTesting() { |
| + WebRestrictionsClient.registerMockForTesting(null); |
| + } |
| + /** |
| + * Start the web restriction provider and setup the content resolver. |
| + */ |
| + MockWebRestrictionsClient() {} |
|
Bernhard Bauer
2016/02/22 12:39:16
Make this private?
aberent
2016/02/23 13:52:37
Done.
|
| + |
| + @Override |
| + void init(String authority, final long nativeProvider) { |
|
Bernhard Bauer
2016/02/22 12:39:16
final isn't necessary.
aberent
2016/02/23 13:52:37
Done.
|
| + mAuthority = authority; |
| + } |
| + |
| + /** |
| + * Simple helper method to expose the constructor over JNI. |
| + */ |
| + private static WebRestrictionsClient create(String authority, long nativeProvider) { |
|
Bernhard Bauer
2016/02/22 12:39:16
I don't think this is still called.
aberent
2016/02/23 13:52:37
Done.
|
| + WebRestrictionsClient client = new WebRestrictionsClient(); |
| + client.init(authority, nativeProvider); |
| + return client; |
| + } |
| + |
| + /** |
| + * @return whether the web restriction provider supports requesting access for a blocked url. |
| + */ |
| + @Override |
| + boolean supportsRequest() { |
| + return mAuthority.contains("Good"); |
| + } |
| + |
| + /** |
| + * Called when the ContentResolverWebRestrictionsProvider is about to be destroyed. |
| + */ |
| + @Override |
| + void onDestroy() {} |
| + |
| + /** |
| + * Whether we can proceed with loading the {@code url}. |
| + * In case the url is not to be loaded, the web restriction provider can return an optional |
| + * error page to show instead. |
| + */ |
| + @Override |
| + ShouldProceedResult shouldProceed(final String url) { |
| + return new ShouldProceedResult(mAuthority.contains("Good"), url); |
| + } |
| + |
| + /** |
| + * Request permission to load the {@code url}. |
| + * The web restriction provider returns a {@code boolean} variable indicating whether it was |
| + * able to forward the request to the appropriate authority who can approve it. |
| + */ |
| + @Override |
| + boolean requestPermission(final String url) { |
| + return mAuthority.contains("Good"); |
| + } |
| +} |