blob: d4e38e3a0bf969473e9cd611a975d0e81f89e9aa [file] [log] [blame]
<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<script src="/js-test-resources/ui-helper.js"></script>
<script src="resources/util.js"></script>
</head>
<body onload="setTimeout(runTest, 0)">
<div id="description">Tests that the attribution is updated if it gets a second attribution with higher priority.</div>
<a id="targetLink">Link</a><br>
<div id="output"></div>
<script>
const path = "/privateClickMeasurement/second-conversion-with-higher-priority.html";
const configuration = [
{
href: "http://localhost:8000" + path + "?stepTwo",
attributionsourceid: 3,
attributiondestination: "http://localhost:8000"
}
];
prepareTest();
function configureLink(index) {
let linkElement = document.getElementById("targetLink");
linkElement.setAttribute("href", configuration[index].href);
linkElement.setAttribute("attributionsourceid", configuration[index].attributionsourceid);
linkElement.setAttribute("attributiondestination", configuration[index].attributiondestination);
}
function activateElement(elementID) {
var element = document.getElementById(elementID);
var centerX = element.offsetLeft + element.offsetWidth / 2;
var centerY = element.offsetTop + element.offsetHeight / 2;
UIHelper.activateAt(centerX, centerY).then(
function () {
},
function () {
document.getElementById("output").innerText = "FAIL Promise rejected.";
tearDownAndFinish();
}
);
}
function convert(priority, callback) {
let pixelElement = document.getElementById("pixel");
if (pixelElement)
document.body.removeChild(pixelElement);
let imageElement = document.createElement("img");
imageElement.src = "https://127.0.0.1:8443/privateClickMeasurement/resources/redirectToConversion.py?conversionData=12&priority=" + priority;
imageElement.id = "pixel";
imageElement.onerror = callback;
document.body.appendChild(imageElement);
}
function runTest() {
if (window.testRunner) {
if (window.location.search === "") {
// Ad click 127.0.0.1 –> localhost.
configureLink(0);
activateElement("targetLink");
} else if (window.location.search === "?stepTwo") {
// Convert the ad click with priority 3.
convert("03", function() {
// Convert the ad click with priority 4.
convert("04", function() {
testRunner.dumpPrivateClickMeasurement();
document.body.removeChild(document.getElementById("targetLink"));
document.body.removeChild(document.getElementById("pixel"));
tearDownAndFinish();
});
});
} else {
document.getElementById("output").innerText = "FAIL Unknown window.location.search == " + window.location.search + ".";
tearDownAndFinish();
}
} else {
document.getElementById("output").innerText = "FAIL No testRunner.";
}
}
</script>
</body>
</html>