1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/test_bug_94514.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=94514 1.8 +Specifically, this tests that a page that is obtained via a post request does 1.9 +not get added to global history. 1.10 +--> 1.11 +<head> 1.12 + <title>Test for Bug 94515</title> 1.13 + <script type="text/javascript" src="http://mochi.test:8888/tests/SimpleTest/SimpleTest.js"></script> 1.14 + 1.15 + <link rel="stylesheet" type="text/css" href="http://mochi.test:8888/tests/SimpleTest/test.css" /> 1.16 +</head> 1.17 +<body> 1.18 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=94514">Mozilla Bug 94514</a> 1.19 + 1.20 +<div id="content" style="display: none"> 1.21 + 1.22 +</div> 1.23 +<pre id="test"> 1.24 +<script class="testbody" type="text/javascript"> 1.25 + 1.26 +SimpleTest.waitForExplicitFinish(); 1.27 + 1.28 +var startURI = "http://mochi.test:8888/tests/toolkit/components/places/tests/bug94514-postpage.html"; 1.29 +var postedURI = startURI + "?posted=1"; 1.30 + 1.31 +const Cc = Components.classes; 1.32 +const Ci = Components.interfaces; 1.33 + 1.34 +Components.utils.import("resource://gre/modules/PlacesUtils.jsm"); 1.35 + 1.36 +var ios = Cc["@mozilla.org/network/io-service;1"]. 1.37 + getService(Ci.nsIIOService); 1.38 +var startPage = ios.newURI(startURI, null, null); 1.39 +var postedPage = ios.newURI(postedURI, null, null); 1.40 +var w = null; 1.41 + 1.42 +// Because adding visits is async, we will not be notified imemdiately. 1.43 +var os = Cc["@mozilla.org/observer-service;1"]. 1.44 + getService(Ci.nsIObserverService); 1.45 +var visitObserver = { 1.46 + _visitCount: 0, 1.47 + observe: function(aSubject, aTopic, aData) { 1.48 + if (!startPage.equals(aSubject.QueryInterface(Ci.nsIURI)) || 1.49 + ++this._visitCount < 2) { 1.50 + return; 1.51 + } 1.52 + os.removeObserver(this, aTopic); 1.53 + finishTest(); 1.54 + }, 1.55 +}; 1.56 +os.addObserver(visitObserver, "uri-visit-saved", false); 1.57 + 1.58 +PlacesUtils.asyncHistory.isURIVisited(startPage, function(aURI, aIsVisited) { 1.59 + SimpleTest.ok(!aIsVisited, "Initial page does not start in global history. " + 1.60 + "Note: this will also fail if you run the test twice."); 1.61 + PlacesUtils.asyncHistory.isURIVisited(postedPage, function(aURI, aIsVisited) { 1.62 + SimpleTest.ok(!aIsVisited, "Posted page does not start in global history."); 1.63 + w = window.open(startURI, "", "width=10,height=10"); 1.64 + }); 1.65 +}); 1.66 + 1.67 +function finishTest() { 1.68 + // We need to check that this was not added to global history. 1.69 + PlacesUtils.asyncHistory.isURIVisited(startPage, function(aURI, aIsVisited) { 1.70 + SimpleTest.ok(aIsVisited, "Initial page was added to global history."); 1.71 + PlacesUtils.asyncHistory.isURIVisited(postedPage, function(aURI, aIsVisited) { 1.72 + SimpleTest.ok(!aIsVisited, "Posted page was not added to global history."); 1.73 + w.close(); 1.74 + SimpleTest.finish(); 1.75 + }); 1.76 + }); 1.77 +} 1.78 + 1.79 +</script> 1.80 +</pre> 1.81 +</body> 1.82 +</html>