mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 777926 - Use URL or title from history for bookmarking error pages. r=Mano
This commit is contained in:
parent
061b7ed9a5
commit
3a43e77786
@ -269,7 +269,11 @@ var PlacesCommandHook = {
|
||||
var description;
|
||||
var charset;
|
||||
try {
|
||||
title = webNav.document.title || url.spec;
|
||||
let isErrorPage = /^about:(neterror|certerror|blocked)/
|
||||
.test(webNav.document.documentURI);
|
||||
title = isErrorPage ? PlacesUtils.history.getPageTitle(url)
|
||||
: webNav.document.title;
|
||||
title = title || url.spec;
|
||||
description = PlacesUIUtils.getDescriptionFromDocument(webNav.document);
|
||||
charset = webNav.document.characterSet;
|
||||
}
|
||||
|
@ -292,6 +292,7 @@ _BROWSER_FILES = \
|
||||
browser_bug676619.js \
|
||||
download_page.html \
|
||||
browser_URLBarSetURI.js \
|
||||
browser_bookmark_titles.js \
|
||||
$(NULL)
|
||||
|
||||
ifneq (cocoa,$(MOZ_WIDGET_TOOLKIT))
|
||||
|
75
browser/base/content/test/browser_bookmark_titles.js
Normal file
75
browser/base/content/test/browser_bookmark_titles.js
Normal file
@ -0,0 +1,75 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// This file is tests for the default titles that new bookmarks get.
|
||||
|
||||
let tests = [
|
||||
['http://example.com/browser/browser/base/content/test/dummy_page.html',
|
||||
'Dummy test page'],
|
||||
['data:text/html;charset=utf-8,<title>test data: url</title>',
|
||||
'test data: url'],
|
||||
['http://unregistered-domain.example',
|
||||
'http://unregistered-domain.example/'],
|
||||
['https://untrusted.example.com/somepage.html',
|
||||
'https://untrusted.example.com/somepage.html']
|
||||
];
|
||||
|
||||
function generatorTest() {
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
|
||||
browser.addEventListener("DOMContentLoaded", nextStep, true);
|
||||
registerCleanupFunction(function () {
|
||||
browser.removeEventListener("DOMContentLoaded", nextStep, true);
|
||||
gBrowser.removeCurrentTab();
|
||||
});
|
||||
|
||||
yield; // Wait for the new tab to load.
|
||||
|
||||
// Test that a bookmark of each URI gets the corresponding default title.
|
||||
for (let i = 0; i < tests.length; ++i) {
|
||||
let [uri, title] = tests[i];
|
||||
content.location = uri;
|
||||
yield;
|
||||
checkBookmark(uri, title);
|
||||
}
|
||||
|
||||
// Network failure test: now that dummy_page.html is in history, bookmarking
|
||||
// it should give the last known page title as the default bookmark title.
|
||||
|
||||
// Simulate a network outage with offline mode. (Localhost is still
|
||||
// accessible in offline mode, so disable the test proxy as well.)
|
||||
BrowserOffline.toggleOfflineStatus();
|
||||
let proxy = Services.prefs.getIntPref('network.proxy.type');
|
||||
Services.prefs.setIntPref('network.proxy.type', 0);
|
||||
registerCleanupFunction(function () {
|
||||
BrowserOffline.toggleOfflineStatus();
|
||||
Services.prefs.setIntPref('network.proxy.type', proxy);
|
||||
});
|
||||
|
||||
// LOAD_FLAGS_BYPASS_CACHE isn't good enough. So clear the cache.
|
||||
Services.cache.evictEntries(Services.cache.STORE_ANYWHERE);
|
||||
|
||||
let [uri, title] = tests[0];
|
||||
content.location = uri;
|
||||
yield;
|
||||
// The offline mode test is only good if the page failed to load.
|
||||
is(content.document.documentURI.substring(0, 14), 'about:neterror',
|
||||
"Offline mode successfully simulated network outage.");
|
||||
checkBookmark(uri, title);
|
||||
}
|
||||
|
||||
// Bookmark the current page and confirm that the new bookmark has the expected
|
||||
// title. (Then delete the bookmark.)
|
||||
function checkBookmark(uri, expected_title) {
|
||||
PlacesCommandHook.bookmarkCurrentPage(false);
|
||||
|
||||
let id = PlacesUtils.getMostRecentBookmarkForURI(PlacesUtils._uri(uri));
|
||||
let title = PlacesUtils.bookmarks.getItemTitle(id);
|
||||
|
||||
is(title, expected_title, "Bookmark got a good default title.");
|
||||
|
||||
PlacesUtils.bookmarks.removeItem(id);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user