Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2016 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.ui;
     17 
     18 import android.app.FragmentManager;
     19 
     20 import com.android.documentsui.base.ConfirmationCallback;
     21 import com.android.documentsui.base.DocumentInfo;
     22 import com.android.documentsui.services.FileOperations;
     23 
     24 import junit.framework.Assert;
     25 
     26 import java.util.List;
     27 
     28 public class TestDialogController implements DialogController {
     29 
     30     public int mNextConfirmationCode;
     31     private boolean mFileOpFailed;
     32     private boolean mNoApplicationFound;
     33     private boolean mDocumentsClipped;
     34     private boolean mViewInArchivesUnsupported;
     35     private DocumentInfo mOverwriteTarget;
     36 
     37     public TestDialogController() {
     38         // by default, always confirm
     39         mNextConfirmationCode = ConfirmationCallback.CONFIRM;
     40     }
     41 
     42     @Override
     43     public void confirmDelete(List<DocumentInfo> docs, ConfirmationCallback callback) {
     44         callback.accept(mNextConfirmationCode);
     45     }
     46 
     47     @Override
     48     public void showFileOperationStatus(int status, int opType, int docCount) {
     49         if (status == FileOperations.Callback.STATUS_REJECTED) {
     50             mFileOpFailed = true;
     51         }
     52     }
     53 
     54     @Override
     55     public void showNoApplicationFound() {
     56         mNoApplicationFound = true;
     57     }
     58 
     59     @Override
     60     public void showViewInArchivesUnsupported() {
     61         mViewInArchivesUnsupported = true;
     62     }
     63 
     64     @Override
     65     public void showDocumentsClipped(int size) {
     66         mDocumentsClipped = true;
     67     }
     68 
     69     @Override
     70     public void confirmOverwrite(FragmentManager fm, DocumentInfo overwriteTarget) {
     71         mOverwriteTarget = overwriteTarget;
     72     }
     73 
     74     public void assertNoFileFailures() {
     75         Assert.assertFalse(mFileOpFailed);
     76     }
     77 
     78     public void assertNoAppFoundShown() {
     79         Assert.assertFalse(mNoApplicationFound);
     80     }
     81 
     82     public void assertViewInArchivesShownUnsupported() {
     83         Assert.assertTrue(mViewInArchivesUnsupported);
     84     }
     85 
     86     public void assertDocumentsClippedNotShown() {
     87         Assert.assertFalse(mDocumentsClipped);
     88     }
     89 
     90     public void assertOverwriteConfirmed(DocumentInfo expected) {
     91         Assert.assertEquals(expected, mOverwriteTarget);
     92     }
     93 
     94     public void confirmNext() {
     95         mNextConfirmationCode = ConfirmationCallback.CONFIRM;
     96     }
     97 
     98     public void rejectNext() {
     99         mNextConfirmationCode = ConfirmationCallback.REJECT;
    100     }
    101 }
    102