summaryrefslogtreecommitdiffstats
path: root/components/devtools_bridge
diff options
context:
space:
mode:
authorserya <serya@chromium.org>2014-11-20 17:10:11 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-21 01:10:30 +0000
commitff7a801dfddaa22643accaf3e0df192470fb7a7b (patch)
tree3526237d28fcfec17d84296d28c2010cfc33a8c9 /components/devtools_bridge
parent9325d7ca3d712a1fcc58d4066984206da6b9e612 (diff)
downloadchromium_src-ff7a801dfddaa22643accaf3e0df192470fb7a7b.zip
chromium_src-ff7a801dfddaa22643accaf3e0df192470fb7a7b.tar.gz
chromium_src-ff7a801dfddaa22643accaf3e0df192470fb7a7b.tar.bz2
Stub for web-base client for DevTools bridge and tests
This patch mostly consists of testing environment for web WebClient. While WebClient intended to be base for a new DeviceProvider in DevTools frontend (https://codereview.chromium.org/720133002/) it is convinient to run tests on android. It lets to test the client directly against server counterpart avoiding flakiness of network and cloud services. TBR=jochen@chromium.org BUG=383418 Review URL: https://codereview.chromium.org/736363002 Cr-Commit-Position: refs/heads/master@{#305131}
Diffstat (limited to 'components/devtools_bridge')
-rw-r--r--components/devtools_bridge/DEPS2
-rw-r--r--components/devtools_bridge/android/client/javatests/AndroidManifest.xml36
-rw-r--r--components/devtools_bridge/android/client/javatests/DEPS4
-rw-r--r--components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClientTest.java43
-rw-r--r--components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/browsertests/TestApplication.java78
-rw-r--r--components/devtools_bridge/android/session_dependency_factory_android.cc4
-rw-r--r--components/devtools_bridge/android/session_dependency_factory_android.h5
-rw-r--r--components/devtools_bridge/client/DEPS5
-rw-r--r--components/devtools_bridge/client/web_client.cc37
-rw-r--r--components/devtools_bridge/client/web_client.h46
-rw-r--r--components/devtools_bridge/test/android/client/DEPS4
-rw-r--r--components/devtools_bridge/test/android/client/javatests/jni/jni_onload.cc30
-rw-r--r--components/devtools_bridge/test/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClient.java27
-rw-r--r--components/devtools_bridge/test/android/client/web_client_android.cc36
-rw-r--r--components/devtools_bridge/test/android/client/web_client_android.h34
-rw-r--r--components/devtools_bridge/test/android/javatests/jni/jni_onload.cc12
16 files changed, 389 insertions, 14 deletions
diff --git a/components/devtools_bridge/DEPS b/components/devtools_bridge/DEPS
index 699e22a..d8f0c53 100644
--- a/components/devtools_bridge/DEPS
+++ b/components/devtools_bridge/DEPS
@@ -1,6 +1,4 @@
include_rules = [
- "-chrome",
- "-content",
"+net",
"+third_party/libjingle",
"+third_party/webrtc",
diff --git a/components/devtools_bridge/android/client/javatests/AndroidManifest.xml b/components/devtools_bridge/android/client/javatests/AndroidManifest.xml
new file mode 100644
index 0000000..4ce7a2e
--- /dev/null
+++ b/components/devtools_bridge/android/client/javatests/AndroidManifest.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2014 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 name must be unique so suffix with "tests" so package loader
+ doesn't ignore this. -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.chromium.components.devtools_bridge.browsertests">
+
+ <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />
+
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+ <uses-permission android:name="android.permission.CAMERA" />
+ <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
+ <uses-permission android:name="android.permission.INJECT_EVENTS" />
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.NFC"/>
+ <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
+ <uses-permission android:name="android.permission.RUN_INSTRUMENTATION" />
+ <uses-permission android:name="android.permission.USE_CREDENTIALS" />
+ <uses-permission android:name="android.permission.WAKE_LOCK"/>
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+ <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
+ <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
+
+ <application android:name=".TestApplication"
+ android:debuggable="true">
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="org.chromium.components.devtools_bridge.browsertests"
+ android:label="Tests for DevTols bride client"/>
+
+</manifest>
diff --git a/components/devtools_bridge/android/client/javatests/DEPS b/components/devtools_bridge/android/client/javatests/DEPS
new file mode 100644
index 0000000..5c694b9
--- /dev/null
+++ b/components/devtools_bridge/android/client/javatests/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ "+chrome",
+ "+content",
+]
diff --git a/components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClientTest.java b/components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClientTest.java
new file mode 100644
index 0000000..2c4299d
--- /dev/null
+++ b/components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClientTest.java
@@ -0,0 +1,43 @@
+// Copyright 2014 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.devtools_bridge;
+
+import android.test.InstrumentationTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.chrome.browser.profiles.Profile;
+import org.chromium.content.browser.BrowserStartupController;
+
+import java.util.concurrent.Callable;
+
+/**
+ * Tests for {@link WebClient}. WebClient is not intended to run on Android but
+ * it can. It is useful for tests: we can test it against the server in the
+ * same process (without dependency on network and cloud services).
+ */
+public class WebClientTest extends InstrumentationTestCase {
+ private Profile mProfile;
+
+ protected void startChromeBrowserProcessSyncOnUIThread() throws Exception {
+ BrowserStartupController.get(getInstrumentation().getTargetContext())
+ .startBrowserProcessesSync(false);
+ mProfile = Profile.getLastUsedProfile();
+ }
+
+ @SmallTest
+ public void testCreationWebClient() throws Exception {
+ ThreadUtils.runOnUiThreadBlocking(new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ startChromeBrowserProcessSyncOnUIThread();
+ assert mProfile != null;
+
+ new WebClient(mProfile).dispose();
+ return null;
+ }
+ });
+ }
+}
diff --git a/components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/browsertests/TestApplication.java b/components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/browsertests/TestApplication.java
new file mode 100644
index 0000000..ff55795
--- /dev/null
+++ b/components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/browsertests/TestApplication.java
@@ -0,0 +1,78 @@
+// Copyright 2013 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.devtools_bridge.browsertests;
+
+import android.content.Context;
+
+import org.chromium.base.CommandLine;
+import org.chromium.base.PathUtils;
+import org.chromium.base.ResourceExtractor;
+import org.chromium.chrome.browser.ChromiumApplication;
+import org.chromium.chrome.browser.PKCS11AuthenticationManager;
+import org.chromium.net.AndroidPrivateKey;
+
+import java.security.cert.X509Certificate;
+
+/**
+ * Host application for DevTools Bridge client code tests.
+ */
+public class TestApplication extends ChromiumApplication {
+ private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "devtools_bridge";
+ private static final String[] MANDATORY_PAKS = {
+ "en-US.pak",
+ "icudtl.dat",
+ "natives_blob.bin",
+ "resources.pak",
+ "snapshot_blob.bin"
+ };
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ ResourceExtractor.setMandatoryPaksToExtract(MANDATORY_PAKS);
+ PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
+ }
+
+ @Override
+ public void initCommandLine() {
+ if (!CommandLine.isInitialized()) {
+ CommandLine.init(null);
+ }
+ }
+
+ @Override
+ protected PKCS11AuthenticationManager getPKCS11AuthenticationManager() {
+ return new PKCS11AuthenticationManager() {
+ @Override
+ public boolean isPKCS11AuthEnabled() {
+ return false;
+ }
+
+ @Override
+ public String getClientCertificateAlias(String hostName, int port) {
+ return null;
+ }
+
+ @Override
+ public void initialize(Context context) {
+ }
+
+ @Override
+ public X509Certificate[] getCertificateChain(String alias) {
+ return null;
+ }
+
+ @Override
+ public AndroidPrivateKey getPrivateKey(String alias) {
+ return null;
+ }
+ };
+ }
+
+ @Override
+ protected boolean areParentalControlsEnabled() {
+ return false;
+ }
+}
diff --git a/components/devtools_bridge/android/session_dependency_factory_android.cc b/components/devtools_bridge/android/session_dependency_factory_android.cc
index 168f2fc..7f3ea56 100644
--- a/components/devtools_bridge/android/session_dependency_factory_android.cc
+++ b/components/devtools_bridge/android/session_dependency_factory_android.cc
@@ -146,8 +146,8 @@ SessionDependencyFactoryAndroid::~SessionDependencyFactoryAndroid() {
}
// static
-void SessionDependencyFactoryAndroid::RegisterNatives(JNIEnv* env) {
- RegisterNativesImpl(env);
+bool SessionDependencyFactoryAndroid::RegisterNatives(JNIEnv* env) {
+ return RegisterNativesImpl(env);
}
scoped_ptr<AbstractPeerConnection>
diff --git a/components/devtools_bridge/android/session_dependency_factory_android.h b/components/devtools_bridge/android/session_dependency_factory_android.h
index 62ecae3..bfc8264 100644
--- a/components/devtools_bridge/android/session_dependency_factory_android.h
+++ b/components/devtools_bridge/android/session_dependency_factory_android.h
@@ -5,8 +5,9 @@
#ifndef COMPONENTS_DEVTOOLS_BRIDGE_ANDROID_SESSION_DEPENDENCY_FACTORY_ANDROID_H_
#define COMPONENTS_DEVTOOLS_BRIDGE_ANDROID_SESSION_DEPENDENCY_FACTORY_ANDROID_H_
+#include <jni.h>
+
#include "components/devtools_bridge/session_dependency_factory.h"
-#include "jni.h"
namespace devtools_bridge {
namespace android {
@@ -16,7 +17,7 @@ class SessionDependencyFactoryAndroid : public SessionDependencyFactory {
SessionDependencyFactoryAndroid();
virtual ~SessionDependencyFactoryAndroid();
- static void RegisterNatives(JNIEnv* env);
+ static bool RegisterNatives(JNIEnv* env);
virtual scoped_ptr<AbstractPeerConnection> CreatePeerConnection(
scoped_ptr<RTCConfiguration> config,
diff --git a/components/devtools_bridge/client/DEPS b/components/devtools_bridge/client/DEPS
new file mode 100644
index 0000000..5bbc0c2
--- /dev/null
+++ b/components/devtools_bridge/client/DEPS
@@ -0,0 +1,5 @@
+include_rules = [
+ "+content/public",
+ "-third_party/libjingle",
+ "-third_party/webrtc",
+]
diff --git a/components/devtools_bridge/client/web_client.cc b/components/devtools_bridge/client/web_client.cc
new file mode 100644
index 0000000..d323db5
--- /dev/null
+++ b/components/devtools_bridge/client/web_client.cc
@@ -0,0 +1,37 @@
+// Copyright 2014 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.
+
+#include "components/devtools_bridge/client/web_client.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_delegate.h"
+
+namespace devtools_bridge {
+
+namespace {
+
+class WebClientImpl : public WebClient, private content::WebContentsDelegate {
+ public:
+ WebClientImpl(content::BrowserContext* context, Delegate* delegate);
+
+ private:
+ Delegate* const delegate_;
+ const scoped_ptr<content::WebContents> web_contents_;
+};
+
+WebClientImpl::WebClientImpl(content::BrowserContext* context,
+ Delegate* delegate)
+ : delegate_(delegate),
+ web_contents_(content::WebContents::Create(
+ content::WebContents::CreateParams(context))) {
+ web_contents_->SetDelegate(this);
+}
+
+} // namespace
+
+scoped_ptr<WebClient> WebClient::CreateInstance(
+ content::BrowserContext* context, Delegate* delegate) {
+ return make_scoped_ptr(new WebClientImpl(context, delegate));
+}
+
+} // namespace devtools_bridge
diff --git a/components/devtools_bridge/client/web_client.h b/components/devtools_bridge/client/web_client.h
new file mode 100644
index 0000000..d980e87
--- /dev/null
+++ b/components/devtools_bridge/client/web_client.h
@@ -0,0 +1,46 @@
+// Copyright 2014 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.
+
+#ifndef COMPONENTS_DEVTOOLS_BRIDGE_CLIENT_WEB_CLIENT_H_
+#define COMPONENTS_DEVTOOLS_BRIDGE_CLIENT_WEB_CLIENT_H_
+
+#include "base/memory/scoped_ptr.h"
+
+namespace content {
+class BrowserContext;
+}
+
+namespace devtools_bridge {
+
+/**
+ * Client for DevTools Bridge for desktop Chrome. Uses WebContents to host
+ * JavaScript implementation (therefore lives on the UI thread and must be
+ * destroyed before |context|). WebContents works as a sandbox for WebRTC
+ * related code.
+ */
+class WebClient {
+ public:
+ class Delegate {
+ public:
+
+ // TODO(serya): implement
+ };
+
+ virtual ~WebClient() {}
+
+ static scoped_ptr<WebClient> CreateInstance(
+ content::BrowserContext* context, Delegate* delegate);
+
+ // TODO(serya): Implement.
+
+ protected:
+ WebClient() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(WebClient);
+};
+
+} // namespace devtools_bridge
+
+#endif // COMPONENTS_DEVTOOLS_BRIDGE_CLIENT_WEB_CLIENT_H_
diff --git a/components/devtools_bridge/test/android/client/DEPS b/components/devtools_bridge/test/android/client/DEPS
new file mode 100644
index 0000000..050660e
--- /dev/null
+++ b/components/devtools_bridge/test/android/client/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ "+chrome",
+ "+jni",
+]
diff --git a/components/devtools_bridge/test/android/client/javatests/jni/jni_onload.cc b/components/devtools_bridge/test/android/client/javatests/jni/jni_onload.cc
new file mode 100644
index 0000000..3f35064
--- /dev/null
+++ b/components/devtools_bridge/test/android/client/javatests/jni/jni_onload.cc
@@ -0,0 +1,30 @@
+// Copyright 2014 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.
+
+#include "base/android/base_jni_registrar.h"
+#include "base/android/jni_android.h"
+#include "base/android/library_loader/library_loader_hooks.h"
+#include "chrome/app/android/chrome_android_initializer.h"
+#include "chrome/app/android/chrome_main_delegate_android.h"
+#include "components/devtools_bridge/android/session_dependency_factory_android.h"
+#include "components/devtools_bridge/test/android/client/web_client_android.h"
+
+using namespace devtools_bridge::android;
+
+namespace {
+
+class Delegate : public ChromeMainDelegateAndroid {
+ public:
+ bool RegisterApplicationNativeMethods(JNIEnv* env) override {
+ return ChromeMainDelegateAndroid::RegisterApplicationNativeMethods(env) &&
+ SessionDependencyFactoryAndroid::InitializeSSL() &&
+ WebClientAndroid::RegisterNatives(env);
+ }
+};
+
+} // namespace
+
+JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
+ return RunChrome(vm, new Delegate());
+}
diff --git a/components/devtools_bridge/test/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClient.java b/components/devtools_bridge/test/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClient.java
new file mode 100644
index 0000000..896710e
--- /dev/null
+++ b/components/devtools_bridge/test/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClient.java
@@ -0,0 +1,27 @@
+// Copyright 2014 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.devtools_bridge;
+
+import org.chromium.base.JNINamespace;
+import org.chromium.chrome.browser.profiles.Profile;
+
+/**
+ * Java wrapper over native WebClient for tests.
+ */
+@JNINamespace("devtools_bridge::android")
+public final class WebClient {
+ private final long mWebClientPtr;
+
+ public WebClient(Profile profile) {
+ mWebClientPtr = nativeCreateWebClient(profile);
+ }
+
+ public void dispose() {
+ nativeDestroyWebClient(mWebClientPtr);
+ }
+
+ private static native long nativeCreateWebClient(Profile profile);
+ private static native void nativeDestroyWebClient(long webClientPtr);
+}
diff --git a/components/devtools_bridge/test/android/client/web_client_android.cc b/components/devtools_bridge/test/android/client/web_client_android.cc
new file mode 100644
index 0000000..8287a24
--- /dev/null
+++ b/components/devtools_bridge/test/android/client/web_client_android.cc
@@ -0,0 +1,36 @@
+// Copyright 2014 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.
+
+#include "components/devtools_bridge/test/android/client/web_client_android.h"
+
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_android.h"
+#include "jni/WebClient_jni.h"
+
+namespace devtools_bridge {
+namespace android {
+
+bool WebClientAndroid::RegisterNatives(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+WebClientAndroid::WebClientAndroid(Profile* profile)
+ : impl_(WebClient::CreateInstance(profile, this)) {
+}
+
+WebClientAndroid::~WebClientAndroid() {
+}
+
+static jlong CreateWebClient(JNIEnv* env, jclass jcaller, jobject j_profile) {
+ Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile);
+ return reinterpret_cast<jlong>(new WebClientAndroid(profile));
+}
+
+static void DestroyWebClient(
+ JNIEnv* env, jclass jcaller, jlong web_client_ptr) {
+ delete reinterpret_cast<WebClientAndroid*>(web_client_ptr);
+}
+
+} // namespace android
+} // namespace devtools_bridge
diff --git a/components/devtools_bridge/test/android/client/web_client_android.h b/components/devtools_bridge/test/android/client/web_client_android.h
new file mode 100644
index 0000000..9bca5bc
--- /dev/null
+++ b/components/devtools_bridge/test/android/client/web_client_android.h
@@ -0,0 +1,34 @@
+// Copyright 2014 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.
+
+#ifndef COMPONENTS_DEVTOOLS_BRIDGE_TEST_ANDROID_CLIENT_WEB_CLIENT_ANDROID_H_
+#define COMPONENTS_DEVTOOLS_BRIDGE_TEST_ANDROID_CLIENT_WEB_CLIENT_ANDROID_H_
+
+#include <jni.h>
+
+#include "components/devtools_bridge/client/web_client.h"
+
+class Profile;
+
+namespace devtools_bridge {
+namespace android {
+
+/**
+ * Android wrapper over WebClient for Java tests. See WebClientTest.java.
+ */
+class WebClientAndroid : private WebClient::Delegate {
+ public:
+ static bool RegisterNatives(JNIEnv* env);
+
+ WebClientAndroid(Profile* profile);
+ ~WebClientAndroid();
+
+ private:
+ scoped_ptr<WebClient> impl_;
+};
+
+} // namespace android
+} // namespace devtools_bridge
+
+#endif // COMPONENTS_DEVTOOLS_BRIDGE_TEST_ANDROID_CLIENT_WEB_CLIENT_ANDROID_H_
diff --git a/components/devtools_bridge/test/android/javatests/jni/jni_onload.cc b/components/devtools_bridge/test/android/javatests/jni/jni_onload.cc
index 8fc74800..49fde3a 100644
--- a/components/devtools_bridge/test/android/javatests/jni/jni_onload.cc
+++ b/components/devtools_bridge/test/android/javatests/jni/jni_onload.cc
@@ -12,15 +12,11 @@ using namespace devtools_bridge::android;
JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
base::android::InitVM(vm);
JNIEnv* env = base::android::AttachCurrentThread();
- if (!base::android::RegisterLibraryLoaderEntryHook(env)) {
+ if (!base::android::RegisterLibraryLoaderEntryHook(env) ||
+ !base::android::RegisterJni(env) ||
+ !SessionDependencyFactoryAndroid::InitializeSSL() ||
+ !SessionDependencyFactoryAndroid::RegisterNatives(env)) {
return -1;
}
- if (!base::android::RegisterJni(env)) {
- return -1;
- }
- if (!SessionDependencyFactoryAndroid::InitializeSSL()) {
- return -1;
- }
- SessionDependencyFactoryAndroid::RegisterNatives(env);
return JNI_VERSION_1_4;
}