Search in sources :

Example 1 with UserPrefs

use of org.edx.mobile.module.prefs.UserPrefs in project edx-app-android by edx.

the class DownloadTests method testAddDownload.

@Test
public void testAddDownload() throws Exception {
    File dir = null;
    try {
        dir = new UserPrefs(RuntimeEnvironment.application, MainApplication.getEnvironment(RuntimeEnvironment.application).getLoginPrefs()).getDownloadDirectory();
    } catch (Exception ex) {
        // it happens in CI environment and we should skip the test.
        print("dir is null, it happens in CI environment and we should skip the test.");
    }
    if (dir == null)
        return;
    String url = "https://s3.amazonaws.com/edx-course-videos/edx-edx101/EDXSPCPJSP13-H010000_100.mp4";
    // test add new download
    long dmid = dm.addDownload(dir, url, true, "Video 1 title");
    long dmid2 = dm.addDownload(dir, url, false, "Video 2 title");
    assertTrue("invalid dmid=" + dmid, dmid > 0);
    assertTrue("invalid dmid2=" + dmid2, dmid2 > 0);
    print("new download dmid: " + dmid);
    print("new download dmid2: " + dmid2);
    // wait for downloads to begin
    Thread.sleep(20 * 1000);
    // test get download info
    NativeDownloadModel model = dm.getDownload(dmid);
    assertNotNull(model);
    print("downloading [dmid=" + dmid + "] to: " + model.filepath);
    int progress = dm.getProgressForDownload(dmid);
    assertTrue(progress >= 0 && progress <= 100);
    print("progress=" + progress);
    int averageProgress = dm.getAverageProgressForDownloads(new long[] { dmid, dmid2 });
    assertTrue(averageProgress >= 0 && averageProgress <= 100);
    print("averageProgress=" + averageProgress);
    // test remove downloads
    boolean removed = dm.removeDownloads(dmid) > 0;
    assertTrue("failed to remove dmid: " + dmid, removed);
    removed = dm.removeDownloads(dmid2) > 0;
    assertTrue("failed to remove dmid: " + dmid2, removed);
    model = dm.getDownload(dmid);
    assertNull("download not removed, dmid: " + dmid, model);
    print("removed the downloads");
}
Also used : NativeDownloadModel(org.edx.mobile.model.download.NativeDownloadModel) File(java.io.File) UserPrefs(org.edx.mobile.module.prefs.UserPrefs) Test(org.junit.Test)

Example 2 with UserPrefs

use of org.edx.mobile.module.prefs.UserPrefs in project edx-app-android by edx.

the class NavigationFragmentTest method testProfileImageUpdation_onGlobalAccountEvent.

@Test
public void testProfileImageUpdation_onGlobalAccountEvent() {
    final NavigationFragment fragment = new NavigationFragment();
    SupportFragmentTestUtil.startVisibleFragment(fragment);
    final View view = fragment.getView();
    assertNotNull(view);
    final ImageView profileImage = (ImageView) view.findViewById(R.id.profile_image);
    assertNotNull(profileImage);
    // Assert: Profile pic not updated when a non-logged in user's account object is broadcasted
    Drawable previousDrawable = profileImage.getDrawable();
    Account account = configureMockAccount("not_logged_in_user");
    EventBus.getDefault().post(new AccountDataLoadedEvent(account));
    assertEquals(previousDrawable, profileImage.getDrawable());
    // Assert: Profile pic is updated when a logged-in user's account object is broadcasted
    UserPrefs userPrefs = RoboGuice.getInjector(context).getInstance(UserPrefs.class);
    final String loggedInUser = userPrefs.getProfile().username;
    account = configureMockAccount(loggedInUser);
    EventBus.getDefault().post(new AccountDataLoadedEvent(account));
    assertNotEquals(previousDrawable, profileImage.getDrawable());
}
Also used : Account(org.edx.mobile.user.Account) Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) AccountDataLoadedEvent(org.edx.mobile.event.AccountDataLoadedEvent) ImageView(android.widget.ImageView) View(android.view.View) UserPrefs(org.edx.mobile.module.prefs.UserPrefs) Test(org.junit.Test)

Aggregations

UserPrefs (org.edx.mobile.module.prefs.UserPrefs)2 Test (org.junit.Test)2 Drawable (android.graphics.drawable.Drawable)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 File (java.io.File)1 AccountDataLoadedEvent (org.edx.mobile.event.AccountDataLoadedEvent)1 NativeDownloadModel (org.edx.mobile.model.download.NativeDownloadModel)1 Account (org.edx.mobile.user.Account)1