Commit e4d149a5 authored by Brian Sheedy's avatar Brian Sheedy Committed by Commit Bot

Automated VR Browser security token + popup tests

Automates the manual tests for ensuring that the security icons that
display in the URL bar and the popups that show when you click on them
look correct while in the VR Browser.

Bug: 887505
Change-Id: I0d826ab1bafb6926bbc2e0da60b27450077bdd1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1544825Reviewed-by: default avatarZhongyi Shi <zhongyi@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#646634}
parent 8618463f
...@@ -35,6 +35,7 @@ import org.chromium.chrome.browser.vr.util.VrShellDelegateUtils; ...@@ -35,6 +35,7 @@ import org.chromium.chrome.browser.vr.util.VrShellDelegateUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.RenderTestRule; import org.chromium.chrome.test.util.RenderTestRule;
import org.chromium.net.test.ServerCertificate;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
...@@ -47,6 +48,11 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -47,6 +48,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, "enable-webvr"}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, "enable-webvr"})
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM_OR_STANDALONE) @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM_OR_STANDALONE)
public class VrBrowserNativeUiTest { public class VrBrowserNativeUiTest {
// We need to make sure the port is constant, otherwise the URL changes between test runs, which
// is really bad for image diff tests. There's nothing special about this port other than that
// it shouldn't be in use by anything.
private static final int SERVER_PORT = 39558;
// We explicitly instantiate a rule here instead of using parameterization since this class // We explicitly instantiate a rule here instead of using parameterization since this class
// only ever runs in ChromeTabbedActivity. // only ever runs in ChromeTabbedActivity.
@Rule @Rule
...@@ -339,24 +345,6 @@ public class VrBrowserNativeUiTest { ...@@ -339,24 +345,6 @@ public class VrBrowserNativeUiTest {
"overflow_menu_visible_browser_ui", mRenderTestRule); "overflow_menu_visible_browser_ui", mRenderTestRule);
} }
/**
* Tests that the page info popup appears when the security token in the URL bar is clicked.
*/
@Test
@LargeTest
@Feature({"Browser", "RenderTest"})
public void testPageInfoAppearsOnSecurityTokenClick()
throws InterruptedException, TimeoutException, IOException {
NativeUiUtils.clickElementAndWaitForUiQuiescence(
UserFriendlyElementName.PAGE_INFO_BUTTON, new PointF());
// Workaround for https://crbug.com/893291, where the text doesn't actually show up until a
// bit after the element is drawn.
SystemClock.sleep(1000);
NativeUiUtils.waitForUiQuiescence();
RenderTestUtils.dumpAndCompare(NativeUiUtils.FRAME_BUFFER_SUFFIX_BROWSER_UI,
"page_info_visible_browser_ui", mRenderTestRule);
}
/** /**
* Tests that data URLs have the data portion of the URL emphasized like in 2D browsing. * Tests that data URLs have the data portion of the URL emphasized like in 2D browsing.
*/ */
...@@ -595,6 +583,17 @@ public class VrBrowserNativeUiTest { ...@@ -595,6 +583,17 @@ public class VrBrowserNativeUiTest {
"suggestion_clicking_bottom", cropBounds, mRenderTestRule); "suggestion_clicking_bottom", cropBounds, mRenderTestRule);
} }
private void resizeContentWindowToMinimum() throws InterruptedException {
NativeUiUtils.selectRepositionBar();
NativeUiUtils.scrollFling(NativeUiUtils.ScrollDirection.DOWN);
// We need to ensure that the scroll has finished, but we can't use waitForUiQuiescence()
// because the UI is never quiescent while the reposition bar is being used. So, wait a
// suitable number of frames.
NativeUiUtils.waitNumFrames(2 * NativeUiUtils.NUM_STEPS_FLING_SCROLL);
NativeUiUtils.deselectRepositionBar();
NativeUiUtils.waitForUiQuiescence();
}
/** /**
* Tests that scrolling while holding the reposition bar causes the content window to be * Tests that scrolling while holding the reposition bar causes the content window to be
* resized and that the resize doesn't affect the dimensions reported to the webpage. * resized and that the resize doesn't affect the dimensions reported to the webpage.
...@@ -608,14 +607,7 @@ public class VrBrowserNativeUiTest { ...@@ -608,14 +607,7 @@ public class VrBrowserNativeUiTest {
"test_content_resizing_does_not_affect_webpage"), "test_content_resizing_does_not_affect_webpage"),
PAGE_LOAD_TIMEOUT_S); PAGE_LOAD_TIMEOUT_S);
mVrBrowserTestFramework.executeStepAndWait("stepGetInitialDimensions()"); mVrBrowserTestFramework.executeStepAndWait("stepGetInitialDimensions()");
NativeUiUtils.selectRepositionBar(); resizeContentWindowToMinimum();
NativeUiUtils.scrollFling(NativeUiUtils.ScrollDirection.DOWN);
// We need to ensure that the scroll has finished, but we can't use waitForUiQuiescence()
// because the UI is never quiescent while the reposition bar is being used. So, wait a
// suitable number of frames.
NativeUiUtils.waitNumFrames(2 * NativeUiUtils.NUM_STEPS_FLING_SCROLL);
NativeUiUtils.deselectRepositionBar();
NativeUiUtils.waitForUiQuiescence();
RenderTestUtils.dumpAndCompare( RenderTestUtils.dumpAndCompare(
NativeUiUtils.FRAME_BUFFER_SUFFIX_BROWSER_UI, "scroll_resizing", mRenderTestRule); NativeUiUtils.FRAME_BUFFER_SUFFIX_BROWSER_UI, "scroll_resizing", mRenderTestRule);
mVrBrowserTestFramework.executeStepAndWait("stepCheckDimensionsAfterResize()"); mVrBrowserTestFramework.executeStepAndWait("stepCheckDimensionsAfterResize()");
...@@ -794,4 +786,64 @@ public class VrBrowserNativeUiTest { ...@@ -794,4 +786,64 @@ public class VrBrowserNativeUiTest {
NativeUiUtils.performActionAndWaitForVisibilityStatus( NativeUiUtils.performActionAndWaitForVisibilityStatus(
UserFriendlyElementName.OMNIBOX_VOICE_INPUT_BUTTON, false /* visible */, () -> {}); UserFriendlyElementName.OMNIBOX_VOICE_INPUT_BUTTON, false /* visible */, () -> {});
} }
/**
* Tests that the security token and page info popup look correct on HTTP sites.
*/
@Test
@MediumTest
@Feature({"Browser", "RenderTest"})
public void testSecurityTokenOnHttp() throws InterruptedException, IOException {
mVrTestRule.getEmbeddedTestServerRule().setServerPort(SERVER_PORT);
testSecurityTokenImpl("security_token_http");
}
/**
* Tests that the security token and page info popup look correct on HTTPS sites.
*/
@Test
@MediumTest
@Feature({"Browser", "RenderTest"})
public void testSecurityTokenOnHttps() throws InterruptedException, IOException {
mVrTestRule.getEmbeddedTestServerRule().setServerPort(SERVER_PORT);
mVrTestRule.getEmbeddedTestServerRule().setServerUsesHttps(true);
testSecurityTokenImpl("security_token_https");
}
/**
* Tests that the security token and page info popup look correct on HTTPS sites when the
* server provides a bad certificate.
*/
@Test
@MediumTest
@Feature({"Browser", "RenderTest"})
public void testSecurityTokenOnHttpsBadCertificate() throws InterruptedException, IOException {
mVrTestRule.getEmbeddedTestServerRule().setServerPort(SERVER_PORT);
mVrTestRule.getEmbeddedTestServerRule().setServerUsesHttps(true);
mVrTestRule.getEmbeddedTestServerRule().setCertificateType(ServerCertificate.CERT_EXPIRED);
testSecurityTokenImpl("security_token_https_bad_cert");
}
private void testSecurityTokenImpl(String identifier) throws InterruptedException, IOException {
NativeUiUtils.enableMockedInput();
mVrTestRule.loadUrl(
mVrBrowserTestFramework.getEmbeddedServerUrlForHtmlTestFile("2d_permission_page"),
PAGE_LOAD_TIMEOUT_S);
// Wait for any residual animations from loading to go away.
NativeUiUtils.waitForUiQuiescence();
RenderTestUtils.dumpAndCompare(NativeUiUtils.FRAME_BUFFER_SUFFIX_BROWSER_UI,
identifier + "_url_bar_token", mRenderTestRule);
// Make the content window as small as possible to hide as much of it behind the upcoming
// popup. See https://crbug.com/947117.
// TODO(https://crbug.com/947117): Remove the resizing once the interstitials are no longer
// offset slightly vertically at random.
resizeContentWindowToMinimum();
NativeUiUtils.clickElementAndWaitForUiQuiescence(
UserFriendlyElementName.PAGE_INFO_BUTTON, new PointF());
// Workaround for https://crbug.com/893291, where the text doesn't actually show up until a
// bit after the element is drawn.
SystemClock.sleep(2000);
RenderTestUtils.dumpAndCompare(NativeUiUtils.FRAME_BUFFER_SUFFIX_BROWSER_UI,
identifier + "_popup", mRenderTestRule);
}
} }
...@@ -29,6 +29,10 @@ public class EmbeddedTestServerRule extends TestWatcher { ...@@ -29,6 +29,10 @@ public class EmbeddedTestServerRule extends TestWatcher {
@GuardedBy("mLock") @GuardedBy("mLock")
private boolean mUseHttps; private boolean mUseHttps;
@GuardedBy("mLock")
@ServerCertificate
private int mCertificateType = ServerCertificate.CERT_OK;
@Override @Override
protected void finished(Description description) { protected void finished(Description description) {
super.finished(description); super.finished(description);
...@@ -51,7 +55,7 @@ public class EmbeddedTestServerRule extends TestWatcher { ...@@ -51,7 +55,7 @@ public class EmbeddedTestServerRule extends TestWatcher {
Context context = InstrumentationRegistry.getContext(); Context context = InstrumentationRegistry.getContext();
mServer = mUseHttps mServer = mUseHttps
? EmbeddedTestServer.createAndStartHTTPSServerWithPort( ? EmbeddedTestServer.createAndStartHTTPSServerWithPort(
context, ServerCertificate.CERT_OK, mServerPort) context, mCertificateType, mServerPort)
: EmbeddedTestServer.createAndStartServerWithPort(context, mServerPort); : EmbeddedTestServer.createAndStartServerWithPort(context, mServerPort);
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new EmbeddedTestServer.EmbeddedTestServerFailure( throw new EmbeddedTestServer.EmbeddedTestServerFailure(
...@@ -86,4 +90,12 @@ public class EmbeddedTestServerRule extends TestWatcher { ...@@ -86,4 +90,12 @@ public class EmbeddedTestServerRule extends TestWatcher {
mUseHttps = useHttps; mUseHttps = useHttps;
} }
} }
/** Sets what type of certificate the server uses when running as an HTTPS server. */
public void setCertificateType(@ServerCertificate int certificateType) {
synchronized (mLock) {
assert mServer == null;
mCertificateType = certificateType;
}
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment