Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/CopylessPasteTest.java

Issue 2819763002: Add end-to-end test for CopylessPaste (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java_sources.gni ('k') | chrome/test/data/android/appindexing/json-ld.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/CopylessPasteTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/CopylessPasteTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/CopylessPasteTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..732fafab3586faefccf6c331bae6dac7335a3e5c
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/CopylessPasteTest.java
@@ -0,0 +1,143 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser;
+
+import android.support.test.filters.LargeTest;
+
+import org.chromium.base.Callback;
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.test.util.CallbackHelper;
+import org.chromium.base.test.util.CommandLineFlags;
+import org.chromium.base.test.util.Feature;
+import org.chromium.base.test.util.Restriction;
+import org.chromium.blink.mojom.document_metadata.Entity;
+import org.chromium.blink.mojom.document_metadata.Property;
+import org.chromium.blink.mojom.document_metadata.Values;
+import org.chromium.blink.mojom.document_metadata.WebPage;
+import org.chromium.chrome.browser.firstrun.FirstRunStatus;
+import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
+import org.chromium.chrome.test.util.ChromeTabUtils;
+import org.chromium.net.test.EmbeddedTestServer;
+import org.chromium.url.mojom.Url;
+
+import java.util.concurrent.TimeoutException;
+
+/**
+ * Tests Copyless Paste AppIndexing using instrumented tests.
+ */
+@CommandLineFlags.Add("enable-features=CopylessPaste")
+@Restriction(Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE)
+public class CopylessPasteTest extends ChromeTabbedActivityTestBase {
+ private static final String NODATA_PAGE = "/chrome/test/data/android/about.html";
+ private static final String DATA_PAGE = "/chrome/test/data/android/appindexing/json-ld.html";
+
+ private EmbeddedTestServer mTestServer;
+
+ @Override
+ protected void setUp() throws Exception {
+ // We have to set up the test server before starting the activity.
+ mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
+
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ FirstRunStatus.setFirstRunFlowComplete(true);
+ }
+ });
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mTestServer.stopAndDestroyServer();
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ FirstRunStatus.setFirstRunFlowComplete(false);
+ }
+ });
+ super.tearDown();
+ }
+
+ @Override
+ public void startMainActivity() throws InterruptedException {
+ startMainActivityOnBlankPage();
+ }
+
+ private static class CopylessHelper extends CallbackHelper {
+ private WebPage mWebPage;
+
+ public WebPage getWebPage() {
+ return mWebPage;
+ }
+
+ public void notifyCalled(WebPage page) {
+ mWebPage = page;
+ notifyCalled();
+ }
+ }
+
+ /**
+ * Tests that CopylessPaste works end-to-end.
+ */
+ @LargeTest
+ @Feature({"CopylessPaste"})
+ public void testValid() throws InterruptedException, TimeoutException {
+ final CopylessHelper callbackHelper = new CopylessHelper();
+
+ AppIndexingUtil.setCallbackForTesting(new Callback<WebPage>() {
+ @Override
+ public void onResult(WebPage webpage) {
+ callbackHelper.notifyCalled(webpage);
+ }
+ });
+
+ // Incognito tabs are ignored.
+ newIncognitoTabsFromMenu(1);
+ loadUrl(mTestServer.getURL(DATA_PAGE));
+ ChromeTabUtils.closeCurrentTab(getInstrumentation(), getActivity());
+ assertEquals(0, callbackHelper.getCallCount());
Maria 2017/04/18 00:01:48 Seems like these ought to be separate test cases (
wychen 2017/04/18 22:19:05 Done.
+
+ // Only parse http and https.
+ loadUrl("chrome://newtab");
+ assertEquals(0, callbackHelper.getCallCount());
+
+ // NODATA_PAGE doesn't contain desired metadata.
+ loadUrl(mTestServer.getURL(NODATA_PAGE));
+ callbackHelper.waitForCallback(0);
+ assertNull(callbackHelper.getWebPage());
+
+ // DATA_PAGE contains desired metadata.
+ loadUrl(mTestServer.getURL(DATA_PAGE));
+ callbackHelper.waitForCallback(1);
+ WebPage extracted = callbackHelper.getWebPage();
+
+ WebPage expected = new WebPage();
+ expected.url = new Url();
+ expected.url.url = mTestServer.getURL(DATA_PAGE);
+ expected.title = "JSON-LD for AppIndexing Test";
+ Entity e = new Entity();
+ e.type = "Hotel";
+ e.properties = new Property[2];
+ e.properties[0] = new Property();
+ e.properties[0].name = "@context";
+ e.properties[0].values = new Values();
+ e.properties[0].values.setStringValues(new String[] {"http://schema.org"});
+ e.properties[1] = new Property();
+ e.properties[1].name = "name";
+ e.properties[1].values = new Values();
+ e.properties[1].values.setStringValues(new String[] {"Hotel Name"});
+ expected.entities = new Entity[1];
+ expected.entities[0] = e;
+ assertEquals(expected, extracted);
+
+ int callCount = callbackHelper.getCallCount();
+ // Cache hit without entities. Shouldn't parse again.
+ loadUrl(mTestServer.getURL(NODATA_PAGE));
+ // Cache hit with entities. Shouldn't parse again.
+ loadUrl(mTestServer.getURL(DATA_PAGE));
+ assertEquals(callCount, callbackHelper.getCallCount());
+ }
+}
« no previous file with comments | « chrome/android/java_sources.gni ('k') | chrome/test/data/android/appindexing/json-ld.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698