Revision control
Copy as Markdown
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
package org.mozilla.focus.screenshots;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import androidx.test.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObjectNotFoundException;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mozilla.focus.MainActivity;
import org.mozilla.focus.R;
import tools.fastlane.screengrab.Screengrab;
import tools.fastlane.screengrab.locale.LocaleTestRule;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.withDecorView;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsNot.not;
@RunWith(AndroidJUnit4.class)
@Ignore // TODO: fix me! #525
public class TVScreenshots extends ScreenshotTest {
private Intent intent;
private SharedPreferences.Editor preferencesEditor;
private UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
@ClassRule
public static final LocaleTestRule localeTestRule = new LocaleTestRule();
@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<MainActivity>(MainActivity.class,
false, false);
@Before
public void setUp() throws Exception {
intent = new Intent();
Context appContext = InstrumentationRegistry.getInstrumentation()
.getTargetContext()
.getApplicationContext();
preferencesEditor = PreferenceManager.getDefaultSharedPreferences(appContext).edit();
}
@After
public void tearDown() throws Exception {
mActivityTestRule.getActivity().finishAndRemoveTask();
}
@Test
public void firstLaunchScreen() throws InterruptedException, UiObjectNotFoundException {
mActivityTestRule.launchActivity(intent);
// onView(withId(R.id.enable_turbo_mode))
// .check(matches(isDisplayed()));
// onView(withId(R.id.turbo_mode_title))
// .check(matches(isDisplayed()));
// onView(withId(R.id.disable_turbo_mode))
// .check(matches(isDisplayed()));
Screengrab.screenshot("first-launch");
}
@Test
public void defaultHomeScreen() throws InterruptedException, UiObjectNotFoundException {
/* capture a screenshot of the default home-screen */
mActivityTestRule.launchActivity(intent);
// onView(withId(R.id.urlInputView))
// .check(matches(isDisplayed()));
// onView(withId(R.id.homeUrlBar))
// .check(matches(isDisplayed()));
Screengrab.screenshot("home-screen");
}
@Test
public void browserNavOverlay () throws InterruptedException, UiObjectNotFoundException {
/* default home-screen in the main activity should be displayed */
mActivityTestRule.launchActivity(intent);
// onView(allOf(withId(R.id.urlInputView), isDisplayed(), hasFocus()))
// .perform(typeTextIntoFocusedView("example.com"))
// .perform(pressImeActionButton());
onView(withId(R.id.webview))
.check(matches(isDisplayed()));
mDevice.pressMenu();
// onView(withId(R.id.navCloseHint))
// .check(matches(isDisplayed()));
//
// onView(withId(R.id.navUrlInput))
// .check(matches(isDisplayed()));
//
// Screengrab.screenshot("browser-overlay");
//
// onView(withId(R.id.navButtonHome)).perform(click());
}
@Test
public void settingsView() throws InterruptedException, UiObjectNotFoundException {
/* default home-screen in the main activity should be displayed */
mActivityTestRule.launchActivity(intent);
// onView(allOf(withId(R.id.urlInputView), isDisplayed(), hasFocus()));
//
// /* visit settings */
// onView(allOf(withId(R.id.settingsButton), isDisplayed()))
// .perform(click());
//
// /* current settings list view */
// onView(allOf(withId(R.id.container), isDisplayed()));
//
// ViewInteraction clearButton = onView(
// allOf(withId(R.id.deleteButton), isDisplayed()));
/* capture a screenshot of the default settings list */
Screengrab.screenshot("settings");
/* capture a screenshot of the clear data dialog */
// clearButton.perform(click());
// ViewInteraction confirmClear = onView(
// allOf(withText(R.string.settings_cookies_dialog_content), isDisplayed()))
// .inRoot(isDialog());
//
// Screengrab.screenshot("clear-all-data");
//
// confirmClear.perform(pressBack());
/* capture a screenshot of the privacy notice */
// onView(allOf(withId(R.id.privacyNoticeButton), isDisplayed()))
// .perform(click());
onView(allOf(withId(R.id.webview), isDisplayed()));
Screengrab.screenshot("privacy-notice");
mDevice.pressBack();
// onView(allOf(withId(R.id.aboutButton), isDisplayed()))
// .perform(click());
onView(allOf(withId(R.id.webview), isDisplayed()));
Screengrab.screenshot("about-screen");
mDevice.pressBack();
}
@Test
public void unpinTileInHome() throws InterruptedException, UiObjectNotFoundException {
/* default home-screen in the main activity should be displayed */
mActivityTestRule.launchActivity(intent);
// onView(allOf(withId(R.id.urlInputView), isDisplayed(), hasFocus()));
mDevice.pressDPadDown();
mDevice.pressMenu();
onView(withText(R.string.homescreen_tile_remove))
.check(matches(isDisplayed()));
Screengrab.screenshot("menu-remove-tile");
mDevice.pressBack();
}
@Test
public void pinTileFromOverlay() throws InterruptedException, UiObjectNotFoundException {
/* default home-screen in the main activity should be displayed */
mActivityTestRule.launchActivity(intent);
// onView(allOf(withId(R.id.urlInputView), isDisplayed(), hasFocus()))
// .perform(typeTextIntoFocusedView("example.com"))
// .perform(pressImeActionButton());
onView(withId(R.id.webview))
.check(matches(isDisplayed()));
mDevice.pressMenu();
// onView(withId(R.id.pinButton))
// .check(matches(isDisplayed()))
// .perform(click());
onView(withText(R.string.notification_pinned_site))
.inRoot(withDecorView(not(is(mActivityTestRule.getActivity().getWindow().getDecorView()))))
.check(matches(isDisplayed()));
Screengrab.screenshot("overlay-pinned-tile");
mDevice.pressBack();
mDevice.pressBack();
}
@Test
public void unpinTileFromOverlay() throws InterruptedException, UiObjectNotFoundException {
/* default home-screen in the main activity should be displayed */
mActivityTestRule.launchActivity(intent);
// onView(allOf(withId(R.id.urlInputView), isDisplayed(), hasFocus()))
// .perform(typeTextIntoFocusedView("example.com"))
// .perform(pressImeActionButton());
onView(withId(R.id.webview))
.check(matches(isDisplayed()));
mDevice.pressMenu();
// onView(withId(R.id.pinButton))
// .check(matches(isDisplayed()))
// .perform(click());
onView(withText(R.string.notification_unpinned_site))
.inRoot(withDecorView(not(is(mActivityTestRule.getActivity().getWindow().getDecorView()))))
.check(matches(isDisplayed()));
Screengrab.screenshot("overlay-unpinned-tile");
mDevice.pressBack();
mDevice.pressBack();
}
}