Bug 474081 - Sporadic failures in browser_bug321000.js, re-enable, clean-up and logging, r=dao

This commit is contained in:
Marco Bonardo 2009-07-09 20:36:56 +02:00
parent 5870101ca3
commit 02ea218b37
2 changed files with 126 additions and 69 deletions

View File

@ -43,7 +43,8 @@ relativesrcdir = browser/base/content/test
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = test_feed_discovery.html \
_TEST_FILES = \
test_feed_discovery.html \
feed_discovery.html \
test_bug395533.html \
bug395533-data.txt \
@ -63,7 +64,6 @@ _TEST_FILES = test_feed_discovery.html \
$(NULL)
# The following tests are disabled because they are unreliable:
# browser_bug321000.js is bug 474081
# browser_bug423833.js is bug 428712
# browser_sanitize-download-history.js is bug 432425
#
@ -71,7 +71,9 @@ _TEST_FILES = test_feed_discovery.html \
# back to the clear recent history dialog (santize.xul), if it ever is (bug
# 480169)
_BROWSER_FILES = browser_sanitize-timespans.js \
_BROWSER_FILES = \
browser_bug321000.js \
browser_sanitize-timespans.js \
browser_bug405137.js \
browser_bug409481.js \
browser_bug413915.js \

View File

@ -1,48 +1,72 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Firefox Browser Test Code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ted Mielczarek <ted.mielczarek@gmail.com> (Original Author)
* Marco Bonardo <mak77@bonardo.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const Ci = Components.interfaces;
const Cc = Components.classes;
const kUrlBarElm = document.getElementById('urlbar');
const kSearchBarElm = document.getElementById('searchbar');
const kTestString = " hello hello \n world\nworld ";
function testPaste(name, element, expected) {
element.focus();
listener.expected = expected;
listener.name = name;
// Pasting is async because the Accel+V codepath ends up going through
// DocumentViewerImpl::FireClipboardEvent.
EventUtils.synthesizeKey("v", { accelKey: true });
}
var gTests = [
var listener = {
expected: "",
name: "",
handleEvent: function(event) {
var element = event.target;
is(element.value, this.expected, this.name);
switch (element) {
case kUrlBarElm:
continue_test();
case kSearchBarElm:
finish_test();
}
}
}
{ desc: "Urlbar strips newlines and surrounding whitespace",
element: gURLBar,
expected: kTestString.replace(/\s*\n\s*/g,'')
},
// test bug 23485 and bug 321000
// urlbar should strip newlines,
// search bar should replace newlines with spaces
{ desc: "Searchbar replaces newlines with spaces",
element: document.getElementById('searchbar'),
expected: kTestString.replace('\n',' ','g')
},
];
// Test for bug 23485 and bug 321000.
// Urlbar should strip newlines,
// search bar should replace newlines with spaces.
function test() {
waitForExplicitFinish();
// register listeners
kUrlBarElm.addEventListener("input", listener, true);
kSearchBarElm.addEventListener("input", listener, true);
// Put a multi-line string in the clipboard
Components.classes["@mozilla.org/widget/clipboardhelper;1"]
.getService(Components.interfaces.nsIClipboardHelper)
.copyString(kTestString);
// Put a multi-line string in the clipboard.
info("About to put a string in clipboard");
Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper)
.copyString(kTestString);
// Setting the clipboard value is an async OS operation, so we need to poll
// the clipboard for valid data before going on.
@ -51,53 +75,84 @@ function test() {
var runCount = 0;
function poll_clipboard() {
// Poll for a maximum of 5s
// Poll for a maximum of 5s (each run happens after 100ms).
if (++runCount > 50) {
// Log the failure
// Log the failure.
ok(false, "Timed out while polling clipboard for pasted data");
// Cleanup and interrupt the test
// Cleanup and interrupt the test.
finish_test();
return;
}
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].
getService(Components.interfaces.nsIClipboard);
var trans = Components.classes["@mozilla.org/widget/transferable;1"].
createInstance(Components.interfaces.nsITransferable);
info("Polling clipboard cycle " + runCount);
var clip = Cc["@mozilla.org/widget/clipboard;1"].
getService(Ci.nsIClipboard);
var trans = Cc["@mozilla.org/widget/transferable;1"].
createInstance(Ci.nsITransferable);
trans.addDataFlavor("text/unicode");
var str = new Object();
try {
// This code could throw if the clipboard is not set
clip.getData(trans,clip.kGlobalClipboard);
trans.getTransferData("text/unicode",str,{});
str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
} catch (ex) {}
// This code could throw if the clipboard is not set yet.
clip.getData(trans, clip.kGlobalClipboard);
trans.getTransferData("text/unicode", str, {});
str = str.value.QueryInterface(Ci.nsISupportsString);
}
catch(ex) {}
if (kTestString == str) {
testPaste('urlbar strips newlines and surrounding whitespace',
kUrlBarElm,
kTestString.replace(/\s*\n\s*/g,''));
next_test();
}
else
setTimeout(poll_clipboard, 100);
}
function continue_test() {
testPaste('searchbar replaces newlines with spaces',
kSearchBarElm,
kTestString.replace('\n',' ','g'));
function next_test() {
if (gTests.length) {
var currentTest = gTests.shift();
test_paste(currentTest);
}
else {
// No more tests to run.
// Clear the clipboard, emptyClipboard would not clear the native one, so
// we are setting it to an empty string.
Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper)
.copyString("");
finish();
}
}
function finish_test() {
kUrlBarElm.removeEventListener("input", listener, true);
kSearchBarElm.removeEventListener("input", listener, true);
// Clear the clipboard, emptyClipboard would not clear the native one, so
// setting it to an empty string.
Components.classes["@mozilla.org/widget/clipboardhelper;1"]
.getService(Components.interfaces.nsIClipboardHelper)
.copyString("");
// Clear fields
kUrlBarElm.value="";
kSearchBarElm.value="";
finish();
function test_paste(aCurrentTest) {
var element = aCurrentTest.element;
// Register input listener.
var inputListener = {
test: aCurrentTest,
handleEvent: function(event) {
var element = event.target;
element.removeEventListener("input", this, false);
is(element.value, this.test.expected, this.test.desc);
// Clear the field and go to next test.
element.value = "";
setTimeout(next_test, 0);
}
}
element.addEventListener("input", inputListener, false);
// Focus the window.
window.focus();
// Focus the element and wait for focus event.
info("About to focus " + element.id);
element.addEventListener("focus", function() {
element.removeEventListener("focus", arguments.callee, false);
executeSoon(function() {
// Pasting is async because the Accel+V codepath ends up going through
// DocumentViewerImpl::FireClipboardEvent.
info("Pasting into " + element.id);
EventUtils.synthesizeKey("v", { accelKey: true });
});
}, false);
element.focus();
}