Commit 0f12b028 authored by Weilun Shi's avatar Weilun Shi Committed by Commit Bot

[NTP] Add automated test for custom links hide add button

Add button should be hidden when there are max number of most visited
tiles.

Bug: 881091
Change-Id: I40d33e533691885204f1fd813ce077fb060678d9
Reviewed-on: https://chromium-review.googlesource.com/1214180
Commit-Queue: Weilun Shi <sweilun@chromium.org>
Reviewed-by: default avatarKristi Park <kristipark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590068}
parent fa02ec1e
...@@ -58,6 +58,10 @@ namespace { ...@@ -58,6 +58,10 @@ namespace {
// default TopSites tile (see history::PrepopulatedPage). // default TopSites tile (see history::PrepopulatedPage).
const int kDefaultMostVisitedItemCount = 1; const int kDefaultMostVisitedItemCount = 1;
// This is the default maximum custom links we can have. The number comes from
// ntp_tiles::CustomLinksManager.
const int kDefaultCustomLinkMaxCount = 10;
class TestMostVisitedObserver : public InstantServiceObserver { class TestMostVisitedObserver : public InstantServiceObserver {
public: public:
explicit TestMostVisitedObserver(InstantService* service) explicit TestMostVisitedObserver(InstantService* service)
...@@ -622,7 +626,47 @@ IN_PROC_BROWSER_TEST_F(LocalNTPCustomLinksTest, ShowsAddCustomLinkButton) { ...@@ -622,7 +626,47 @@ IN_PROC_BROWSER_TEST_F(LocalNTPCustomLinksTest, ShowsAddCustomLinkButton) {
EXPECT_TRUE(has_add_button); EXPECT_TRUE(has_add_button);
} }
// TODO(851293): Add test for not showing add button when at max links. IN_PROC_BROWSER_TEST_F(LocalNTPCustomLinksTest,
DontShowAddCustomLinkButtonWhenMaxLinks) {
content::WebContents* active_tab =
local_ntp_test_utils::OpenNewTab(browser(), GURL("about:blank"));
TestMostVisitedObserver observer(
InstantServiceFactory::GetForProfile(browser()->profile()));
local_ntp_test_utils::NavigateToNTPAndWaitUntilLoaded(browser());
observer.WaitForNumberOfItems(kDefaultMostVisitedItemCount);
// Get the iframe and add to maximum number of tiles.
content::RenderFrameHost* iframe = GetMostVisitedIframe(active_tab);
for (int i = kDefaultMostVisitedItemCount; i < kDefaultCustomLinkMaxCount;
++i) {
std::string rid = std::to_string(i + 100);
std::string url = "https://" + rid + ".com";
std::string title = "url for" + rid;
// Add most visited tiles via the EmbeddedSearch API. rid = -1 means add new
// most visited tile.
EXPECT_TRUE(content::ExecuteScript(
iframe,
"window.chrome.embeddedSearch.newTabPage.updateCustomLink(-1, '" + url +
"', '" + title + "')"));
}
// Confirm that there are max number of custom link tiles.
observer.WaitForNumberOfItems(kDefaultCustomLinkMaxCount);
// Open a new tab and check if the add button still exists
active_tab = local_ntp_test_utils::OpenNewTab(browser(), GURL("about:blank"));
local_ntp_test_utils::NavigateToNTPAndWaitUntilLoaded(browser());
iframe = GetMostVisitedIframe(active_tab);
// Check there is no add button in the iframe.
bool no_add_button = false;
ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
iframe, "document.querySelectorAll('.md-add-icon').length === 0",
&no_add_button));
EXPECT_TRUE(no_add_button);
}
// A minimal implementation of an interstitial page. // A minimal implementation of an interstitial page.
class TestInterstitialPageDelegate : public content::InterstitialPageDelegate { class TestInterstitialPageDelegate : public content::InterstitialPageDelegate {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment