Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 file is tests for the default titles that new bookmarks get.
7 let tests = [
8 // Common page.
9 ['http://example.com/browser/browser/base/content/test/general/dummy_page.html',
10 'Dummy test page'],
11 // Data URI.
12 ['data:text/html;charset=utf-8,<title>test%20data:%20url</title>',
13 'test data: url'],
14 // about:neterror
15 ['data:application/vnd.mozilla.xul+xml,',
16 'data:application/vnd.mozilla.xul+xml,'],
17 // about:certerror
18 ['https://untrusted.example.com/somepage.html',
19 'https://untrusted.example.com/somepage.html']
20 ];
22 function generatorTest() {
23 gBrowser.selectedTab = gBrowser.addTab();
24 let browser = gBrowser.selectedBrowser;
25 browser.stop(); // stop the about:blank load.
27 browser.addEventListener("DOMContentLoaded", event => {
28 if (event.originalTarget != browser.contentDocument ||
29 event.target.location.href == "about:blank") {
30 info("skipping spurious load event");
31 return;
32 }
33 nextStep();
34 }, true);
35 registerCleanupFunction(function () {
36 browser.removeEventListener("DOMContentLoaded", nextStep, true);
37 gBrowser.removeCurrentTab();
38 });
40 // Test that a bookmark of each URI gets the corresponding default title.
41 for (let i = 0; i < tests.length; ++i) {
42 let [uri, title] = tests[i];
43 content.location = uri;
44 yield undefined;
45 checkBookmark(uri, title);
46 }
48 // Network failure test: now that dummy_page.html is in history, bookmarking
49 // it should give the last known page title as the default bookmark title.
51 // Simulate a network outage with offline mode. (Localhost is still
52 // accessible in offline mode, so disable the test proxy as well.)
53 BrowserOffline.toggleOfflineStatus();
54 let proxy = Services.prefs.getIntPref('network.proxy.type');
55 Services.prefs.setIntPref('network.proxy.type', 0);
56 registerCleanupFunction(function () {
57 BrowserOffline.toggleOfflineStatus();
58 Services.prefs.setIntPref('network.proxy.type', proxy);
59 });
61 // LOAD_FLAGS_BYPASS_CACHE isn't good enough. So clear the cache.
62 Services.cache2.clear();
64 let [uri, title] = tests[0];
65 content.location = uri;
66 yield undefined;
67 // The offline mode test is only good if the page failed to load.
68 is(content.document.documentURI.substring(0, 14), 'about:neterror',
69 "Offline mode successfully simulated network outage.");
70 checkBookmark(uri, title);
71 }
73 // Bookmark the current page and confirm that the new bookmark has the expected
74 // title. (Then delete the bookmark.)
75 function checkBookmark(uri, expected_title) {
76 is(gBrowser.selectedBrowser.currentURI.spec, uri,
77 "Trying to bookmark the expected uri");
78 PlacesCommandHook.bookmarkCurrentPage(false);
80 let id = PlacesUtils.getMostRecentBookmarkForURI(PlacesUtils._uri(uri));
81 ok(id > 0, "Found the expected bookmark");
82 let title = PlacesUtils.bookmarks.getItemTitle(id);
83 is(title, expected_title, "Bookmark got a good default title.");
85 PlacesUtils.bookmarks.removeItem(id);
86 }