Commit a6a6f007 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

weblayer: add test for WebLayer.registerExternalExperimentIDs()

I naively thought the wiring was so simple nothing could go
wrong. Time has proven me wrong.

BUG=11478276
TEST=test only change

Change-Id: I4dfdd7a7613a1f6a04a2e4356f63b040da063b03
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2535919
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827096}
parent df984eaa
...@@ -31,6 +31,7 @@ android_library("weblayer_java_tests") { ...@@ -31,6 +31,7 @@ android_library("weblayer_java_tests") {
"src/org/chromium/weblayer/test/OnTabRemovedTabListCallbackImpl.java", "src/org/chromium/weblayer/test/OnTabRemovedTabListCallbackImpl.java",
"src/org/chromium/weblayer/test/PrerenderControllerTest.java", "src/org/chromium/weblayer/test/PrerenderControllerTest.java",
"src/org/chromium/weblayer/test/ProfileTest.java", "src/org/chromium/weblayer/test/ProfileTest.java",
"src/org/chromium/weblayer/test/RegisterExternalExperimentIdsTest.java",
"src/org/chromium/weblayer/test/RenderingTest.java", "src/org/chromium/weblayer/test/RenderingTest.java",
"src/org/chromium/weblayer/test/ScrollOffsetCallbackTest.java", "src/org/chromium/weblayer/test/ScrollOffsetCallbackTest.java",
"src/org/chromium/weblayer/test/SmokeTest.java", "src/org/chromium/weblayer/test/SmokeTest.java",
......
// Copyright 2020 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.weblayer.test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.chromium.content_public.browser.test.util.TestThreadUtils.runOnUiThreadBlocking;
import androidx.test.filters.SmallTest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.net.test.util.TestWebServer;
import org.chromium.weblayer.shell.InstrumentationActivity;
/**
* Assertions for WebLayer.registerExternalExperimentIDs().
*/
// The flags are necessary for the following reasons:
// force-enable-metrics-reporting: forces metrics to be enabled. Without this, whether metrics are
// enabled depends upon the android version and system. The test needs metrics to be enabled.
// host-resolver-rules: to make 'google.com' redirect to the port created by TestWebServer.
// ignore-certificate-errors: TestWebServer doesn't have a real cert.
@CommandLineFlags.Add({"force-enable-metrics-reporting", "host-resolver-rules='MAP * 127.0.0.1'",
"ignore-certificate-errors"})
@RunWith(WebLayerJUnit4ClassRunner.class)
public class RegisterExternalExperimentIdsTest {
@Rule
public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
/**
* This is an end-to-end test of registerExternalExperimentIDs. It also covers
* https://crbug.com/1147827.
*/
@Test
@SmallTest
@MinWebLayerVersion(88) // Fix landed in 88.
public void testRegisterExternalExperimentIds() throws Exception {
mActivityTestRule.getTestServerRule().setServerUsesHttps(true);
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(null);
TestWebServer testServer = TestWebServer.startSsl();
// Experiment ids are only added for certain domains, of which google is one.
testServer.setServerHost("google.com");
String url = testServer.setResponse("/ok.html", "<html>ok</html>", null);
mActivityTestRule.navigateAndWait(url);
String initialValue = testServer.getLastRequest("/ok.html").headerValue("X-Client-Data");
runOnUiThreadBlocking(() -> {
mActivityTestRule.getWebLayer().registerExternalExperimentIDs("Test", new int[] {1});
});
String url2 = testServer.setResponse("/ok2.html", "<html>ok</html>", null);
mActivityTestRule.navigateAndWait(url2);
String secondValue = testServer.getLastRequest("/ok2.html").headerValue("X-Client-Data");
// The contents of the header are an encoded protobuf, which is a bit hard to verify in a
// test. The key things to assert is registering an id changes the value, and that it's not
// empty.
assertFalse(secondValue.isEmpty());
assertNotEquals(initialValue, secondValue);
}
}
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