Simple connection testing is one reason why malware might connect to Google, Yahoo and other search engines, but I would like to present a different explanation.
One frequent application for botnets is search engine
As you might notice, the result page of Google (and most other search engines) doesn't lead to the results directly, but to redirect-links instead. This allows them to check which results their visitors actually visit. Search engines use this information as part of their ranking algorithms. When many users search for a specific phrase and then all pick a specific result which is not the first one, that result must obviously be more relevant than the number one result and should be moved up. So simulating lots of search requests for a certain phrase and then picking a specific website from the results can result in that page getting ranked higher for that phrase.
Also, the auto-complete feature of many search engines is based on what other users search for which makes it another interesting target for search engine spam. When I would have a million bots search
malware behavior stackexchange.com, anyone else starting to type
malware behavi into google would then get the phrase above as auto-complete suggestion. Searching for
malware behavior returns all kinds of different websites, while clicking on that auto-complete result would mostly return results from this website. That would really increase our traffic.