Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc

Issue 151003006: Add support for distilling arbitrary URLs in DOM Distiller Viewer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string.h> 5 #include <string.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/guid.h"
8 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" 9 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
14 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
16 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" 17 #include "components/dom_distiller/content/dom_distiller_viewer_source.h"
17 #include "components/dom_distiller/core/distiller.h" 18 #include "components/dom_distiller/core/distiller.h"
18 #include "components/dom_distiller/core/dom_distiller_service.h" 19 #include "components/dom_distiller/core/dom_distiller_service.h"
19 #include "components/dom_distiller/core/dom_distiller_store.h" 20 #include "components/dom_distiller/core/dom_distiller_store.h"
20 #include "components/dom_distiller/core/dom_distiller_test_util.h" 21 #include "components/dom_distiller/core/dom_distiller_test_util.h"
21 #include "components/dom_distiller/core/fake_db.h" 22 #include "components/dom_distiller/core/fake_db.h"
22 #include "components/dom_distiller/core/fake_distiller.h" 23 #include "components/dom_distiller/core/fake_distiller.h"
23 #include "components/dom_distiller/core/task_tracker.h" 24 #include "components/dom_distiller/core/task_tracker.h"
25 #include "components/dom_distiller/core/url_constants.h"
24 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
25 #include "content/public/browser/url_data_source.h" 27 #include "content/public/browser/url_data_source.h"
26 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
27 #include "content/public/browser/web_contents_observer.h" 29 #include "content/public/browser/web_contents_observer.h"
30 #include "net/base/escape.h"
28 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
29 32
30 namespace dom_distiller { 33 namespace dom_distiller {
31 34
32 using test::FakeDB; 35 using test::FakeDB;
33 using test::FakeDistiller; 36 using test::FakeDistiller;
34 using test::MockDistillerFactory; 37 using test::MockDistillerFactory;
35 using test::util::CreateStoreWithFakeDB; 38 using test::util::CreateStoreWithFakeDB;
36 39
37 namespace { 40 namespace {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (expect_distillation_) { 134 if (expect_distillation_) {
132 // There will only be destillation of an article if the database contains 135 // There will only be destillation of an article if the database contains
133 // the article. 136 // the article.
134 FakeDistiller* distiller = new FakeDistiller(true); 137 FakeDistiller* distiller = new FakeDistiller(true);
135 EXPECT_CALL(*factory, CreateDistillerImpl()) 138 EXPECT_CALL(*factory, CreateDistillerImpl())
136 .WillOnce(testing::Return(distiller)); 139 .WillOnce(testing::Return(distiller));
137 } 140 }
138 return service; 141 return service;
139 } 142 }
140 143
141 void ViewSingleDistilledPage(); 144 void ViewSingleDistilledPage(const GURL& url);
142 145
143 // Database entries. 146 // Database entries.
144 static FakeDB::EntryMap* database_model_; 147 static FakeDB::EntryMap* database_model_;
145 static bool expect_distillation_; 148 static bool expect_distillation_;
146 }; 149 };
147 150
148 FakeDB::EntryMap* DomDistillerViewerSourceBrowserTest::database_model_; 151 FakeDB::EntryMap* DomDistillerViewerSourceBrowserTest::database_model_;
149 bool DomDistillerViewerSourceBrowserTest::expect_distillation_ = false; 152 bool DomDistillerViewerSourceBrowserTest::expect_distillation_ = false;
150 153
151 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings 154 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings
152 // are enabled when the article exists in the database. 155 // are enabled when the article exists in the database.
153 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, 156 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
154 NoWebUIBindingsArticleExists) { 157 NoWebUIBindingsArticleExists) {
155 // Ensure there is one item in the database, which will trigger distillation. 158 // Ensure there is one item in the database, which will trigger distillation.
156 ArticleEntry entry = CreateEntry("DISTILLED", "http://example.com/1"); 159 const ArticleEntry entry = CreateEntry("DISTILLED", "http://example.com/1");
157 AddEntry(entry, database_model_); 160 AddEntry(entry, database_model_);
158 expect_distillation_ = true; 161 expect_distillation_ = true;
159 ViewSingleDistilledPage(); 162 const GURL url(std::string(chrome::kDomDistillerScheme) + "://" +
shashi 2014/02/05 22:28:08 nit: can be refactored into a function, e.g. GetDi
nyquist 2014/02/25 20:30:24 Done.
163 base::GenerateGUID() + "/?" + std::string(kEntryIdKey) + "=" +
164 net::EscapeQueryParamValue(entry.entry_id(), true));
165 ViewSingleDistilledPage(url);
160 } 166 }
161 167
162 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings 168 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings
163 // are enabled when the article is not found. 169 // are enabled when the article is not found.
164 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, 170 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
165 NoWebUIBindingsArticleNotFound) { 171 NoWebUIBindingsArticleNotFound) {
166 // The article does not exist, so assume no distillation will happen. 172 // The article does not exist, so assume no distillation will happen.
167 expect_distillation_ = false; 173 expect_distillation_ = false;
168 ViewSingleDistilledPage(); 174 const GURL url(std::string(chrome::kDomDistillerScheme) + "://" +
175 base::GenerateGUID() + "/");
176 ViewSingleDistilledPage(url);
169 } 177 }
170 178
171 void DomDistillerViewerSourceBrowserTest::ViewSingleDistilledPage() { 179 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings
180 // are enabled when requesting to view an arbitrary URL.
181 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
182 NoWebUIBindingsViewUrl) {
183 // We should expect distillation for any valid URL.
184 expect_distillation_ = true;
185 std::string view_url = "http://www.example.com/1";
186 const GURL url(std::string(chrome::kDomDistillerScheme) + "://" +
187 base::GenerateGUID() + "/?" + std::string(kUrlKey) + "=" +
188 net::EscapeQueryParamValue(view_url, true));
shashi 2014/02/05 22:28:08 nit: can be refactored to a function GetDistillerV
nyquist 2014/02/25 20:30:24 Done.
189 ViewSingleDistilledPage(url);
190 }
191
192 void DomDistillerViewerSourceBrowserTest::ViewSingleDistilledPage(
193 const GURL& url) {
172 // Create the service. 194 // Create the service.
173 DomDistillerContextKeyedService* service = 195 DomDistillerContextKeyedService* service =
174 static_cast<DomDistillerContextKeyedService*>( 196 static_cast<DomDistillerContextKeyedService*>(
175 dom_distiller::DomDistillerServiceFactory::GetInstance() 197 dom_distiller::DomDistillerServiceFactory::GetInstance()
176 ->SetTestingFactoryAndUse(browser()->profile(), &Build)); 198 ->SetTestingFactoryAndUse(browser()->profile(), &Build));
177 199
178 // Ensure the source is registered. 200 // Ensure the source is registered.
179 // TODO(nyquist): Remove when the source is always registered on startup. 201 // TODO(nyquist): Remove when the source is always registered on startup.
180 DomDistillerViewerSource* source = 202 DomDistillerViewerSource* source =
181 new DomDistillerViewerSource(service, chrome::kDomDistillerScheme); 203 new DomDistillerViewerSource(service, chrome::kDomDistillerScheme);
182 content::URLDataSource::Add(browser()->profile(), source); 204 content::URLDataSource::Add(browser()->profile(), source);
183 205
184 // Setup observer to inspect the RenderViewHost after committed navigation. 206 // Setup observer to inspect the RenderViewHost after committed navigation.
185 content::WebContents* contents = 207 content::WebContents* contents =
186 browser()->tab_strip_model()->GetActiveWebContents(); 208 browser()->tab_strip_model()->GetActiveWebContents();
187 LoadSuccessObserver observer(contents); 209 LoadSuccessObserver observer(contents);
188 210
189 // Navigate to a URL which the source should respond to. 211 // Navigate to a URL which the source should respond to.
190 std::string url_without_scheme = "://distilled";
191 GURL url(chrome::kDomDistillerScheme + url_without_scheme);
192 ui_test_utils::NavigateToURL(browser(), url); 212 ui_test_utils::NavigateToURL(browser(), url);
193 213
194 // A navigation should have succeeded to the correct URL. 214 // A navigation should have succeeded to the correct URL.
195 ASSERT_FALSE(observer.load_failed()); 215 ASSERT_FALSE(observer.load_failed());
196 ASSERT_TRUE(observer.finished_load()); 216 ASSERT_TRUE(observer.finished_load());
197 ASSERT_EQ(url, observer.validated_url()); 217 ASSERT_EQ(url, observer.validated_url());
198 // Ensure no bindings. 218 // Ensure no bindings.
199 const content::RenderViewHost* render_view_host = observer.render_view_host(); 219 const content::RenderViewHost* render_view_host = observer.render_view_host();
200 ASSERT_EQ(0, render_view_host->GetEnabledBindings()); 220 ASSERT_EQ(0, render_view_host->GetEnabledBindings());
201 // The MIME-type should always be text/html for the distilled articles. 221 // The MIME-type should always be text/html for the distilled articles.
(...skipping 26 matching lines...) Expand all
228 ASSERT_TRUE(observer.finished_load()); 248 ASSERT_TRUE(observer.finished_load());
229 ASSERT_EQ(url, observer.validated_url()); 249 ASSERT_EQ(url, observer.validated_url());
230 // Ensure no bindings. 250 // Ensure no bindings.
231 const content::RenderViewHost* render_view_host = observer.render_view_host(); 251 const content::RenderViewHost* render_view_host = observer.render_view_host();
232 ASSERT_EQ(0, render_view_host->GetEnabledBindings()); 252 ASSERT_EQ(0, render_view_host->GetEnabledBindings());
233 // The MIME-type should always be text/css for the CSS resources. 253 // The MIME-type should always be text/css for the CSS resources.
234 EXPECT_EQ("text/css", observer.web_contents()->GetContentsMimeType()); 254 EXPECT_EQ("text/css", observer.web_contents()->GetContentsMimeType());
235 } 255 }
236 256
237 } // namespace dom_distiller 257 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « no previous file | components/dom_distiller.gypi » ('j') | components/dom_distiller/content/dom_distiller_viewer_source.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698