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

Commit 1bbf37a6 authored by Tony Huang's avatar Tony Huang
Browse files

Add test case for rename file in internal strorage

Add test case for internal strorage whinch provide by
ExternalStorageProvider.It will verify that rename sucess and
check exception happen or not.

Test: atest RenameActualProviderUiTest
Bug: 113302685
Bug: 115304092
Change-Id: Iae9b35e555b0644ec411332b99228d931e2a54ba
parent ead02358
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -197,6 +197,22 @@ public class UiBot extends Bots.BaseBot {
        return (bar != null);
    }

    public void clickRename() throws UiObjectNotFoundException {
        if (!waitForActionModeBarToAppear()) {
            throw new UiObjectNotFoundException("ActionMode bar not found");
        }
        clickActionbarOverflowItem(mContext.getString(R.string.menu_rename));
        mDevice.waitForIdle();
    }

    public void clickDelete() throws UiObjectNotFoundException {
        if (!waitForActionModeBarToAppear()) {
            throw new UiObjectNotFoundException("ActionMode bar not found");
        }
        clickToolbarItem(R.id.action_menu_delete);
        mDevice.waitForIdle();
    }

    public UiObject findDownloadRetryDialog() {
        UiSelector selector = new UiSelector().text("Couldn't download");
        UiObject title = mDevice.findObject(selector);
+106 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.documentsui;

import com.android.documentsui.base.Providers;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.State;
import com.android.documentsui.files.FilesActivity;

/**
 * A Ui test will do tests in the internal storage root. It is implemented because some operations
 * is failed and its result will different from the test on the StubProvider. b/115304092 is a
 * example which only happen on root from ExternalStorageProvidrer.
 */
public class InternalStorageUiTest extends ActivityTest<FilesActivity> {

    private static final String fileName = "Test3345678Test.txt";
    private static final String newFileName = "9527TestTestTest.txt";
    private RootInfo rootPrimary;

    public InternalStorageUiTest() {
        super(FilesActivity.class);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();

        mClient = mResolver.acquireUnstableContentProviderClient(Providers.AUTHORITY_STORAGE);
        mDocsHelper = new DocumentsProviderHelper(Providers.AUTHORITY_STORAGE, mClient);
        rootPrimary = mDocsHelper.getRoot(Providers.ROOT_ID_DEVICE);

        // If Internal Storage is not shown, turn on.
        State state = ((FilesActivity) getActivity()).getDisplayState();
        if (!state.showAdvanced) {
            bots.main.clickToolbarOverflowItem(
                    context.getResources().getString(R.string.menu_advanced_show));
        }

        bots.roots.openRoot(rootPrimary.title);
        deleteTestFiles();
    }

    @Override
    public void tearDown() throws Exception {
        super.tearDown();
        deleteTestFiles();
    }

    public void testRenameFile() throws Exception {
        createTestFiles();

        bots.directory.selectDocument(fileName);
        device.waitForIdle();

        bots.main.clickRename();

        bots.main.setDialogText(newFileName);
        device.waitForIdle();

        bots.keyboard.pressEnter();

        bots.directory.assertDocumentsAbsent(fileName);
        bots.directory.assertDocumentsPresent(newFileName);
        // Snackbar will not show if no exception.
        assertNull(bots.directory.getSnackbar(context.getString(R.string.rename_error)));
    }

    private void createTestFiles() {
        mDocsHelper.createDocument(rootPrimary, "text/plain", fileName);
    }

    private void deleteTestFiles() throws Exception {
        boolean selected = false;
        // Delete the added file for not affect user and also avoid error on next test.
        if (bots.directory.hasDocuments(fileName)) {
            bots.directory.selectDocument(fileName);
            device.waitForIdle();
            selected = true;
        }
        if (bots.directory.hasDocuments(newFileName)) {
            bots.directory.selectDocument(newFileName);
            device.waitForIdle();
            selected = true;
        }
        if (selected) {
            bots.main.clickDelete();
            device.waitForIdle();
            bots.directory.waitForDeleteSnackbarGone();
        }
    }
}