summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/urlbar/browser_urlbar_autoFill_backspaced.js
blob: 7fefd3f77acde74b0230cac320e0c924aa4553fc (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* This test ensures that backspacing autoFilled values still allows to
 * confirm the remaining value.
 */

function* test_autocomplete(data) {
  let {desc, typed, autofilled, modified, keys, action, onAutoFill} = data;
  info(desc);

  yield promiseAutocompleteResultPopup(typed);
  is(gURLBar.textValue, autofilled, "autofilled value is as expected");
  if (onAutoFill)
    onAutoFill()

  keys.forEach(key => EventUtils.synthesizeKey(key, {}));

  is(gURLBar.textValue, modified, "backspaced value is as expected");

  yield promiseSearchComplete();

  ok(gURLBar.popup.richlistbox.children.length > 0, "Should get at least 1 result");
  let result = gURLBar.popup.richlistbox.children[0];
  let type = result.getAttribute("type");
  let types = type.split(/\s+/);
  ok(types.indexOf(action) >= 0, `The type attribute "${type}" includes the expected action "${action}"`);

  gURLBar.popup.hidePopup();
  yield promisePopupHidden(gURLBar.popup);
  gURLBar.blur();
}

add_task(function* () {
  registerCleanupFunction(function* () {
    Services.prefs.clearUserPref("browser.urlbar.autoFill");
    gURLBar.handleRevert();
    yield PlacesTestUtils.clearHistory();
  });
  Services.prefs.setBoolPref("browser.urlbar.autoFill", true);

  // Add a typed visit, so it will be autofilled.
  yield PlacesTestUtils.addVisits({
    uri: NetUtil.newURI("http://example.com/"),
    transition: Ci.nsINavHistoryService.TRANSITION_TYPED
  });

  yield test_autocomplete({ desc: "DELETE the autofilled part should search",
                            typed: "exam",
                            autofilled: "example.com/",
                            modified: "exam",
                            keys: ["VK_DELETE"],
                            action: "searchengine"
                          });
  yield test_autocomplete({ desc: "DELETE the final slash should visit",
                            typed: "example.com",
                            autofilled: "example.com/",
                            modified: "example.com",
                            keys: ["VK_DELETE"],
                            action: "visiturl"
                          });

  yield test_autocomplete({ desc: "BACK_SPACE the autofilled part should search",
                            typed: "exam",
                            autofilled: "example.com/",
                            modified: "exam",
                            keys: ["VK_BACK_SPACE"],
                            action: "searchengine"
                          });
  yield test_autocomplete({ desc: "BACK_SPACE the final slash should visit",
                            typed: "example.com",
                            autofilled: "example.com/",
                            modified: "example.com",
                            keys: ["VK_BACK_SPACE"],
                            action: "visiturl"
                          });

  yield test_autocomplete({ desc: "DELETE the autofilled part, then BACK_SPACE, should search",
                            typed: "exam",
                            autofilled: "example.com/",
                            modified: "exa",
                            keys: ["VK_DELETE", "VK_BACK_SPACE"],
                            action: "searchengine"
                          });
  yield test_autocomplete({ desc: "DELETE the final slash, then BACK_SPACE, should search",
                            typed: "example.com",
                            autofilled: "example.com/",
                            modified: "example.co",
                            keys: ["VK_DELETE", "VK_BACK_SPACE"],
                            action: "visiturl"
                          });

  yield test_autocomplete({ desc: "BACK_SPACE the autofilled part, then BACK_SPACE, should search",
                            typed: "exam",
                            autofilled: "example.com/",
                            modified: "exa",
                            keys: ["VK_BACK_SPACE", "VK_BACK_SPACE"],
                            action: "searchengine"
                          });
  yield test_autocomplete({ desc: "BACK_SPACE the final slash, then BACK_SPACE, should search",
                            typed: "example.com",
                            autofilled: "example.com/",
                            modified: "example.co",
                            keys: ["VK_BACK_SPACE", "VK_BACK_SPACE"],
                            action: "visiturl"
                          });

  yield test_autocomplete({ desc: "BACK_SPACE after blur should search",
                            typed: "ex",
                            autofilled: "example.com/",
                            modified: "e",
                            keys: ["VK_BACK_SPACE"],
                            action: "searchengine",
                            onAutoFill: () => {
                              gURLBar.blur();
                              gURLBar.focus();
                              gURLBar.selectionStart = 1;
                              gURLBar.selectionEnd = 12;
                            }
                         });
  yield test_autocomplete({ desc: "DELETE after blur should search",
                            typed: "ex",
                            autofilled: "example.com/",
                            modified: "e",
                            keys: ["VK_DELETE"],
                            action: "searchengine",
                            onAutoFill: () => {
                              gURLBar.blur();
                              gURLBar.focus();
                              gURLBar.selectionStart = 1;
                              gURLBar.selectionEnd = 12;
                            }
                          });
  yield test_autocomplete({ desc: "double BACK_SPACE after blur should search",
                            typed: "ex",
                            autofilled: "example.com/",
                            modified: "e",
                            keys: ["VK_BACK_SPACE", "VK_BACK_SPACE"],
                            action: "searchengine",
                            onAutoFill: () => {
                              gURLBar.blur();
                              gURLBar.focus();
                              gURLBar.selectionStart = 2;
                              gURLBar.selectionEnd = 12;
                            }
                         });

  yield PlacesTestUtils.clearHistory();
});