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 @@ ...@@ -10,14 +10,18 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "chrome/browser/profiles/profile.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/browser.h"
#include "chrome/browser/ui/search/local_ntp_test_utils.h" #include "chrome/browser/ui/search/local_ntp_test_utils.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/test/base/in_process_browser_test.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_view_host.h"
#include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
...@@ -49,7 +53,8 @@ class LocalNTPRenderTest : public InProcessBrowserTest { ...@@ -49,7 +53,8 @@ class LocalNTPRenderTest : public InProcessBrowserTest {
public: public:
LocalNTPRenderTest() { LocalNTPRenderTest() {
// Making sure we are running with the Local NTP. // 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 { void SetUpCommandLine(base::CommandLine* command_line) override {
...@@ -57,6 +62,36 @@ class LocalNTPRenderTest : public InProcessBrowserTest { ...@@ -57,6 +62,36 @@ class LocalNTPRenderTest : public InProcessBrowserTest {
command_line->AppendSwitch(switches::kEnablePixelOutputInTests); 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|. // Will write |bitmap| as a png in the test data directory with |filename|.
void OnCapturedBitmap(const std::string& filename, const SkBitmap& bitmap) { void OnCapturedBitmap(const std::string& filename, const SkBitmap& bitmap) {
std::vector<unsigned char> bitmap_data; std::vector<unsigned char> bitmap_data;
...@@ -71,46 +106,31 @@ class LocalNTPRenderTest : public InProcessBrowserTest { ...@@ -71,46 +106,31 @@ class LocalNTPRenderTest : public InProcessBrowserTest {
run_loop_->Quit(); 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_; base::test::ScopedFeatureList feature_list_;
std::unique_ptr<base::RunLoop> run_loop_; std::unique_ptr<base::RunLoop> run_loop_;
}; };
IN_PROC_BROWSER_TEST_F(LocalNTPRenderTest, 1200x800_DefaultMV) { IN_PROC_BROWSER_TEST_F(LocalNTPRenderTest, 1200x800_DefaultMV) {
const int kViewportWidth = 1200; LoadNewTabPageAndCapture(/*viewport_width=*/1200, /*viewport_height=*/800,
const int kViewportHeight = 800; /*filename=*/"1200x800_DefaultMV.png");
const std::string kCaptureFilename("1200x800_DefaultMV.png"); }
// Open an NTP and wait until it has fully loaded (tiles may animate, so we IN_PROC_BROWSER_TEST_F(LocalNTPRenderTest, 1200x800_MVWithCustomLinks) {
// give this some delay). InstantService* instant_service =
local_ntp_test_utils::NavigateToNTPAndWaitUntilLoaded(browser(), InstantServiceFactory::GetForProfile(browser()->profile());
/*delay=*/1000); instant_service->AddCustomLink(GURL("http://192.168.1.1"), "My Router");
content::WebContents* active_tab = instant_service->AddCustomLink(GURL("https://www.apple.com"), "Apple");
browser()->tab_strip_model()->GetActiveWebContents(); instant_service->AddCustomLink(GURL("https://bobpay.xyz"), "BobPay");
instant_service->AddCustomLink(GURL("https://cnn.com"), "CNN");
content::RenderWidgetHost* render_widget_host = instant_service->AddCustomLink(GURL("https://paymentrequest.show"),
active_tab->GetRenderViewHost()->GetWidget(); "Payment Request Demo Site");
content::RenderWidgetHostView* view = render_widget_host->GetView(); instant_service->AddCustomLink(GURL("https://google.com"), "Google");
ASSERT_TRUE(view && view->IsSurfaceAvailableForCopy()); instant_service->AddCustomLink(GURL("https://reddit.com/r/whatever"),
"Reddit");
// Resize the view to the desired size. instant_service->AddCustomLink(GURL("https://samsung.com"), "Samsung");
view->SetSize(gfx::Size(kViewportWidth, kViewportHeight));
LoadNewTabPageAndCapture(/*viewport_width=*/1200, /*viewport_height=*/800,
gfx::Rect copy_rect = gfx::Rect(view->GetViewBounds().size()); /*filename=*/"1200x800_MVWithCustomLinks.png");
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();
} }
} // namespace } // 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