Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 /**
6 * Tests that visits across frames are correctly represented in the database.
7 */
9 const BASE_URL = "http://mochi.test:8888/browser/browser/components/places/tests/browser";
10 const PAGE_URL = BASE_URL + "/framedPage.html";
11 const LEFT_URL = BASE_URL + "/frameLeft.html";
12 const RIGHT_URL = BASE_URL + "/frameRight.html";
14 let gTabLoaded = false;
15 let gLeftFrameVisited = false;
17 let observer = {
18 observe: function(aSubject, aTopic, aData)
19 {
20 let url = aSubject.QueryInterface(Ci.nsIURI).spec;
21 if (url == LEFT_URL ) {
22 is(getTransitionForUrl(url), null,
23 "Embed visits should not get a database entry.");
24 gLeftFrameVisited = true;
25 maybeClickLink();
26 }
27 else if (url == RIGHT_URL ) {
28 is(getTransitionForUrl(url), PlacesUtils.history.TRANSITION_FRAMED_LINK,
29 "User activated visits should get a FRAMED_LINK transition.");
30 finish();
31 }
32 },
33 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver])
34 };
35 Services.obs.addObserver(observer, "uri-visit-saved", false);
37 function test()
38 {
39 waitForExplicitFinish();
40 gBrowser.selectedTab = gBrowser.addTab(PAGE_URL);
41 let frameCount = 0;
42 gBrowser.selectedTab.linkedBrowser.addEventListener("DOMContentLoaded",
43 function (event)
44 {
45 // Wait for all the frames.
46 if (frameCount++ < 2)
47 return;
48 gBrowser.selectedTab.linkedBrowser.removeEventListener("DOMContentLoaded", arguments.callee, false)
49 gTabLoaded = true;
50 maybeClickLink();
51 }, false
52 );
53 }
55 function maybeClickLink() {
56 if (gTabLoaded && gLeftFrameVisited) {
57 // Click on the link in the left frame to cause a page load in the
58 // right frame.
59 EventUtils.sendMouseEvent({type: "click"}, "clickme", content.frames[0]);
60 }
61 }
63 function getTransitionForUrl(aUrl)
64 {
65 let dbConn = PlacesUtils.history
66 .QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
67 let stmt = dbConn.createStatement(
68 "SELECT visit_type FROM moz_historyvisits WHERE place_id = " +
69 "(SELECT id FROM moz_places WHERE url = :page_url)");
70 stmt.params.page_url = aUrl;
71 try {
72 if (!stmt.executeStep()) {
73 return null;
74 }
75 return stmt.row.visit_type;
76 }
77 finally {
78 stmt.finalize();
79 }
80 }
82 registerCleanupFunction(function ()
83 {
84 gBrowser.removeTab(gBrowser.selectedTab);
85 Services.obs.removeObserver(observer, "uri-visit-saved");
86 })