summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/browser/browser_bug557943.js
blob: 94a8b6f4926f8d57e03774dedddcbdd29e434c26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// Bug 557943 - Searching for addons can result in wrong results

var gManagerWindow;
var gProvider;

function test() {
  waitForExplicitFinish();

  gProvider = new MockProvider();

  gProvider.createAddons([{
    id: "addon1@tests.mozilla.org",
    name: "Microsoft .NET Framework Assistant",
    description: "",
    version: "6.66"
  }, {
    id: "addon2@tests.mozilla.org",
    name: "AwesomeNet Addon",
    description: ""
  }, {
    id: "addon3@tests.mozilla.org",
    name: "Dictionnaire MySpell en Francais (réforme 1990)",
    description: ""
  }]);

  open_manager("addons://list/extension", function(aWindow) {
    gManagerWindow = aWindow;
    run_next_test();
  });
}

function end_test() {
  close_manager(gManagerWindow, function() {
    finish();
  });
}


function perform_search(aQuery, aCallback) {
  waitForFocus(function() {
    var searchBox = gManagerWindow.document.getElementById("header-search");
    searchBox.value = aQuery;

    EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
    EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
    wait_for_view_load(gManagerWindow, function() {
      var list = gManagerWindow.document.getElementById("search-list");
      var rows = list.getElementsByTagName("richlistitem");
      aCallback(rows);
    });
  }, gManagerWindow);
}


add_test(function() {
  perform_search(".net", function(aRows) {
    is(aRows.length, 1, "Should only get one result");
    is(aRows[0].mAddon.id, "addon1@tests.mozilla.org", "Should get expected addon as only result");
    run_next_test();
  });
});

add_test(function() {
  perform_search("réf", function(aRows) {
    is(aRows.length, 1, "Should only get one result");
    is(aRows[0].mAddon.id, "addon3@tests.mozilla.org", "Should get expected addon as only result");
    run_next_test();
  });
});

add_test(function() {
  perform_search("javascript:void()", function(aRows) {
    is(aRows.length, 0, "Should not get any results");
    run_next_test();
  });
});