Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
Revert "fix(mc): #2917 Only initialize search on focus"
Browse files Browse the repository at this point in the history
  • Loading branch information
Mardak committed Jul 20, 2017
1 parent 4d4bd12 commit eade774
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 49 deletions.
45 changes: 16 additions & 29 deletions system-addon/content-src/components/Search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,33 @@ const {actionCreators: ac} = require("common/Actions.jsm");
class Search extends React.Component {
constructor(props) {
super(props);
this.controller = null;
this.onClick = this.onClick.bind(this);
this.onFocus = this.onFocus.bind(this);
this.onInputMount = this.onInputMount.bind(this);
}

handleEvent(event) {
// Also track search events with our own telemetry
if (event.detail.type === "Search") {
this.props.dispatch(ac.UserEvent({event: "SEARCH"}));
}
}
onInputMount(input) {
this.input = input;
}
ensureSearchIsInitialized() {
if (this.controller) {
return;
}
// The first "newtab" parameter here is called the "healthReportKey" and needs
// to be "newtab" so that BrowserUsageTelemetry.jsm knows to handle events with
// this name, and can add the appropriate telemetry probes for search. Without the
// correct name, certain tests like browser_UsageTelemetry_content.js will fail (See
// github ticket #2348 for more details)
this.controller = new ContentSearchUIController(this.input, this.input.parentNode,
"newtab", "newtab");
}
onClick(event) {
this.ensureSearchIsInitialized();
this.controller.search(event);
}
onFocus(e) {
this.ensureSearchIsInitialized();
}
componentDidMount() {
addEventListener("ContentSearchClient", this);
}
componentWillUnmount() {
this.controller = null;
removeEventListener("ContentSearchClient", this);
onInputMount(input) {
if (input) {
// The first "newtab" parameter here is called the "healthReportKey" and needs
// to be "newtab" so that BrowserUsageTelemetry.jsm knows to handle events with
// this name, and can add the appropriate telemetry probes for search. Without the
// correct name, certain tests like browser_UsageTelemetry_content.js will fail (See
// github ticket #2348 for more details)
this.controller = new ContentSearchUIController(input, input.parentNode,
"newtab", "newtab");
addEventListener("ContentSearchClient", this);
} else {
this.controller = null;
removeEventListener("ContentSearchClient", this);
}
}

/*
Expand All @@ -61,10 +49,9 @@ class Search extends React.Component {
</label>
<input
id="newtab-search-text"
ref={this.onInputMount}
maxLength="256"
onFocus={this.onFocus}
placeholder={this.props.intl.formatMessage({id: "search_web_placeholder"})}
ref={this.onInputMount}
title={this.props.intl.formatMessage({id: "search_web_placeholder"})}
type="search" />
<button
Expand Down
20 changes: 0 additions & 20 deletions system-addon/test/unit/content-src/components/Search.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,6 @@ describe("<Search>", () => {
assert.equal(spy.firstCall.args[0], "ContentSearchClient");
assert.equal(spy.firstCall.args[1], wrapper.node);
});
it("should create a ContentSearchUIController when the search input is focused", () => {
const wrapper = mountWithIntl(<Search {...DEFAULT_PROPS} />);

assert.isNull(wrapper.node.controller);

wrapper.find("#newtab-search-text").simulate("focus");

assert.instanceOf(wrapper.node.controller, global.ContentSearchUIController);
});
it("should not reinitialize ContentSearchUIController a second time", () => {
const wrapper = mountWithIntl(<Search {...DEFAULT_PROPS} />);

wrapper.find("#newtab-search-text").simulate("focus");

const originalController = wrapper.node.controller;

wrapper.find("#newtab-search-text").simulate("focus");

assert.strictEqual(wrapper.node.controller, originalController);
});
it("should pass along search when clicking the search button", () => {
const wrapper = mountWithIntl(<Search {...DEFAULT_PROPS} />);

Expand Down

0 comments on commit eade774

Please sign in to comment.