Skip to content

Commit

Permalink
Merge central to inbound
Browse files Browse the repository at this point in the history
  • Loading branch information
mak77 committed Mar 9, 2012
2 parents 00aaba7 + fb82e94 commit faacb3c
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 43 deletions.
1 change: 1 addition & 0 deletions browser/base/content/test/newtab/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ _BROWSER_FILES = \
browser_newtab_reset.js \
browser_newtab_tabsync.js \
browser_newtab_unpin.js \
browser_newtab_bug722273.js \
browser_newtab_bug723102.js \
browser_newtab_bug723121.js \
head.js \
Expand Down
62 changes: 62 additions & 0 deletions browser/base/content/test/newtab/browser_newtab_bug722273.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

const NOW = Date.now() * 1000;
const URL = "http://fake-site.com/";

let tmp = {};
Cu.import("resource:///modules/NewTabUtils.jsm", tmp);
Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader)
.loadSubScript("chrome://browser/content/sanitize.js", tmp);

let {NewTabUtils, Sanitizer} = tmp;

let bhist = Cc["@mozilla.org/browser/global-history;2"]
.getService(Ci.nsIBrowserHistory);

function runTests() {
clearHistory();
fillHistory();
yield addNewTabPageTab();

is(cells[0].site.url, URL, "first site is our fake site");

let page = {
update: function () {
executeSoon(TestRunner.next);
},

observe: function () {}
};

NewTabUtils.allPages.register(page);
yield clearHistory();

NewTabUtils.allPages.unregister(page);
ok(!cells[0].site, "the fake site is gone");
}

function fillHistory() {
let uri = makeURI(URL);
for (let i = 59; i > 0; i--)
bhist.addPageWithDetails(uri, "fake site", NOW - i * 60 * 1000000);
}

function clearHistory() {
let s = new Sanitizer();
s.prefDomain = "privacy.cpd.";

let prefs = gPrefService.getBranch(s.prefDomain);
prefs.setBoolPref("history", true);
prefs.setBoolPref("downloads", false);
prefs.setBoolPref("cache", false);
prefs.setBoolPref("cookies", false);
prefs.setBoolPref("formdata", false);
prefs.setBoolPref("offlineApps", false);
prefs.setBoolPref("passwords", false);
prefs.setBoolPref("sessions", false);
prefs.setBoolPref("siteSettings", false);

s.sanitize();
}
9 changes: 6 additions & 3 deletions browser/base/content/test/newtab/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ function addNewTabPageTab() {
cw = browser.contentWindow;

if (NewTabUtils.allPages.enabled) {
cells = cw.gGrid.cells;

// Continue when the link cache has been populated.
NewTabUtils.links.populateCache(TestRunner.next);
NewTabUtils.links.populateCache(function () {
cells = cw.gGrid.cells;
executeSoon(TestRunner.next);
});
} else {
TestRunner.next();
}
Expand Down Expand Up @@ -246,6 +247,8 @@ function unpinCell(aCell) {
*/
function simulateDrop(aDropTarget, aDragSource) {
let event = {
clientX: 0,
clientY: 0,
dataTransfer: {
mozUserCancelled: false,
setData: function () null,
Expand Down
27 changes: 25 additions & 2 deletions browser/devtools/styleinspector/CssRuleView.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,26 @@ CssRuleView.prototype = {
}.bind(this);

this._createEditors();

// When creating a new property, we fake the normal property
// editor behavior (focusing a property's value after entering its
// name) by responding to the name's blur event, creating the
// value editor, and grabbing focus to the value editor. But if
// focus has already moved to another document, we won't be able
// to move focus to the new editor.
// Create a focusable item at the end of the editors to catch these
// cases.
this._focusBackstop = createChild(this.element, "div", {
tabindex: 0,
});
this._backstopHandler = function() {
// If this item is actually focused long enough to get the focus
// event, allow focus to move on out of this document.
moveFocus(this.doc.defaultView, FOCUS_FORWARD);
}.bind(this);
this._focusBackstop.addEventListener("focus", this._backstopHandler, false);
},

/**
* Update the rules for the currently highlighted element.
*/
Expand Down Expand Up @@ -762,6 +780,12 @@ CssRuleView.prototype = {
this._clearRules();
this._viewedElement = null;
this._elementStyle = null;

if (this._focusBackstop) {
this._focusBackstop.removeEventListener("focus", this._backstopHandler, false);
this._backstopHandler = null;
this._focusBackstop = null;
}
},

/**
Expand Down Expand Up @@ -845,7 +869,6 @@ RuleEditor.prototype = {

this.openBrace = createChild(header, "span", {
class: "ruleview-ruleopen",
tabindex: "0",
textContent: " {"
});

Expand Down
1 change: 1 addition & 0 deletions browser/devtools/styleinspector/test/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ _BROWSER_TEST_FILES = \
browser_ruleview_manipulation.js \
browser_ruleview_override.js \
browser_ruleview_ui.js \
browser_ruleview_focus.js \
browser_bug705707_is_content_stylesheet.js \
browser_bug722196_property_view_media_queries.js \
browser_bug722196_rule_view_media_queries.js \
Expand Down
106 changes: 106 additions & 0 deletions browser/devtools/styleinspector/test/browser_ruleview_focus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

// Test that focus doesn't leave the style editor when adding a property
// (bug 719916)

let doc;
let stylePanel;

function waitForRuleView(aCallback)
{
if (InspectorUI.ruleView) {
aCallback();
return;
}

let ruleViewFrame = InspectorUI.getToolIframe(InspectorUI.ruleViewObject);
ruleViewFrame.addEventListener("load", function(evt) {
ruleViewFrame.removeEventListener(evt.type, arguments.callee, true);
executeSoon(function() {
aCallback();
});
}, true);
}

function waitForEditorFocus(aParent, aCallback)
{
aParent.addEventListener("focus", function onFocus(evt) {
if (evt.target.inplaceEditor) {
aParent.removeEventListener("focus", onFocus, true);
let editor = evt.target.inplaceEditor;
executeSoon(function() {
aCallback(editor);
});
}
}, true);
}

function openRuleView()
{
Services.obs.addObserver(function onOpened() {
Services.obs.removeObserver(onOpened,
InspectorUI.INSPECTOR_NOTIFICATIONS.OPENED, false);

// Highlight a node.
let node = content.document.getElementsByTagName("h1")[0];
InspectorUI.inspectNode(node);
InspectorUI.stopInspecting();

// Open the rule view sidebar.
waitForRuleView(testFocus);

InspectorUI.showSidebar();
InspectorUI.ruleButton.click();

testFocus();
}, InspectorUI.INSPECTOR_NOTIFICATIONS.OPENED, false);
InspectorUI.openInspectorUI();
}

function testFocus()
{
let ruleViewFrame = InspectorUI.getToolIframe(InspectorUI.ruleViewObject);
let brace = ruleViewFrame.contentDocument.querySelectorAll(".ruleview-ruleclose")[0];
waitForEditorFocus(brace.parentNode, function onNewElement(aEditor) {
aEditor.input.value = "color";
waitForEditorFocus(brace.parentNode, function onEditingValue(aEditor) {
// If we actually get this focus we're ok.
ok(true, "We got focus.");
aEditor.input.value = "green";

// If we've retained focus, pressing return will start a new editor.
// If not, we'll wait here until we time out.
waitForEditorFocus(brace.parentNode, function onNewEditor(aEditor) {
aEditor.input.blur();
finishTest();
});
EventUtils.sendKey("return");
});
EventUtils.sendKey("return");
});

brace.focus();
}

function finishUp()
{
doc = stylePanel = null;
gBrowser.removeCurrentTab();
finish();
}

function test()
{
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function(evt) {
gBrowser.selectedBrowser.removeEventListener(evt.type, arguments.callee, true);
doc = content.document;
doc.title = "Rule View Test";
waitForFocus(openRuleView, content);
}, true);

content.location = "data:text/html,<h1>Some header text</h1>";
}
60 changes: 46 additions & 14 deletions browser/modules/NewTabUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ let Storage = {
// want any data from private browsing to show up.
PinnedLinks.resetCache();
BlockedLinks.resetCache();

Pages.update();
}
},

Expand Down Expand Up @@ -187,11 +185,6 @@ let AllPages = {
*/
_pages: [],

/**
* Tells whether we already added a preference observer.
*/
_observing: false,

/**
* Cached value that tells whether the New Tab Page feature is enabled.
*/
Expand All @@ -203,12 +196,7 @@ let AllPages = {
*/
register: function AllPages_register(aPage) {
this._pages.push(aPage);

// Add the preference observer if we haven't already.
if (!this._observing) {
this._observing = true;
Services.prefs.addObserver(PREF_NEWTAB_ENABLED, this, true);
}
this._addObserver();
},

/**
Expand Down Expand Up @@ -238,6 +226,14 @@ let AllPages = {
Services.prefs.setBoolPref(PREF_NEWTAB_ENABLED, !!aEnabled);
},

/**
* Returns the number of registered New Tab Pages (i.e. the number of open
* about:newtab instances).
*/
get length() {
return this._pages.length;
},

/**
* Updates all currently active pages but the given one.
* @param aExceptPage The page to exclude from updating.
Expand All @@ -264,6 +260,15 @@ let AllPages = {
}, this);
},

/**
* Adds a preference observer and turns itself into a no-op after the first
* invokation.
*/
_addObserver: function AllPages_addObserver() {
Services.prefs.addObserver(PREF_NEWTAB_ENABLED, this, true);
this._addObserver = function () {};
},

QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference])
};
Expand Down Expand Up @@ -512,6 +517,8 @@ let Links = {
this._links = aLinks;
executeCallbacks();
}.bind(this));

this._addObserver();
}
},

Expand Down Expand Up @@ -544,7 +551,32 @@ let Links = {
*/
resetCache: function Links_resetCache() {
this._links = [];
}
},

/**
* Implements the nsIObserver interface to get notified about browser history
* sanitization.
*/
observe: function Links_observe(aSubject, aTopic, aData) {
// Make sure to update open about:newtab instances. If there are no opened
// pages we can just wait for the next new tab to populate the cache again.
if (AllPages.length && AllPages.enabled)
this.populateCache(function () { AllPages.update() }, true);
else
this._links = null;
},

/**
* Adds a sanitization observer and turns itself into a no-op after the first
* invokation.
*/
_addObserver: function Links_addObserver() {
Services.obs.addObserver(this, "browser:purge-session-history", true);
this._addObserver = function () {};
},

QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference])
};

/**
Expand Down
2 changes: 1 addition & 1 deletion build/automationutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class ShutdownLeakLogger(object):
DOM windows (that are still around after test suite shutdown, despite running
the GC) to the tests that created them and prints leak statistics.
"""
MAX_LEAK_COUNT = 123
MAX_LEAK_COUNT = 120

def __init__(self, logger):
self.logger = logger
Expand Down
2 changes: 1 addition & 1 deletion dom/sms/src/ril/SmsDatabaseService.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ SmsDatabaseService.prototype = {
// In first place, we retrieve the keys that match the filter.startDate
// and filter.endDate search criteria.
let timeKeyRange = null;
if (!filter.startDate != null && filter.endDate != null) {
if (filter.startDate != null && filter.endDate != null) {
timeKeyRange = IDBKeyRange.bound(filter.startDate.getTime(),
filter.endDate.getTime());
} else if (filter.startDate != null) {
Expand Down
Loading

0 comments on commit faacb3c

Please sign in to comment.