1 /* 2 * Copyright (C) 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.documentsui 17 18 import android.content.Intent 19 import android.platform.test.annotations.RequiresFlagsEnabled 20 import android.platform.test.flag.junit.CheckFlagsRule 21 import android.platform.test.flag.junit.DeviceFlagsValueProvider 22 import androidx.test.espresso.Espresso.onView 23 import androidx.test.espresso.action.ViewActions.click 24 import androidx.test.espresso.assertion.ViewAssertions.doesNotExist 25 import androidx.test.espresso.assertion.ViewAssertions.matches 26 import androidx.test.espresso.matcher.ViewMatchers.isDisplayed 27 import androidx.test.espresso.matcher.ViewMatchers.withId 28 import androidx.test.ext.junit.runners.AndroidJUnit4 29 import androidx.test.platform.app.InstrumentationRegistry 30 import com.android.documentsui.files.FilesActivity 31 import com.android.documentsui.flags.Flags.FLAG_USE_MATERIAL3 32 import com.android.documentsui.flags.Flags.FLAG_VISUAL_SIGNALS_RO 33 import com.android.documentsui.services.FileOperationService.ACTION_PROGRESS 34 import com.android.documentsui.services.FileOperationService.EXTRA_PROGRESS 35 import com.android.documentsui.services.Job 36 import com.android.documentsui.services.JobProgress 37 import com.android.documentsui.testing.MutableJobProgress 38 import org.junit.After 39 import org.junit.Before 40 import org.junit.Rule 41 import org.junit.Test 42 import org.junit.runner.RunWith 43 44 @RequiresFlagsEnabled(FLAG_USE_MATERIAL3, FLAG_VISUAL_SIGNALS_RO) 45 @RunWith(AndroidJUnit4::class) 46 class JobPanelUiTest : ActivityTestJunit4<FilesActivity>() { 47 @get:Rule 48 val mCheckFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule() 49 50 private var mLastId = 0L 51 sendProgressnull52 private fun sendProgress(progresses: ArrayList<JobProgress>, id: Long = mLastId++) { 53 val context = InstrumentationRegistry.getInstrumentation().targetContext 54 var intent = Intent(ACTION_PROGRESS).apply { 55 `package` = context.packageName 56 putExtra("id", id) 57 putParcelableArrayListExtra(EXTRA_PROGRESS, progresses) 58 } 59 context.sendBroadcast(intent) 60 } 61 62 @Before setUpnull63 override fun setUp() { 64 super.setUp() 65 } 66 67 @After tearDownnull68 override fun tearDown() { 69 super.tearDown() 70 } 71 72 @Test testJobPanelAppearsOnClicknull73 fun testJobPanelAppearsOnClick() { 74 onView(withId(R.id.option_menu_job_progress)).check(doesNotExist()) 75 onView(withId(R.id.job_progress_panel_title)).check(doesNotExist()) 76 77 val progress = MutableJobProgress( 78 id = "jobId1", 79 state = Job.STATE_SET_UP, 80 msg = "Job started", 81 hasFailures = false, 82 currentBytes = 4, 83 requiredBytes = 10, 84 msRemaining = -1 85 ) 86 sendProgress(arrayListOf(progress.toJobProgress())) 87 88 onView(withId(R.id.option_menu_job_progress)) 89 .check(matches(isDisplayed())) 90 .perform(click()) 91 onView(withId(R.id.job_progress_panel_title)).check(matches(isDisplayed())) 92 } 93 } 94