| Index: chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc
|
| diff --git a/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc b/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc
|
| index 98a0a69587a27807e320a7e4a9f30e7919d0e5ba..ae6e19e7aa3ea47381fea5ed5fa3a5c7b26a61de 100644
|
| --- a/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc
|
| +++ b/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc
|
| @@ -6,6 +6,8 @@
|
|
|
| #include "base/command_line.h"
|
| #include "base/guid.h"
|
| +#include "base/path_service.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/browser.h"
|
| @@ -21,23 +23,39 @@
|
| #include "components/dom_distiller/core/dom_distiller_test_util.h"
|
| #include "components/dom_distiller/core/fake_db.h"
|
| #include "components/dom_distiller/core/fake_distiller.h"
|
| +#include "components/dom_distiller/core/fake_distiller_page.h"
|
| #include "components/dom_distiller/core/task_tracker.h"
|
| +#include "components/dom_distiller/core/url_constants.h"
|
| #include "components/dom_distiller/core/url_utils.h"
|
| #include "content/public/browser/render_view_host.h"
|
| #include "content/public/browser/url_data_source.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/browser/web_contents_observer.h"
|
| +#include "content/public/test/browser_test_utils.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace dom_distiller {
|
|
|
| using test::FakeDB;
|
| using test::FakeDistiller;
|
| +using test::MockDistillerPage;
|
| using test::MockDistillerFactory;
|
| +using test::MockDistillerPageFactory;
|
| using test::util::CreateStoreWithFakeDB;
|
| +using testing::HasSubstr;
|
| +using testing::Not;
|
|
|
| namespace {
|
|
|
| +const char kGetLoadIndicatorClassName[] =
|
| + "window.domAutomationController.send("
|
| + "document.getElementById('loadingIndicator').className)";
|
| +
|
| +const char kGetContent[] =
|
| + "window.domAutomationController.send("
|
| + "document.getElementById('content').innerHTML)";
|
| +
|
| void AddEntry(const ArticleEntry& e, FakeDB::EntryMap* map) {
|
| (*map)[e.entry_id()] = e;
|
| }
|
| @@ -122,34 +140,41 @@ class DomDistillerViewerSourceBrowserTest : public InProcessBrowserTest {
|
|
|
| static KeyedService* Build(content::BrowserContext* context) {
|
| FakeDB* fake_db = new FakeDB(database_model_);
|
| - MockDistillerFactory* factory = new MockDistillerFactory();
|
| + distiller_factory_ = new MockDistillerFactory();
|
| + MockDistillerPageFactory* distiller_page_factory_ =
|
| + new MockDistillerPageFactory();
|
| DomDistillerContextKeyedService* service =
|
| new DomDistillerContextKeyedService(
|
| scoped_ptr<DomDistillerStoreInterface>(
|
| CreateStoreWithFakeDB(fake_db, FakeDB::EntryMap())),
|
| - scoped_ptr<DistillerFactory>(factory),
|
| - scoped_ptr<DistillerPageFactory>());
|
| + scoped_ptr<DistillerFactory>(distiller_factory_),
|
| + scoped_ptr<DistillerPageFactory>(distiller_page_factory_));
|
| + MockDistillerPage* distiller_page = new MockDistillerPage();
|
| + EXPECT_CALL(*distiller_page_factory_, CreateDistillerPageImpl())
|
| + .WillOnce(testing::Return(distiller_page));
|
| fake_db->InitCallback(true);
|
| fake_db->LoadCallback(true);
|
| if (expect_distillation_) {
|
| // There will only be destillation of an article if the database contains
|
| // the article.
|
| FakeDistiller* distiller = new FakeDistiller(true);
|
| - EXPECT_CALL(*factory, CreateDistillerImpl())
|
| + EXPECT_CALL(*distiller_factory_, CreateDistillerImpl())
|
| .WillOnce(testing::Return(distiller));
|
| }
|
| return service;
|
| }
|
|
|
| void ViewSingleDistilledPage(const GURL& url);
|
| -
|
| // Database entries.
|
| static FakeDB::EntryMap* database_model_;
|
| static bool expect_distillation_;
|
| + static MockDistillerFactory* distiller_factory_;
|
| };
|
|
|
| FakeDB::EntryMap* DomDistillerViewerSourceBrowserTest::database_model_;
|
| bool DomDistillerViewerSourceBrowserTest::expect_distillation_ = false;
|
| +MockDistillerFactory* DomDistillerViewerSourceBrowserTest::distiller_factory_ =
|
| + NULL;
|
|
|
| // The DomDistillerViewerSource renders untrusted content, so ensure no bindings
|
| // are enabled when the article exists in the database.
|
| @@ -226,7 +251,7 @@ IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
|
| LoadSuccessObserver observer(contents);
|
|
|
| // Navigate to a URL which the source should respond to with CSS.
|
| - std::string url_without_scheme = "://foobar/readability.css";
|
| + std::string url_without_scheme = std::string("://foobar/") + kViewerCssPath;
|
| GURL url(chrome::kDomDistillerScheme + url_without_scheme);
|
| ui_test_utils::NavigateToURL(browser(), url);
|
|
|
| @@ -241,4 +266,102 @@ IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
|
| EXPECT_EQ("text/css", observer.web_contents()->GetContentsMimeType());
|
| }
|
|
|
| +
|
| +IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
|
| + MultiPageArticle) {
|
| + expect_distillation_ = false;
|
| + dom_distiller::DomDistillerServiceFactory::GetInstance()
|
| + ->SetTestingFactoryAndUse(browser()->profile(), &Build);
|
| +
|
| + scoped_refptr<content::MessageLoopRunner> distillation_done_runner =
|
| + new content::MessageLoopRunner;
|
| +
|
| + FakeDistiller* distiller = new FakeDistiller(
|
| + false,
|
| + distillation_done_runner->QuitClosure());
|
| + EXPECT_CALL(*distiller_factory_, CreateDistillerImpl())
|
| + .WillOnce(testing::Return(distiller));
|
| +
|
| + // Setup observer to inspect the RenderViewHost after committed navigation.
|
| + content::WebContents* contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + LoadSuccessObserver observer(contents);
|
| +
|
| + // Navigate to a URL and wait for the distiller to flush contents to the page.
|
| + GURL url(dom_distiller::url_utils::GetDistillerViewUrlFromUrl(
|
| + chrome::kDomDistillerScheme, GURL("http://urlthatlooksvalid.com")));
|
| + chrome::NavigateParams params(browser(), url, content::PAGE_TRANSITION_TYPED);
|
| + chrome::Navigate(¶ms);
|
| + distillation_done_runner->Run();
|
| +
|
| + // Fake a multi-page response from distiller.
|
| +
|
| + std::vector<scoped_refptr<ArticleDistillationUpdate::RefCountedPageProto> >
|
| + update_pages;
|
| + scoped_ptr<DistilledArticleProto> article(new DistilledArticleProto());
|
| +
|
| + // Flush page 1.
|
| + {
|
| + scoped_refptr<base::RefCountedData<DistilledPageProto> > page_proto =
|
| + new base::RefCountedData<DistilledPageProto>();
|
| + page_proto->data.set_url("http://foobar.1.html");
|
| + page_proto->data.set_html("<div>Page 1 content</div>");
|
| + update_pages.push_back(page_proto);
|
| + *(article->add_pages()) = page_proto->data;
|
| +
|
| + ArticleDistillationUpdate update(update_pages, true, false);
|
| + distiller->RunDistillerUpdateCallback(update);
|
| +
|
| + // Wait for the page load to complete as the first page completes the root
|
| + // document.
|
| + content::WaitForLoadStop(contents);
|
| +
|
| + std::string result;
|
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString(
|
| + contents, kGetLoadIndicatorClassName , &result));
|
| + EXPECT_EQ("visible", result);
|
| +
|
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString(
|
| + contents, kGetContent , &result));
|
| + EXPECT_THAT(result, HasSubstr("Page 1 content"));
|
| + EXPECT_THAT(result, Not(HasSubstr("Page 2 content")));
|
| + }
|
| +
|
| + // Flush page 2.
|
| + {
|
| + scoped_refptr<base::RefCountedData<DistilledPageProto> > page_proto =
|
| + new base::RefCountedData<DistilledPageProto>();
|
| + page_proto->data.set_url("http://foobar.2.html");
|
| + page_proto->data.set_html("<div>Page 2 content</div>");
|
| + update_pages.push_back(page_proto);
|
| + *(article->add_pages()) = page_proto->data;
|
| +
|
| + ArticleDistillationUpdate update(update_pages, false, false);
|
| + distiller->RunDistillerUpdateCallback(update);
|
| +
|
| + std::string result;
|
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString(
|
| + contents, kGetLoadIndicatorClassName , &result));
|
| + EXPECT_EQ("visible", result);
|
| +
|
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString(
|
| + contents, kGetContent , &result));
|
| + EXPECT_THAT(result, HasSubstr("Page 1 content"));
|
| + EXPECT_THAT(result, HasSubstr("Page 2 content"));
|
| + }
|
| +
|
| + // Complete the load.
|
| + distiller->RunDistillerCallback(article.Pass());
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + std::string result;
|
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString(
|
| + contents, kGetLoadIndicatorClassName, &result));
|
| + EXPECT_EQ("hidden", result);
|
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString(
|
| + contents, kGetContent , &result));
|
| + EXPECT_THAT(result, HasSubstr("Page 1 content"));
|
| + EXPECT_THAT(result, HasSubstr("Page 2 content"));
|
| +}
|
| +
|
| } // namespace dom_distiller
|
|
|