Bug 326743: update tests to know about the Find Clipboard on OSX. r=Unfocused

This commit is contained in:
Mike de Boer 2014-02-14 11:38:28 +01:00
parent 3e8f27bc11
commit 360593cbc3
4 changed files with 47 additions and 8 deletions

View File

@ -11,6 +11,9 @@ let texts = [
"To err is human; to forgive is not company policy." "To err is human; to forgive is not company policy."
]; ];
let Clipboard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
let HasFindClipboard = Clipboard.supportsFindClipboard();
function addTabWithText(aText, aCallback) { function addTabWithText(aText, aCallback) {
let newTab = gBrowser.addTab("data:text/html,<h1 id='h1'>" + aText + "</h1>"); let newTab = gBrowser.addTab("data:text/html,<h1 id='h1'>" + aText + "</h1>");
tabs.push(newTab); tabs.push(newTab);
@ -61,7 +64,9 @@ function continueTests1() {
// Confirm the first tab is still correct, ensure re-hiding works as expected // Confirm the first tab is still correct, ensure re-hiding works as expected
gBrowser.selectedTab = tabs[0]; gBrowser.selectedTab = tabs[0];
ok(!gFindBar.hidden, "First tab shows find bar!"); ok(!gFindBar.hidden, "First tab shows find bar!");
is(gFindBar._findField.value, texts[0], "First tab persists find value!"); // When the Find Clipboard is supported, this test not relevant.
if (!HasFindClipboard)
is(gFindBar._findField.value, texts[0], "First tab persists find value!");
ok(gFindBar.getElement("highlight").checked, ok(gFindBar.getElement("highlight").checked,
"Highlight button state persists!"); "Highlight button state persists!");
@ -94,7 +99,8 @@ function continueTests2() {
ok(gFindBar.hidden, "Fourth tab doesn't show find bar!"); ok(gFindBar.hidden, "Fourth tab doesn't show find bar!");
is(gFindBar, gBrowser.getFindBar(), "Find bar is right one!"); is(gFindBar, gBrowser.getFindBar(), "Find bar is right one!");
gFindBar.open(); gFindBar.open();
is(gFindBar._findField.value, texts[1], let toTest = HasFindClipboard ? texts[2] : texts[1];
is(gFindBar._findField.value, toTest,
"Fourth tab has second tab's find value!"); "Fourth tab has second tab's find value!");
newWindow = gBrowser.replaceTabWithWindow(tabs.pop()); newWindow = gBrowser.replaceTabWithWindow(tabs.pop());
@ -104,7 +110,8 @@ function continueTests2() {
// Test that findbar gets restored when a tab is moved to a new window. // Test that findbar gets restored when a tab is moved to a new window.
function checkNewWindow() { function checkNewWindow() {
ok(!newWindow.gFindBar.hidden, "New window shows find bar!"); ok(!newWindow.gFindBar.hidden, "New window shows find bar!");
is(newWindow.gFindBar._findField.value, texts[1], let toTest = HasFindClipboard ? texts[2] : texts[1];
is(newWindow.gFindBar._findField.value, toTest,
"New window find bar has correct find value!"); "New window find bar has correct find value!");
ok(!newWindow.gFindBar.getElement("find-next").disabled, ok(!newWindow.gFindBar.getElement("find-next").disabled,
"New window findbar has enabled buttons!"); "New window findbar has enabled buttons!");

View File

@ -2,7 +2,10 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
let Ci = Components.interfaces; const {Ci: interfaces, Cc: classes} = Components;
let Clipboard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
let HasFindClipboard = Clipboard.supportsFindClipboard();
function test() { function test() {
waitForExplicitFinish(); waitForExplicitFinish();
@ -37,7 +40,10 @@ function onFocus(win) {
let findBar = win.gFindBar; let findBar = win.gFindBar;
selectText(win.content); selectText(win.content);
findBar.onFindCommand(); findBar.onFindCommand();
is(findBar._findField.value, "Select Me", "Findbar is initialized with selection"); // When the OS supports the Find Clipboard (OSX), the find field value is
// persisted across Fx sessions, thus not useful to test.
if (!HasFindClipboard)
is(findBar._findField.value, "Select Me", "Findbar is initialized with selection");
findBar.close(); findBar.close();
win.close(); win.close();
finish(); finish();

View File

@ -58,6 +58,7 @@
// Simulate typical input // Simulate typical input
textbox.focus(); textbox.focus();
gFindBar.clear();
sendChar("m"); sendChar("m");
ok(gFindBar.canClear, "canClear property true after input"); ok(gFindBar.canClear, "canClear property true after input");
let preSelection = gBrowser.contentWindow.getSelection(); let preSelection = gBrowser.contentWindow.getSelection();

View File

@ -30,6 +30,9 @@
var gFindBar = null; var gFindBar = null;
var gBrowser; var gBrowser;
var gClipboard = Cc["@mozilla.org/widget/clipboard;1"].getService("nsIClipboard");
var gHasFindClipboard = gClipboard.supportsFindClipboard();
var gStatusText; var gStatusText;
var gXULBrowserWindow = { var gXULBrowserWindow = {
QueryInterface: function(aIID) { QueryInterface: function(aIID) {
@ -94,7 +97,8 @@
testFindbarSelection(); testFindbarSelection();
testDrop(); testDrop();
testQuickFindLink(); testQuickFindLink();
testStatusText(); if (gHasFindClipboard)
testStatusText();
testQuickFindClose(); testQuickFindClose();
} }
@ -104,8 +108,12 @@
ok(!gFindBar.hidden, "testFindbarSelection: failed to open findbar: " + aTestName); ok(!gFindBar.hidden, "testFindbarSelection: failed to open findbar: " + aTestName);
ok(document.commandDispatcher.focusedElement == gFindBar._findField.inputField, ok(document.commandDispatcher.focusedElement == gFindBar._findField.inputField,
"testFindbarSelection: find field is not focused: " + aTestName); "testFindbarSelection: find field is not focused: " + aTestName);
ok(gFindBar._findField.value == aExpSelection, if (gHasFindClipboard) {
"Incorrect selection in testFindbarSelection: " + aTestName + ". Selection: " + gFindBar._findField.value); ok(gFindBar._findField.value == aExpSelection,
"Incorrect selection in testFindbarSelection: " + aTestName +
". Selection: " + gFindBar._findField.value);
}
testClipboardSearchString(aExpSelection);
// Clear the value, close the findbar // Clear the value, close the findbar
gFindBar._findField.value = ""; gFindBar._findField.value = "";
@ -185,12 +193,14 @@
enterStringIntoFindField(searchStr); enterStringIntoFindField(searchStr);
ok(gBrowser.contentWindow.getSelection().toString().toLowerCase() == searchStr, ok(gBrowser.contentWindow.getSelection().toString().toLowerCase() == searchStr,
"testNormalFind: failed to find '" + searchStr + "'"); "testNormalFind: failed to find '" + searchStr + "'");
testClipboardSearchString(gBrowser.contentWindow.getSelection().toString());
if (!matchCaseCheckbox.hidden) { if (!matchCaseCheckbox.hidden) {
matchCaseCheckbox.click(); matchCaseCheckbox.click();
enterStringIntoFindField("t"); enterStringIntoFindField("t");
ok(gBrowser.contentWindow.getSelection() != searchStr, ok(gBrowser.contentWindow.getSelection() != searchStr,
"testNormalFind: Case-sensitivy is broken '" + searchStr + "'"); "testNormalFind: Case-sensitivy is broken '" + searchStr + "'");
testClipboardSearchString(gBrowser.contentWindow.getSelection().toString());
matchCaseCheckbox.click(); matchCaseCheckbox.click();
} }
} }
@ -228,6 +238,7 @@
ok(gBrowser.contentWindow.getSelection().toString().toLowerCase() != searchStr, ok(gBrowser.contentWindow.getSelection().toString().toLowerCase() != searchStr,
"testNormalFindWithComposition: text shouldn't be found during composition"); "testNormalFindWithComposition: text shouldn't be found during composition");
testClipboardSearchString(gBrowser.contentWindow.getSelection().toString());
synthesizeText( synthesizeText(
{ "composition": { "composition":
@ -243,6 +254,7 @@
ok(gBrowser.contentWindow.getSelection().toString().toLowerCase() == searchStr, ok(gBrowser.contentWindow.getSelection().toString().toLowerCase() == searchStr,
"testNormalFindWithComposition: text should be found after committing composition"); "testNormalFindWithComposition: text should be found after committing composition");
testClipboardSearchString(gBrowser.contentWindow.getSelection().toString());
if (clicked) { if (clicked) {
matchCaseCheckbox.click(); matchCaseCheckbox.click();
@ -302,6 +314,7 @@
enterStringIntoFindField(searchStr); enterStringIntoFindField(searchStr);
ok(gBrowser.contentWindow.getSelection() == searchStr, ok(gBrowser.contentWindow.getSelection() == searchStr,
"testQuickFindLink: failed to find sample link"); "testQuickFindLink: failed to find sample link");
testClipboardSearchString(searchStr);
} }
function testQuickFindText() { function testQuickFindText() {
@ -319,6 +332,18 @@
enterStringIntoFindField(SEARCH_TEXT); enterStringIntoFindField(SEARCH_TEXT);
ok(gBrowser.contentWindow.getSelection() == SEARCH_TEXT, ok(gBrowser.contentWindow.getSelection() == SEARCH_TEXT,
"testQuickFindText: failed to find '" + SEARCH_TEXT + "'"); "testQuickFindText: failed to find '" + SEARCH_TEXT + "'");
testClipboardSearchString(SEARCH_TEXT);
}
function testClipboardSearchString(aExpected) {
if (!gHasFindClipboard)
return;
if (!aExpected)
aExpected = "";
var searchStr = gFindBar.browser.finder.clipboardSearchString;
ok(searchStr == aExpected, "testClipboardSearchString: search string not " +
"set to '" + aExpected + "', instead found '" + searchStr + "'");
} }
]]></script> ]]></script>