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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser;
6
7 import android.support.test.filters.LargeTest;
8
9 import org.chromium.base.Callback;
10 import org.chromium.base.ThreadUtils;
11 import org.chromium.base.test.util.CallbackHelper;
12 import org.chromium.base.test.util.CommandLineFlags;
13 import org.chromium.base.test.util.Feature;
14 import org.chromium.base.test.util.Restriction;
15 import org.chromium.blink.mojom.document_metadata.Entity;
16 import org.chromium.blink.mojom.document_metadata.Property;
17 import org.chromium.blink.mojom.document_metadata.Values;
18 import org.chromium.blink.mojom.document_metadata.WebPage;
19 import org.chromium.chrome.browser.firstrun.FirstRunStatus;
20 import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
21 import org.chromium.chrome.test.util.ChromeTabUtils;
22 import org.chromium.net.test.EmbeddedTestServer;
23 import org.chromium.url.mojom.Url;
24
25 import java.util.concurrent.TimeoutException;
26
27 /**
28 * Tests Copyless Paste AppIndexing using instrumented tests.
29 */
30 @CommandLineFlags.Add("enable-features=CopylessPaste")
31 @Restriction(Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE)
32 public class CopylessPasteTest extends ChromeTabbedActivityTestBase {
33 private static final String NODATA_PAGE = "/chrome/test/data/android/about.h tml";
34 private static final String DATA_PAGE = "/chrome/test/data/android/appindexi ng/json-ld.html";
35
36 private EmbeddedTestServer mTestServer;
37
38 @Override
39 protected void setUp() throws Exception {
40 // We have to set up the test server before starting the activity.
41 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation ().getContext());
42
43 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
44 @Override
45 public void run() {
46 FirstRunStatus.setFirstRunFlowComplete(true);
47 }
48 });
49 super.setUp();
50 }
51
52 @Override
53 protected void tearDown() throws Exception {
54 mTestServer.stopAndDestroyServer();
55 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
56 @Override
57 public void run() {
58 FirstRunStatus.setFirstRunFlowComplete(false);
59 }
60 });
61 super.tearDown();
62 }
63
64 @Override
65 public void startMainActivity() throws InterruptedException {
66 startMainActivityOnBlankPage();
67 }
68
69 private static class CopylessHelper extends CallbackHelper {
70 private WebPage mWebPage;
71
72 public WebPage getWebPage() {
73 return mWebPage;
74 }
75
76 public void notifyCalled(WebPage page) {
77 mWebPage = page;
78 notifyCalled();
79 }
80 }
81
82 /**
83 * Tests that CopylessPaste works end-to-end.
84 */
85 @LargeTest
86 @Feature({"CopylessPaste"})
87 public void testValid() throws InterruptedException, TimeoutException {
88 final CopylessHelper callbackHelper = new CopylessHelper();
89
90 AppIndexingUtil.setCallbackForTesting(new Callback<WebPage>() {
91 @Override
92 public void onResult(WebPage webpage) {
93 callbackHelper.notifyCalled(webpage);
94 }
95 });
96
97 // Incognito tabs are ignored.
98 newIncognitoTabsFromMenu(1);
99 loadUrl(mTestServer.getURL(DATA_PAGE));
100 ChromeTabUtils.closeCurrentTab(getInstrumentation(), getActivity());
101 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.
102
103 // Only parse http and https.
104 loadUrl("chrome://newtab");
105 assertEquals(0, callbackHelper.getCallCount());
106
107 // NODATA_PAGE doesn't contain desired metadata.
108 loadUrl(mTestServer.getURL(NODATA_PAGE));
109 callbackHelper.waitForCallback(0);
110 assertNull(callbackHelper.getWebPage());
111
112 // DATA_PAGE contains desired metadata.
113 loadUrl(mTestServer.getURL(DATA_PAGE));
114 callbackHelper.waitForCallback(1);
115 WebPage extracted = callbackHelper.getWebPage();
116
117 WebPage expected = new WebPage();
118 expected.url = new Url();
119 expected.url.url = mTestServer.getURL(DATA_PAGE);
120 expected.title = "JSON-LD for AppIndexing Test";
121 Entity e = new Entity();
122 e.type = "Hotel";
123 e.properties = new Property[2];
124 e.properties[0] = new Property();
125 e.properties[0].name = "@context";
126 e.properties[0].values = new Values();
127 e.properties[0].values.setStringValues(new String[] {"http://schema.org" });
128 e.properties[1] = new Property();
129 e.properties[1].name = "name";
130 e.properties[1].values = new Values();
131 e.properties[1].values.setStringValues(new String[] {"Hotel Name"});
132 expected.entities = new Entity[1];
133 expected.entities[0] = e;
134 assertEquals(expected, extracted);
135
136 int callCount = callbackHelper.getCallCount();
137 // Cache hit without entities. Shouldn't parse again.
138 loadUrl(mTestServer.getURL(NODATA_PAGE));
139 // Cache hit with entities. Shouldn't parse again.
140 loadUrl(mTestServer.getURL(DATA_PAGE));
141 assertEquals(callCount, callbackHelper.getCallCount());
142 }
143 }
OLDNEW
« 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