| Index: chrome/browser/ui/app_list/search/people/people_provider_browsertest.cc
|
| diff --git a/chrome/browser/ui/app_list/search/webstore_provider_browsertest.cc b/chrome/browser/ui/app_list/search/people/people_provider_browsertest.cc
|
| similarity index 51%
|
| copy from chrome/browser/ui/app_list/search/webstore_provider_browsertest.cc
|
| copy to chrome/browser/ui/app_list/search/people/people_provider_browsertest.cc
|
| index 5b83a34bb1d4a587242574f7400d6b0d75a6e206..8234b2103f8ed883e80f18a56f8186516bec2b32 100644
|
| --- a/chrome/browser/ui/app_list/search/webstore_provider_browsertest.cc
|
| +++ b/chrome/browser/ui/app_list/search/people/people_provider_browsertest.cc
|
| @@ -12,7 +12,7 @@
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/ui/app_list/search/chrome_search_result.h"
|
| -#include "chrome/browser/ui/app_list/search/webstore_provider.h"
|
| +#include "chrome/browser/ui/app_list/search/people/people_provider.h"
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chrome/test/base/in_process_browser_test.h"
|
| #include "content/public/browser/browser_thread.h"
|
| @@ -32,46 +32,105 @@ namespace {
|
|
|
| // Mock results.
|
| const char kOneResult[] = "{"
|
| - "\"search_url\": \"http://host/search\","
|
| - "\"results\":["
|
| + "\"items\":["
|
| "{"
|
| - "\"id\": \"app1_id\","
|
| - "\"localized_name\": \"app1 name\","
|
| - "\"icon_url\": \"http://host/icon\""
|
| + "\"person\" : {"
|
| + "\"id\": \"1\","
|
| + "\"names\" : [{"
|
| + "\"displayName\": \"first person\""
|
| + "}],"
|
| + "\"images\" : [{"
|
| + "\"url\": \"http://host/icon\""
|
| + "}],"
|
| + "\"sortKeys\" : {"
|
| + "\"interactionRank\": \"0.98\""
|
| + "}"
|
| + "}"
|
| "}"
|
| "]}";
|
|
|
| -const char kThreeResults[] = "{"
|
| - "\"search_url\": \"http://host/search\","
|
| - "\"results\":["
|
| +const char kThreeValidResults[] = "{"
|
| + "\"items\":["
|
| "{"
|
| - "\"id\": \"app1_id\","
|
| - "\"localized_name\": \"one\","
|
| - "\"icon_url\": \"http://host/icon\""
|
| + "\"person\" : {"
|
| + "\"id\": \"1\","
|
| + "\"names\" : [{"
|
| + "\"displayName\": \"first person\""
|
| + "}],"
|
| + "\"images\" : [{"
|
| + "\"url\": \"http://host/icon\""
|
| + "}],"
|
| + "\"sortKeys\" : {"
|
| + "\"interactionRank\": \"0.98\""
|
| + "}"
|
| + "}"
|
| "},"
|
| "{"
|
| - "\"id\": \"app2_id\","
|
| - "\"localized_name\": \"two\","
|
| - "\"icon_url\": \"http://host/icon\""
|
| + "\"person\" : {"
|
| + "\"id\": \"2\","
|
| + "\"names\" : [{"
|
| + "\"displayName\": \"second person\""
|
| + "}],"
|
| + "\"images\" : [{"
|
| + "\"url\": \"http://host/icon\""
|
| + "}],"
|
| + "\"sortKeys\" : {"
|
| + "\"interactionRank\": \"0.84\""
|
| + "}"
|
| + "}"
|
| "},"
|
| "{"
|
| - "\"id\": \"app3_id\","
|
| - "\"localized_name\": \"three\","
|
| - "\"icon_url\": \"http://host/icon\""
|
| + "\"person\" : {"
|
| + "\"id\": \"3\","
|
| + "\"names\" : [{"
|
| + "\"displayName\": \"third person\""
|
| + "}],"
|
| + "\"images\" : [{"
|
| + "\"url\": \"http://host/icon\""
|
| + "}],"
|
| + "\"sortKeys\" : {"
|
| + "\"interactionRank\": \"0.67\""
|
| + "}"
|
| + "}"
|
| + "},"
|
| + "{"
|
| + "\"person\" : {"
|
| + "\"id\": \"4\","
|
| + "\"names\" : [{"
|
| + "\"displayName\": \"fourth person\""
|
| + "}],"
|
| + "\"images\" : [{"
|
| + "\"url\": \"http://host/icon\""
|
| + "}],"
|
| + "\"sortKeys\" : {"
|
| + "\"interactionRank\": \"0.0\""
|
| + "}"
|
| + "}"
|
| + "},"
|
| + "{"
|
| + "\"person\" : {"
|
| + "\"id\": \"5\","
|
| + "\"names\" : [{"
|
| + "\"displayName\": \"fifth person\""
|
| + "}],"
|
| + // Images field is missing on purpose.
|
| + "\"sortKeys\" : {"
|
| + "\"interactionRank\": \"0.98\""
|
| + "}"
|
| + "}"
|
| "}"
|
| "]}";
|
|
|
| } // namespace
|
|
|
| -class WebstoreProviderTest : public InProcessBrowserTest {
|
| +class PeopleProviderTest : public InProcessBrowserTest {
|
| public:
|
| - WebstoreProviderTest() {}
|
| - virtual ~WebstoreProviderTest() {}
|
| + PeopleProviderTest() {}
|
| + virtual ~PeopleProviderTest() {}
|
|
|
| // InProcessBrowserTest overrides:
|
| virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
|
| - command_line->AppendSwitchASCII(switches::kForceFieldTrials,
|
| - "LauncherUseWebstoreSearch/Enable/");
|
| + command_line->AppendSwitch(switches::kEnablePeopleSearch);
|
| }
|
|
|
| virtual void SetUpOnMainThread() OVERRIDE {
|
| @@ -80,18 +139,17 @@ class WebstoreProviderTest : public InProcessBrowserTest {
|
|
|
| ASSERT_TRUE(test_server_->InitializeAndWaitUntilReady());
|
| test_server_->RegisterRequestHandler(
|
| - base::Bind(&WebstoreProviderTest::HandleRequest,
|
| + base::Bind(&PeopleProviderTest::HandleRequest,
|
| base::Unretained(this)));
|
| - CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
| - switches::kAppsGalleryURL, test_server_->base_url().spec());
|
|
|
| - webstore_provider_.reset(new WebstoreProvider(
|
| - ProfileManager::GetDefaultProfile(), NULL));
|
| - webstore_provider_->set_webstore_search_fetched_callback(
|
| - base::Bind(&WebstoreProviderTest::OnSearchResultsFetched,
|
| - base::Unretained(this)));
|
| - // TODO(mukai): add test cases for throttling.
|
| - webstore_provider_->set_use_throttling(false);
|
| + people_provider_.reset(new PeopleProvider(
|
| + ProfileManager::GetDefaultProfile()));
|
| +
|
| + people_provider_->SetupForTest(
|
| + base::Bind(&PeopleProviderTest::OnSearchResultsFetched,
|
| + base::Unretained(this)),
|
| + test_server_->base_url());
|
| + people_provider_->set_use_throttling(false);
|
| }
|
|
|
| virtual void CleanUpOnMainThread() OVERRIDE {
|
| @@ -101,9 +159,9 @@ class WebstoreProviderTest : public InProcessBrowserTest {
|
|
|
| std::string RunQuery(const std::string& query,
|
| const std::string& mock_server_response) {
|
| - webstore_provider_->Start(UTF8ToUTF16(query));
|
| + people_provider_->Start(UTF8ToUTF16(query));
|
|
|
| - if (webstore_provider_->webstore_search_ && !mock_server_response.empty()) {
|
| + if (people_provider_->people_search_ && !mock_server_response.empty()) {
|
| mock_server_response_ = mock_server_response;
|
|
|
| DCHECK(!run_loop_);
|
| @@ -114,15 +172,15 @@ class WebstoreProviderTest : public InProcessBrowserTest {
|
| mock_server_response_.clear();
|
| }
|
|
|
| - webstore_provider_->Stop();
|
| + people_provider_->Stop();
|
| return GetResults();
|
| }
|
|
|
| std::string GetResults() const {
|
| std::string results;
|
| for (SearchProvider::Results::const_iterator it =
|
| - webstore_provider_->results().begin();
|
| - it != webstore_provider_->results().end();
|
| + people_provider_->results().begin();
|
| + it != people_provider_->results().end();
|
| ++it) {
|
| if (!results.empty())
|
| results += ',';
|
| @@ -131,22 +189,13 @@ class WebstoreProviderTest : public InProcessBrowserTest {
|
| return results;
|
| }
|
|
|
| - WebstoreProvider* webstore_provider() { return webstore_provider_.get(); }
|
| + PeopleProvider* people_provider() { return people_provider_.get(); }
|
|
|
| private:
|
| scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
|
| scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse);
|
| -
|
| - if (request.relative_url.find("/jsonsearch?") != std::string::npos) {
|
| - if (mock_server_response_ == "404") {
|
| - response->set_code(net::HTTP_NOT_FOUND);
|
| - } else if (mock_server_response_ == "500") {
|
| - response->set_code(net::HTTP_INTERNAL_SERVER_ERROR);
|
| - } else {
|
| - response->set_code(net::HTTP_OK);
|
| - response->set_content(mock_server_response_);
|
| - }
|
| - }
|
| + response->set_code(net::HTTP_OK);
|
| + response->set_content(mock_server_response_);
|
|
|
| return response.PassAs<HttpResponse>();
|
| }
|
| @@ -161,32 +210,19 @@ class WebstoreProviderTest : public InProcessBrowserTest {
|
|
|
| std::string mock_server_response_;
|
|
|
| - scoped_ptr<WebstoreProvider> webstore_provider_;
|
| + scoped_ptr<PeopleProvider> people_provider_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(WebstoreProviderTest);
|
| + DISALLOW_COPY_AND_ASSIGN(PeopleProviderTest);
|
| };
|
|
|
| -// Flaky on Windows: http://crbug.com/246136.
|
| -#if defined(OS_WIN)
|
| -#define MAYBE_Basic DISABLED_Basic
|
| -#else
|
| -#define MAYBE_Basic Basic
|
| -#endif
|
| -IN_PROC_BROWSER_TEST_F(WebstoreProviderTest, MAYBE_Basic) {
|
| +IN_PROC_BROWSER_TEST_F(PeopleProviderTest, Basic) {
|
| struct {
|
| const char* query;
|
| const char* mock_server_response;
|
| const char* expected_results_content;
|
| } kTestCases[] = {
|
| - // "Search in web store" result with query text itself is used for
|
| - // synchronous placeholder, bad server response etc.
|
| - {"synchronous", "", "synchronous" },
|
| - {"404", "404", "404" },
|
| - {"500", "500", "500" },
|
| - {"bad json", "invalid json", "bad json" },
|
| - // Good results.
|
| - {"1 result", kOneResult, "app1 name" },
|
| - {"3 result", kThreeResults, "one,two,three" },
|
| + {"first", kOneResult, "first person" },
|
| + {"person", kThreeValidResults, "first person,second person,third person" },
|
| };
|
|
|
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
|
| @@ -197,7 +233,7 @@ IN_PROC_BROWSER_TEST_F(WebstoreProviderTest, MAYBE_Basic) {
|
| }
|
| }
|
|
|
| -IN_PROC_BROWSER_TEST_F(WebstoreProviderTest, NoSearchForSensitiveData) {
|
| +IN_PROC_BROWSER_TEST_F(PeopleProviderTest, NoSearchForSensitiveData) {
|
| // None of the following input strings should be accepted because they may
|
| // contain private data.
|
| const char* inputs[] = {
|
| @@ -218,17 +254,10 @@ IN_PROC_BROWSER_TEST_F(WebstoreProviderTest, NoSearchForSensitiveData) {
|
| EXPECT_EQ("", RunQuery(inputs[i], kOneResult));
|
| }
|
|
|
| -IN_PROC_BROWSER_TEST_F(WebstoreProviderTest, NoSearchForShortQueries) {
|
| - EXPECT_EQ("", RunQuery("a", kOneResult));
|
| - EXPECT_EQ("", RunQuery("ab", kOneResult));
|
| - EXPECT_EQ("app1 name", RunQuery("abc", kOneResult));
|
| -}
|
| -
|
| -IN_PROC_BROWSER_TEST_F(WebstoreProviderTest, SearchCache) {
|
| - EXPECT_EQ("app1 name", RunQuery("foo", kOneResult));
|
| -
|
| - // No result is provided but the provider gets the result from the cache.
|
| - EXPECT_EQ("app1 name", RunQuery("foo", ""));
|
| +IN_PROC_BROWSER_TEST_F(PeopleProviderTest, NoSearchForShortQueries) {
|
| + EXPECT_EQ("", RunQuery("f", kOneResult));
|
| + EXPECT_EQ("", RunQuery("fi", kOneResult));
|
| + EXPECT_EQ("first person", RunQuery("fir", kOneResult));
|
| }
|
|
|
| } // namespace test
|
|
|