Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7fc1bd7 authored by Ben Reich's avatar Ben Reich
Browse files

Move class initialization to setUp method

The class initialization (which is always ran) was looking for
R.id.job_progress_indicator. Unfortunately this isn't available when the
USE_VISUAL_SIGNALS_RO flag is off (the ID is eliminated from the R
class). Move the initialization to the setUp method instead to ensure it
isn't ran when the flag is disabled.

Fix: 420543245
Test: atest com.android.documentsui.JobPanelControllerTest
Flag: com.android.documentsui.flags.visual_signals_ro
Change-Id: I08ea4d75e18f73b34f21e7136c2886cc653555fc
parent bb3cd8d5
Loading
Loading
Loading
Loading
+24 −18
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.documentsui

import android.content.Intent
import android.platform.test.annotations.RequiresFlagsEnabled
import android.view.MenuItem
import android.widget.ActionMenuView
import android.widget.FrameLayout
import android.widget.ImageView
@@ -52,38 +53,43 @@ class JobPanelControllerTest {

    private val context = InstrumentationRegistry.getInstrumentation().targetContext

    private lateinit var progressBar: ProgressBar
    private lateinit var badge: ImageView
    private lateinit var menuItem: MenuItem

    private lateinit var controller: JobPanelController
    private var lastId = 0L

    private fun sendProgress(progress: ArrayList<JobProgress>, id: Long = lastId++) {
        var intent = Intent(ACTION_PROGRESS).apply {
            `package` = context.packageName
            putExtra("id", id)
            putParcelableArrayListExtra(EXTRA_PROGRESS, progress)
        }
        controller.onReceive(context, intent)
    }

    @Before
    fun setUp() {
        // The default progress bar only has an indeterminate state, so we need to style it to allow
        // determinate progress.
    private val progressBar = ProgressBar(
        progressBar = ProgressBar(
            context,
            null,
            android.R.attr.progressBarStyleHorizontal
        ).apply {
            id = getRes(R.id.job_progress_toolbar_indicator)
        }
    private val badge = ImageView(context).apply {
        badge = ImageView(context).apply {
            id = getRes(R.id.job_progress_toolbar_badge)
        }
    private val menuItem = ActionMenuView(context).menu.add("job_panel").apply {
        menuItem = ActionMenuView(context).menu.add("job_panel").apply {
            actionView = FrameLayout(context).apply {
                addView(progressBar)
                addView(badge)
            }
        }
    private lateinit var controller: JobPanelController
    private var lastId = 0L

    private fun sendProgress(progress: ArrayList<JobProgress>, id: Long = lastId++) {
        var intent = Intent(ACTION_PROGRESS).apply {
            `package` = context.packageName
            putExtra("id", id)
            putParcelableArrayListExtra(EXTRA_PROGRESS, progress)
        }
        controller.onReceive(context, intent)
    }

    @Before
    fun setUp() {
        controller = JobPanelController(context, TestActionHandler(), JobPanelViewModel())
        controller.setMenuItem(menuItem)
    }