Skip to content

Commit

Permalink
Add test to catch Speedreader Icon regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Kuehler committed Sep 22, 2021
1 parent 3ff2018 commit 103ac3f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
39 changes: 39 additions & 0 deletions browser/speedreader/speedreader_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/page_action/page_action_icon_type.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/toolbar_button_provider.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/keep_alive_registry/keep_alive_types.h"
Expand All @@ -30,8 +34,19 @@
#include "net/test/embedded_test_server/embedded_test_server.h"

const char kTestHost[] = "theguardian.com";

// The path is not readable. None of the URL components match the heuristic so
// the SpeedreaderThrottle is never created.
const char kTestPageSimple[] = "/simple.html";

// The URL path appears readable and the page has text content. This is used to
// test distillation in the common case.
const char kTestPageReadable[] = "/articles/guardian.html";

// The URL path appears readable but the page has no text content. This is used
// to test the case where Speedreader aborts.
const char kTestPageFakeReadable[] = "/articles/fake.html";

const base::FilePath::StringPieceType kTestWhitelist =
FILE_PATH_LITERAL("speedreader_whitelist.json");

Expand Down Expand Up @@ -116,6 +131,12 @@ class SpeedReaderBrowserTest : public InProcessBrowserTest {
ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP);
}

PageActionIconView* SpeedreaderIcon() {
return BrowserView::GetBrowserViewForBrowser(browser())
->toolbar_button_provider()
->GetPageActionIconView(PageActionIconType::kReaderMode);
}

protected:
base::test::ScopedFeatureList feature_list_;
net::EmbeddedTestServer https_server_;
Expand All @@ -126,6 +147,7 @@ IN_PROC_BROWSER_TEST_F(SpeedReaderBrowserTest, RestoreSpeedreaderPage) {
NavigateToPageSynchronously(kTestPageReadable);
EXPECT_TRUE(
speedreader::PageStateIsDistilled(tab_helper()->PageDistillState()));
EXPECT_TRUE(SpeedreaderIcon()->GetVisible());

Profile* profile = browser()->profile();

Expand All @@ -143,34 +165,51 @@ IN_PROC_BROWSER_TEST_F(SpeedReaderBrowserTest, RestoreSpeedreaderPage) {
restore_observer.Wait();
EXPECT_TRUE(
speedreader::PageStateIsDistilled(tab_helper()->PageDistillState()));
EXPECT_TRUE(SpeedreaderIcon()->GetVisible());
}

IN_PROC_BROWSER_TEST_F(SpeedReaderBrowserTest, NavigationNostickTest) {
ToggleSpeedreader();
NavigateToPageSynchronously(kTestPageSimple);
EXPECT_FALSE(
speedreader::PageStateIsDistilled(tab_helper()->PageDistillState()));
EXPECT_FALSE(SpeedreaderIcon()->GetVisible());

NavigateToPageSynchronously(kTestPageReadable,
WindowOpenDisposition::CURRENT_TAB);
EXPECT_TRUE(
speedreader::PageStateIsDistilled(tab_helper()->PageDistillState()));
EXPECT_TRUE(SpeedreaderIcon()->GetVisible());

// Ensure distill state doesn't stick when we back-navigate from a readable
// page to a non-readable one.
GoBack(browser());
EXPECT_FALSE(
speedreader::PageStateIsDistilled(tab_helper()->PageDistillState()));
EXPECT_FALSE(SpeedreaderIcon()->GetVisible());
}

IN_PROC_BROWSER_TEST_F(SpeedReaderBrowserTest, DisableSiteWorks) {
ToggleSpeedreader();
NavigateToPageSynchronously(kTestPageReadable);
EXPECT_TRUE(
speedreader::PageStateIsDistilled(tab_helper()->PageDistillState()));
EXPECT_TRUE(SpeedreaderIcon()->GetVisible());

tab_helper()->MaybeToggleEnabledForSite(false);
EXPECT_TRUE(WaitForLoadStop(ActiveWebContents()));
EXPECT_FALSE(
speedreader::PageStateIsDistilled(tab_helper()->PageDistillState()));
// Disabled sites show the icon
EXPECT_TRUE(SpeedreaderIcon()->GetVisible());
}

IN_PROC_BROWSER_TEST_F(SpeedReaderBrowserTest, TestFakeReadable) {
ToggleSpeedreader();
NavigateToPageSynchronously(kTestPageFakeReadable);
EXPECT_FALSE(
speedreader::PageStateIsDistilled(tab_helper()->PageDistillState()));
EXPECT_FALSE(SpeedreaderIcon()->GetVisible());
}

// disabled in https://github.com/brave/brave-browser/issues/11328
Expand Down
7 changes: 7 additions & 0 deletions test/data/articles/fake.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- We have this site under a readable path but it is just a video and has no text content.
This is used in tests to propagate distill results to different browser services. -->

<video width="256" height="240" autoplay>
<source src="video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

0 comments on commit 103ac3f

Please sign in to comment.