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

Unified Diff: components/web_restrictions/browser/javatest/src/org/chromium/components/webrestrictions/MockWebRestrictionsClient.java

Issue 1684153002: Web restrictions component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use source_set for test_support Created 4 years, 10 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: 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..c8c553f1564835a0cfffba027a8fedd68a11c043
--- /dev/null
+++ b/components/web_restrictions/browser/javatest/src/org/chromium/components/webrestrictions/MockWebRestrictionsClient.java
@@ -0,0 +1,68 @@
+// 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.
+ */
+ private MockWebRestrictionsClient() {}
+
+ @Override
+ void init(String authority, long nativeProvider) {
+ mAuthority = authority;
+ }
+
+ /**
+ * @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");
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698