continue_section_view_unittest.cc 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/app_list/views/continue_section_view.h"
  5. #include <memory>
  6. #include <set>
  7. #include <string>
  8. #include <utility>
  9. #include <vector>
  10. #include "ash/app_list/app_list_controller_impl.h"
  11. #include "ash/app_list/app_list_metrics.h"
  12. #include "ash/app_list/app_list_test_view_delegate.h"
  13. #include "ash/app_list/model/search/search_model.h"
  14. #include "ash/app_list/model/search/test_search_result.h"
  15. #include "ash/app_list/test/app_list_test_helper.h"
  16. #include "ash/app_list/views/app_list_bubble_apps_page.h"
  17. #include "ash/app_list/views/app_list_toast_container_view.h"
  18. #include "ash/app_list/views/app_list_toast_view.h"
  19. #include "ash/app_list/views/apps_container_view.h"
  20. #include "ash/app_list/views/apps_grid_view_test_api.h"
  21. #include "ash/app_list/views/continue_task_view.h"
  22. #include "ash/app_list/views/recent_apps_view.h"
  23. #include "ash/app_list/views/scrollable_apps_grid_view.h"
  24. #include "ash/app_list/views/search_box_view.h"
  25. #include "ash/constants/ash_features.h"
  26. #include "ash/constants/ash_pref_names.h"
  27. #include "ash/public/cpp/app_list/app_list_features.h"
  28. #include "ash/public/cpp/app_list/app_list_types.h"
  29. #include "ash/session/session_controller_impl.h"
  30. #include "ash/shell.h"
  31. #include "ash/test/ash_test_base.h"
  32. #include "ash/test/layer_animation_stopped_waiter.h"
  33. #include "base/run_loop.h"
  34. #include "base/test/metrics/histogram_tester.h"
  35. #include "base/test/scoped_feature_list.h"
  36. #include "base/test/task_environment.h"
  37. #include "testing/gtest/include/gtest/gtest.h"
  38. #include "third_party/abseil-cpp/absl/types/optional.h"
  39. #include "ui/compositor/layer.h"
  40. #include "ui/compositor/scoped_animation_duration_scale_mode.h"
  41. #include "ui/events/event.h"
  42. #include "ui/events/keycodes/keyboard_codes.h"
  43. #include "ui/views/animation/ink_drop.h"
  44. #include "ui/views/controls/button/label_button.h"
  45. #include "ui/views/controls/button/radio_button.h"
  46. #include "ui/views/controls/scroll_view.h"
  47. #include "ui/views/controls/textfield/textfield.h"
  48. #include "ui/views/widget/widget_delegate.h"
  49. namespace ash {
  50. namespace {
  51. using test::AppListTestViewDelegate;
  52. std::unique_ptr<TestSearchResult> CreateTestResult(const std::string& id,
  53. AppListSearchResultType type,
  54. const std::string& title) {
  55. auto result = std::make_unique<TestSearchResult>();
  56. result->set_result_id(id);
  57. result->SetTitle(base::ASCIIToUTF16(title));
  58. result->set_result_type(type);
  59. result->set_display_type(SearchResultDisplayType::kContinue);
  60. return result;
  61. }
  62. void AddSearchResultToModel(const std::string& id,
  63. AppListSearchResultType type,
  64. SearchModel* model,
  65. const std::string& title) {
  66. model->results()->Add(CreateTestResult(id, type, title));
  67. }
  68. void WaitForAllChildrenAnimationsToComplete(views::View* view) {
  69. while (true) {
  70. bool found_animation = false;
  71. for (views::View* child : view->children()) {
  72. if (child->layer() && child->layer()->GetAnimator()->is_animating()) {
  73. LayerAnimationStoppedWaiter waiter;
  74. waiter.Wait(child->layer());
  75. found_animation = true;
  76. break;
  77. }
  78. }
  79. if (!found_animation)
  80. return;
  81. }
  82. }
  83. class ContinueSectionViewTestBase : public AshTestBase {
  84. public:
  85. explicit ContinueSectionViewTestBase(bool tablet_mode)
  86. : AshTestBase(base::test::TaskEnvironment::TimeSource::MOCK_TIME),
  87. tablet_mode_(tablet_mode) {
  88. scoped_feature_list_.InitWithFeatures(
  89. {features::kLauncherAppSort, features::kProductivityLauncher}, {});
  90. }
  91. ~ContinueSectionViewTestBase() override = default;
  92. void TearDown() override {
  93. AshTestBase::TearDown();
  94. // Clean up global variables used for metrics on continue section removals.
  95. ContinueSectionView::ResetContinueSectionFileRemovalMetricEnabledForTest();
  96. ResetContinueSectionFileRemovedCountForTest();
  97. }
  98. // Whether we should run the test in tablet mode.
  99. bool tablet_mode_param() { return tablet_mode_; }
  100. // Sets up the continue section view (and app list) state for testing continue
  101. // section update animations. `result_count` is the number of continue tasks
  102. // that should initially be added to search model.
  103. // Returns the list of current task view layer bounds.
  104. std::vector<gfx::RectF> InitializeForAnimationTest(int result_count) {
  105. // Ensure display is large enough to display 4 chips in tablet mode.
  106. UpdateDisplay("1200x800");
  107. AddTestSearchResults(result_count);
  108. EnsureLauncherShown();
  109. base::RunLoop().RunUntilIdle();
  110. base::OneShotTimer* animations_timer = GetContinueSectionView()
  111. ->suggestions_container()
  112. ->animations_timer_for_test();
  113. if (animations_timer)
  114. animations_timer->FireNow();
  115. animation_duration_.emplace(
  116. ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
  117. return GetCurrentLayerBoundsForAllTaskViews();
  118. }
  119. ContinueSectionView* GetContinueSectionView() {
  120. if (Shell::Get()->tablet_mode_controller()->InTabletMode())
  121. return GetAppListTestHelper()->GetFullscreenContinueSectionView();
  122. return GetAppListTestHelper()->GetBubbleContinueSectionView();
  123. }
  124. AppListNudgeController* GetAppListNudgeController() {
  125. return GetContinueSectionView()->nudge_controller_for_test();
  126. }
  127. views::View* GetRecentAppsView() {
  128. if (Shell::Get()->tablet_mode_controller()->InTabletMode())
  129. return GetAppListTestHelper()->GetFullscreenRecentAppsView();
  130. return GetAppListTestHelper()->GetBubbleRecentAppsView();
  131. }
  132. views::View* GetAppsGridView() {
  133. if (Shell::Get()->tablet_mode_controller()->InTabletMode())
  134. return GetAppListTestHelper()->GetRootPagedAppsGridView();
  135. return GetAppListTestHelper()->GetScrollableAppsGridView();
  136. }
  137. void AddTestSearchResults(int count) {
  138. for (int i = 0; i < count; ++i)
  139. AddSearchResult(base::StringPrintf("id_%d", i),
  140. AppListSearchResultType::kZeroStateFile);
  141. }
  142. void AddSearchResult(const std::string& id, AppListSearchResultType type) {
  143. AddSearchResultToModel(
  144. id, type, AppListModelProvider::Get()->search_model(), "Fake Title");
  145. }
  146. void AddSearchResultWithTitle(const std::string& id,
  147. AppListSearchResultType type,
  148. const std::string& title) {
  149. AddSearchResultToModel(id, type,
  150. AppListModelProvider::Get()->search_model(), title);
  151. }
  152. void RemoveSearchResultAt(size_t index) {
  153. GetAppListTestHelper()->GetSearchResults()->RemoveAt(index);
  154. }
  155. SearchModel::SearchResults* GetResults() {
  156. return GetAppListTestHelper()->GetSearchResults();
  157. }
  158. std::vector<SearchResult*> GetContinueResults() {
  159. auto continue_filter = [](const SearchResult& r) -> bool {
  160. return r.display_type() == SearchResultDisplayType::kContinue;
  161. };
  162. std::vector<SearchResult*> continue_results;
  163. continue_results = SearchModel::FilterSearchResultsByFunction(
  164. GetResults(), base::BindRepeating(continue_filter),
  165. /*max_results=*/4);
  166. return continue_results;
  167. }
  168. SearchBoxView* GetSearchBoxView() {
  169. if (Shell::Get()->tablet_mode_controller()->InTabletMode())
  170. return GetAppListTestHelper()->GetSearchBoxView();
  171. return GetAppListTestHelper()->GetBubbleSearchBoxView();
  172. }
  173. ContinueTaskView* GetResultViewAt(int index) {
  174. return GetContinueSectionView()->GetTaskViewAtForTesting(index);
  175. }
  176. std::vector<std::string> GetResultIds() {
  177. const size_t result_count =
  178. GetContinueSectionView()->GetTasksSuggestionsCount();
  179. std::vector<std::string> ids;
  180. for (size_t i = 0; i < result_count; ++i)
  181. ids.push_back(GetResultViewAt(i)->result()->id());
  182. return ids;
  183. }
  184. void VerifyResultViewsUpdated() {
  185. // Wait for the view to update any pending SearchResults.
  186. base::RunLoop().RunUntilIdle();
  187. std::vector<SearchResult*> results = GetContinueResults();
  188. for (size_t i = 0; i < results.size(); ++i)
  189. EXPECT_EQ(results[i], GetResultViewAt(i)->result()) << i;
  190. }
  191. void EnsureLauncherShown() {
  192. if (tablet_mode_param()) {
  193. // Convert to tablet mode to show fullscren launcher.
  194. Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
  195. Shell::Get()->app_list_controller()->ShowAppList();
  196. test_api_ = std::make_unique<test::AppsGridViewTestApi>(
  197. GetAppListTestHelper()->GetRootPagedAppsGridView());
  198. } else {
  199. Shell::Get()->app_list_controller()->ShowAppList();
  200. test_api_ = std::make_unique<test::AppsGridViewTestApi>(
  201. GetAppListTestHelper()->GetScrollableAppsGridView());
  202. }
  203. ASSERT_TRUE(GetAppsGridView());
  204. }
  205. void HideLauncher() { Shell::Get()->app_list_controller()->DismissAppList(); }
  206. void ResetPrivacyNoticePref() {
  207. AppListNudgeController::SetPrivacyNoticeAcceptedForTest(false);
  208. }
  209. void SimulateRightClickOrLongPressOn(const views::View* view) {
  210. gfx::Point location = view->GetBoundsInScreen().CenterPoint();
  211. if (tablet_mode_param()) {
  212. ui::test::EventGenerator* generator = GetEventGenerator();
  213. generator->set_current_screen_location(location);
  214. generator->PressTouch();
  215. ui::GestureEventDetails event_details(ui::ET_GESTURE_LONG_PRESS);
  216. ui::GestureEvent long_press(location.x(), location.y(), 0,
  217. base::TimeTicks::Now(), event_details);
  218. generator->Dispatch(&long_press);
  219. generator->ReleaseTouch();
  220. GetAppListTestHelper()->WaitUntilIdle();
  221. } else {
  222. RightClickOn(view);
  223. }
  224. }
  225. bool IsPrivacyNoticeVisible() {
  226. auto* privacy_notice = GetContinueSectionView()->GetPrivacyNoticeForTest();
  227. return privacy_notice && privacy_notice->GetVisible();
  228. }
  229. gfx::RectF GetTargetLayerBounds(views::View* view) {
  230. gfx::RectF bounds(view->layer()->GetTargetBounds());
  231. view->layer()->GetTargetTransform().TransformRect(&bounds);
  232. return bounds;
  233. }
  234. gfx::RectF GetCurrentLayerBounds(views::View* view) {
  235. gfx::RectF bounds(view->layer()->bounds());
  236. view->layer()->transform().TransformRect(&bounds);
  237. return bounds;
  238. }
  239. std::vector<gfx::RectF> GetCurrentLayerBoundsForAllTaskViews() {
  240. std::vector<gfx::RectF> bounds;
  241. const size_t count = GetContinueSectionView()->GetTasksSuggestionsCount();
  242. bounds.reserve(count);
  243. for (size_t i = 0; i < count; ++i) {
  244. views::View* result_view = GetResultViewAt(i);
  245. bounds.push_back(GetCurrentLayerBounds(result_view));
  246. }
  247. return bounds;
  248. }
  249. void RemoveSearchResultWithContextMenuAt(int index) {
  250. ContinueTaskView* continue_task_view = GetResultViewAt(index);
  251. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  252. SimulateRightClickOrLongPressOn(continue_task_view);
  253. EXPECT_TRUE(continue_task_view->IsMenuShowing()) << index;
  254. continue_task_view->ExecuteCommand(ContinueTaskCommandId::kRemoveResult,
  255. ui::EF_NONE);
  256. EXPECT_FALSE(continue_task_view->IsMenuShowing());
  257. }
  258. test::AppsGridViewTestApi* test_api() { return test_api_.get(); }
  259. private:
  260. bool tablet_mode_ = false;
  261. absl::optional<ui::ScopedAnimationDurationScaleMode> animation_duration_;
  262. std::unique_ptr<test::AppsGridViewTestApi> test_api_;
  263. base::test::ScopedFeatureList scoped_feature_list_;
  264. };
  265. class ContinueSectionViewTest : public ContinueSectionViewTestBase,
  266. public testing::WithParamInterface<bool> {
  267. public:
  268. ContinueSectionViewTest()
  269. : ContinueSectionViewTestBase(/*tablet_mode=*/GetParam()) {}
  270. ~ContinueSectionViewTest() override = default;
  271. };
  272. class ContinueSectionViewClamshellModeTest
  273. : public ContinueSectionViewTestBase {
  274. public:
  275. ContinueSectionViewClamshellModeTest()
  276. : ContinueSectionViewTestBase(/*tablet_mode=*/false) {}
  277. ~ContinueSectionViewClamshellModeTest() override = default;
  278. };
  279. class ContinueSectionViewTabletModeTest : public ContinueSectionViewTestBase {
  280. public:
  281. ContinueSectionViewTabletModeTest()
  282. : ContinueSectionViewTestBase(/*tablet_mode=*/true) {}
  283. ~ContinueSectionViewTabletModeTest() override = default;
  284. };
  285. class ContinueSectionViewWithReorderNudgeTest
  286. : public ContinueSectionViewTestBase,
  287. public testing::WithParamInterface<bool> {
  288. public:
  289. ContinueSectionViewWithReorderNudgeTest()
  290. : ContinueSectionViewTestBase(/*tablet_mode=*/GetParam()) {}
  291. ~ContinueSectionViewWithReorderNudgeTest() override = default;
  292. // AshTestBase:
  293. void SetUp() override {
  294. AshTestBase::SetUp();
  295. GetAppListTestHelper()->DisableAppListNudge(false);
  296. }
  297. AppListToastContainerView* GetToastContainerView() {
  298. if (!Shell::Get()->tablet_mode_controller()->InTabletMode()) {
  299. return GetAppListTestHelper()
  300. ->GetBubbleAppsPage()
  301. ->toast_container_for_test();
  302. }
  303. return GetAppListTestHelper()->GetAppsContainerView()->toast_container();
  304. }
  305. };
  306. // Instantiate the values in the parameterized tests. Used to toggle tablet
  307. // mode.
  308. INSTANTIATE_TEST_SUITE_P(All, ContinueSectionViewTest, testing::Bool());
  309. INSTANTIATE_TEST_SUITE_P(All,
  310. ContinueSectionViewWithReorderNudgeTest,
  311. testing::Bool());
  312. TEST_P(ContinueSectionViewTest, CreatesViewsForTasks) {
  313. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  314. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  315. EnsureLauncherShown();
  316. ContinueSectionView* view = GetContinueSectionView();
  317. EXPECT_EQ(view->GetTasksSuggestionsCount(), 2u);
  318. }
  319. TEST_P(ContinueSectionViewTest, VerifyAddedViewsOrder) {
  320. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  321. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  322. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  323. EnsureLauncherShown();
  324. VerifyResultViewsUpdated();
  325. ContinueSectionView* view = GetContinueSectionView();
  326. ASSERT_EQ(view->GetTasksSuggestionsCount(), 3u);
  327. EXPECT_EQ(GetResultViewAt(0)->result()->id(), "id1");
  328. EXPECT_EQ(GetResultViewAt(1)->result()->id(), "id2");
  329. EXPECT_EQ(GetResultViewAt(2)->result()->id(), "id3");
  330. }
  331. TEST_P(ContinueSectionViewTest, ShowsHelpAppResults) {
  332. AddSearchResult("id1", AppListSearchResultType::kZeroStateHelpApp);
  333. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  334. AddSearchResult("id3", AppListSearchResultType::kZeroStateFile);
  335. AddSearchResult("id4", AppListSearchResultType::kZeroStateDrive);
  336. EnsureLauncherShown();
  337. VerifyResultViewsUpdated();
  338. EXPECT_TRUE(GetContinueSectionView()->GetVisible());
  339. ContinueSectionView* view = GetContinueSectionView();
  340. ASSERT_EQ(view->GetTasksSuggestionsCount(), 4u);
  341. EXPECT_EQ(GetResultViewAt(0)->result()->id(), "id1");
  342. EXPECT_EQ(GetResultViewAt(1)->result()->id(), "id2");
  343. EXPECT_EQ(GetResultViewAt(2)->result()->id(), "id3");
  344. EXPECT_EQ(GetResultViewAt(3)->result()->id(), "id4");
  345. }
  346. TEST_P(ContinueSectionViewTest, HelpAppResultNotShownWithoutEnoughOtherFiles) {
  347. AddSearchResult("id1", AppListSearchResultType::kZeroStateHelpApp);
  348. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  349. EnsureLauncherShown();
  350. VerifyResultViewsUpdated();
  351. ContinueSectionView* view = GetContinueSectionView();
  352. ASSERT_EQ(view->GetTasksSuggestionsCount(), 2u);
  353. EXPECT_FALSE(GetContinueSectionView()->GetVisible());
  354. }
  355. TEST_P(ContinueSectionViewTest, HelpAppShownInTabletModeWith2FileResults) {
  356. AddSearchResult("id1", AppListSearchResultType::kZeroStateHelpApp);
  357. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  358. AddSearchResult("id2", AppListSearchResultType::kZeroStateFile);
  359. EnsureLauncherShown();
  360. VerifyResultViewsUpdated();
  361. ContinueSectionView* view = GetContinueSectionView();
  362. ASSERT_EQ(view->GetTasksSuggestionsCount(), 3u);
  363. EXPECT_EQ(GetParam(), GetContinueSectionView()->GetVisible());
  364. }
  365. TEST_P(ContinueSectionViewTest, ModelObservers) {
  366. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  367. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  368. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  369. EnsureLauncherShown();
  370. VerifyResultViewsUpdated();
  371. // Remove from end.
  372. GetResults()->DeleteAt(2);
  373. VerifyResultViewsUpdated();
  374. // Insert a new result.
  375. AddSearchResult("id4", AppListSearchResultType::kZeroStateFile);
  376. VerifyResultViewsUpdated();
  377. // Delete from start.
  378. GetResults()->DeleteAt(0);
  379. VerifyResultViewsUpdated();
  380. }
  381. TEST_P(ContinueSectionViewTest, HideContinueSectionWhenResultRemoved) {
  382. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  383. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  384. // Minimum files for clamshell mode are 3.
  385. if (!tablet_mode_param())
  386. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  387. EnsureLauncherShown();
  388. VerifyResultViewsUpdated();
  389. EXPECT_TRUE(GetContinueSectionView()->GetVisible());
  390. RemoveSearchResultAt(1);
  391. VerifyResultViewsUpdated();
  392. ASSERT_LE(GetContinueSectionView()->GetTasksSuggestionsCount(), 2u);
  393. EXPECT_FALSE(GetContinueSectionView()->GetVisible());
  394. }
  395. TEST_P(ContinueSectionViewTest, ShowContinueSectionWhenResultAdded) {
  396. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  397. // Minimum files for clamshell mode are 3.
  398. if (!tablet_mode_param())
  399. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  400. EnsureLauncherShown();
  401. VerifyResultViewsUpdated();
  402. EXPECT_FALSE(GetContinueSectionView()->GetVisible());
  403. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  404. VerifyResultViewsUpdated();
  405. EXPECT_TRUE(GetContinueSectionView()->GetVisible());
  406. }
  407. TEST_P(ContinueSectionViewTest, ClickOpensSearchResult) {
  408. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  409. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  410. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  411. EnsureLauncherShown();
  412. VerifyResultViewsUpdated();
  413. ContinueTaskView* continue_task_view = GetResultViewAt(0);
  414. EXPECT_EQ(continue_task_view->result()->id(), "id1");
  415. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  416. LeftClickOn(continue_task_view);
  417. // The item was activated.
  418. TestAppListClient* client = GetAppListTestHelper()->app_list_client();
  419. EXPECT_EQ("id1", client->last_opened_search_result());
  420. }
  421. TEST_P(ContinueSectionViewTest, TapOpensSearchResult) {
  422. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  423. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  424. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  425. EnsureLauncherShown();
  426. VerifyResultViewsUpdated();
  427. ContinueTaskView* continue_task_view = GetResultViewAt(0);
  428. EXPECT_EQ(continue_task_view->result()->id(), "id1");
  429. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  430. GestureTapOn(continue_task_view);
  431. // The item was activated.
  432. TestAppListClient* client = GetAppListTestHelper()->app_list_client();
  433. EXPECT_EQ("id1", client->last_opened_search_result());
  434. }
  435. TEST_F(ContinueSectionViewClamshellModeTest, PressEnterOpensSearchResult) {
  436. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  437. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  438. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  439. EnsureLauncherShown();
  440. VerifyResultViewsUpdated();
  441. ContinueTaskView* continue_task_view = GetResultViewAt(0);
  442. EXPECT_EQ(continue_task_view->result()->id(), "id1");
  443. SearchBoxView* search_box_view = GetSearchBoxView();
  444. EXPECT_TRUE(search_box_view->search_box()->HasFocus());
  445. PressAndReleaseKey(ui::VKEY_DOWN);
  446. EXPECT_TRUE(continue_task_view->HasFocus());
  447. PressAndReleaseKey(ui::VKEY_RETURN);
  448. // The item was activated.
  449. TestAppListClient* client = GetAppListTestHelper()->app_list_client();
  450. EXPECT_EQ("id1", client->last_opened_search_result());
  451. }
  452. TEST_F(ContinueSectionViewClamshellModeTest, DownArrowMovesFocusVertically) {
  453. AddSearchResult("id0", AppListSearchResultType::kZeroStateFile);
  454. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  455. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  456. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  457. EnsureLauncherShown();
  458. VerifyResultViewsUpdated();
  459. ContinueTaskView* task0 = GetResultViewAt(0);
  460. ContinueTaskView* task1 = GetResultViewAt(1);
  461. ContinueTaskView* task2 = GetResultViewAt(2);
  462. ContinueTaskView* task3 = GetResultViewAt(3);
  463. ASSERT_FALSE(task0->HasFocus());
  464. ASSERT_FALSE(task1->HasFocus());
  465. ASSERT_FALSE(task2->HasFocus());
  466. ASSERT_FALSE(task3->HasFocus());
  467. // Down arrow from search box moves to first continue task.
  468. PressAndReleaseKey(ui::VKEY_DOWN);
  469. EXPECT_TRUE(task0->HasFocus());
  470. EXPECT_FALSE(task1->HasFocus());
  471. EXPECT_FALSE(task2->HasFocus());
  472. EXPECT_FALSE(task3->HasFocus());
  473. // Down arrow from first continue task moves down by one row, focusing
  474. // `task2` instead of the next task in tab order (`task1`).
  475. PressAndReleaseKey(ui::VKEY_DOWN);
  476. EXPECT_FALSE(task0->HasFocus());
  477. EXPECT_FALSE(task1->HasFocus());
  478. EXPECT_TRUE(task2->HasFocus());
  479. EXPECT_FALSE(task3->HasFocus());
  480. // Down again moves focus out of continue section.
  481. PressAndReleaseKey(ui::VKEY_DOWN);
  482. EXPECT_FALSE(task0->HasFocus());
  483. EXPECT_FALSE(task1->HasFocus());
  484. EXPECT_FALSE(task2->HasFocus());
  485. EXPECT_FALSE(task3->HasFocus());
  486. }
  487. TEST_F(ContinueSectionViewClamshellModeTest, UpArrowMovesFocusVertically) {
  488. AddSearchResult("id0", AppListSearchResultType::kZeroStateFile);
  489. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  490. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  491. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  492. EnsureLauncherShown();
  493. VerifyResultViewsUpdated();
  494. ContinueTaskView* task0 = GetResultViewAt(0);
  495. ContinueTaskView* task1 = GetResultViewAt(1);
  496. ContinueTaskView* task2 = GetResultViewAt(2);
  497. ContinueTaskView* task3 = GetResultViewAt(3);
  498. ASSERT_FALSE(task0->HasFocus());
  499. ASSERT_FALSE(task1->HasFocus());
  500. ASSERT_FALSE(task2->HasFocus());
  501. ASSERT_FALSE(task3->HasFocus());
  502. // Focus the last task (in the second row, second column).
  503. task3->RequestFocus();
  504. EXPECT_FALSE(task0->HasFocus());
  505. EXPECT_FALSE(task1->HasFocus());
  506. EXPECT_FALSE(task2->HasFocus());
  507. EXPECT_TRUE(task3->HasFocus());
  508. // Up arrow moves up by one row, focusing `task1` instead of the previous
  509. // task in tab order (`task2`).
  510. PressAndReleaseKey(ui::VKEY_UP);
  511. EXPECT_FALSE(task0->HasFocus());
  512. EXPECT_TRUE(task1->HasFocus());
  513. EXPECT_FALSE(task2->HasFocus());
  514. EXPECT_FALSE(task3->HasFocus());
  515. // Up again moves focus out of continue section.
  516. PressAndReleaseKey(ui::VKEY_UP);
  517. EXPECT_FALSE(task0->HasFocus());
  518. EXPECT_FALSE(task1->HasFocus());
  519. EXPECT_FALSE(task2->HasFocus());
  520. EXPECT_FALSE(task3->HasFocus());
  521. }
  522. TEST_F(ContinueSectionViewClamshellModeTest, FocusingChipScrollsToShowLabel) {
  523. auto* helper = GetAppListTestHelper();
  524. helper->AddContinueSuggestionResults(4);
  525. // Add enough apps to allow the apps page to scroll.
  526. helper->AddAppItems(50);
  527. EnsureLauncherShown();
  528. VerifyResultViewsUpdated();
  529. // Up arrow moves focus to the last row of the apps grid, forcing the apps
  530. // page to scroll.
  531. PressAndReleaseKey(ui::VKEY_UP);
  532. auto* scroll_view = helper->GetBubbleAppsPage()->scroll_view();
  533. const int initial_scroll_offset = scroll_view->GetVisibleRect().y();
  534. ASSERT_GT(initial_scroll_offset, 0);
  535. // Down arrow twice moves focus to search box, then to continue section.
  536. PressAndReleaseKey(ui::VKEY_DOWN);
  537. PressAndReleaseKey(ui::VKEY_DOWN);
  538. ASSERT_TRUE(GetResultViewAt(0)->HasFocus());
  539. // Scroll view has scrolled to the top to reveal the label.
  540. const int final_scroll_offset = scroll_view->GetVisibleRect().y();
  541. EXPECT_EQ(final_scroll_offset, 0);
  542. }
  543. TEST_F(ContinueSectionViewClamshellModeTest,
  544. FocusingPrivacyNoticeScrollsToShowNotice) {
  545. auto* helper = GetAppListTestHelper();
  546. helper->AddContinueSuggestionResults(4);
  547. // Add enough apps to allow the apps page to scroll.
  548. helper->AddAppItems(50);
  549. ResetPrivacyNoticePref();
  550. EnsureLauncherShown();
  551. VerifyResultViewsUpdated();
  552. ASSERT_TRUE(IsPrivacyNoticeVisible());
  553. // Up arrow moves focus to the last row of the apps grid, forcing the apps
  554. // page to scroll.
  555. PressAndReleaseKey(ui::VKEY_UP);
  556. auto* scroll_view = helper->GetBubbleAppsPage()->scroll_view();
  557. const int initial_scroll_offset = scroll_view->GetVisibleRect().y();
  558. ASSERT_GT(initial_scroll_offset, 0);
  559. // Down arrow twice moves focus to search box, then to privacy notice.
  560. PressAndReleaseKey(ui::VKEY_DOWN);
  561. PressAndReleaseKey(ui::VKEY_DOWN);
  562. auto* privacy_notice = GetContinueSectionView()->GetPrivacyNoticeForTest();
  563. ASSERT_TRUE(privacy_notice->toast_button()->HasFocus());
  564. // Scroll view has scrolled to the top to reveal the whole notice.
  565. const int final_scroll_offset = scroll_view->GetVisibleRect().y();
  566. EXPECT_EQ(final_scroll_offset, 0);
  567. }
  568. // Regression test for https://crbug.com/1273170.
  569. TEST_F(ContinueSectionViewClamshellModeTest, SearchAndCancelDoesNotChangeSize) {
  570. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  571. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  572. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  573. EnsureLauncherShown();
  574. auto* apps_grid_view = GetAppListTestHelper()->GetScrollableAppsGridView();
  575. const gfx::Point apps_grid_origin = apps_grid_view->origin();
  576. auto* continue_section_view = GetContinueSectionView();
  577. const gfx::Rect continue_section_bounds = continue_section_view->bounds();
  578. auto* widget = continue_section_view->GetWidget();
  579. // Start a search.
  580. PressAndReleaseKey(ui::VKEY_A);
  581. // Simulate the suggestions changing.
  582. GetResults()->RemoveAll();
  583. AddSearchResult("id3", AppListSearchResultType::kZeroStateFile);
  584. AddSearchResult("id4", AppListSearchResultType::kZeroStateDrive);
  585. AddSearchResult("id5", AppListSearchResultType::kZeroStateDrive);
  586. // Cancel the search.
  587. PressAndReleaseKey(ui::VKEY_ESCAPE);
  588. base::RunLoop().RunUntilIdle(); // Wait for SearchResult updates to views.
  589. widget->LayoutRootViewIfNecessary();
  590. // Continue section bounds did not grow.
  591. EXPECT_EQ(continue_section_bounds, continue_section_view->bounds());
  592. // Apps grid view position did not change.
  593. EXPECT_EQ(apps_grid_origin, apps_grid_view->origin());
  594. }
  595. TEST_P(ContinueSectionViewTest, RightClickOpensContextMenu) {
  596. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  597. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  598. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  599. EnsureLauncherShown();
  600. VerifyResultViewsUpdated();
  601. ContinueTaskView* continue_task_view = GetResultViewAt(0);
  602. EXPECT_EQ(continue_task_view->result()->id(), "id1");
  603. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  604. SimulateRightClickOrLongPressOn(continue_task_view);
  605. EXPECT_TRUE(continue_task_view->IsMenuShowing());
  606. }
  607. TEST_P(ContinueSectionViewTest, OpenWithContextMenuOption) {
  608. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  609. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  610. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  611. EnsureLauncherShown();
  612. VerifyResultViewsUpdated();
  613. ContinueTaskView* continue_task_view = GetResultViewAt(0);
  614. EXPECT_EQ(continue_task_view->result()->id(), "id1");
  615. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  616. SimulateRightClickOrLongPressOn(continue_task_view);
  617. EXPECT_TRUE(continue_task_view->IsMenuShowing());
  618. continue_task_view->ExecuteCommand(ContinueTaskCommandId::kOpenResult,
  619. ui::EF_NONE);
  620. // The item was activated.
  621. TestAppListClient* client = GetAppListTestHelper()->app_list_client();
  622. EXPECT_EQ("id1", client->last_opened_search_result());
  623. }
  624. TEST_P(ContinueSectionViewTest, RemoveWithContextMenuOption) {
  625. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  626. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  627. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  628. EnsureLauncherShown();
  629. VerifyResultViewsUpdated();
  630. EXPECT_EQ(GetResultViewAt(0)->result()->id(), "id1");
  631. RemoveSearchResultWithContextMenuAt(0);
  632. TestAppListClient* client = GetAppListTestHelper()->app_list_client();
  633. std::vector<TestAppListClient::SearchResultActionId> expected_actions = {
  634. {"id1", SearchResultActionType::kRemove}};
  635. std::vector<TestAppListClient::SearchResultActionId> invoked_actions =
  636. client->GetAndResetInvokedResultActions();
  637. EXPECT_EQ(expected_actions, invoked_actions);
  638. }
  639. TEST_P(ContinueSectionViewTest, ResultRemovedLogsMetricInBucket) {
  640. base::HistogramTester histogram_tester;
  641. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  642. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  643. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  644. AddSearchResult("id4", AppListSearchResultType::kZeroStateFile);
  645. EnsureLauncherShown();
  646. VerifyResultViewsUpdated();
  647. // Remove two results.
  648. EXPECT_EQ(GetResultViewAt(0)->result()->id(), "id1");
  649. RemoveSearchResultWithContextMenuAt(0);
  650. EXPECT_EQ(GetResultViewAt(1)->result()->id(), "id2");
  651. RemoveSearchResultWithContextMenuAt(1);
  652. TestAppListClient* client = GetAppListTestHelper()->app_list_client();
  653. std::vector<TestAppListClient::SearchResultActionId> expected_actions = {
  654. {"id1", SearchResultActionType::kRemove},
  655. {"id2", SearchResultActionType::kRemove}};
  656. std::vector<TestAppListClient::SearchResultActionId> invoked_actions =
  657. client->GetAndResetInvokedResultActions();
  658. EXPECT_EQ(expected_actions, invoked_actions);
  659. EXPECT_EQ(1, histogram_tester.GetBucketCount(
  660. kContinueSectionFilesRemovedInSessionHistogram, 1));
  661. EXPECT_EQ(1, histogram_tester.GetBucketCount(
  662. kContinueSectionFilesRemovedInSessionHistogram, 2));
  663. histogram_tester.ExpectTotalCount(
  664. kContinueSectionFilesRemovedInSessionHistogram, 2);
  665. }
  666. TEST_P(ContinueSectionViewTest, ResultRemovedContextMenuCloses) {
  667. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  668. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  669. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  670. AddSearchResult("id4", AppListSearchResultType::kZeroStateFile);
  671. EnsureLauncherShown();
  672. VerifyResultViewsUpdated();
  673. ContinueTaskView* continue_task_view = GetResultViewAt(1);
  674. EXPECT_EQ(continue_task_view->result()->id(), "id2");
  675. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  676. SimulateRightClickOrLongPressOn(continue_task_view);
  677. EXPECT_TRUE(continue_task_view->IsMenuShowing());
  678. RemoveSearchResultAt(1);
  679. VerifyResultViewsUpdated();
  680. ASSERT_EQ(std::vector<std::string>({"id1", "id3", "id4"}), GetResultIds());
  681. // Click on another result and verify it activates the item to confirm the
  682. // event is not consumed by a context menu.
  683. EXPECT_EQ(GetResultViewAt(0)->result()->id(), "id1");
  684. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  685. LeftClickOn(GetResultViewAt(0));
  686. // The item was activated.
  687. TestAppListClient* client = GetAppListTestHelper()->app_list_client();
  688. EXPECT_EQ("id1", client->last_opened_search_result());
  689. }
  690. TEST_P(ContinueSectionViewTest, UpdateAppsOnModelChange) {
  691. AddSearchResult("id11", AppListSearchResultType::kZeroStateFile);
  692. AddSearchResult("id12", AppListSearchResultType::kZeroStateDrive);
  693. AddSearchResult("id13", AppListSearchResultType::kZeroStateDrive);
  694. AddSearchResult("id14", AppListSearchResultType::kZeroStateFile);
  695. UpdateDisplay("1200x800");
  696. EnsureLauncherShown();
  697. EXPECT_EQ(std::vector<std::string>({"id11", "id12", "id13", "id14"}),
  698. GetResultIds());
  699. // Update active model, and make sure the shown results view get updated
  700. // accordingly.
  701. auto model_override = std::make_unique<test::AppListTestModel>();
  702. auto search_model_override = std::make_unique<SearchModel>();
  703. AddSearchResultToModel("id21", AppListSearchResultType::kZeroStateFile,
  704. search_model_override.get(), "Fake Title");
  705. AddSearchResultToModel("id22", AppListSearchResultType::kZeroStateFile,
  706. search_model_override.get(), "Fake Title");
  707. AddSearchResultToModel("id23", AppListSearchResultType::kZeroStateFile,
  708. search_model_override.get(), "Fake Title");
  709. Shell::Get()->app_list_controller()->SetActiveModel(
  710. /*profile_id=*/1, model_override.get(), search_model_override.get());
  711. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  712. EXPECT_EQ(std::vector<std::string>({"id21", "id22", "id23"}), GetResultIds());
  713. // Tap a result, and verify it gets activated.
  714. GestureTapOn(GetResultViewAt(2));
  715. // The item was activated.
  716. TestAppListClient* client = GetAppListTestHelper()->app_list_client();
  717. EXPECT_EQ("id23", client->last_opened_search_result());
  718. // Results should be cleared if app list models get reset.
  719. Shell::Get()->app_list_controller()->ClearActiveModel();
  720. EXPECT_EQ(std::vector<std::string>{}, GetResultIds());
  721. }
  722. TEST_F(ContinueSectionViewTabletModeTest,
  723. TabletModeLayoutWithThreeSuggestions) {
  724. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  725. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  726. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  727. UpdateDisplay("1200x800");
  728. EnsureLauncherShown();
  729. VerifyResultViewsUpdated();
  730. ASSERT_TRUE(GetContinueSectionView()->GetVisible());
  731. ASSERT_EQ(3u, GetContinueSectionView()->GetTasksSuggestionsCount());
  732. const gfx::Size size = GetResultViewAt(0)->size();
  733. const int vertical_position = GetResultViewAt(0)->y();
  734. for (int i = 1; i < 3; i++) {
  735. const ContinueTaskView* task_view = GetResultViewAt(i);
  736. EXPECT_TRUE(task_view->GetVisible());
  737. EXPECT_EQ(size, task_view->size());
  738. EXPECT_EQ(vertical_position, task_view->y());
  739. EXPECT_GT(task_view->x(), GetResultViewAt(i - 1)->bounds().right());
  740. }
  741. views::View* parent_view = GetResultViewAt(0)->parent();
  742. EXPECT_EQ(std::abs(parent_view->GetContentsBounds().x() -
  743. GetResultViewAt(0)->bounds().x()),
  744. std::abs(parent_view->GetContentsBounds().right() -
  745. GetResultViewAt(2)->bounds().right()));
  746. }
  747. TEST_F(ContinueSectionViewTabletModeTest, TabletModeLayoutWithFourSuggestions) {
  748. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  749. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  750. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  751. AddSearchResult("id4", AppListSearchResultType::kZeroStateFile);
  752. UpdateDisplay("1200x800");
  753. EnsureLauncherShown();
  754. VerifyResultViewsUpdated();
  755. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  756. ASSERT_TRUE(GetContinueSectionView()->GetVisible());
  757. ASSERT_EQ(4u, GetContinueSectionView()->GetTasksSuggestionsCount());
  758. const gfx::Size size = GetResultViewAt(0)->size();
  759. const int vertical_position = GetResultViewAt(0)->y();
  760. for (int i = 1; i < 4; i++) {
  761. const ContinueTaskView* task_view = GetResultViewAt(i);
  762. EXPECT_TRUE(task_view->GetVisible());
  763. EXPECT_EQ(size, task_view->size());
  764. EXPECT_EQ(vertical_position, task_view->y());
  765. EXPECT_GT(task_view->x(), GetResultViewAt(i - 1)->bounds().right());
  766. }
  767. views::View* parent_view = GetResultViewAt(0)->parent();
  768. EXPECT_EQ(std::abs(parent_view->GetContentsBounds().x() -
  769. GetResultViewAt(0)->bounds().x()),
  770. std::abs(parent_view->GetContentsBounds().right() -
  771. GetResultViewAt(3)->bounds().right()));
  772. }
  773. TEST_P(ContinueSectionViewTest, NoOverlapsWithRecentApps) {
  774. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  775. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  776. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  777. AddSearchResult("id4", AppListSearchResultType::kZeroStateFile);
  778. GetAppListTestHelper()->AddRecentApps(5);
  779. GetAppListTestHelper()->AddAppItems(5);
  780. EnsureLauncherShown();
  781. VerifyResultViewsUpdated();
  782. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  783. EXPECT_FALSE(GetContinueSectionView()->bounds().Intersects(
  784. GetRecentAppsView()->bounds()));
  785. }
  786. TEST_P(ContinueSectionViewTest, NoOverlapsWithAppsGridItems) {
  787. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  788. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  789. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  790. AddSearchResult("id4", AppListSearchResultType::kZeroStateFile);
  791. GetAppListTestHelper()->AddAppItems(5);
  792. EnsureLauncherShown();
  793. VerifyResultViewsUpdated();
  794. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  795. gfx::Rect continue_bounds = GetContinueSectionView()->GetBoundsInScreen();
  796. for (size_t i = 0; i < test_api()->GetItemList()->item_count(); i++) {
  797. gfx::Rect app_bounds =
  798. test_api()->GetViewAtModelIndex(i)->GetBoundsInScreen();
  799. EXPECT_FALSE(continue_bounds.Intersects(app_bounds)) << i;
  800. }
  801. }
  802. // Tests that number of shown continue section items is reduced if they don't
  803. // all fit into the available space (while maintaining min width).
  804. TEST_F(ContinueSectionViewTabletModeTest,
  805. TabletModeLayoutWithFourSuggestionsWithRestrictedSpace) {
  806. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  807. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  808. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  809. AddSearchResult("id4", AppListSearchResultType::kZeroStateFile);
  810. // Set the display width so only 2 continue section tasks fit into available
  811. // space.
  812. UpdateDisplay("600x800");
  813. EnsureLauncherShown();
  814. VerifyResultViewsUpdated();
  815. ASSERT_EQ(4u, GetContinueSectionView()->GetTasksSuggestionsCount());
  816. // Only first two tasks are visible.
  817. for (int i = 0; i < 4; ++i)
  818. EXPECT_EQ(i <= 1, GetResultViewAt(i)->GetVisible()) << i;
  819. const ContinueTaskView* first_task = GetResultViewAt(0);
  820. const ContinueTaskView* second_task = GetResultViewAt(1);
  821. EXPECT_EQ(first_task->size(), second_task->size());
  822. EXPECT_EQ(first_task->y(), second_task->y());
  823. EXPECT_GT(second_task->x(), first_task->bounds().right());
  824. }
  825. TEST_P(ContinueSectionViewTest, AllTasksShareTheSameWidth) {
  826. AddSearchResultWithTitle("id1", AppListSearchResultType::kZeroStateFile,
  827. "title");
  828. AddSearchResultWithTitle(
  829. "id2", AppListSearchResultType::kZeroStateDrive,
  830. "Really really really long title text for the label");
  831. AddSearchResultWithTitle("id3", AppListSearchResultType::kZeroStateDrive,
  832. "-");
  833. AddSearchResultWithTitle("id4", AppListSearchResultType::kZeroStateFile,
  834. "medium title");
  835. UpdateDisplay("1200x800");
  836. EnsureLauncherShown();
  837. VerifyResultViewsUpdated();
  838. ASSERT_EQ(4u, GetContinueSectionView()->GetTasksSuggestionsCount());
  839. const gfx::Size size = GetResultViewAt(0)->size();
  840. for (int i = 1; i < 4; i++) {
  841. const ContinueTaskView* task_view = GetResultViewAt(i);
  842. EXPECT_TRUE(task_view->GetVisible());
  843. EXPECT_EQ(size, task_view->size());
  844. }
  845. }
  846. TEST_P(ContinueSectionViewTest, HideContinueSectionWhithLessThanMinimumFiles) {
  847. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  848. // Minimum files for clamshell mode are 3.
  849. if (!tablet_mode_param())
  850. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  851. EnsureLauncherShown();
  852. // Wait for the view to update any pending SearchResults.
  853. base::RunLoop().RunUntilIdle();
  854. EXPECT_FALSE(GetContinueSectionView()->GetVisible());
  855. }
  856. TEST_P(ContinueSectionViewTest, ShowContinueSectionWhithMinimumFiles) {
  857. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  858. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  859. // Minimum files for clamshell mode are 3.
  860. if (!tablet_mode_param())
  861. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  862. EnsureLauncherShown();
  863. // Wait for the view to update any pending SearchResults.
  864. base::RunLoop().RunUntilIdle();
  865. EXPECT_TRUE(GetContinueSectionView()->GetVisible());
  866. }
  867. TEST_P(ContinueSectionViewTest, TaskViewHasRippleWithMenuOpen) {
  868. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  869. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  870. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  871. EnsureLauncherShown();
  872. VerifyResultViewsUpdated();
  873. ContinueTaskView* continue_task_view = GetResultViewAt(0);
  874. EXPECT_EQ(continue_task_view->result()->id(), "id1");
  875. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  876. SimulateRightClickOrLongPressOn(continue_task_view);
  877. EXPECT_TRUE(continue_task_view->IsMenuShowing());
  878. EXPECT_EQ(views::InkDropState::ACTIVATED,
  879. views::InkDrop::Get(continue_task_view)
  880. ->GetInkDrop()
  881. ->GetTargetInkDropState());
  882. }
  883. TEST_P(ContinueSectionViewTest, TaskViewHidesRippleAfterMenuCloses) {
  884. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  885. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  886. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  887. EnsureLauncherShown();
  888. VerifyResultViewsUpdated();
  889. ContinueTaskView* continue_task_view = GetResultViewAt(0);
  890. EXPECT_EQ(continue_task_view->result()->id(), "id1");
  891. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  892. SimulateRightClickOrLongPressOn(continue_task_view);
  893. EXPECT_TRUE(continue_task_view->IsMenuShowing());
  894. // Click on other task view to hide context menu.
  895. GetContinueSectionView()->GetWidget()->LayoutRootViewIfNecessary();
  896. SimulateRightClickOrLongPressOn(GetResultViewAt(2));
  897. EXPECT_FALSE(continue_task_view->IsMenuShowing());
  898. // Wait for the view to update the ink drop.
  899. base::RunLoop().RunUntilIdle();
  900. EXPECT_EQ(views::InkDropState::HIDDEN, views::InkDrop::Get(continue_task_view)
  901. ->GetInkDrop()
  902. ->GetTargetInkDropState());
  903. }
  904. TEST_P(ContinueSectionViewWithReorderNudgeTest, ShowPrivacyNotice) {
  905. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  906. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  907. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  908. ResetPrivacyNoticePref();
  909. EnsureLauncherShown();
  910. VerifyResultViewsUpdated();
  911. EXPECT_TRUE(IsPrivacyNoticeVisible());
  912. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  913. AppListNudgeController::NudgeType::kPrivacyNotice);
  914. EXPECT_NE(GetToastContainerView()->current_toast(),
  915. AppListToastType::kReorderNudge);
  916. }
  917. TEST_P(ContinueSectionViewWithReorderNudgeTest, AcceptPrivacyNotice) {
  918. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  919. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  920. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  921. ResetPrivacyNoticePref();
  922. EnsureLauncherShown();
  923. VerifyResultViewsUpdated();
  924. EXPECT_TRUE(IsPrivacyNoticeVisible());
  925. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  926. AppListNudgeController::NudgeType::kPrivacyNotice);
  927. EXPECT_NE(GetToastContainerView()->current_toast(),
  928. AppListToastType::kReorderNudge);
  929. GestureTapOn(
  930. GetContinueSectionView()->GetPrivacyNoticeForTest()->toast_button());
  931. EXPECT_FALSE(GetContinueSectionView()->ShouldShowPrivacyNotice());
  932. HideLauncher();
  933. EnsureLauncherShown();
  934. EXPECT_FALSE(IsPrivacyNoticeVisible());
  935. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  936. AppListNudgeController::NudgeType::kReorderNudge);
  937. EXPECT_EQ(GetToastContainerView()->current_toast(),
  938. AppListToastType::kReorderNudge);
  939. }
  940. TEST_P(ContinueSectionViewWithReorderNudgeTest, TimeDismissPrivacyNotice) {
  941. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  942. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  943. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  944. ResetPrivacyNoticePref();
  945. EnsureLauncherShown();
  946. VerifyResultViewsUpdated();
  947. EXPECT_TRUE(IsPrivacyNoticeVisible());
  948. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  949. AppListNudgeController::NudgeType::kPrivacyNotice);
  950. EXPECT_NE(GetToastContainerView()->current_toast(),
  951. AppListToastType::kReorderNudge);
  952. ASSERT_TRUE(GetContinueSectionView()->FirePrivacyNoticeShownTimerForTest());
  953. EXPECT_TRUE(IsPrivacyNoticeVisible());
  954. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  955. AppListNudgeController::NudgeType::kPrivacyNotice);
  956. EXPECT_NE(GetToastContainerView()->current_toast(),
  957. AppListToastType::kReorderNudge);
  958. }
  959. // TODO(crbug.com/1317428): Switch to ContinueSectionViewWithReorderNudgeTest
  960. // when this feature works in tablet mode.
  961. TEST_F(ContinueSectionViewClamshellModeTest,
  962. HidingContinueSectionHidesPrivacyNotice) {
  963. base::test::ScopedFeatureList feature_list(
  964. features::kLauncherHideContinueSection);
  965. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  966. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  967. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  968. ResetPrivacyNoticePref();
  969. EnsureLauncherShown();
  970. VerifyResultViewsUpdated();
  971. ASSERT_TRUE(IsPrivacyNoticeVisible());
  972. ASSERT_EQ(GetAppListNudgeController()->current_nudge(),
  973. AppListNudgeController::NudgeType::kPrivacyNotice);
  974. // Simulate the user hiding the continue section.
  975. Shell::Get()->app_list_controller()->SetHideContinueSection(true);
  976. EXPECT_FALSE(GetContinueSectionView()->GetVisible());
  977. // The privacy notice is suppressed.
  978. EXPECT_FALSE(IsPrivacyNoticeVisible());
  979. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  980. AppListNudgeController::NudgeType::kNone);
  981. }
  982. TEST_P(ContinueSectionViewWithReorderNudgeTest,
  983. DoNotShowPrivacyNoticeAndReorderNudgeAlternitively) {
  984. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  985. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  986. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  987. ResetPrivacyNoticePref();
  988. EnsureLauncherShown();
  989. VerifyResultViewsUpdated();
  990. EXPECT_TRUE(IsPrivacyNoticeVisible());
  991. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  992. AppListNudgeController::NudgeType::kPrivacyNotice);
  993. EXPECT_NE(GetToastContainerView()->current_toast(),
  994. AppListToastType::kReorderNudge);
  995. // Close the launcher without waiting long enough for the privacy notice to be
  996. // considered shown.
  997. HideLauncher();
  998. // The privacy notice should be showing instead of the reorder nudge when the
  999. // next time the launcher is open.
  1000. EnsureLauncherShown();
  1001. EXPECT_TRUE(IsPrivacyNoticeVisible());
  1002. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1003. AppListNudgeController::NudgeType::kPrivacyNotice);
  1004. EXPECT_NE(GetToastContainerView()->current_toast(),
  1005. AppListToastType::kReorderNudge);
  1006. }
  1007. TEST_P(ContinueSectionViewWithReorderNudgeTest,
  1008. DoNotShowPrivacyNoticeAndReorderNudgeAlternitively2) {
  1009. // Open the launcher without any search result added.
  1010. EnsureLauncherShown();
  1011. // Reorder nudge should be showing and privacy notice should not.
  1012. EXPECT_FALSE(GetContinueSectionView()->ShouldShowPrivacyNotice());
  1013. EXPECT_FALSE(GetContinueSectionView()->GetPrivacyNoticeForTest());
  1014. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1015. AppListNudgeController::NudgeType::kReorderNudge);
  1016. EXPECT_EQ(GetToastContainerView()->current_toast(),
  1017. AppListToastType::kReorderNudge);
  1018. // Wait for long enough for the reorder nudge to be considered shown.
  1019. task_environment()->AdvanceClock(base::Seconds(1));
  1020. HideLauncher();
  1021. // After hiding the launcher, add some search results and open the launcher
  1022. // again.
  1023. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  1024. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  1025. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  1026. ResetPrivacyNoticePref();
  1027. EnsureLauncherShown();
  1028. VerifyResultViewsUpdated();
  1029. // If the reorder nudge was shown and hasn't reached the shown times limit,
  1030. // keep showing the reorder nudge instead of the privacy notice.
  1031. EXPECT_FALSE(GetContinueSectionView()->ShouldShowPrivacyNotice());
  1032. EXPECT_FALSE(GetContinueSectionView()->GetPrivacyNoticeForTest());
  1033. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1034. AppListNudgeController::NudgeType::kReorderNudge);
  1035. EXPECT_EQ(GetToastContainerView()->current_toast(),
  1036. AppListToastType::kReorderNudge);
  1037. // Wait for long enough for the reorder nudge to be considered shown.
  1038. task_environment()->AdvanceClock(base::Seconds(1));
  1039. HideLauncher();
  1040. EnsureLauncherShown();
  1041. EXPECT_FALSE(GetContinueSectionView()->ShouldShowPrivacyNotice());
  1042. EXPECT_FALSE(GetContinueSectionView()->GetPrivacyNoticeForTest());
  1043. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1044. AppListNudgeController::NudgeType::kReorderNudge);
  1045. EXPECT_EQ(GetToastContainerView()->current_toast(),
  1046. AppListToastType::kReorderNudge);
  1047. // Wait for long enough for the reorder nudge to be considered shown.
  1048. task_environment()->AdvanceClock(base::Seconds(1));
  1049. HideLauncher();
  1050. EnsureLauncherShown();
  1051. // After the reorder nudge has been shown for three times, starts showing the
  1052. // privacy notice and removes the reorder nudge.
  1053. EXPECT_TRUE(IsPrivacyNoticeVisible());
  1054. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1055. AppListNudgeController::NudgeType::kPrivacyNotice);
  1056. EXPECT_NE(GetToastContainerView()->current_toast(),
  1057. AppListToastType::kReorderNudge);
  1058. }
  1059. TEST_P(ContinueSectionViewWithReorderNudgeTest,
  1060. SearchResultsFetchedAfterLauncherShown) {
  1061. ResetPrivacyNoticePref();
  1062. // Open the launcher without any search result added.
  1063. EnsureLauncherShown();
  1064. // Reorder nudge should be showing and privacy notice should not.
  1065. EXPECT_FALSE(GetContinueSectionView()->ShouldShowPrivacyNotice());
  1066. EXPECT_FALSE(GetContinueSectionView()->GetPrivacyNoticeForTest());
  1067. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1068. AppListNudgeController::NudgeType::kReorderNudge);
  1069. EXPECT_EQ(GetToastContainerView()->current_toast(),
  1070. AppListToastType::kReorderNudge);
  1071. // Add some search results while the launcher is open.
  1072. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  1073. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  1074. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  1075. VerifyResultViewsUpdated();
  1076. // Neither the privacy notice nor the search results should show.
  1077. EXPECT_FALSE(GetContinueSectionView()->ShouldShowPrivacyNotice());
  1078. EXPECT_FALSE(GetContinueSectionView()->ShouldShowFilesSection());
  1079. EXPECT_FALSE(GetContinueSectionView()->GetPrivacyNoticeForTest());
  1080. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1081. AppListNudgeController::NudgeType::kReorderNudge);
  1082. EXPECT_EQ(GetToastContainerView()->current_toast(),
  1083. AppListToastType::kReorderNudge);
  1084. // Wait for long enough for the reorder nudge to be considered shown.
  1085. task_environment()->AdvanceClock(base::Seconds(1));
  1086. HideLauncher();
  1087. // Open the launcher, wait for the reorder nudge to be shown and close it two
  1088. // more times. After the reorder nudge has been shown for three times, starts
  1089. // showing the privacy notice and removes the reorder nudge.
  1090. EnsureLauncherShown();
  1091. VerifyResultViewsUpdated();
  1092. // Wait for long enough for the reorder nudge to be considered shown.
  1093. task_environment()->AdvanceClock(base::Seconds(1));
  1094. HideLauncher();
  1095. EnsureLauncherShown();
  1096. VerifyResultViewsUpdated();
  1097. // Wait for long enough for the reorder nudge to be considered shown.
  1098. task_environment()->AdvanceClock(base::Seconds(1));
  1099. HideLauncher();
  1100. EnsureLauncherShown();
  1101. VerifyResultViewsUpdated();
  1102. EXPECT_TRUE(IsPrivacyNoticeVisible());
  1103. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1104. AppListNudgeController::NudgeType::kPrivacyNotice);
  1105. EXPECT_NE(GetToastContainerView()->current_toast(),
  1106. AppListToastType::kReorderNudge);
  1107. HideLauncher();
  1108. }
  1109. TEST_F(ContinueSectionViewTabletModeTest, PrivacyNoticeIsShownInBackground) {
  1110. AddSearchResult("id1", AppListSearchResultType::kZeroStateFile);
  1111. AddSearchResult("id2", AppListSearchResultType::kZeroStateDrive);
  1112. AddSearchResult("id3", AppListSearchResultType::kZeroStateDrive);
  1113. ResetPrivacyNoticePref();
  1114. EnsureLauncherShown();
  1115. VerifyResultViewsUpdated();
  1116. EXPECT_TRUE(IsPrivacyNoticeVisible());
  1117. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1118. AppListNudgeController::NudgeType::kPrivacyNotice);
  1119. // Activate the search box. The privacy notice will become inactive but the
  1120. // view still exists.
  1121. auto* search_box = GetAppListTestHelper()->GetSearchBoxView();
  1122. search_box->SetSearchBoxActive(true, ui::ET_MOUSE_PRESSED);
  1123. EXPECT_TRUE(IsPrivacyNoticeVisible());
  1124. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1125. AppListNudgeController::NudgeType::kPrivacyNotice);
  1126. // The privacy notice is not considered as shown when the search box is
  1127. // active. Therefore the privacy notice timer should not be running.
  1128. EXPECT_FALSE(GetContinueSectionView()->FirePrivacyNoticeShownTimerForTest());
  1129. // Reopen the app list.
  1130. HideLauncher();
  1131. EnsureLauncherShown();
  1132. // As the privacy notice was not active during the last shown, shows the
  1133. // notice again.
  1134. EXPECT_TRUE(IsPrivacyNoticeVisible());
  1135. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1136. AppListNudgeController::NudgeType::kPrivacyNotice);
  1137. // Activate the search box and then deactivate it.
  1138. search_box->SetSearchBoxActive(true, ui::ET_MOUSE_PRESSED);
  1139. search_box->SetSearchBoxActive(false, ui::ET_MOUSE_PRESSED);
  1140. // The privacy notice timer should be restarted after the search box becomes
  1141. // inactive.
  1142. EXPECT_TRUE(GetContinueSectionView()->FirePrivacyNoticeShownTimerForTest());
  1143. // Reopen the app list. The privacy notice should be removed.
  1144. HideLauncher();
  1145. EnsureLauncherShown();
  1146. EXPECT_FALSE(GetContinueSectionView()->ShouldShowPrivacyNotice());
  1147. EXPECT_FALSE(GetContinueSectionView()->GetPrivacyNoticeForTest());
  1148. }
  1149. TEST_P(ContinueSectionViewTest, InitialShowDoesNotAnimate) {
  1150. std::vector<gfx::RectF> initial_bounds =
  1151. InitializeForAnimationTest(/*result_count=*/5);
  1152. ASSERT_EQ(4u, initial_bounds.size());
  1153. std::vector<views::View*> container_children =
  1154. GetContinueSectionView()->suggestions_container()->children();
  1155. ASSERT_EQ(4u, container_children.size());
  1156. for (int i = 0; i < 4; ++i) {
  1157. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1158. EXPECT_FALSE(container_children[i]->layer()->GetAnimator()->is_animating());
  1159. }
  1160. }
  1161. TEST_P(ContinueSectionViewTest, UpdateWithNoChangesDoesNotAnimate) {
  1162. std::vector<gfx::RectF> initial_bounds =
  1163. InitializeForAnimationTest(/*result_count=*/5);
  1164. ASSERT_EQ(4u, initial_bounds.size());
  1165. GetContinueSectionView()->suggestions_container()->Update();
  1166. base::RunLoop().RunUntilIdle();
  1167. std::vector<views::View*> container_children =
  1168. GetContinueSectionView()->suggestions_container()->children();
  1169. ASSERT_EQ(4u, container_children.size());
  1170. for (int i = 0; i < 4; ++i) {
  1171. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1172. EXPECT_FALSE(container_children[i]->layer()->GetAnimator()->is_animating());
  1173. }
  1174. }
  1175. TEST_P(ContinueSectionViewTest, AnimatesWhenLastItemReplaced) {
  1176. std::vector<gfx::RectF> initial_bounds =
  1177. InitializeForAnimationTest(/*result_count=*/5);
  1178. ASSERT_EQ(4u, initial_bounds.size());
  1179. GetResults()->DeleteAt(3);
  1180. ContinueTaskContainerView* const container_view =
  1181. GetContinueSectionView()->suggestions_container();
  1182. container_view->Update();
  1183. std::vector<views::View*> container_children = container_view->children();
  1184. const size_t new_views_start = 4;
  1185. ASSERT_EQ(new_views_start + 4, container_children.size());
  1186. // The removed view should fade out.
  1187. views::View* view_fading_out = container_children[3];
  1188. EXPECT_EQ(initial_bounds[3], GetCurrentLayerBounds(view_fading_out));
  1189. EXPECT_EQ(0.0f, view_fading_out->layer()->GetTargetOpacity());
  1190. // Verify views for results that are not changing do not animate.
  1191. for (int i : std::set<int>{0, 1, 2}) {
  1192. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1193. EXPECT_FALSE(container_children[i]->GetVisible());
  1194. views::View* new_result_view = container_children[i + new_views_start];
  1195. EXPECT_FALSE(new_result_view->layer()->GetAnimator()->is_animating());
  1196. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(new_result_view));
  1197. EXPECT_EQ(1.0f, new_result_view->layer()->opacity());
  1198. }
  1199. // Verify views that are expected to slide in.
  1200. for (int i : std::set<int>{3}) {
  1201. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1202. views::View* result_view = container_children[i + new_views_start];
  1203. EXPECT_EQ(initial_bounds[i], GetTargetLayerBounds(result_view));
  1204. const gfx::RectF current_bounds = GetCurrentLayerBounds(result_view);
  1205. EXPECT_EQ(initial_bounds[i].size(), current_bounds.size());
  1206. EXPECT_LT(initial_bounds[i].x(), current_bounds.x());
  1207. EXPECT_EQ(0.0f, result_view->layer()->opacity());
  1208. EXPECT_EQ(1.0f, result_view->layer()->GetTargetOpacity());
  1209. }
  1210. WaitForAllChildrenAnimationsToComplete(container_view);
  1211. VerifyResultViewsUpdated();
  1212. container_children = container_view->children();
  1213. EXPECT_EQ(4u, container_children.size());
  1214. for (int i = 0; i < 3; ++i) {
  1215. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1216. views::View* result_view = GetResultViewAt(i);
  1217. EXPECT_EQ(initial_bounds[i], gfx::RectF(result_view->layer()->bounds()));
  1218. EXPECT_EQ(gfx::Transform(), result_view->layer()->transform());
  1219. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1220. EXPECT_EQ(gfx::Rect(), result_view->layer()->clip_rect());
  1221. }
  1222. }
  1223. TEST_P(ContinueSectionViewTest, AnimatesWhenFirstItemRemoved) {
  1224. std::vector<gfx::RectF> initial_bounds =
  1225. InitializeForAnimationTest(/*result_count=*/5);
  1226. ASSERT_EQ(4u, initial_bounds.size());
  1227. GetResults()->DeleteAt(0);
  1228. ContinueTaskContainerView* const container_view =
  1229. GetContinueSectionView()->suggestions_container();
  1230. container_view->Update();
  1231. std::vector<views::View*> container_children = container_view->children();
  1232. const size_t new_views_start = 4;
  1233. ASSERT_EQ(new_views_start + 4, container_children.size());
  1234. // The removed view should fade out.
  1235. views::View* view_fading_out = container_children[0];
  1236. EXPECT_EQ(initial_bounds[0], GetCurrentLayerBounds(view_fading_out));
  1237. EXPECT_EQ(0.0f, view_fading_out->layer()->GetTargetOpacity());
  1238. // Verify views that are expected to slide in.
  1239. for (int i : std::set<int>{0, 1, 2, 3}) {
  1240. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1241. views::View* result_view = container_children[i + new_views_start];
  1242. EXPECT_EQ(initial_bounds[i], GetTargetLayerBounds(result_view));
  1243. const gfx::RectF current_bounds = GetCurrentLayerBounds(result_view);
  1244. EXPECT_EQ(initial_bounds[i].size(), current_bounds.size());
  1245. EXPECT_LT(initial_bounds[i].x(), current_bounds.x());
  1246. EXPECT_EQ(0.0f, result_view->layer()->opacity());
  1247. EXPECT_EQ(1.0f, result_view->layer()->GetTargetOpacity());
  1248. }
  1249. // Verify views that are expected to slide out.
  1250. for (int i : std::set<int>{1, 2, 3}) {
  1251. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1252. views::View* result_view = container_children[i];
  1253. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(result_view));
  1254. const gfx::RectF target_bounds = GetTargetLayerBounds(result_view);
  1255. if (tablet_mode_param()) {
  1256. EXPECT_EQ(initial_bounds[i], target_bounds);
  1257. } else {
  1258. EXPECT_EQ(initial_bounds[i].size(), target_bounds.size());
  1259. EXPECT_GT(initial_bounds[i].x(), target_bounds.x());
  1260. }
  1261. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1262. EXPECT_EQ(0.0f, result_view->layer()->GetTargetOpacity());
  1263. }
  1264. WaitForAllChildrenAnimationsToComplete(container_view);
  1265. VerifyResultViewsUpdated();
  1266. container_children = container_view->children();
  1267. EXPECT_EQ(4u, container_children.size());
  1268. for (int i = 0; i < 3; ++i) {
  1269. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1270. views::View* result_view = GetResultViewAt(i);
  1271. EXPECT_EQ(initial_bounds[i], gfx::RectF(result_view->layer()->bounds()));
  1272. EXPECT_EQ(gfx::Transform(), result_view->layer()->transform());
  1273. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1274. }
  1275. }
  1276. TEST_P(ContinueSectionViewTest, AnimatesWhenSecondItemRemoved) {
  1277. std::vector<gfx::RectF> initial_bounds =
  1278. InitializeForAnimationTest(/*result_count=*/5);
  1279. ASSERT_EQ(4u, initial_bounds.size());
  1280. GetResults()->DeleteAt(1);
  1281. ContinueTaskContainerView* const container_view =
  1282. GetContinueSectionView()->suggestions_container();
  1283. container_view->Update();
  1284. std::vector<views::View*> container_children = container_view->children();
  1285. const size_t new_views_start = 4;
  1286. ASSERT_EQ(new_views_start + 4, container_children.size());
  1287. // The removed view should fade out.
  1288. views::View* view_fading_out = container_children[0];
  1289. EXPECT_EQ(initial_bounds[0], GetCurrentLayerBounds(view_fading_out));
  1290. EXPECT_EQ(1.0f, view_fading_out->layer()->GetTargetOpacity());
  1291. // Verify the view for the result that's not changing does not animate.
  1292. EXPECT_FALSE(container_children[0]->GetVisible());
  1293. views::View* stationary_view = container_children[new_views_start];
  1294. EXPECT_FALSE(stationary_view->layer()->GetAnimator()->is_animating());
  1295. EXPECT_EQ(initial_bounds[0], GetCurrentLayerBounds(stationary_view));
  1296. EXPECT_EQ(1.0f, stationary_view->layer()->opacity());
  1297. // Verify views that are expected to slide in.
  1298. for (int i : std::set<int>{1, 2, 3}) {
  1299. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1300. views::View* result_view = container_children[i + new_views_start];
  1301. EXPECT_EQ(initial_bounds[i], GetTargetLayerBounds(result_view));
  1302. const gfx::RectF current_bounds = GetCurrentLayerBounds(result_view);
  1303. EXPECT_EQ(initial_bounds[i].size(), current_bounds.size());
  1304. EXPECT_LT(initial_bounds[i].x(), current_bounds.x());
  1305. EXPECT_EQ(0.0f, result_view->layer()->opacity());
  1306. EXPECT_EQ(1.0f, result_view->layer()->GetTargetOpacity());
  1307. }
  1308. // Verify views that are expected to slide out.
  1309. for (int i : std::set<int>{2, 3}) {
  1310. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1311. views::View* result_view = container_children[i];
  1312. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(result_view));
  1313. const gfx::RectF target_bounds = GetTargetLayerBounds(result_view);
  1314. if (tablet_mode_param()) {
  1315. EXPECT_EQ(initial_bounds[i], target_bounds);
  1316. } else {
  1317. EXPECT_EQ(initial_bounds[i].size(), target_bounds.size());
  1318. EXPECT_GT(initial_bounds[i].x(), target_bounds.x());
  1319. }
  1320. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1321. EXPECT_EQ(0.0f, result_view->layer()->GetTargetOpacity());
  1322. }
  1323. WaitForAllChildrenAnimationsToComplete(container_view);
  1324. VerifyResultViewsUpdated();
  1325. container_children = container_view->children();
  1326. EXPECT_EQ(4u, container_children.size());
  1327. for (int i = 0; i < 3; ++i) {
  1328. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1329. views::View* result_view = GetResultViewAt(i);
  1330. EXPECT_EQ(initial_bounds[i], gfx::RectF(result_view->layer()->bounds()));
  1331. EXPECT_EQ(gfx::Transform(), result_view->layer()->transform());
  1332. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1333. EXPECT_EQ(gfx::Rect(), result_view->layer()->clip_rect());
  1334. }
  1335. }
  1336. TEST_P(ContinueSectionViewTest, AnimatesWhenThirdItemRemoved) {
  1337. std::vector<gfx::RectF> initial_bounds =
  1338. InitializeForAnimationTest(/*result_count=*/5);
  1339. ASSERT_EQ(4u, initial_bounds.size());
  1340. GetResults()->DeleteAt(2);
  1341. ContinueTaskContainerView* const container_view =
  1342. GetContinueSectionView()->suggestions_container();
  1343. container_view->Update();
  1344. std::vector<views::View*> container_children = container_view->children();
  1345. const size_t new_views_start = 4;
  1346. ASSERT_EQ(new_views_start + 4, container_children.size());
  1347. // The removed view should fade out.
  1348. views::View* view_fading_out = container_children[2];
  1349. EXPECT_EQ(initial_bounds[2], GetCurrentLayerBounds(view_fading_out));
  1350. EXPECT_EQ(0.0f, view_fading_out->layer()->GetTargetOpacity());
  1351. // Verify views for results that are not changing do not animate.
  1352. for (int i : std::set<int>{0, 1}) {
  1353. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1354. EXPECT_FALSE(container_children[i]->GetVisible());
  1355. views::View* new_result_view = container_children[i + new_views_start];
  1356. EXPECT_FALSE(new_result_view->layer()->GetAnimator()->is_animating());
  1357. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(new_result_view));
  1358. EXPECT_EQ(1.0f, new_result_view->layer()->opacity());
  1359. }
  1360. // Verify views that are expected to slide in.
  1361. for (int i : std::set<int>{2, 3}) {
  1362. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1363. views::View* result_view = container_children[i + new_views_start];
  1364. EXPECT_EQ(initial_bounds[i], GetTargetLayerBounds(result_view));
  1365. const gfx::RectF current_bounds = GetCurrentLayerBounds(result_view);
  1366. EXPECT_EQ(initial_bounds[i].size(), current_bounds.size());
  1367. EXPECT_LT(initial_bounds[i].x(), current_bounds.x());
  1368. EXPECT_EQ(0.0f, result_view->layer()->opacity());
  1369. EXPECT_EQ(1.0f, result_view->layer()->GetTargetOpacity());
  1370. }
  1371. // Verify views that are expected to slide out.
  1372. for (int i : std::set<int>{3}) {
  1373. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1374. views::View* result_view = container_children[i];
  1375. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(result_view));
  1376. const gfx::RectF target_bounds = GetTargetLayerBounds(result_view);
  1377. if (tablet_mode_param()) {
  1378. EXPECT_EQ(initial_bounds[i], target_bounds);
  1379. } else {
  1380. EXPECT_EQ(initial_bounds[i].size(), target_bounds.size());
  1381. EXPECT_GT(initial_bounds[i].x(), target_bounds.x());
  1382. }
  1383. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1384. EXPECT_EQ(0.0f, result_view->layer()->GetTargetOpacity());
  1385. }
  1386. WaitForAllChildrenAnimationsToComplete(container_view);
  1387. VerifyResultViewsUpdated();
  1388. container_children = container_view->children();
  1389. EXPECT_EQ(4u, container_children.size());
  1390. for (int i = 0; i < 3; ++i) {
  1391. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1392. views::View* result_view = GetResultViewAt(i);
  1393. EXPECT_EQ(initial_bounds[i], gfx::RectF(result_view->layer()->bounds()));
  1394. EXPECT_EQ(gfx::Transform(), result_view->layer()->transform());
  1395. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1396. EXPECT_EQ(gfx::Rect(), result_view->layer()->clip_rect());
  1397. }
  1398. }
  1399. TEST_P(ContinueSectionViewTest, AnimatesWhenItemInserted) {
  1400. std::vector<gfx::RectF> initial_bounds =
  1401. InitializeForAnimationTest(/*result_count=*/4);
  1402. ASSERT_EQ(4u, initial_bounds.size());
  1403. GetResults()->AddAt(
  1404. 1, CreateTestResult("id5", AppListSearchResultType::kZeroStateDrive,
  1405. "new result"));
  1406. ContinueTaskContainerView* const container_view =
  1407. GetContinueSectionView()->suggestions_container();
  1408. container_view->Update();
  1409. std::vector<views::View*> container_children = container_view->children();
  1410. const size_t new_views_start = 4;
  1411. ASSERT_EQ(new_views_start + 4, container_children.size());
  1412. // The removed view should fade out.
  1413. views::View* view_fading_out = container_children[3];
  1414. EXPECT_EQ(initial_bounds[3], GetCurrentLayerBounds(view_fading_out));
  1415. EXPECT_EQ(0.0f, view_fading_out->layer()->GetTargetOpacity());
  1416. // Verify views for results that are not changing do not animate.
  1417. for (int i : std::set<int>{0}) {
  1418. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1419. EXPECT_FALSE(container_children[i]->GetVisible());
  1420. views::View* new_result_view = container_children[i + new_views_start];
  1421. EXPECT_FALSE(new_result_view->layer()->GetAnimator()->is_animating());
  1422. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(new_result_view));
  1423. EXPECT_EQ(1.0f, new_result_view->layer()->opacity());
  1424. }
  1425. // Verify views that are expected to slide in.
  1426. for (int i : std::set<int>{1, 2, 3}) {
  1427. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1428. views::View* result_view = container_children[i + new_views_start];
  1429. EXPECT_EQ(initial_bounds[i], GetTargetLayerBounds(result_view));
  1430. const gfx::RectF current_bounds = GetCurrentLayerBounds(result_view);
  1431. EXPECT_EQ(initial_bounds[i].size(), current_bounds.size());
  1432. if (tablet_mode_param() && i > 1) {
  1433. EXPECT_GT(initial_bounds[i].x(), current_bounds.x());
  1434. } else {
  1435. EXPECT_LT(initial_bounds[i].x(), current_bounds.x());
  1436. }
  1437. EXPECT_EQ(0.0f, result_view->layer()->opacity());
  1438. EXPECT_EQ(1.0f, result_view->layer()->GetTargetOpacity());
  1439. }
  1440. // Verify views that are expected to slide out.
  1441. for (int i : std::set<int>{1, 2}) {
  1442. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1443. views::View* result_view = container_children[i];
  1444. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(result_view));
  1445. const gfx::RectF target_bounds = GetTargetLayerBounds(result_view);
  1446. if (tablet_mode_param()) {
  1447. EXPECT_EQ(initial_bounds[i], target_bounds);
  1448. } else {
  1449. EXPECT_EQ(initial_bounds[i].size(), target_bounds.size());
  1450. EXPECT_GT(initial_bounds[i].x(), target_bounds.x());
  1451. }
  1452. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1453. EXPECT_EQ(0.0f, result_view->layer()->GetTargetOpacity());
  1454. }
  1455. WaitForAllChildrenAnimationsToComplete(container_view);
  1456. VerifyResultViewsUpdated();
  1457. container_children = container_view->children();
  1458. EXPECT_EQ(4u, container_children.size());
  1459. for (int i = 0; i < 3; ++i) {
  1460. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1461. views::View* result_view = GetResultViewAt(i);
  1462. EXPECT_EQ(initial_bounds[i], gfx::RectF(result_view->layer()->bounds()));
  1463. EXPECT_EQ(gfx::Transform(), result_view->layer()->transform());
  1464. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1465. EXPECT_EQ(gfx::Rect(), result_view->layer()->clip_rect());
  1466. }
  1467. }
  1468. TEST_P(ContinueSectionViewTest, AnimatesWhenTwoItemsRemoved) {
  1469. std::vector<gfx::RectF> initial_bounds =
  1470. InitializeForAnimationTest(/*result_count=*/6);
  1471. ASSERT_EQ(4u, initial_bounds.size());
  1472. GetResults()->DeleteAt(1);
  1473. GetResults()->DeleteAt(1);
  1474. ContinueTaskContainerView* const container_view =
  1475. GetContinueSectionView()->suggestions_container();
  1476. container_view->Update();
  1477. std::vector<views::View*> container_children = container_view->children();
  1478. const size_t new_views_start = 4;
  1479. ASSERT_EQ(new_views_start + 4, container_children.size());
  1480. // Removed views should fade out.
  1481. for (int i : std::set<int>{1, 2}) {
  1482. views::View* view_fading_out = container_children[i];
  1483. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(view_fading_out));
  1484. EXPECT_EQ(0.0f, view_fading_out->layer()->GetTargetOpacity());
  1485. }
  1486. // Verify views for results that are not changing do not animate.
  1487. for (int i : std::set<int>{0}) {
  1488. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1489. EXPECT_FALSE(container_children[i]->GetVisible());
  1490. views::View* new_result_view = container_children[i + new_views_start];
  1491. EXPECT_FALSE(new_result_view->layer()->GetAnimator()->is_animating());
  1492. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(new_result_view));
  1493. EXPECT_EQ(1.0f, new_result_view->layer()->opacity());
  1494. }
  1495. // Verify views that are expected to slide in.
  1496. for (int i : std::set<int>{1, 2, 3}) {
  1497. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1498. views::View* result_view = container_children[i + new_views_start];
  1499. EXPECT_EQ(initial_bounds[i], GetTargetLayerBounds(result_view));
  1500. const gfx::RectF current_bounds = GetCurrentLayerBounds(result_view);
  1501. EXPECT_EQ(initial_bounds[i].size(), current_bounds.size());
  1502. EXPECT_LT(initial_bounds[i].x(), current_bounds.x());
  1503. EXPECT_EQ(0.0f, result_view->layer()->opacity());
  1504. EXPECT_EQ(1.0f, result_view->layer()->GetTargetOpacity());
  1505. }
  1506. // Verify views that are expected to slide out.
  1507. for (int i : std::set<int>{3}) {
  1508. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1509. views::View* result_view = container_children[i];
  1510. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(result_view));
  1511. const gfx::RectF target_bounds = GetTargetLayerBounds(result_view);
  1512. if (tablet_mode_param()) {
  1513. EXPECT_EQ(initial_bounds[i], target_bounds);
  1514. } else {
  1515. EXPECT_EQ(initial_bounds[i].size(), target_bounds.size());
  1516. EXPECT_GT(initial_bounds[i].x(), target_bounds.x());
  1517. }
  1518. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1519. EXPECT_EQ(0.0f, result_view->layer()->GetTargetOpacity());
  1520. }
  1521. WaitForAllChildrenAnimationsToComplete(container_view);
  1522. VerifyResultViewsUpdated();
  1523. container_children = container_view->children();
  1524. EXPECT_EQ(4u, container_children.size());
  1525. for (int i = 0; i < 4; ++i) {
  1526. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1527. views::View* result_view = GetResultViewAt(i);
  1528. EXPECT_EQ(initial_bounds[i], gfx::RectF(result_view->layer()->bounds()));
  1529. EXPECT_EQ(gfx::Transform(), result_view->layer()->transform());
  1530. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1531. EXPECT_EQ(gfx::Rect(), result_view->layer()->clip_rect());
  1532. }
  1533. }
  1534. TEST_P(ContinueSectionViewTest, ResultRemovedMidAnimation) {
  1535. std::vector<gfx::RectF> initial_bounds =
  1536. InitializeForAnimationTest(/*result_count=*/6);
  1537. ASSERT_EQ(4u, initial_bounds.size());
  1538. GetResults()->DeleteAt(1);
  1539. ContinueTaskContainerView* const container_view =
  1540. GetContinueSectionView()->suggestions_container();
  1541. container_view->Update();
  1542. // Remove another result after update (which triggers an update animation).
  1543. GetResults()->DeleteAt(1);
  1544. container_view->Update();
  1545. std::vector<views::View*> container_children = container_view->children();
  1546. const size_t new_views_start = 4;
  1547. ASSERT_EQ(new_views_start + 4, container_children.size());
  1548. // The removed view should fade out.
  1549. views::View* view_fading_out = container_children[1];
  1550. EXPECT_EQ(initial_bounds[1], GetCurrentLayerBounds(view_fading_out));
  1551. EXPECT_EQ(0.0f, view_fading_out->layer()->GetTargetOpacity());
  1552. // Verify views for results that are not changing do not animate.
  1553. for (int i : std::set<int>{0}) {
  1554. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1555. EXPECT_FALSE(container_children[i]->GetVisible());
  1556. views::View* new_result_view = container_children[i + new_views_start];
  1557. EXPECT_FALSE(new_result_view->layer()->GetAnimator()->is_animating());
  1558. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(new_result_view));
  1559. EXPECT_EQ(1.0f, new_result_view->layer()->opacity());
  1560. }
  1561. // Verify views that are expected to slide in.
  1562. for (int i : std::set<int>{1, 2, 3}) {
  1563. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1564. views::View* result_view = container_children[i + new_views_start];
  1565. EXPECT_EQ(initial_bounds[i], GetTargetLayerBounds(result_view));
  1566. const gfx::RectF current_bounds = GetCurrentLayerBounds(result_view);
  1567. EXPECT_EQ(initial_bounds[i].size(), current_bounds.size());
  1568. EXPECT_LT(initial_bounds[i].x(), current_bounds.x());
  1569. EXPECT_EQ(0.0f, result_view->layer()->opacity());
  1570. EXPECT_EQ(1.0f, result_view->layer()->GetTargetOpacity());
  1571. }
  1572. // Verify views that are expected to slide out.
  1573. for (int i : std::set<int>{2, 3}) {
  1574. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1575. views::View* result_view = container_children[i];
  1576. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(result_view));
  1577. const gfx::RectF target_bounds = GetTargetLayerBounds(result_view);
  1578. if (tablet_mode_param()) {
  1579. EXPECT_EQ(initial_bounds[i], target_bounds);
  1580. } else {
  1581. EXPECT_EQ(initial_bounds[i].size(), target_bounds.size());
  1582. EXPECT_GT(initial_bounds[i].x(), target_bounds.x());
  1583. }
  1584. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1585. EXPECT_EQ(0.0f, result_view->layer()->GetTargetOpacity());
  1586. }
  1587. WaitForAllChildrenAnimationsToComplete(container_view);
  1588. VerifyResultViewsUpdated();
  1589. container_children = container_view->children();
  1590. EXPECT_EQ(4u, container_children.size());
  1591. for (int i = 0; i < 3; ++i) {
  1592. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1593. views::View* result_view = GetResultViewAt(i);
  1594. EXPECT_EQ(initial_bounds[i], gfx::RectF(result_view->layer()->bounds()));
  1595. EXPECT_EQ(gfx::Transform(), result_view->layer()->transform());
  1596. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1597. EXPECT_EQ(gfx::Rect(), result_view->layer()->clip_rect());
  1598. }
  1599. }
  1600. TEST_P(ContinueSectionViewTest, ContinueSectionHiddenMidAnimation) {
  1601. std::vector<gfx::RectF> initial_bounds =
  1602. InitializeForAnimationTest(/*result_count=*/4);
  1603. ASSERT_EQ(4u, initial_bounds.size());
  1604. // Remove one item to trigger update animation.
  1605. GetResults()->DeleteAt(1);
  1606. ContinueTaskContainerView* const container_view =
  1607. GetContinueSectionView()->suggestions_container();
  1608. container_view->Update();
  1609. // Remove two extra results which should hide the continue section.
  1610. GetResults()->DeleteAt(0);
  1611. GetResults()->DeleteAt(0);
  1612. container_view->Update();
  1613. EXPECT_FALSE(GetContinueSectionView()->GetVisible());
  1614. std::vector<views::View*> container_children = container_view->children();
  1615. ASSERT_EQ(1u, container_children.size());
  1616. EXPECT_FALSE(container_children[0]->layer()->GetAnimator()->is_animating());
  1617. }
  1618. TEST_P(ContinueSectionViewTest, AnimatesWhenNumberOfChipsChanges) {
  1619. std::vector<gfx::RectF> initial_bounds =
  1620. InitializeForAnimationTest(/*result_count=*/4);
  1621. ASSERT_EQ(4u, initial_bounds.size());
  1622. GetResults()->DeleteAt(2);
  1623. ContinueTaskContainerView* const container_view =
  1624. GetContinueSectionView()->suggestions_container();
  1625. container_view->Update();
  1626. std::vector<views::View*> container_children = container_view->children();
  1627. const size_t new_views_start = 4;
  1628. ASSERT_EQ(new_views_start + 3, container_children.size());
  1629. // The removed view should fade out.
  1630. views::View* view_fading_out = container_children[2];
  1631. EXPECT_EQ(initial_bounds[2], GetCurrentLayerBounds(view_fading_out));
  1632. EXPECT_EQ(0.0f, view_fading_out->layer()->GetTargetOpacity());
  1633. // In tablet mode, all views animate when the number of items shown in the
  1634. // container changes.
  1635. if (tablet_mode_param()) {
  1636. for (int i : std::set<int>{0, 1, 3}) {
  1637. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1638. const bool result_after_removed = i > 2;
  1639. views::View* new_result_view =
  1640. container_children[i + new_views_start -
  1641. (result_after_removed ? 1 : 0)];
  1642. const gfx::RectF current_bounds = GetCurrentLayerBounds(new_result_view);
  1643. EXPECT_EQ(initial_bounds[i].y(), current_bounds.y());
  1644. EXPECT_LT(initial_bounds[i].width(), current_bounds.width());
  1645. const gfx::RectF new_view_target_bounds =
  1646. GetTargetLayerBounds(new_result_view);
  1647. EXPECT_EQ(current_bounds.size(), new_view_target_bounds.size());
  1648. // Items after removed item should animate from the right, and items
  1649. // before the removed item should animate from the left.
  1650. if (i > 1) {
  1651. EXPECT_LT(new_view_target_bounds.x(), current_bounds.x());
  1652. } else {
  1653. EXPECT_GT(new_view_target_bounds.x(), current_bounds.x());
  1654. }
  1655. EXPECT_EQ(0.0f, new_result_view->layer()->opacity());
  1656. EXPECT_EQ(1.0f, new_result_view->layer()->GetTargetOpacity());
  1657. views::View* old_result_view = container_children[i];
  1658. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(old_result_view));
  1659. const gfx::RectF target_bounds = GetTargetLayerBounds(old_result_view);
  1660. EXPECT_EQ(initial_bounds[i].size(), target_bounds.size());
  1661. EXPECT_EQ(initial_bounds[i].x(), target_bounds.x());
  1662. EXPECT_EQ(1.0f, old_result_view->layer()->opacity());
  1663. EXPECT_EQ(0.0f, old_result_view->layer()->GetTargetOpacity());
  1664. }
  1665. } else {
  1666. // Views before removed one should not animate.
  1667. for (int i : std::set<int>{0, 1}) {
  1668. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1669. EXPECT_FALSE(container_children[i]->GetVisible());
  1670. views::View* new_result_view = container_children[new_views_start + i];
  1671. EXPECT_FALSE(new_result_view->layer()->GetAnimator()->is_animating());
  1672. EXPECT_EQ(initial_bounds[i], GetCurrentLayerBounds(new_result_view));
  1673. EXPECT_EQ(1.0f, new_result_view->layer()->opacity());
  1674. }
  1675. // The last new view should slide in.
  1676. views::View* last_new_result_view = container_children[new_views_start + 2];
  1677. EXPECT_EQ(initial_bounds[2], GetTargetLayerBounds(last_new_result_view));
  1678. const gfx::RectF last_old_current_bounds =
  1679. GetCurrentLayerBounds(last_new_result_view);
  1680. EXPECT_EQ(initial_bounds[2].size(), last_old_current_bounds.size());
  1681. EXPECT_LT(initial_bounds[2].x(), last_old_current_bounds.x());
  1682. EXPECT_EQ(0.0f, last_new_result_view->layer()->opacity());
  1683. EXPECT_EQ(1.0f, last_new_result_view->layer()->GetTargetOpacity());
  1684. // The last old view should slide out.
  1685. views::View* last_old_result_view = container_children[3];
  1686. EXPECT_EQ(initial_bounds[3], GetCurrentLayerBounds(last_old_result_view));
  1687. const gfx::RectF last_old_target_bounds =
  1688. GetTargetLayerBounds(last_old_result_view);
  1689. EXPECT_EQ(initial_bounds[3].size(), last_old_target_bounds.size());
  1690. EXPECT_GT(initial_bounds[3].x(), last_old_target_bounds.x());
  1691. EXPECT_EQ(1.0f, last_old_result_view->layer()->opacity());
  1692. EXPECT_EQ(0.0f, last_old_result_view->layer()->GetTargetOpacity());
  1693. }
  1694. WaitForAllChildrenAnimationsToComplete(container_view);
  1695. VerifyResultViewsUpdated();
  1696. container_children = container_view->children();
  1697. EXPECT_EQ(3u, container_children.size());
  1698. for (int i = 0; i < 2; ++i) {
  1699. SCOPED_TRACE(testing::Message() << "Item at " << i);
  1700. views::View* result_view = GetResultViewAt(i);
  1701. if (tablet_mode_param()) {
  1702. EXPECT_EQ(initial_bounds[i].y(), result_view->layer()->bounds().y());
  1703. } else {
  1704. EXPECT_EQ(initial_bounds[i], gfx::RectF(result_view->layer()->bounds()));
  1705. }
  1706. EXPECT_EQ(gfx::Transform(), result_view->layer()->transform());
  1707. EXPECT_EQ(1.0f, result_view->layer()->opacity());
  1708. }
  1709. }
  1710. TEST_F(ContinueSectionViewClamshellModeTest, AnimatesOutAfterRemovingResults) {
  1711. ResetPrivacyNoticePref();
  1712. InitializeForAnimationTest(/*result_count=*/3);
  1713. EXPECT_TRUE(IsPrivacyNoticeVisible());
  1714. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1715. AppListNudgeController::NudgeType::kPrivacyNotice);
  1716. views::View* privacy_notice =
  1717. GetContinueSectionView()->GetPrivacyNoticeForTest();
  1718. RemoveSearchResultAt(1);
  1719. ContinueTaskContainerView* const container_view =
  1720. GetContinueSectionView()->suggestions_container();
  1721. container_view->Update();
  1722. EXPECT_EQ(1.0f, privacy_notice->layer()->opacity());
  1723. EXPECT_EQ(0.0f, privacy_notice->layer()->GetTargetOpacity());
  1724. EXPECT_TRUE(privacy_notice->layer()->GetAnimator()->is_animating());
  1725. LayerAnimationStoppedWaiter waiter;
  1726. waiter.Wait(privacy_notice->layer());
  1727. VerifyResultViewsUpdated();
  1728. ASSERT_LE(GetContinueSectionView()->GetTasksSuggestionsCount(), 2u);
  1729. EXPECT_FALSE(IsPrivacyNoticeVisible());
  1730. EXPECT_FALSE(GetContinueSectionView()->GetVisible());
  1731. }
  1732. TEST_P(ContinueSectionViewTest, AnimatesPrivacyNoticeAccept) {
  1733. ResetPrivacyNoticePref();
  1734. InitializeForAnimationTest(/*result_count=*/3);
  1735. EXPECT_TRUE(IsPrivacyNoticeVisible());
  1736. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1737. AppListNudgeController::NudgeType::kPrivacyNotice);
  1738. AppListToastView* privacy_notice =
  1739. GetContinueSectionView()->GetPrivacyNoticeForTest();
  1740. GestureTapOn(privacy_notice->toast_button());
  1741. EXPECT_EQ(1.0f, privacy_notice->layer()->opacity());
  1742. EXPECT_EQ(0.0f, privacy_notice->layer()->GetTargetOpacity());
  1743. EXPECT_TRUE(privacy_notice->layer()->GetAnimator()->is_animating());
  1744. LayerAnimationStoppedWaiter waiter;
  1745. waiter.Wait(privacy_notice->layer());
  1746. ContinueTaskContainerView* container_view =
  1747. GetContinueSectionView()->suggestions_container();
  1748. EXPECT_TRUE(container_view->layer()->GetAnimator()->is_animating());
  1749. WaitForAllChildrenAnimationsToComplete(container_view);
  1750. EXPECT_FALSE(IsPrivacyNoticeVisible());
  1751. EXPECT_TRUE(GetContinueSectionView()->GetVisible());
  1752. }
  1753. // Regression test for https://crbug.com/1326237.
  1754. TEST_F(ContinueSectionViewClamshellModeTest,
  1755. RemoveSearchResultWhileAnimatingContinueSection) {
  1756. ResetPrivacyNoticePref();
  1757. InitializeForAnimationTest(/*result_count=*/3);
  1758. EXPECT_TRUE(IsPrivacyNoticeVisible());
  1759. EXPECT_EQ(GetAppListNudgeController()->current_nudge(),
  1760. AppListNudgeController::NudgeType::kPrivacyNotice);
  1761. AppListToastView* privacy_notice =
  1762. GetContinueSectionView()->GetPrivacyNoticeForTest();
  1763. GestureTapOn(privacy_notice->toast_button());
  1764. EXPECT_EQ(1.0f, privacy_notice->layer()->opacity());
  1765. EXPECT_EQ(0.0f, privacy_notice->layer()->GetTargetOpacity());
  1766. EXPECT_TRUE(privacy_notice->layer()->GetAnimator()->is_animating());
  1767. RemoveSearchResultAt(0);
  1768. EXPECT_EQ(0.0f, privacy_notice->layer()->GetTargetOpacity());
  1769. EXPECT_TRUE(privacy_notice->layer()->GetAnimator()->is_animating());
  1770. LayerAnimationStoppedWaiter waiter;
  1771. waiter.Wait(privacy_notice->layer());
  1772. WaitForAllChildrenAnimationsToComplete(
  1773. GetContinueSectionView()->suggestions_container());
  1774. EXPECT_FALSE(IsPrivacyNoticeVisible());
  1775. EXPECT_FALSE(GetContinueSectionView()->GetVisible());
  1776. }
  1777. } // namespace
  1778. } // namespace ash