| 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 3f85c6c33d8d113643e20aa02d1938c015122164..9c4fb88d972697bb075afd2288061e21dc4a6cbe 100644
|
| --- a/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc
|
| +++ b/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc
|
| @@ -5,6 +5,7 @@
|
| #include <string.h>
|
|
|
| #include "base/command_line.h"
|
| +#include "base/guid.h"
|
| #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/browser.h"
|
| @@ -21,10 +22,13 @@
|
| #include "components/dom_distiller/core/fake_db.h"
|
| #include "components/dom_distiller/core/fake_distiller.h"
|
| #include "components/dom_distiller/core/task_tracker.h"
|
| +#include "components/dom_distiller/core/url_constants.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 "net/base/escape.h"
|
| +#include "net/base/url_util.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace dom_distiller {
|
| @@ -50,6 +54,18 @@ ArticleEntry CreateEntry(std::string entry_id, std::string page_url) {
|
| return entry;
|
| }
|
|
|
| +const GURL GetDistillerViewUrlFromEntryId(const std::string& entry_id) {
|
| + GURL url(std::string(chrome::kDomDistillerScheme) + "://" +
|
| + base::GenerateGUID());
|
| + return net::AppendOrReplaceQueryParameter(url, kEntryIdKey, entry_id);
|
| +}
|
| +
|
| +const GURL GetDistillerViewUrlFromUrl(const std::string& view_url) {
|
| + GURL url(std::string(chrome::kDomDistillerScheme) + "://" +
|
| + base::GenerateGUID());
|
| + return net::AppendOrReplaceQueryParameter(url, kUrlKey, view_url);
|
| +}
|
| +
|
| } // namespace
|
|
|
| // WebContents observer that stores reference to the current |RenderViewHost|.
|
| @@ -138,7 +154,7 @@ class DomDistillerViewerSourceBrowserTest : public InProcessBrowserTest {
|
| return service;
|
| }
|
|
|
| - void ViewSingleDistilledPage();
|
| + void ViewSingleDistilledPage(const GURL& url);
|
|
|
| // Database entries.
|
| static FakeDB::EntryMap* database_model_;
|
| @@ -153,10 +169,11 @@ bool DomDistillerViewerSourceBrowserTest::expect_distillation_ = false;
|
| IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
|
| NoWebUIBindingsArticleExists) {
|
| // Ensure there is one item in the database, which will trigger distillation.
|
| - ArticleEntry entry = CreateEntry("DISTILLED", "http://example.com/1");
|
| + const ArticleEntry entry = CreateEntry("DISTILLED", "http://example.com/1");
|
| AddEntry(entry, database_model_);
|
| expect_distillation_ = true;
|
| - ViewSingleDistilledPage();
|
| + const GURL url = GetDistillerViewUrlFromEntryId(entry.entry_id());
|
| + ViewSingleDistilledPage(url);
|
| }
|
|
|
| // The DomDistillerViewerSource renders untrusted content, so ensure no bindings
|
| @@ -165,10 +182,24 @@ IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
|
| NoWebUIBindingsArticleNotFound) {
|
| // The article does not exist, so assume no distillation will happen.
|
| expect_distillation_ = false;
|
| - ViewSingleDistilledPage();
|
| + const GURL url(std::string(chrome::kDomDistillerScheme) + "://" +
|
| + base::GenerateGUID() + "/");
|
| + ViewSingleDistilledPage(url);
|
| +}
|
| +
|
| +// The DomDistillerViewerSource renders untrusted content, so ensure no bindings
|
| +// are enabled when requesting to view an arbitrary URL.
|
| +IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
|
| + NoWebUIBindingsViewUrl) {
|
| + // We should expect distillation for any valid URL.
|
| + expect_distillation_ = true;
|
| + std::string view_url = "http://www.example.com/1";
|
| + const GURL url = GetDistillerViewUrlFromUrl(view_url);
|
| + ViewSingleDistilledPage(url);
|
| }
|
|
|
| -void DomDistillerViewerSourceBrowserTest::ViewSingleDistilledPage() {
|
| +void DomDistillerViewerSourceBrowserTest::ViewSingleDistilledPage(
|
| + const GURL& url) {
|
| // Create the service.
|
| DomDistillerContextKeyedService* service =
|
| static_cast<DomDistillerContextKeyedService*>(
|
| @@ -187,8 +218,6 @@ void DomDistillerViewerSourceBrowserTest::ViewSingleDistilledPage() {
|
| LoadSuccessObserver observer(contents);
|
|
|
| // Navigate to a URL which the source should respond to.
|
| - std::string url_without_scheme = "://distilled";
|
| - GURL url(chrome::kDomDistillerScheme + url_without_scheme);
|
| ui_test_utils::NavigateToURL(browser(), url);
|
|
|
| // A navigation should have succeeded to the correct URL.
|
|
|