Home | History | Annotate | Download | only in documentsui
      1 /*
      2  * Copyright (C) 2017 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 
     17 package com.android.documentsui;
     18 
     19 import static junit.framework.Assert.assertEquals;
     20 import static junit.framework.Assert.assertTrue;
     21 
     22 import android.database.Cursor;
     23 import android.provider.DocumentsContract.Document;
     24 import android.support.test.filters.MediumTest;
     25 import android.support.test.runner.AndroidJUnit4;
     26 
     27 import com.android.documentsui.base.DocumentInfo;
     28 import com.android.documentsui.base.State;
     29 import com.android.documentsui.testing.ActivityManagers;
     30 import com.android.documentsui.testing.TestEnv;
     31 import com.android.documentsui.testing.TestFeatures;
     32 import com.android.documentsui.testing.TestFileTypeLookup;
     33 import com.android.documentsui.testing.TestImmediateExecutor;
     34 import com.android.documentsui.testing.TestProvidersAccess;
     35 
     36 import org.junit.Before;
     37 import org.junit.Test;
     38 import org.junit.runner.RunWith;
     39 
     40 @RunWith(AndroidJUnit4.class)
     41 @MediumTest
     42 public class RecentsLoaderTests {
     43 
     44     private TestEnv mEnv;
     45     private TestActivity mActivity;
     46     private RecentsLoader mLoader;
     47 
     48     @Before
     49     public void setUp() {
     50         mEnv = TestEnv.create();
     51         mActivity = TestActivity.create(mEnv);
     52         mActivity.activityManager = ActivityManagers.create(false);
     53 
     54         mEnv.state.action = State.ACTION_BROWSE;
     55         mEnv.state.acceptMimes = new String[] { "*/*" };
     56 
     57         mLoader = new RecentsLoader(mActivity, mEnv.providers, mEnv.state, mEnv.features,
     58                 TestImmediateExecutor.createLookup(), new TestFileTypeLookup());
     59     }
     60 
     61     @Test
     62     public void testDocumentsNotMovable() {
     63         final DocumentInfo doc = mEnv.model.createFile("freddy.jpg",
     64                 Document.FLAG_SUPPORTS_MOVE
     65                         | Document.FLAG_SUPPORTS_DELETE
     66                         | Document.FLAG_SUPPORTS_REMOVE);
     67         doc.lastModified = System.currentTimeMillis();
     68         mEnv.mockProviders.get(TestProvidersAccess.HOME.authority)
     69                 .setNextRecentDocumentsReturns(doc);
     70 
     71         final DirectoryResult result = mLoader.loadInBackground();
     72 
     73         final Cursor c = result.cursor;
     74         assertEquals(1, c.getCount());
     75         for (int i = 0; i < c.getCount(); ++i) {
     76             c.moveToNext();
     77             final int flags = c.getInt(c.getColumnIndex(Document.COLUMN_FLAGS));
     78             assertEquals(0, flags & Document.FLAG_SUPPORTS_DELETE);
     79             assertEquals(0, flags & Document.FLAG_SUPPORTS_REMOVE);
     80             assertEquals(0, flags & Document.FLAG_SUPPORTS_MOVE);
     81         }
     82     }
     83 }
     84