Commit bf715ea3 authored by Jiaquan He's avatar Jiaquan He Committed by Commit Bot

Add more unit tests for ArcPlayStoreSearchProvider.

Cover more failing cases in ArcPlayStoreSearchProvider.

Bug: 765757
Change-Id: Idb04ffc4a2b7fbeb40df183b6cefb0a00a0f2841
Reviewed-on: https://chromium-review.googlesource.com/736677
Commit-Queue: Jiaquan He <hejq@google.com>
Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Reviewed-by: default avatarYury Khmel <khmel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546155}
parent 43535078
......@@ -18,6 +18,7 @@
#include "chrome/browser/ui/app_list/search/arc/icon_decode_request.h"
#include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h"
#include "chrome/test/base/testing_profile.h"
#include "components/arc/app/arc_playstore_search_request_state.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/value_builder.h"
......@@ -103,4 +104,57 @@ TEST_F(ArcPlayStoreSearchProviderTest, Basic) {
}
}
TEST_F(ArcPlayStoreSearchProviderTest, FailedQuery) {
constexpr size_t kMaxResults = 12;
constexpr char kQuery[] = "Play App";
const base::string16 kQueryString16 = base::UTF8ToUTF16(kQuery);
std::unique_ptr<ArcPlayStoreSearchProvider> provider =
CreateSearch(kMaxResults);
EXPECT_TRUE(provider->results().empty());
IconDecodeRequest::DisableSafeDecodingForTesting();
// Test for empty queries.
// Create a non-empty query.
provider->Start(kQueryString16);
EXPECT_GT(provider->results().size(), 0u);
// Create an empty query and it should clear the result list.
provider->Start(base::string16());
EXPECT_EQ(0u, provider->results().size());
// Test for queries with a failure state code.
constexpr char kFailedQueryPrefix[] = "FailedQueryWithCode-";
using RequestState = arc::ArcPlayStoreSearchRequestState;
const std::array<RequestState, 15> kErrorStates = {
RequestState::PLAY_STORE_PROXY_NOT_AVAILABLE,
RequestState::FAILED_TO_CALL_CANCEL,
RequestState::FAILED_TO_CALL_FINDAPPS,
RequestState::REQUEST_HAS_INVALID_PARAMS,
RequestState::REQUEST_TIMEOUT,
RequestState::PHONESKY_RESULT_REQUEST_CODE_UNMATCHED,
RequestState::PHONESKY_RESULT_SESSION_ID_UNMATCHED,
RequestState::PHONESKY_REQUEST_REQUEST_CODE_UNMATCHED,
RequestState::PHONESKY_APP_DISCOVERY_NOT_AVAILABLE,
RequestState::PHONESKY_VERSION_NOT_SUPPORTED,
RequestState::PHONESKY_UNEXPECTED_EXCEPTION,
RequestState::PHONESKY_MALFORMED_QUERY,
RequestState::PHONESKY_INTERNAL_ERROR,
RequestState::PHONESKY_RESULT_INVALID_DATA,
RequestState::CHROME_GOT_INVALID_RESULT,
};
static_assert(
kErrorStates.size() == static_cast<size_t>(RequestState::STATE_COUNT) - 3,
"Missing entries");
for (const auto& error_state : kErrorStates) {
// Create a non-empty query.
provider->Start(kQueryString16);
EXPECT_GT(provider->results().size(), 0u);
// Fabricate a failing query and it should clear the result list.
provider->Start(base::UTF8ToUTF16(
base::StringPrintf("%s%d", kFailedQueryPrefix, error_state)));
EXPECT_EQ(0u, provider->results().size());
}
}
} // namespace app_list
......@@ -306,6 +306,17 @@ void FakeAppInstance::GetRecentAndSuggestedAppsFromPlayStore(
// Fake Play Store app info
std::vector<arc::mojom::AppDiscoveryResultPtr> fake_apps;
// Check if we're fabricating failed query.
const std::string kFailedQueryPrefix("FailedQueryWithCode-");
ArcPlayStoreSearchRequestState state_code =
ArcPlayStoreSearchRequestState::SUCCESS;
if (!query.compare(0, kFailedQueryPrefix.size(), kFailedQueryPrefix)) {
state_code = static_cast<ArcPlayStoreSearchRequestState>(
stoi(query.substr(kFailedQueryPrefix.size())));
std::move(callback).Run(state_code, std::move(fake_apps));
return;
}
// Fake icon data.
std::string png_data_as_string;
GetFakeIcon(mojom::ScaleFactor::SCALE_FACTOR_100P, &png_data_as_string);
......@@ -337,8 +348,8 @@ void FakeAppInstance::GetRecentAndSuggestedAppsFromPlayStore(
fake_icon_png_data, // icon_png_data
base::StringPrintf("test.package.%d", i))); // package_name
}
std::move(callback).Run(ArcPlayStoreSearchRequestState::SUCCESS,
std::move(fake_apps));
std::move(callback).Run(state_code, std::move(fake_apps));
}
void FakeAppInstance::GetIcingGlobalQueryResults(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment