michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Bug 557943 - Searching for addons can result in wrong results michael@0: michael@0: var gManagerWindow; michael@0: var gProvider; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gProvider = new MockProvider(); michael@0: michael@0: gProvider.createAddons([{ michael@0: id: "addon1@tests.mozilla.org", michael@0: name: "Microsoft .NET Framework Assistant", michael@0: description: "", michael@0: version: "6.66" michael@0: }, { michael@0: id: "addon2@tests.mozilla.org", michael@0: name: "AwesomeNet Addon", michael@0: description: "" michael@0: }, { michael@0: id: "addon3@tests.mozilla.org", michael@0: name: "Dictionnaire MySpell en Francais (réforme 1990)", michael@0: description: "" michael@0: }]); michael@0: michael@0: open_manager("addons://list/extension", function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: close_manager(gManagerWindow, function() { michael@0: finish(); michael@0: }); michael@0: } michael@0: michael@0: michael@0: function perform_search(aQuery, aCallback) { michael@0: waitForFocus(function() { michael@0: var searchBox = gManagerWindow.document.getElementById("header-search"); michael@0: searchBox.value = aQuery; michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); michael@0: EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: var rows = list.getElementsByTagName("richlistitem"); michael@0: aCallback(rows); michael@0: }); michael@0: }, gManagerWindow); michael@0: } michael@0: michael@0: michael@0: add_test(function() { michael@0: perform_search(".net", function(aRows) { michael@0: is(aRows.length, 1, "Should only get one result"); michael@0: is(aRows[0].mAddon.id, "addon1@tests.mozilla.org", "Should get expected addon as only result"); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: add_test(function() { michael@0: perform_search("réf", function(aRows) { michael@0: is(aRows.length, 1, "Should only get one result"); michael@0: is(aRows[0].mAddon.id, "addon3@tests.mozilla.org", "Should get expected addon as only result"); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: add_test(function() { michael@0: perform_search("javascript:void()", function(aRows) { michael@0: is(aRows.length, 0, "Should not get any results"); michael@0: run_next_test(); michael@0: }); michael@0: });