1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 sts=2 expandtab
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Mozilla Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2008
21 * the Initial Developer. All Rights Reserved.
24 * Marco Bonardo <mak77@bonardo.net> (Original Author)
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
41 * This test checks that embed visits are not synced down to disk, we hold
42 * them in memory since they're going to be purged at session close
45 var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
46 getService(Ci.nsINavHistoryService);
47 var dbConn = hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
48 var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
49 getService(Ci.nsINavBookmarksService);
50 var prefs = Cc["@mozilla.org/preferences-service;1"].
51 getService(Ci.nsIPrefService).
53 var os = Cc["@mozilla.org/observer-service;1"].
54 getService(Ci.nsIObserverService);
56 const TEST_URI = "http://test.com/";
57 const EMBED_URI = "http://embed.test.com/";
58 const PLACE_URI = "place:test.com/";
60 const kSyncPrefName = "syncDBTableIntervalInSecs";
61 const SYNC_INTERVAL = 1;
62 const kSyncFinished = "places-sync-finished";
64 var transitions = [ hs.TRANSITION_LINK,
66 hs.TRANSITION_BOOKMARK,
68 hs.TRANSITION_REDIRECT_PERMANENT,
69 hs.TRANSITION_REDIRECT_TEMPORARY,
70 hs.TRANSITION_DOWNLOAD ];
73 observe: function(aSubject, aTopic, aData) {
74 if (aTopic == kSyncFinished && this.visitId != -1) {
75 // remove the observer, we don't need to observe sync on quit
76 os.removeObserver(this, kSyncFinished);
78 // Check that moz_places table has been correctly synced
79 var stmt = dbConn.createStatement(
80 "SELECT id FROM moz_places WHERE url = :url");
81 stmt.params["url"] = TEST_URI;
82 do_check_true(stmt.executeStep());
84 stmt = dbConn.createStatement(
85 "SELECT id FROM moz_places_temp WHERE url = :url");
86 stmt.params["url"] = TEST_URI;
87 do_check_false(stmt.executeStep());
90 stmt = dbConn.createStatement(
91 "SELECT id FROM moz_places WHERE url = :url");
92 stmt.params["url"] = EMBED_URI;
93 do_check_false(stmt.executeStep());
95 stmt = dbConn.createStatement(
96 "SELECT id FROM moz_places_temp WHERE url = :url");
97 stmt.params["url"] = EMBED_URI;
98 do_check_true(stmt.executeStep());
101 stmt = dbConn.createStatement(
102 "SELECT id FROM moz_places WHERE url = :url");
103 stmt.params["url"] = PLACE_URI;
104 do_check_true(stmt.executeStep());
106 stmt = dbConn.createStatement(
107 "SELECT id FROM moz_places_temp WHERE url = :url");
108 stmt.params["url"] = PLACE_URI;
109 do_check_false(stmt.executeStep());
112 // Check that all visits but embed ones are in disk table
113 stmt = dbConn.createStatement(
114 "SELECT count(*) FROM moz_historyvisits h WHERE visit_type <> :t_embed");
115 stmt.params["t_embed"] = hs.TRANSITION_EMBED;
116 do_check_true(stmt.executeStep());
117 do_check_eq(stmt.getInt32(0), (transitions.length - 1) * 2);
119 stmt = dbConn.createStatement(
120 "SELECT id FROM moz_historyvisits h WHERE visit_type = :t_embed");
121 stmt.params["t_embed"] = hs.TRANSITION_EMBED;
122 do_check_false(stmt.executeStep());
124 stmt = dbConn.createStatement(
125 "SELECT id FROM moz_historyvisits_temp h WHERE visit_type = :t_embed");
126 stmt.params["t_embed"] = hs.TRANSITION_EMBED;
127 do_check_true(stmt.executeStep());
129 stmt = dbConn.createStatement(
130 "SELECT id FROM moz_historyvisits_temp h WHERE visit_type <> :t_embed");
131 stmt.params["t_embed"] = hs.TRANSITION_EMBED;
132 do_check_false(stmt.executeStep());
142 // First set the preference for the timer to a small value
143 prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL);
145 // Add a visit for every transition type on TEST_URI
146 // Embed visit should stay in temp table, while other should be synced
147 // Place entry for this uri should be synced to disk table
148 transitions.forEach(function addVisit(aTransition) {
149 hs.addVisit(uri(TEST_URI), Date.now() * 1000, null,
150 aTransition, false, 0);
153 // Add an embed visit for EMBED_URI
154 // Embed visit should stay in temp table
155 // Place entry for this uri should stay in temp table
156 hs.addVisit(uri(EMBED_URI), Date.now() * 1000, null,
157 hs.TRANSITION_EMBED, false, 0);
159 // Add a visit for every transition type on PLACE_URI
160 // Embed visit should stay in temp table
161 // Place entry for this uri should be synced to disk table
162 transitions.forEach(function addVisit(aTransition) {
163 hs.addVisit(uri(PLACE_URI), Date.now() * 1000, null,
164 aTransition, false, 0);
167 os.addObserver(observer, kSyncFinished, false);