| <!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/js-test.js"></script> |
| <script src="/js-test-resources/ui-helper.js"></script> |
| <style> |
| .wide-link { |
| width: 150px; |
| display: inline-block; |
| } |
| </style> |
| </head> |
| <body onload="runAllTests()"> |
| <div id="description"></div> |
| <div id="output"></div><br> |
| <div id="console"></div> |
| <script> |
| description("Test for validity of ad click attribution attributes on anchor tags."); |
| jsTestIsAsync = true; |
| |
| function createAdClickAttributionAnchorElement(elementID, adCampaignID, adDestination) { |
| let anchorElement = document.createElement("a"); |
| anchorElement.id = elementID; |
| anchorElement.classList.add("wide-link"); |
| anchorElement.adcampaignid = adCampaignID; |
| anchorElement.addestination = adDestination; |
| anchorElement.href = "#"; |
| anchorElement.innerText = "Link" + currentTest; |
| return anchorElement; |
| } |
| |
| function activateElement(elementID, callback) { |
| UIHelper.activateElement(document.getElementById(elementID)).then( |
| function () { |
| callback(); |
| }, |
| function () { |
| testFailed("Promise rejected."); |
| finishJSTest(); |
| } |
| ); |
| } |
| |
| let currentTest = 0; |
| function runOneTest(adCampaignID, adDestination, callback) { |
| const currentElementID = "test" + currentTest++; |
| const anchorElement = createAdClickAttributionAnchorElement(currentElementID, adCampaignID, adDestination); |
| output.appendChild(anchorElement); |
| activateElement(currentElementID, callback); |
| } |
| |
| const validAdCampaignID = "03"; |
| const validAdDestination = "http://webkit.org"; |
| const sameSite = document.location.origin; |
| const testCases = [ |
| [ validAdCampaignID, validAdDestination ], |
| [ "100", validAdDestination ], // Too many characters. |
| [ "1", validAdDestination ], // Too few characters. |
| [ "98", validAdDestination ], // Too high value. |
| [ "-1", validAdDestination ], // Negative value. |
| [ "ab", validAdDestination ], // Non-digits. |
| [ "1", validAdDestination ], // Non-ASCII. |
| [ " 1", validAdDestination ], // Leading space. |
| [ "1 ", validAdDestination ], // Trailing space. |
| [ validAdCampaignID, "webkit.org" ], // Missing protocol. |
| [ validAdCampaignID, "://webkit.org" ], // Partially missing protocol. |
| [ validAdCampaignID, "" ], // Non-ASCII characters as destination. |
| [ "", validAdDestination ], // Empty campaign ID. |
| [ validAdCampaignID, "" ], // Empty destination. |
| [ validAdCampaignID, sameSite ] // Same-site destination. |
| ]; |
| |
| function runAllTests() { |
| if (currentTest < testCases.length) |
| runOneTest(testCases[currentTest][0], testCases[currentTest][1], runAllTests); |
| else { |
| document.body.removeChild(output); |
| finishJSTest(); |
| } |
| } |
| </script> |
| </body> |
| </html> |