diff --git a/FoldingVideo/app/build.gradle b/FoldingVideo/app/build.gradle index d136de3..0791ed5 100644 --- a/FoldingVideo/app/build.gradle +++ b/FoldingVideo/app/build.gradle @@ -35,11 +35,11 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.core:core-ktx:1.6.0' - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0' - implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.core:core-ktx:1.7.0' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1' + implementation 'com.google.android.material:material:1.5.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.2' + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' implementation 'androidx.window:window:1.0.0' implementation 'com.google.android.exoplayer:exoplayer:2.14.0' @@ -48,6 +48,7 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation "androidx.test.espresso:espresso-contrib:3.4.0" - androidTestImplementation "androidx.test:rules:1.3.0" + androidTestImplementation "androidx.test:rules:1.4.0" androidTestImplementation "androidx.test.uiautomator:uiautomator:2.2.0" + androidTestImplementation "com.microsoft.device.dualscreen.testing:testing-kotlin:1.0.0-alpha2" } \ No newline at end of file diff --git a/FoldingVideo/app/src/androidTest/java/com/example/foldingvideo/UITests.kt b/FoldingVideo/app/src/androidTest/java/com/example/foldingvideo/UITests.kt index a622b7b..14995e1 100644 --- a/FoldingVideo/app/src/androidTest/java/com/example/foldingvideo/UITests.kt +++ b/FoldingVideo/app/src/androidTest/java/com/example/foldingvideo/UITests.kt @@ -10,10 +10,12 @@ import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.rule.ActivityTestRule import androidx.test.uiautomator.UiDevice +import com.microsoft.device.dualscreen.testing.resetOrientation +import com.microsoft.device.dualscreen.testing.spanFromStart import org.hamcrest.Description import org.hamcrest.Matcher import org.hamcrest.TypeSafeMatcher @@ -25,7 +27,7 @@ import org.junit.runner.RunWith class UITests { @get:Rule - val activityRule = ActivityTestRule(MainActivity::class.java) + val activityRule = ActivityScenarioRule(MainActivity::class.java) private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) @@ -60,7 +62,7 @@ class UITests { } override fun describeTo(description: Description) { - description.appendText("View should have height $size") + description.appendText("View should have width $size") } } } @@ -72,7 +74,7 @@ class UITests { } override fun describeTo(description: Description) { - description.appendText("View shouldn't have height $size") + description.appendText("View shouldn't have width $size") } } } @@ -81,7 +83,7 @@ class UITests { fun dual_landscape() { // span app - device.swipe(675, 1780, 1350, 900, 400) + device.spanFromStart() // check bottom background is 0 height onView(withId(R.id.horiz_background)).check(matches(withHeight(0))) @@ -94,15 +96,14 @@ class UITests { onView(withId(R.id.horiz_background)).check(matches(notWithHeight(0))) // reset rotation - device.setOrientationNatural() - device.unfreezeRotation() + device.resetOrientation() } @Test fun dual_portrait_split_ctrls() { // span app - device.swipe(675, 1780, 1350, 900, 400) + device.spanFromStart() // check right background is 0 width onView(withId(R.id.vert_background)).check(matches(withWidth(0))) @@ -123,7 +124,7 @@ class UITests { @Test fun dual_portrait_split_ctrls_saved() { // span app - device.swipe(675, 1780, 1350, 900, 400) + device.spanFromStart() // check right background is 0 width onView(withId(R.id.vert_background)).check(matches(withWidth(0))) @@ -139,8 +140,7 @@ class UITests { device.unfreezeRotation() // rotate back - device.setOrientationNatural() - device.unfreezeRotation() + device.resetOrientation() // check right background is non 0 width - split ctrls have saved onView(withId(R.id.vert_background)).check(matches(notWithWidth(0))) diff --git a/FoldingVideo/build.gradle b/FoldingVideo/build.gradle index 77b8142..b6854d2 100644 --- a/FoldingVideo/build.gradle +++ b/FoldingVideo/build.gradle @@ -1,12 +1,12 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = "1.5.0" + ext.kotlin_version = "1.6.10" repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.0.0' + classpath 'com.android.tools.build:gradle:7.1.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/FoldingVideo/gradle/wrapper/gradle-wrapper.properties b/FoldingVideo/gradle/wrapper/gradle-wrapper.properties index c9653df..4e491e3 100644 --- a/FoldingVideo/gradle/wrapper/gradle-wrapper.properties +++ b/FoldingVideo/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Tue May 25 17:39:54 EDT 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/FoldingVideo/ktlint.gradle b/FoldingVideo/ktlint.gradle index 9f8139b..1ef63bf 100644 --- a/FoldingVideo/ktlint.gradle +++ b/FoldingVideo/ktlint.gradle @@ -18,7 +18,7 @@ dependencies { task ktlint(type: JavaExec, group: "verification") { description = "Check Kotlin code style." classpath = configurations.ktlint - main = "com.pinterest.ktlint.Main" + mainClass.set("com.pinterest.ktlint.Main") args "src/**/*.kt" // to generate report in checkstyle format prepend following args: // "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml" @@ -28,6 +28,6 @@ task ktlint(type: JavaExec, group: "verification") { task ktlintFormat(type: JavaExec, group: "formatting") { description = "Fix Kotlin code style deviations." classpath = configurations.ktlint - main = "com.pinterest.ktlint.Main" + mainClass.set("com.pinterest.ktlint.Main") args "-F", "src/**/*.kt" } diff --git a/PhotoEditor/app/build.gradle b/PhotoEditor/app/build.gradle index c7c14c5..c433d9b 100644 --- a/PhotoEditor/app/build.gradle +++ b/PhotoEditor/app/build.gradle @@ -5,7 +5,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' android { compileSdkVersion rootProject.ext.compileSdkVersion @@ -41,7 +40,7 @@ dependencies { implementation androidxDependencies.ktxFragment implementation androidxDependencies.windowManager - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1' testImplementation testDependencies.junit androidTestImplementation instrumentationTestDependencies.junit @@ -49,4 +48,5 @@ dependencies { androidTestImplementation instrumentationTestDependencies.testRunner androidTestImplementation instrumentationTestDependencies.testRules androidTestImplementation instrumentationTestDependencies.uiautomator + androidTestImplementation instrumentationTestDependencies.kotlinTesting } diff --git a/PhotoEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/photoeditor/PhotoEditorUITest.kt b/PhotoEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/photoeditor/PhotoEditorUITest.kt index 754ac2f..32ce5fd 100644 --- a/PhotoEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/photoeditor/PhotoEditorUITest.kt +++ b/PhotoEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/photoeditor/PhotoEditorUITest.kt @@ -23,6 +23,8 @@ import androidx.test.rule.ActivityTestRule import androidx.test.uiautomator.By import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.Until +import com.microsoft.device.dualscreen.testing.closeEnd +import com.microsoft.device.dualscreen.testing.spanFromStart import org.hamcrest.CoreMatchers.not import org.junit.Rule import org.junit.Test @@ -39,6 +41,8 @@ class PhotoEditorUITest { @get:Rule val activityRule = ActivityTestRule(MainActivity::class.java) + private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + /** * Tests visibility of controls when app spanned vs. unspanned * @@ -56,7 +60,7 @@ class PhotoEditorUITest { onView(withId(R.id.brightness)).check(matches(withEffectiveVisibility(Visibility.INVISIBLE))) onView(withId(R.id.warmth)).check(matches(withEffectiveVisibility(Visibility.INVISIBLE))) - spanFromLeft() + device.spanFromStart() // Switched to dual-screen mode, so dropdown should not exist and all sliders should be visible onView(withId(R.id.controls)).check(doesNotExist()) @@ -88,7 +92,7 @@ class PhotoEditorUITest { val prev = activityRule.activity.findViewById(R.id.image).drawable val filesPackage = - if (Build.MODEL.contains("Emulator")) { + if (Build.MODEL.contains("Emulator") || Build.MODEL.contains("Image")) { "com.android.documentsui" // emulator apk package name } else { "com.google.android.documentsui" // device apk package name @@ -122,90 +126,9 @@ class PhotoEditorUITest { ) // Close Files app - closeRight() + device.closeEnd() // Unlock rotation device.unfreezeRotation() } - - /** - * HELPER FUNCTIONS FOR DUAL-SCREEN BEHAVIOR - * - * Use the functions below in your tests when testing dual-screen behaviors and transitions. - * Run the "testSpanningHelperFunctions" test below to check that the methods produce - * the expected behavior on your device. - * - * If the test fails, modify the swipe parameters as needed- usually either an increase in the - * "steps" parameter or a slight shift in the "endX" parameter. - * - */ - - /** - * Runs helper functions and checks that they work as expected - * - * @precondition device in portrait mode, no other applications are open - * (so app by default opens on left screen) - */ - @Test - fun testSpanningHelperFunctions() { - spanFromLeft() - - unspanToRight() - - spanFromRight() - - unspanToLeft() - - switchToRight() - switchToLeft() - closeLeft() - } - - companion object { - // testing device - val device: UiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - - // Swipe constants - const val leftX: Int = 675 // middle of left screen - const val rightX: Int = 2109 // middle of right screen - const val middleX: Int = 1350 // hinge area - const val bottomY: Int = 1780 // bottom of screen - const val middleY: Int = 900 // middle of screen - const val spanSteps: Int = 400 // spanning swipe - const val unspanSteps: Int = 200 // unspanning swipe - const val switchSteps: Int = 100 // swipe to switch from one screen to the other - const val closeSteps: Int = 50 // swipe to close app - } - - private fun spanFromLeft() { - device.swipe(leftX, bottomY, middleX, middleY, spanSteps) - } - - private fun unspanToLeft() { - device.swipe(rightX, bottomY, leftX, middleY, unspanSteps) - } - - private fun spanFromRight() { - device.swipe(rightX, bottomY, middleX, middleY, spanSteps) - } - - private fun unspanToRight() { - device.swipe(leftX, bottomY, rightX, middleY, unspanSteps) - } - - private fun switchToLeft() { - device.swipe(rightX, bottomY, leftX, middleY, switchSteps) - } - - private fun switchToRight() { - device.swipe(leftX, bottomY, rightX, middleY, switchSteps) - } - - private fun closeLeft() { - device.swipe(leftX, bottomY, leftX, middleY, closeSteps) - } - - private fun closeRight() { - device.swipe(rightX, bottomY, rightX, middleY, closeSteps) - } } diff --git a/PhotoEditor/dependencies.gradle b/PhotoEditor/dependencies.gradle index 531c521..035ae82 100644 --- a/PhotoEditor/dependencies.gradle +++ b/PhotoEditor/dependencies.gradle @@ -4,8 +4,8 @@ */ ext { - gradlePluginVersion = "4.1.1" - kotlinVersion = "1.6.0" + gradlePluginVersion = "7.1.1" + kotlinVersion = "1.6.10" compileSdkVersion = 31 buildToolsVersion = '30.0.3' targetSdkVersion = compileSdkVersion @@ -62,12 +62,14 @@ ext { testRunnerVersion = "1.2.0" testRulesVersion = "1.2.0" uiautomatorVersion = "2.2.0" + kotlinTestingVersion = "1.0.0-alpha2" instrumentationTestDependencies = [ - junit : "androidx.test.ext:junit:$junitInstrumentationVersion", - espressoCore: "androidx.test.espresso:espresso-core:$espressoCoreVersion", - testRunner : "androidx.test:runner:$testRunnerVersion", - testRules : "androidx.test:rules:$testRulesVersion", - uiautomator : "androidx.test.uiautomator:uiautomator:$uiautomatorVersion" + junit : "androidx.test.ext:junit:$junitInstrumentationVersion", + espressoCore : "androidx.test.espresso:espresso-core:$espressoCoreVersion", + testRunner : "androidx.test:runner:$testRunnerVersion", + testRules : "androidx.test:rules:$testRulesVersion", + uiautomator : "androidx.test.uiautomator:uiautomator:$uiautomatorVersion", + kotlinTesting : "com.microsoft.device.dualscreen.testing:testing-kotlin:$kotlinTestingVersion" ] } \ No newline at end of file diff --git a/PhotoEditor/gradle/wrapper/gradle-wrapper.properties b/PhotoEditor/gradle/wrapper/gradle-wrapper.properties index aede9ef..5d9e687 100644 --- a/PhotoEditor/gradle/wrapper/gradle-wrapper.properties +++ b/PhotoEditor/gradle/wrapper/gradle-wrapper.properties @@ -8,4 +8,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip diff --git a/PhotoEditor/ktlint.gradle b/PhotoEditor/ktlint.gradle index 1d5d70e..6177257 100644 --- a/PhotoEditor/ktlint.gradle +++ b/PhotoEditor/ktlint.gradle @@ -18,7 +18,7 @@ dependencies { task ktlint(type: JavaExec, group: "verification") { description = "Check Kotlin code style." classpath = configurations.ktlint - main = "com.pinterest.ktlint.Main" + mainClass.set("com.pinterest.ktlint.Main") args "src/**/*.kt" // to generate report in checkstyle format prepend following args: // "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml" @@ -28,6 +28,6 @@ task ktlint(type: JavaExec, group: "verification") { task ktlintFormat(type: JavaExec, group: "formatting") { description = "Fix Kotlin code style deviations." classpath = configurations.ktlint - main = "com.pinterest.ktlint.Main" + mainClass.set("com.pinterest.ktlint.Main") args "-F", "src/**/*.kt" } \ No newline at end of file diff --git a/SourceEditor/app/build.gradle b/SourceEditor/app/build.gradle index 2cb70d6..be3d793 100644 --- a/SourceEditor/app/build.gradle +++ b/SourceEditor/app/build.gradle @@ -5,7 +5,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' android { compileSdkVersion rootProject.ext.compileSdkVersion @@ -42,7 +41,7 @@ dependencies { implementation androidxDependencies.ktxFragment implementation androidxDependencies.windowManager - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1' testImplementation testDependencies.junit @@ -53,5 +52,6 @@ dependencies { androidTestImplementation instrumentationTestDependencies.testRunner androidTestImplementation instrumentationTestDependencies.testRules androidTestImplementation instrumentationTestDependencies.uiautomator + androidTestImplementation instrumentationTestDependencies.kotlinTesting } diff --git a/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/SourceEditorInDualScreenTest.kt b/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/SourceEditorInDualScreenTest.kt index 61d47cc..336964b 100644 --- a/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/SourceEditorInDualScreenTest.kt +++ b/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/SourceEditorInDualScreenTest.kt @@ -6,12 +6,11 @@ import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.filters.MediumTest import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner +import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.ActivityTestRule +import androidx.test.uiautomator.UiDevice import com.microsoft.device.display.wm_samples.sourceeditor.utils.childOf -import com.microsoft.device.display.wm_samples.sourceeditor.utils.setOrientationLeft -import com.microsoft.device.display.wm_samples.sourceeditor.utils.setOrientationRight -import com.microsoft.device.display.wm_samples.sourceeditor.utils.switchFromSingleToDualScreen -import com.microsoft.device.display.wm_samples.sourceeditor.utils.unfreezeRotation +import com.microsoft.device.dualscreen.testing.spanFromStart import org.hamcrest.Matchers import org.junit.After import org.junit.Rule @@ -23,29 +22,30 @@ import org.junit.runner.RunWith class SourceEditorInDualScreenTest { @get:Rule val activityRule = ActivityTestRule(MainActivity::class.java) + private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) @After fun tearDown() { - unfreezeRotation() + device.unfreezeRotation() } @Test fun previewWithoutOrientation() { - switchFromSingleToDualScreen() + device.spanFromStart() testPreview() } @Test fun previewWithOrientationLeft() { - switchFromSingleToDualScreen() - setOrientationLeft() + device.spanFromStart() + device.setOrientationLeft() testPreview() } @Test fun previewWithOrientationRight() { - switchFromSingleToDualScreen() - setOrientationRight() + device.spanFromStart() + device.setOrientationRight() testPreview() } diff --git a/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/SourceEditorInSingleScreenTest.kt b/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/SourceEditorInSingleScreenTest.kt index 0f59ad4..5d2b1c1 100644 --- a/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/SourceEditorInSingleScreenTest.kt +++ b/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/SourceEditorInSingleScreenTest.kt @@ -12,12 +12,11 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.filters.MediumTest import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner +import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.ActivityTestRule +import androidx.test.uiautomator.UiDevice import com.microsoft.device.display.wm_samples.sourceeditor.utils.SimpleFragmentBackStackListener import com.microsoft.device.display.wm_samples.sourceeditor.utils.forceClick -import com.microsoft.device.display.wm_samples.sourceeditor.utils.setOrientationLeft -import com.microsoft.device.display.wm_samples.sourceeditor.utils.setOrientationRight -import com.microsoft.device.display.wm_samples.sourceeditor.utils.unfreezeRotation import org.junit.After import org.junit.Before import org.junit.Rule @@ -30,6 +29,7 @@ class SourceEditorInSingleScreenTest { @get:Rule val activityRule = ActivityTestRule(MainActivity::class.java) private var backStackChangeListener = SimpleFragmentBackStackListener() + private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) @Before fun setup() { @@ -38,7 +38,7 @@ class SourceEditorInSingleScreenTest { @After fun tearDown() { - unfreezeRotation() + device.unfreezeRotation() } @Test @@ -55,13 +55,13 @@ class SourceEditorInSingleScreenTest { @Test fun previewWithOrientationLeft() { - setOrientationLeft() + device.setOrientationLeft() previewWithoutOrientation() } @Test fun previewWithOrientationRight() { - setOrientationRight() + device.setOrientationRight() previewWithoutOrientation() } } diff --git a/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/utils/ForceClick.kt b/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/utils/ForceClick.kt deleted file mode 100644 index f936128..0000000 --- a/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/utils/ForceClick.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - * - */ - -package com.microsoft.device.display.wm_samples.sourceeditor.utils - -import android.view.View -import androidx.test.espresso.UiController -import androidx.test.espresso.ViewAction -import androidx.test.espresso.matcher.ViewMatchers.isClickable -import androidx.test.espresso.matcher.ViewMatchers.isEnabled -import org.hamcrest.Matcher -import org.hamcrest.Matchers.allOf - -/** - * Click action for a view without to check the coordinates for the view on the screen. when device is rotated. - */ -class ForceClick : ViewAction { - override fun getConstraints(): Matcher { - return allOf(isClickable(), isEnabled()) - } - - override fun getDescription(): String { - return "force click" - } - - override fun perform(uiController: UiController?, view: View?) { - view?.performClick() - uiController?.loopMainThreadForAtLeast(500) - } -} diff --git a/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/utils/SurfaceDuoUtils.kt b/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/utils/SurfaceDuoUtils.kt deleted file mode 100644 index e67c7e6..0000000 --- a/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/utils/SurfaceDuoUtils.kt +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - * - */ - -package com.microsoft.device.display.wm_samples.sourceeditor.utils - -import android.view.Surface -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.uiautomator.UiDevice - -// testing device -private val device: UiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - -private const val leftX: Int = 675 // middle of left screen -private const val rightX: Int = 2109 // middle of right screen -private const val leftMiddleX: Int = 1340 // left of hinge area -private const val rightMiddleX: Int = 1434 // right of hinge area -private const val bottomY: Int = 1780 // bottom of screen -private const val middleY: Int = 900 // middle of screen -private const val spanSteps: Int = 400 // spanning/unspanning swipe -private const val switchSteps: Int = 600 // switch from one screen to the other - -fun spanFromLeft() { - device.swipe(leftX, bottomY, leftMiddleX, middleY, spanSteps) -} - -fun unspanToLeft() { - device.swipe(rightX, bottomY, leftX, middleY, spanSteps) -} - -fun spanFromRight() { - device.swipe(rightX, bottomY, rightMiddleX, middleY, spanSteps) -} - -fun unspanToRight() { - device.swipe(leftX, bottomY, rightX, middleY, spanSteps) -} - -fun moveToLeft() { - device.swipe(rightX, bottomY, leftX, middleY, switchSteps) -} - -fun moveToRight() { - device.swipe(leftX, bottomY, rightX, middleY, switchSteps) -} - -/** - * Switches application from single screen mode to dual screen mode - */ -fun switchFromSingleToDualScreen() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - when (device.displayRotation) { - Surface.ROTATION_0, Surface.ROTATION_180 -> device.swipe(675, 1780, 1350, 900, 400) - Surface.ROTATION_270 -> device.swipe(1780, 675, 900, 1350, 400) - Surface.ROTATION_90 -> device.swipe(1780, 2109, 900, 1400, 400) - } -} - -/** - * Switches application from dual screen mode to single screen - */ -fun switchFromDualToSingleScreen() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - when (device.displayRotation) { - Surface.ROTATION_0, Surface.ROTATION_180 -> device.swipe(1500, 1780, 650, 900, 400) - Surface.ROTATION_270 -> device.swipe(1780, 1500, 900, 650, 400) - Surface.ROTATION_90 -> device.swipe(1780, 1250, 900, 1500, 400) - } -} - -/** - * Re-enables the sensors and un-freezes the device rotation allowing its contents - * to rotate with the device physical rotation. During a test execution, it is best to - * keep the device frozen in a specific orientation until the test case execution has completed. - */ -fun unfreezeRotation() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - device.unfreezeRotation() -} - -/** - * Simulates orienting the device to the left and also freezes rotation - * by disabling the sensors. - */ -fun setOrientationLeft() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - device.setOrientationLeft() -} - -/** - * Simulates orienting the device into its natural orientation and also freezes rotation - * by disabling the sensors. - */ -fun setOrientationNatural() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - device.setOrientationNatural() -} - -/** - * Simulates orienting the device to the right and also freezes rotation - * by disabling the sensors. - */ -fun setOrientationRight() { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - device.setOrientationRight() -} diff --git a/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/utils/TestUtils.kt b/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/utils/TestUtils.kt index c0e6de9..d147227 100644 --- a/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/utils/TestUtils.kt +++ b/SourceEditor/app/src/androidTest/java/com/microsoft/device/display/wm_samples/sourceeditor/utils/TestUtils.kt @@ -2,6 +2,7 @@ package com.microsoft.device.display.wm_samples.sourceeditor.utils import android.view.View import androidx.test.espresso.ViewAction +import com.microsoft.device.dualscreen.testing.ForceClick import org.hamcrest.Matcher /** diff --git a/SourceEditor/dependencies.gradle b/SourceEditor/dependencies.gradle index 7f39ba0..50ab832 100644 --- a/SourceEditor/dependencies.gradle +++ b/SourceEditor/dependencies.gradle @@ -5,8 +5,8 @@ */ ext { - gradlePluginVersion = "4.1.1" - kotlinVersion = "1.6.0" + gradlePluginVersion = "7.1.1" + kotlinVersion = "1.6.10" compileSdkVersion = 31 buildToolsVersion = '30.0.3' targetSdkVersion = compileSdkVersion @@ -66,6 +66,7 @@ ext { testRulesVersion = "1.2.0" testRunnerVersion = "1.2.0" uiautomatorVersion = "2.2.0" + kotlinTesting = "1.0.0-alpha2" instrumentationTestDependencies = [ junit : "androidx.test.ext:junit:$junitInstrumentationVersion", @@ -73,6 +74,7 @@ ext { espressoWeb : "androidx.test.espresso:espresso-web:$espressoWebVersion", testRunner : "androidx.test:runner:$testRunnerVersion", testRules : "androidx.test:rules:$testRulesVersion", - uiautomator : "androidx.test.uiautomator:uiautomator:$uiautomatorVersion" + uiautomator : "androidx.test.uiautomator:uiautomator:$uiautomatorVersion", + kotlinTesting: "com.microsoft.device.dualscreen.testing:testing-kotlin:$kotlinTesting" ] } diff --git a/SourceEditor/gradle/wrapper/gradle-wrapper.properties b/SourceEditor/gradle/wrapper/gradle-wrapper.properties index 3f95c2e..276f292 100644 --- a/SourceEditor/gradle/wrapper/gradle-wrapper.properties +++ b/SourceEditor/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip diff --git a/SourceEditor/ktlint.gradle b/SourceEditor/ktlint.gradle index f5075ed..0d93ac9 100644 --- a/SourceEditor/ktlint.gradle +++ b/SourceEditor/ktlint.gradle @@ -19,13 +19,13 @@ dependencies { task ktlint(type: JavaExec, group: "verification") { description = "Check Kotlin code style." classpath = configurations.ktlint - main = "com.pinterest.ktlint.Main" + mainClass.set("com.pinterest.ktlint.Main") args "src/**/*.kt" } task ktlintFormat(type: JavaExec, group: "formatting") { description = "Fix Kotlin code style deviations." classpath = configurations.ktlint - main = "com.pinterest.ktlint.Main" + mainClass.set("com.pinterest.ktlint.Main") args "-F", "src/**/*.kt" } diff --git a/TwoNote/app/build.gradle b/TwoNote/app/build.gradle index 173897e..23220b7 100644 --- a/TwoNote/app/build.gradle +++ b/TwoNote/app/build.gradle @@ -63,4 +63,5 @@ dependencies { androidTestImplementation instrumentationTestDependencies.testRunner androidTestImplementation instrumentationTestDependencies.testRules androidTestImplementation instrumentationTestDependencies.uiAutomator + androidTestImplementation instrumentationTestDependencies.kotlinTesting } diff --git a/TwoNote/app/src/androidTest/java/com/microsoft/device/display/wm_samples/twonote/FragmentNavigationTest.kt b/TwoNote/app/src/androidTest/java/com/microsoft/device/display/wm_samples/twonote/FragmentNavigationTest.kt index 18866de..2ff4080 100644 --- a/TwoNote/app/src/androidTest/java/com/microsoft/device/display/wm_samples/twonote/FragmentNavigationTest.kt +++ b/TwoNote/app/src/androidTest/java/com/microsoft/device/display/wm_samples/twonote/FragmentNavigationTest.kt @@ -19,6 +19,7 @@ import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.ActivityTestRule import androidx.test.uiautomator.UiDevice +import com.microsoft.device.dualscreen.testing.spanFromStart import org.hamcrest.Matchers.allOf import org.hamcrest.Matchers.hasToString import org.junit.After @@ -34,7 +35,7 @@ class FragmentNavigationTest { private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) @get:Rule - val activityRule = ActivityTestRule(MainActivity::class.java) + val activityRule = ActivityTestRule(MainActivity::class.java) @After fun resetOrientation() { @@ -107,7 +108,7 @@ class FragmentNavigationTest { } private fun spanApplication() { - device.swipe(675, 1780, 1350, 900, 400) + device.spanFromStart() } private fun rotateDevice() { diff --git a/TwoNote/dependencies.gradle b/TwoNote/dependencies.gradle index d940ac8..228d389 100644 --- a/TwoNote/dependencies.gradle +++ b/TwoNote/dependencies.gradle @@ -84,6 +84,7 @@ ext { testRulesVersion = "1.2.0" testRunnerVersion = "1.2.0" uiAutomatorVersion = "2.2.0" + kotlinTestingVersion = "1.0.0-alpha2" instrumentationTestDependencies = [ junit : "androidx.test.ext:junit:$junitInstrumentationVersion", @@ -91,5 +92,6 @@ ext { testRunner : "androidx.test:runner:$testRunnerVersion", testRules : "androidx.test:rules:$testRulesVersion", uiAutomator : "androidx.test.uiautomator:uiautomator:$uiAutomatorVersion", + kotlinTesting: "com.microsoft.device.dualscreen.testing:testing-kotlin:$kotlinTestingVersion" ] } diff --git a/TwoNote/gradle/wrapper/gradle-wrapper.properties b/TwoNote/gradle/wrapper/gradle-wrapper.properties index c748fc0..d065189 100644 --- a/TwoNote/gradle/wrapper/gradle-wrapper.properties +++ b/TwoNote/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Jul 28 14:47:59 PDT 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/TwoNote/ink/build.gradle b/TwoNote/ink/build.gradle index 5b26fe9..bd3a5f5 100644 --- a/TwoNote/ink/build.gradle +++ b/TwoNote/ink/build.gradle @@ -22,7 +22,6 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionName rootProject.ext.inkSDKVersionName testInstrumentationRunner rootProject.ext.config.testInstrumentationRunner consumerProguardFiles "consumer-rules.pro"