Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // This test makes sure that the title of existing history entries does not
6 // change inside a private window.
8 function test() {
9 waitForExplicitFinish();
11 const TEST_URL = "http://mochi.test:8888/browser/browser/components/" +
12 "privatebrowsing/test/browser/title.sjs";
13 let cm = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
15 function waitForCleanup(aCallback) {
16 // delete all cookies
17 cm.removeAll();
18 // delete all history items
19 Services.obs.addObserver(function observeCH(aSubject, aTopic, aData) {
20 Services.obs.removeObserver(observeCH, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
21 aCallback();
22 }, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
23 PlacesUtils.bhistory.removeAllPages();
24 }
26 let testNumber = 0;
27 let historyObserver = {
28 onTitleChanged: function(aURI, aPageTitle) {
29 if (aURI.spec != TEST_URL)
30 return;
31 switch (++testNumber) {
32 case 1:
33 // The first time that the page is loaded
34 is(aPageTitle, "No Cookie",
35 "The page should be loaded without any cookie for the first time");
36 openTestPage(selectedWin);
37 break;
38 case 2:
39 // The second time that the page is loaded
40 is(aPageTitle, "Cookie",
41 "The page should be loaded with a cookie for the second time");
42 waitForCleanup(function () {
43 openTestPage(selectedWin);
44 });
45 break;
46 case 3:
47 // After clean up
48 is(aPageTitle, "No Cookie",
49 "The page should be loaded without any cookie again");
50 testOnWindow(true, function(win) {
51 whenPageLoad(win, function() {
52 waitForCleanup(finish);
53 });
54 });
55 break;
56 default:
57 // Checks that opening the page in a private window should not fire a
58 // title change.
59 ok(false, "Title changed. Unexpected pass: " + testNumber);
60 }
61 },
63 onBeginUpdateBatch: function () {},
64 onEndUpdateBatch: function () {},
65 onVisit: function () {},
66 onDeleteURI: function () {},
67 onClearHistory: function () {},
68 onPageChanged: function () {},
69 onDeleteVisits: function() {},
70 QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver])
71 };
72 PlacesUtils.history.addObserver(historyObserver, false);
74 let selectedWin = null;
75 let windowsToClose = [];
76 registerCleanupFunction(function() {
77 PlacesUtils.history.removeObserver(historyObserver);
78 windowsToClose.forEach(function(win) {
79 win.close();
80 });
81 });
83 function openTestPage(aWin) {
84 aWin.gBrowser.selectedTab = aWin.gBrowser.addTab(TEST_URL);
85 }
87 function whenPageLoad(aWin, aCallback) {
88 aWin.gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
89 aWin.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
90 aCallback();
91 }, true);
92 aWin.gBrowser.selectedBrowser.loadURI(TEST_URL);
93 }
95 function testOnWindow(aPrivate, aCallback) {
96 whenNewWindowLoaded({ private: aPrivate }, function(win) {
97 selectedWin = win;
98 windowsToClose.push(win);
99 executeSoon(function() { aCallback(win) });
100 });
101 }
103 waitForCleanup(function() {
104 testOnWindow(false, function(win) {
105 openTestPage(win);
106 });
107 });
108 }