Commit d8844385 authored by Mathieu Perreault's avatar Mathieu Perreault Committed by Commit Bot

[New Tab Page] Add a custom links test case to the render framework.

Bug: 863174
Change-Id: I4d694bc9d8faedb7d74a5aedb0d6bf7caffc8d0a
Reviewed-on: https://chromium-review.googlesource.com/1157662Reviewed-by: default avatarKristi Park <kristipark@chromium.org>
Commit-Queue: Mathieu Perreault <mathp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579882}
parent a701a64a
......@@ -10,14 +10,18 @@
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/instant_service.h"
#include "chrome/browser/search/instant_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/search/local_ntp_test_utils.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/ntp_tiles/constants.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
......@@ -49,7 +53,8 @@ class LocalNTPRenderTest : public InProcessBrowserTest {
public:
LocalNTPRenderTest() {
// Making sure we are running with the Local NTP.
feature_list_.InitWithFeatures({features::kUseGoogleLocalNtp}, {});
feature_list_.InitWithFeatures(
{features::kUseGoogleLocalNtp, ntp_tiles::kNtpCustomLinks}, {});
}
void SetUpCommandLine(base::CommandLine* command_line) override {
......@@ -57,6 +62,36 @@ class LocalNTPRenderTest : public InProcessBrowserTest {
command_line->AppendSwitch(switches::kEnablePixelOutputInTests);
}
void LoadNewTabPageAndCapture(int viewport_width,
int viewport_height,
const std::string& filename) {
// Open an NTP and wait until it has fully loaded (tiles may animate, so we
// give this some delay).
local_ntp_test_utils::NavigateToNTPAndWaitUntilLoaded(browser(),
/*delay=*/1000);
content::WebContents* active_tab =
browser()->tab_strip_model()->GetActiveWebContents();
content::RenderWidgetHost* render_widget_host =
active_tab->GetRenderViewHost()->GetWidget();
content::RenderWidgetHostView* view = render_widget_host->GetView();
ASSERT_TRUE(view && view->IsSurfaceAvailableForCopy());
// Resize the view to the desired size.
view->SetSize(gfx::Size(viewport_width, viewport_height));
gfx::Rect copy_rect = gfx::Rect(view->GetViewBounds().size());
ASSERT_TRUE(!copy_rect.IsEmpty());
ASSERT_TRUE(view->IsScrollOffsetAtTop());
run_loop_ = std::make_unique<base::RunLoop>();
view->CopyFromSurface(copy_rect, copy_rect.size(),
base::BindOnce(&LocalNTPRenderTest::OnCapturedBitmap,
base::Unretained(this), filename));
run_loop_->Run();
}
private:
// Will write |bitmap| as a png in the test data directory with |filename|.
void OnCapturedBitmap(const std::string& filename, const SkBitmap& bitmap) {
std::vector<unsigned char> bitmap_data;
......@@ -71,46 +106,31 @@ class LocalNTPRenderTest : public InProcessBrowserTest {
run_loop_->Quit();
}
protected:
// Capture run loop operations.
void ResetRunLoop() { run_loop_ = std::make_unique<base::RunLoop>(); }
void StartRunLoop() { run_loop_->Run(); }
private:
base::test::ScopedFeatureList feature_list_;
std::unique_ptr<base::RunLoop> run_loop_;
};
IN_PROC_BROWSER_TEST_F(LocalNTPRenderTest, 1200x800_DefaultMV) {
const int kViewportWidth = 1200;
const int kViewportHeight = 800;
const std::string kCaptureFilename("1200x800_DefaultMV.png");
// Open an NTP and wait until it has fully loaded (tiles may animate, so we
// give this some delay).
local_ntp_test_utils::NavigateToNTPAndWaitUntilLoaded(browser(),
/*delay=*/1000);
content::WebContents* active_tab =
browser()->tab_strip_model()->GetActiveWebContents();
content::RenderWidgetHost* render_widget_host =
active_tab->GetRenderViewHost()->GetWidget();
content::RenderWidgetHostView* view = render_widget_host->GetView();
ASSERT_TRUE(view && view->IsSurfaceAvailableForCopy());
// Resize the view to the desired size.
view->SetSize(gfx::Size(kViewportWidth, kViewportHeight));
gfx::Rect copy_rect = gfx::Rect(view->GetViewBounds().size());
ASSERT_TRUE(!copy_rect.IsEmpty());
ASSERT_TRUE(view->IsScrollOffsetAtTop());
ResetRunLoop();
view->CopyFromSurface(
copy_rect, copy_rect.size(),
base::BindOnce(&LocalNTPRenderTest::OnCapturedBitmap,
base::Unretained(this), kCaptureFilename));
StartRunLoop();
LoadNewTabPageAndCapture(/*viewport_width=*/1200, /*viewport_height=*/800,
/*filename=*/"1200x800_DefaultMV.png");
}
IN_PROC_BROWSER_TEST_F(LocalNTPRenderTest, 1200x800_MVWithCustomLinks) {
InstantService* instant_service =
InstantServiceFactory::GetForProfile(browser()->profile());
instant_service->AddCustomLink(GURL("http://192.168.1.1"), "My Router");
instant_service->AddCustomLink(GURL("https://www.apple.com"), "Apple");
instant_service->AddCustomLink(GURL("https://bobpay.xyz"), "BobPay");
instant_service->AddCustomLink(GURL("https://cnn.com"), "CNN");
instant_service->AddCustomLink(GURL("https://paymentrequest.show"),
"Payment Request Demo Site");
instant_service->AddCustomLink(GURL("https://google.com"), "Google");
instant_service->AddCustomLink(GURL("https://reddit.com/r/whatever"),
"Reddit");
instant_service->AddCustomLink(GURL("https://samsung.com"), "Samsung");
LoadNewTabPageAndCapture(/*viewport_width=*/1200, /*viewport_height=*/800,
/*filename=*/"1200x800_MVWithCustomLinks.png");
}
} // namespace
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