Skip to content

Commit

Permalink
[WIP] Instrumentation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhani committed Aug 13, 2024
1 parent c78e8b5 commit 2b4264b
Show file tree
Hide file tree
Showing 15 changed files with 290 additions and 48 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/build-feature-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ on:
- main

jobs:
check:
uses: ./.github/workflows/check.yml
lint:
needs: check
uses: ./.github/workflows/lint.yml
with:
build_type: Debug
test:
needs: lint
uses: ./.github/workflows/test.yml
build:
needs: test
strategy:
matrix:
build_type: [Release, Debug]
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/build-latest-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ on:
- main

jobs:
check:
uses: ./.github/workflows/check.yml
lint:
needs: check
uses: ./.github/workflows/lint.yml
with:
build_type: Debug
test:
needs: lint
uses: ./.github/workflows/test.yml
build:
needs: test
uses: ./.github/workflows/build.yml
with:
build_type: Debug
Expand Down
52 changes: 8 additions & 44 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,34 @@ on:
type: string

jobs:
check-format:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Java™ Setup
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
- name: Check Code Format
uses: gradle/gradle-build-action@v2.4.2
with:
arguments: checkFormat

check-jni:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Java™ Setup
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
- name: Check JNI
run: |
cd tools/jni-test && \
cmake -S. -Bbuild && \
cmake --build build --target run
build-code:
needs: [check-format, check-jni]
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Fetch Dependencies (WPE Bootstrap)
run: python3 tools/scripts/bootstrap.py -a all
- name: Java™ Setup
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Execute Android Linter
uses: gradle/gradle-build-action@v2.4.2
with:
arguments: lint
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build Project
uses: gradle/gradle-build-action@v2.4.2
with:
arguments: assemble${{ inputs.build_type }}
run: ./gradlew assemble${{ inputs.build_type }}
- name: Save MiniBrowser Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: minibrowser-${{ inputs.build_type }}
path: tools/minibrowser/build/outputs/apk/**/*.apk
- name: Save Mediaplayer Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: mediaplayer-${{ inputs.build_type }}
path: tools/mediaplayer/build/outputs/apk/**/*.apk
- name: Save WebDriver Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: webdriver-${{ inputs.build_type }}
path: tools/webdriver/build/outputs/apk/**/*.apk
34 changes: 34 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Check
on: workflow_call

jobs:
check-format:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Java™ Setup
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Check Code Format
run: ./gradlew checkFormat

check-jni:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Java™ Setup
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Check JNI
run: |
cd tools/jni-test && \
cmake -S. -Bbuild && \
cmake --build build --target run
25 changes: 25 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Lint
on:
workflow_call:
inputs:
build_type:
required: true
type: string

jobs:
lint-checks:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch Dependencies (WPE Bootstrap)
run: python3 tools/scripts/bootstrap.py -a all
- name: Java™ Setup
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Lint checks
run: ./gradlew lint${{ inputs.build_type }}
1 change: 1 addition & 0 deletions .github/workflows/run-webdriver-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
matrix:
api-level: [33]
arch: [x86_64]
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: checkout
uses: actions/checkout@v4
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Test
on: workflow_call

env:
apiLevel: '33'
arch: 'x86_64'

jobs:
instrumentation-tests:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Java™ Setup
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Fetch Dependencies (WPE Bootstrap)
run: python3 tools/scripts/bootstrap.py -a x86_64
- name: Remmove layouttests and webdrivertests
run: |
rm -rf layouttests
rm -rf webdrivertests
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: AVD cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ env.apiLevel }}
- name: Create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ env.apiLevel }}
arch: ${{ env.arch }}
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."
- name: Instrumented Tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ env.apiLevel }}
arch: ${{ env.arch }}
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
script: ./gradlew wpe:connectedDebugAndroidTest
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import com.wpe.tools.minibrowse.Utils
import com.wpe.tools.minibrowser.databinding.FragmentBrowserBinding
import com.wpe.wpeview.WPECallback
import com.wpe.wpeview.WPEChromeClient
import com.wpe.wpeview.WPEView
import com.wpe.wpeview.WPEViewClient
Expand Down
5 changes: 5 additions & 0 deletions wpe/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ android {
defaultConfig {
minSdk 31
targetSdk 35

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

lintOptions {
Expand Down Expand Up @@ -90,6 +92,9 @@ android {

dependencies {
implementation 'androidx.annotation:annotation:1.8.2'
androidTestImplementation "androidx.test:runner:1.6.1"
androidTestImplementation "androidx.test:rules:1.6.1"
androidTestImplementation "androidx.test.ext:junit:1.2.1"
}

gradle.afterProject { project ->
Expand Down
94 changes: 94 additions & 0 deletions wpe/src/androidTest/java/com/wpe/wpeview/WPEViewImeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.wpe.wpeview;

import android.content.Context;
import android.graphics.Insets;
import android.util.Log;
import android.view.WindowInsets;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle;
import androidx.test.core.app.ActivityScenario;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@RunWith(AndroidJUnit4.class)
public class WPEViewImeTest {
@Rule
public ActivityScenarioRule<WPEViewTestActivity> wpeViewActivityTestRule =
new ActivityScenarioRule<>(WPEViewTestActivity.class);
@Test
public void testIMEVisible() {
CountDownLatch latch = new CountDownLatch(1);
ActivityScenario<WPEViewTestActivity> scenario = wpeViewActivityTestRule.getScenario();
scenario.onActivity(activity -> {
activity.getWPEView().setWPEViewClient(new WPEViewClient() {
@Override
public void onPageFinished(@NonNull WPEView view, @NonNull String url) {
String focusScript = "function onDocumentFocused() {\n"
+ " document.getElementById('editor').focus();\n"
+ " test.onEditorFocused();\n"
+ "}\n"
+ "(function() {\n"
+ "if (document.hasFocus()) {\n"
+ " onDocumentFocused();"
+ "} else {\n"
+ " window.addEventListener('focus', onDocumentFocused);\n"
+ "}})();";
view.evaluateJavascript(focusScript, new WPECallback<String>() {
@Override
public void onResult(String value) {
latch.countDown();
}
});
}
});

String htmlDocument = "<html><body contenteditable id='editor'></body></html>";
activity.getWPEView().loadHtml(htmlDocument, null);
});

scenario.moveToState(Lifecycle.State.RESUMED);

try {
latch.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

try {
// Give IME time to popup
Thread.sleep(10000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

CountDownLatch secondLatch = new CountDownLatch(1);

AtomicBoolean keyboardShown = new AtomicBoolean(false);
scenario.onActivity(activity -> {
keyboardShown.set(activity.getWPEView().getRootWindowInsets().isVisible(WindowInsets.Type.ime()));

secondLatch.countDown();
});

try {
secondLatch.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

assertTrue(keyboardShown.get());
}
}
30 changes: 30 additions & 0 deletions wpe/src/androidTest/java/com/wpe/wpeview/WPEViewTestActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.wpe.wpeview;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;

public class WPEViewTestActivity extends Activity {

private WPEView wpeView;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));

wpeView = new WPEView(getApplicationContext());
wpeView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT, 1f));
linearLayout.addView(wpeView);

setContentView(linearLayout);
}

public WPEView getWPEView() { return wpeView; }
}
Loading

0 comments on commit 2b4264b

Please sign in to comment.