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

Side by Side Diff: chrome/test/data/safe_browsing/download_protection/navigation_observer/navigation_observer_tests.html

Issue 2302913003: Add SafeBrowsingNavigationObserver to listen to navigation events (Closed)
Patch Set: nit Created 4 years, 3 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
OLDNEW
1 <html> 1 <html>
2 <head> 2 <head>
3 <script> 3 <script>
4 // Identify the link by id and click on it. 4 // Click on a link by id to star a test case.
5 // targetId: document element id 5 function clickLink(linkId) {
6 // newTab: whether open link in new tab. 6 var node = document.getElementById(linkId);
7 function clickLink(targetId, newTab) { 7 if (node != null) {
8 var node = document.getElementById(targetId);
9 if (newTab == 1) {
10 // Click and opens link in new tab.
11 var evt = document.createEvent("MouseEvents");
12 evt.initMouseEvent("click", false, true, window, 0, 0, 0, 0, 0,
13 newTab, false, false, false, 0, null);
14 node.dispatchEvent(evt);
15 } else {
16 // Click and open link in the same tab. 8 // Click and open link in the same tab.
17 node.click(); 9 node.click();
18 } 10 }
19 } 11 }
20 12
21 // Helper function to query string parmeter in the URL. 13 // Redirect to download via window.location.href
22 function getParameterByName(name) { 14 function windowLocationHrefDownload() {
23 url = window.location.href; 15 window.location.href = "../signed.exe";
24 name = name.replace(/[\[\]]/g, "\\$&"); 16 return true;
25 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
26 results = regex.exec(url);
27 if (!results) return null;
28 if (!results[2]) return '';
29 return decodeURIComponent(results[2].replace(/\+/g, " "));
30 } 17 }
31 18
32 // Start test case based on URL query string paramter. 19 function mixRedirectDownload() {
33 function startTestCase() { 20 window.location.href = "redirect.html";
34 var node = getParameterByName("test_case"); 21 return true;
35 var openInNewTab = getParameterByName("new_tab");
36 if (node != null)
37 clickLink(node, openInNewTab);
38 } 22 }
39 23
40 // Trigger a download in new tab and old tab navigate to an irrelevant page. 24 // Trigger a download in new tab.
41 function downloadInNewTab(willNavigateAway) { 25 function downloadInNewTab() {
42 var tab = window.open(''); 26 var tab = window.open('');
43 tab.opener = null; 27 tab.opener = null;
44 tab.document.write('<META HTTP-EQUIV="refresh" content="0; url=../signed.e xe">'); 28 tab.document.write('<META HTTP-EQUIV="refresh" content="0; url=../signed.e xe">');
45 tab.document.close(); 29 tab.document.close();
46 if (willNavigateAway) 30 return true;
47 window.location.href = "safe_page.html";
48 } 31 }
49 32
50 // Trigger download in a new tab and the download is from a data url. 33 // Trigger download in a new tab and the download is from a data url.
51 function downloadInNewTabWithDataURL() { 34 function downloadInNewTabWithDataURL() {
52 var tab = window.open(''); 35 var tab = window.open('');
53 tab.opener = null; 36 tab.opener = null;
54 tab.document.write('<META HTTP-EQUIV="refresh" content="0; url=data:appli cation/octet-stream;base64,a2poYWxrc2hkbGtoYXNka2xoYXNsa2RoYWxraGtoYWxza2hka2xza mFoZGxramhhc2xka2hhc2xrZGgKYXNrZGpoa2FzZGpoYWtzaGRrYXNoZGtoYXNrZGhhc2tkaGthc2hka 2Foc2RraGFrc2hka2FzaGRraGFzCmFza2pkaGFrc2hkbSxjbmtzamFoZGtoYXNrZGhhc2tka2hrYXNkC jg3MzQ2ODEyNzQ2OGtqc2hka2FoZHNrZGhraApha3NqZGthc2Roa3NkaGthc2hka2FzaGtkaAohISomX kAqJl4qYWhpZGFzeWRpeWlhc1xcb1wKa2Fqc2Roa2FzaGRrYXNoZGsKYWtzamRoc2tkaAplbmQK">'); 37 tab.document.write('<META HTTP-EQUIV="refresh" content="0; url=data:appli cation/octet-stream;base64,a2poYWxrc2hkbGtoYXNka2xoYXNsa2RoYWxraGtoYWxza2hka2xza mFoZGxramhhc2xka2hhc2xrZGgKYXNrZGpoa2FzZGpoYWtzaGRrYXNoZGtoYXNrZGhhc2tkaGthc2hka 2Foc2RraGFrc2hka2FzaGRraGFzCmFza2pkaGFrc2hkbSxjbmtzamFoZGtoYXNrZGhhc2tka2hrYXNkC jg3MzQ2ODEyNzQ2OGtqc2hka2FoZHNrZGhraApha3NqZGthc2Roa3NkaGthc2hka2FzaGtkaAohISomX kAqJl4qYWhpZGFzeWRpeWlhc1xcb1wKa2Fqc2Roa2FzaGRrYXNoZGsKYWtzamRoc2tkaAplbmQK">');
55 tab.document.close(); 38 tab.document.close();
56 } 39 }
57 40
58 // Trigger download by using html5 system API. 41 // Create a data blob and save it as a test.exe file in filesystem's
59 var fileLocation = null; 42 // space with use URL filesystem:http://test_host/temporary/test.exe
60 (function getFileLocationByHtml5FileSystemAPI(){ 43 // to download it.
44 function downloadViaFileApi(){
61 var errorize = function(e){console.log(e);}; 45 var errorize = function(e){console.log(e);};
62 var filename = 'msghello-bypass.exe'; 46 var filename = 'test.exe';
63 var blob = new Blob([new Uint8Array([1, 2, 3, 4])],{type:'application/octe t-stream'}); 47 var blob = new Blob([new Uint8Array([1, 2, 3, 4])],{type:'application/octe t-stream'});
64 window.webkitRequestFileSystem( 48 window.webkitRequestFileSystem(
65 window.TEMPORARY,1048576, 49 window.TEMPORARY,1048576,
66 function(fs){ 50 function(fs){
67 var createFile = function(){ 51 var createFile = function(){
68 fs.root.getFile( 52 fs.root.getFile(
69 filename, 53 filename,
70 {create:true, exclusive:true}, 54 {create:true, exclusive:true},
71 function(fileEntry){ 55 function(fileEntry){
72 fileEntry.createWriter( 56 fileEntry.createWriter(
73 function(writer){ 57 function(writer){
74 writer.onwriteend = function(){fileLocation = fileEntry.toUR L();}; 58 writer.onwriteend = function(){
59 window.location.href = fileEntry.toURL();
60 };
75 writer.onerror = errorize; 61 writer.onerror = errorize;
76 writer.write(blob); 62 writer.write(blob);
77 }, 63 },
78 errorize); 64 errorize);
79 }, 65 },
80 errorize); 66 errorize);
81 }; 67 };
82 fs.root.getFile( 68 fs.root.getFile(
83 filename,{create:false}, 69 filename,{create:false},
84 function(fileEntry){ 70 function(fileEntry){
85 fileEntry.remove(createFile,errorize); 71 fileEntry.remove(createFile,errorize);
86 }, 72 },
87 createFile); 73 createFile);
88 }, 74 },
89 errorize); 75 errorize);
90 })(); 76 }
77
91 </script> 78 </script>
92 </head> 79 </head>
93 <body onload="startTestCase();"> 80 <body>
94 <a id="direct_download" href="../signed.exe">Direct download</a><br> 81 <a id="direct_download" href="../signed.exe">
95 <a id="noreferrer" href="../signed.exe" rel="noreferrer">Direct download nor eferrer</a><br> 82 Direct download
96 <a id="single_meta_refresh_redirect" href="redirect.html" >Redirect download </a><br> 83 </a><br>
97 <a id="single_meta_refresh_redirect_noreferrer" href="redirect.html" rel="no referrer">Redirect download with noreferrer</a><br> 84 <a id="direct_download_noreferrer" href="../signed.exe" rel="noreferrer">
Charlie Reis 2016/09/16 23:35:06 For all the noreferrer cases, you might want to al
Jialiu Lin 2016/09/22 21:30:29 Add a couple of more cases for target=_blank
98 <a id="multiple_meta_refresh_redirects" href="double_redirect.html"> Redirec t download multiple times</a><br> 85 Direct download noreferrer
99 <a id="new_tab_download" href="#" onclick="downloadInNewTab(false)"> Open do wnload in new tab</a><br> 86 </a><br>
100 <a id="new_tab_download_navigate_away" href="#" onclick="downloadInNewTab(tr ue)"> Open download in new tab and navigate away </a><br> 87 <a id="single_meta_refresh_redirect" href="redirect.html">
101 <a id="new_tab_download_with_data_url" href="#" onclick="downloadInNewTabWit hDataURL()"> Open download in new tab with data url </a><br> 88 Redirect download via meta refresh
102 <button id="html5_file_api" onclick="window.location.href=fileLocation; retu rn false"> Download via html5 file system API</button><br> 89 </a><br>
103 More testing cases are coming soon... 90 <a id="multiple_meta_refresh_redirects" href="double_redirect.html">
91 Redirect download multiple times via meta refresh
92 </a><br>
93 <a id="window_location_href_redirect" href="#" onclick="windowLocationHrefDo wnload()">
94 Redirect download via window.location.href
95 </a><br>
96 <a id="mix_redirects" href="#" onclick="mixRedirectDownload()">
97 Redirect download via mix of window.location.href and meta refresh
98 </a><br>
99 <a id="new_tab_download" href="#" onclick="downloadInNewTab(false)">
100 Open download in new tab
101 </a><br>
102 <a id="new_tab_download_with_data_url" href="#" onclick="downloadInNewTabWit hDataURL()">
103 Open download in new tab with data url
104 </a><br>
105 <a id="html5_file_api" href="#" onclick="downloadViaFileApi()">
106 Download via HTML5 file system API
107 </a>
104 </body> 108 </body>
105 </html> 109 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698