Commit 5b00f678 authored by Jiaquan He's avatar Jiaquan He Committed by Commit Bot

Fix a SearchResultPageView unit test broken by answer cards.

Enabling answer cards will add a SearchResultContainerView to
SearchResultPageView. This will intefere the relevance sorting
with SearchResultTileItemListView and SearchResultListView,
which then breaks some unit tests.

Bug: 766784
Change-Id: I513f006a5d552eb91b20b834b123d2233d5048c2
Reviewed-on: https://chromium-review.googlesource.com/673850
Commit-Queue: Jiaquan He <hejq@google.com>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#503610}
parent be24b04f
......@@ -48,9 +48,8 @@ const base::Feature& GetPlaystoreAppSearchFeature() {
} // namespace
bool IsAnswerCardEnabled() {
static const bool enabled =
base::FeatureList::IsEnabled(GetAnswerCardFeature());
return enabled;
// Not using local static variable to allow tests to change this value.
return base::FeatureList::IsEnabled(GetAnswerCardFeature());
}
bool IsAnswerCardDarkRunEnabled() {
......
......@@ -11,6 +11,7 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/test/scoped_feature_list.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/app_list/app_list_features.h"
#include "ui/app_list/app_list_model.h"
#include "ui/app_list/test/app_list_test_view_delegate.h"
......@@ -24,11 +25,22 @@
#include "ui/aura/window.h"
#include "ui/views/test/views_test_base.h"
namespace {
enum class AnswerCardState {
ANSWER_CARD_OFF,
ANSWER_CARD_ON_WITH_RESULT,
ANSWER_CARD_ON_WITHOUT_RESULT,
};
} // namespace
namespace app_list {
namespace test {
class SearchResultPageViewTest : public views::ViewsTestBase,
public testing::WithParamInterface<bool> {
public testing::WithParamInterface<
::testing::tuple<bool, AnswerCardState>> {
public:
SearchResultPageViewTest() = default;
~SearchResultPageViewTest() override = default;
......@@ -37,13 +49,44 @@ class SearchResultPageViewTest : public views::ViewsTestBase,
void SetUp() override {
views::ViewsTestBase::SetUp();
if (testing::UnitTest::GetInstance()->current_test_info()->value_param())
test_with_fullscreen_ = GetParam();
if (!test_with_fullscreen_) {
scoped_feature_list_.InitAndDisableFeature(
features::kEnableFullscreenAppList);
// Reading test parameters.
bool test_with_answer_card = true;
if (testing::UnitTest::GetInstance()->current_test_info()->value_param()) {
test_with_fullscreen_ = testing::get<0>(GetParam());
const AnswerCardState answer_card_state = testing::get<1>(GetParam());
test_with_answer_card =
answer_card_state != AnswerCardState::ANSWER_CARD_OFF;
test_with_answer_card_result_ =
answer_card_state == AnswerCardState::ANSWER_CARD_ON_WITH_RESULT;
}
// Setting up the feature set.
if (test_with_fullscreen_) {
if (test_with_answer_card) {
scoped_feature_list_.InitWithFeatures(
{features::kEnableFullscreenAppList,
features::kEnableAnswerCardDefaultOff},
{});
} else {
scoped_feature_list_.InitWithFeatures(
{features::kEnableFullscreenAppList},
{features::kEnableAnswerCardDefaultOff});
}
} else {
if (test_with_answer_card) {
scoped_feature_list_.InitWithFeatures(
{features::kEnableAnswerCardDefaultOff},
{features::kEnableFullscreenAppList});
} else {
scoped_feature_list_.InitWithFeatures(
{}, {features::kEnableFullscreenAppList,
features::kEnableAnswerCardDefaultOff});
}
}
ASSERT_EQ(test_with_fullscreen_, features::IsFullscreenAppListEnabled());
ASSERT_EQ(test_with_answer_card, features::IsAnswerCardEnabled());
// Setting up views.
delegate_.reset(new AppListTestViewDelegate);
app_list_view_ = new AppListView(delegate_.get());
gfx::NativeView parent = GetContext();
......@@ -130,6 +173,9 @@ class SearchResultPageViewTest : public views::ViewsTestBase,
}
bool test_with_fullscreen() const { return test_with_fullscreen_; }
bool test_with_answer_card_result() const {
return test_with_answer_card_result_;
}
private:
AppListView* app_list_view_ = nullptr; // Owned by native widget.
......@@ -139,6 +185,7 @@ class SearchResultPageViewTest : public views::ViewsTestBase,
SearchResultListView* list_view_ = nullptr; // Owned by views hierarchy.
std::unique_ptr<AppListTestViewDelegate> delegate_;
bool test_with_fullscreen_ = true;
bool test_with_answer_card_result_ = true;
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(SearchResultPageViewTest);
......@@ -146,7 +193,14 @@ class SearchResultPageViewTest : public views::ViewsTestBase,
// Instantiate the Boolean which is used to toggle the Fullscreen app list in
// the parameterized tests.
INSTANTIATE_TEST_CASE_P(, SearchResultPageViewTest, testing::Bool());
INSTANTIATE_TEST_CASE_P(
,
SearchResultPageViewTest,
::testing::Combine(
::testing::Bool(),
::testing::Values(AnswerCardState::ANSWER_CARD_OFF,
AnswerCardState::ANSWER_CARD_ON_WITHOUT_RESULT,
AnswerCardState::ANSWER_CARD_ON_WITH_RESULT)));
// TODO(warx): This test applies to bubble launcher only. Remove this test once
// bubble launcher is removed from code base.
......@@ -295,10 +349,13 @@ TEST_P(SearchResultPageViewTest, ResultsSorted) {
}
TEST_P(SearchResultPageViewTest, UpdateWithSelection) {
const int kCardResultNum = test_with_answer_card_result() ? 1 : 0;
{
std::vector<std::pair<SearchResult::DisplayType, int>> result_types;
result_types.push_back(std::make_pair(SearchResult::DISPLAY_TILE, 3));
result_types.push_back(std::make_pair(SearchResult::DISPLAY_LIST, 2));
result_types.push_back(
std::make_pair(SearchResult::DISPLAY_CARD, kCardResultNum));
SetUpSearchResults(result_types);
}
......@@ -322,6 +379,8 @@ TEST_P(SearchResultPageViewTest, UpdateWithSelection) {
std::vector<std::pair<SearchResult::DisplayType, int>> result_types;
result_types.push_back(std::make_pair(SearchResult::DISPLAY_TILE, 3));
result_types.push_back(std::make_pair(SearchResult::DISPLAY_LIST, 3));
result_types.push_back(
std::make_pair(SearchResult::DISPLAY_CARD, kCardResultNum));
SetUpSearchResults(result_types);
}
......@@ -335,6 +394,8 @@ TEST_P(SearchResultPageViewTest, UpdateWithSelection) {
std::vector<std::pair<SearchResult::DisplayType, int>> result_types;
result_types.push_back(std::make_pair(SearchResult::DISPLAY_TILE, 3));
result_types.push_back(std::make_pair(SearchResult::DISPLAY_LIST, 1));
result_types.push_back(
std::make_pair(SearchResult::DISPLAY_CARD, kCardResultNum));
SetUpSearchResults(result_types);
}
......@@ -349,6 +410,8 @@ TEST_P(SearchResultPageViewTest, UpdateWithSelection) {
std::vector<std::pair<SearchResult::DisplayType, int>> result_types;
result_types.push_back(std::make_pair(SearchResult::DISPLAY_LIST, 1));
result_types.push_back(std::make_pair(SearchResult::DISPLAY_TILE, 3));
result_types.push_back(
std::make_pair(SearchResult::DISPLAY_CARD, kCardResultNum));
SetUpSearchResults(result_types);
}
......@@ -362,6 +425,8 @@ TEST_P(SearchResultPageViewTest, UpdateWithSelection) {
{
std::vector<std::pair<SearchResult::DisplayType, int>> result_types;
result_types.push_back(std::make_pair(SearchResult::DISPLAY_LIST, 3));
result_types.push_back(
std::make_pair(SearchResult::DISPLAY_CARD, kCardResultNum));
SetUpSearchResults(result_types);
}
......
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