browser/base/content/test/general/browser_bookmark_titles.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial