 Chromium Code Reviews
 Chromium Code Reviews Issue 2302913003:
  Add SafeBrowsingNavigationObserver to listen to navigation events  (Closed)
    
  
    Issue 2302913003:
  Add SafeBrowsingNavigationObserver to listen to navigation events  (Closed) 
  | Index: chrome/test/data/safe_browsing/download_protection/navigation_observer/navigation_observer_tests.html | 
| diff --git a/chrome/test/data/safe_browsing/download_protection/navigation_observer/navigation_observer_tests.html b/chrome/test/data/safe_browsing/download_protection/navigation_observer/navigation_observer_tests.html | 
| index eb1cfee4e96103cc2d1cc0bb851534eab06b8881..74788d3d231e40a263f79e7507a17a374ef858d7 100644 | 
| --- a/chrome/test/data/safe_browsing/download_protection/navigation_observer/navigation_observer_tests.html | 
| +++ b/chrome/test/data/safe_browsing/download_protection/navigation_observer/navigation_observer_tests.html | 
| @@ -1,50 +1,33 @@ | 
| <html> | 
| <head> | 
| <script> | 
| - // Identify the link by id and click on it. | 
| - // targetId: document element id | 
| - // newTab: whether open link in new tab. | 
| - function clickLink(targetId, newTab) { | 
| - var node = document.getElementById(targetId); | 
| - if (newTab == 1) { | 
| - // Click and opens link in new tab. | 
| - var evt = document.createEvent("MouseEvents"); | 
| - evt.initMouseEvent("click", false, true, window, 0, 0, 0, 0, 0, | 
| - newTab, false, false, false, 0, null); | 
| - node.dispatchEvent(evt); | 
| - } else { | 
| + // Click on a link by id to star a test case. | 
| + function clickLink(linkId) { | 
| + var node = document.getElementById(linkId); | 
| + if (node != null) { | 
| // Click and open link in the same tab. | 
| node.click(); | 
| } | 
| } | 
| - | 
| - // Helper function to query string parmeter in the URL. | 
| - function getParameterByName(name) { | 
| - url = window.location.href; | 
| - name = name.replace(/[\[\]]/g, "\\$&"); | 
| - var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), | 
| - results = regex.exec(url); | 
| - if (!results) return null; | 
| - if (!results[2]) return ''; | 
| - return decodeURIComponent(results[2].replace(/\+/g, " ")); | 
| + | 
| + // Redirect to download via window.location.href | 
| + function windowLocationHrefDownload() { | 
| + window.location.href = "../signed.exe"; | 
| + return true; | 
| } | 
| - // Start test case based on URL query string paramter. | 
| - function startTestCase() { | 
| - var node = getParameterByName("test_case"); | 
| - var openInNewTab = getParameterByName("new_tab"); | 
| - if (node != null) | 
| - clickLink(node, openInNewTab); | 
| + function mixRedirectDownload() { | 
| + window.location.href = "redirect.html"; | 
| + return true; | 
| } | 
| - // Trigger a download in new tab and old tab navigate to an irrelevant page. | 
| - function downloadInNewTab(willNavigateAway) { | 
| + // Trigger a download in new tab. | 
| + function downloadInNewTab() { | 
| var tab = window.open(''); | 
| tab.opener = null; | 
| tab.document.write('<META HTTP-EQUIV="refresh" content="0; url=../signed.exe">'); | 
| tab.document.close(); | 
| - if (willNavigateAway) | 
| - window.location.href = "safe_page.html"; | 
| + return true; | 
| } | 
| // Trigger download in a new tab and the download is from a data url. | 
| @@ -55,9 +38,7 @@ | 
| tab.document.close(); | 
| } | 
| - // Trigger download by using html5 system API. | 
| - var fileLocation = null; | 
| - (function getFileLocationByHtml5FileSystemAPI(){ | 
| + function downloadViaFileApi(){ | 
| var errorize = function(e){console.log(e);}; | 
| var filename = 'msghello-bypass.exe'; | 
| var blob = new Blob([new Uint8Array([1, 2, 3, 4])],{type:'application/octet-stream'}); | 
| @@ -71,7 +52,9 @@ | 
| function(fileEntry){ | 
| fileEntry.createWriter( | 
| function(writer){ | 
| - writer.onwriteend = function(){fileLocation = fileEntry.toURL();}; | 
| + writer.onwriteend = function(){ | 
| + window.location.href = fileEntry.toURL(); | 
| + }; | 
| writer.onerror = errorize; | 
| writer.write(blob); | 
| }, | 
| @@ -87,19 +70,19 @@ | 
| createFile); | 
| }, | 
| errorize); | 
| - })(); | 
| + } | 
| + | 
| </script> | 
| </head> | 
| - <body onload="startTestCase();"> | 
| + <body> | 
| <a id="direct_download" href="../signed.exe">Direct download</a><br> | 
| - <a id="noreferrer" href="../signed.exe" rel="noreferrer">Direct download noreferrer</a><br> | 
| - <a id="single_meta_refresh_redirect" href="redirect.html" >Redirect download</a><br> | 
| - <a id="single_meta_refresh_redirect_noreferrer" href="redirect.html" rel="noreferrer">Redirect download with noreferrer</a><br> | 
| - <a id="multiple_meta_refresh_redirects" href="double_redirect.html"> Redirect download multiple times</a><br> | 
| + <a id="direct_download_noreferrer" href="../signed.exe" rel="noreferrer">Direct download noreferrer</a><br> | 
| + <a id="single_meta_refresh_redirect" href="redirect.html" >Redirect download via meta refresh</a><br> | 
| 
Nathan Parker
2016/09/03 00:21:35
nit: space after quote.  You could break+indent th
 
Jialiu Lin
2016/09/07 00:42:41
done.
 | 
| + <a id="multiple_meta_refresh_redirects" href="double_redirect.html"> Redirect download multiple times via meta refresh</a><br> | 
| + <a id="window_location_href_redirect" href="#" onclick="windowLocationHrefDownload()"> Redirect download via window.location.href</a><br> | 
| + <a id="mix_redirects" href="#" onclick="mixRedirectDownload()"> Redirect download via mix of window.location.href and meta refresh</a><br> | 
| <a id="new_tab_download" href="#" onclick="downloadInNewTab(false)"> Open download in new tab</a><br> | 
| - <a id="new_tab_download_navigate_away" href="#" onclick="downloadInNewTab(true)"> Open download in new tab and navigate away </a><br> | 
| <a id="new_tab_download_with_data_url" href="#" onclick="downloadInNewTabWithDataURL()"> Open download in new tab with data url </a><br> | 
| - <button id="html5_file_api" onclick="window.location.href=fileLocation; return false"> Download via html5 file system API</button><br> | 
| - More testing cases are coming soon... | 
| + <a id="html5_file_api" href="#" onclick="downloadViaFileApi();"> Download via HTML5 file system API </a> | 
| </body> | 
| </html> |