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

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: Added new strings to iOS whitelist Created 6 years, 9 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
« no previous file with comments | « build/ios/grit_whitelist.txt ('k') | components/components_tests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_utils.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"
28 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
29 31
30 namespace dom_distiller { 32 namespace dom_distiller {
31 33
32 using test::FakeDB; 34 using test::FakeDB;
33 using test::FakeDistiller; 35 using test::FakeDistiller;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (expect_distillation_) { 133 if (expect_distillation_) {
132 // There will only be destillation of an article if the database contains 134 // There will only be destillation of an article if the database contains
133 // the article. 135 // the article.
134 FakeDistiller* distiller = new FakeDistiller(true); 136 FakeDistiller* distiller = new FakeDistiller(true);
135 EXPECT_CALL(*factory, CreateDistillerImpl()) 137 EXPECT_CALL(*factory, CreateDistillerImpl())
136 .WillOnce(testing::Return(distiller)); 138 .WillOnce(testing::Return(distiller));
137 } 139 }
138 return service; 140 return service;
139 } 141 }
140 142
141 void ViewSingleDistilledPage(); 143 void ViewSingleDistilledPage(const GURL& url);
142 144
143 // Database entries. 145 // Database entries.
144 static FakeDB::EntryMap* database_model_; 146 static FakeDB::EntryMap* database_model_;
145 static bool expect_distillation_; 147 static bool expect_distillation_;
146 }; 148 };
147 149
148 FakeDB::EntryMap* DomDistillerViewerSourceBrowserTest::database_model_; 150 FakeDB::EntryMap* DomDistillerViewerSourceBrowserTest::database_model_;
149 bool DomDistillerViewerSourceBrowserTest::expect_distillation_ = false; 151 bool DomDistillerViewerSourceBrowserTest::expect_distillation_ = false;
150 152
151 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings 153 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings
152 // are enabled when the article exists in the database. 154 // are enabled when the article exists in the database.
153 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, 155 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
154 NoWebUIBindingsArticleExists) { 156 NoWebUIBindingsArticleExists) {
155 // Ensure there is one item in the database, which will trigger distillation. 157 // Ensure there is one item in the database, which will trigger distillation.
156 ArticleEntry entry = CreateEntry("DISTILLED", "http://example.com/1"); 158 const ArticleEntry entry = CreateEntry("DISTILLED", "http://example.com/1");
157 AddEntry(entry, database_model_); 159 AddEntry(entry, database_model_);
158 expect_distillation_ = true; 160 expect_distillation_ = true;
159 ViewSingleDistilledPage(); 161 const GURL url = url_utils::GetDistillerViewUrlFromEntryId(
162 chrome::kDomDistillerScheme, entry.entry_id());
163 ViewSingleDistilledPage(url);
160 } 164 }
161 165
162 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings 166 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings
163 // are enabled when the article is not found. 167 // are enabled when the article is not found.
164 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, 168 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
165 NoWebUIBindingsArticleNotFound) { 169 NoWebUIBindingsArticleNotFound) {
166 // The article does not exist, so assume no distillation will happen. 170 // The article does not exist, so assume no distillation will happen.
167 expect_distillation_ = false; 171 expect_distillation_ = false;
168 ViewSingleDistilledPage(); 172 const GURL url(std::string(chrome::kDomDistillerScheme) + "://" +
173 base::GenerateGUID() + "/");
174 ViewSingleDistilledPage(url);
169 } 175 }
170 176
171 void DomDistillerViewerSourceBrowserTest::ViewSingleDistilledPage() { 177 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings
178 // are enabled when requesting to view an arbitrary URL.
179 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
180 NoWebUIBindingsViewUrl) {
181 // We should expect distillation for any valid URL.
182 expect_distillation_ = true;
183 GURL view_url("http://www.example.com/1");
184 const GURL url = url_utils::GetDistillerViewUrlFromUrl(
185 chrome::kDomDistillerScheme, view_url);
186 ViewSingleDistilledPage(url);
187 }
188
189 void DomDistillerViewerSourceBrowserTest::ViewSingleDistilledPage(
190 const GURL& url) {
172 // Create the service. 191 // Create the service.
173 DomDistillerContextKeyedService* service = 192 DomDistillerContextKeyedService* service =
174 static_cast<DomDistillerContextKeyedService*>( 193 static_cast<DomDistillerContextKeyedService*>(
175 dom_distiller::DomDistillerServiceFactory::GetInstance() 194 dom_distiller::DomDistillerServiceFactory::GetInstance()
176 ->SetTestingFactoryAndUse(browser()->profile(), &Build)); 195 ->SetTestingFactoryAndUse(browser()->profile(), &Build));
177 196
178 // Ensure the source is registered. 197 // Ensure the source is registered.
179 // TODO(nyquist): Remove when the source is always registered on startup. 198 // TODO(nyquist): Remove when the source is always registered on startup.
180 DomDistillerViewerSource* source = 199 DomDistillerViewerSource* source =
181 new DomDistillerViewerSource(service, chrome::kDomDistillerScheme); 200 new DomDistillerViewerSource(service, chrome::kDomDistillerScheme);
182 content::URLDataSource::Add(browser()->profile(), source); 201 content::URLDataSource::Add(browser()->profile(), source);
183 202
184 // Setup observer to inspect the RenderViewHost after committed navigation. 203 // Setup observer to inspect the RenderViewHost after committed navigation.
185 content::WebContents* contents = 204 content::WebContents* contents =
186 browser()->tab_strip_model()->GetActiveWebContents(); 205 browser()->tab_strip_model()->GetActiveWebContents();
187 LoadSuccessObserver observer(contents); 206 LoadSuccessObserver observer(contents);
188 207
189 // Navigate to a URL which the source should respond to. 208 // 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); 209 ui_test_utils::NavigateToURL(browser(), url);
193 210
194 // A navigation should have succeeded to the correct URL. 211 // A navigation should have succeeded to the correct URL.
195 ASSERT_FALSE(observer.load_failed()); 212 ASSERT_FALSE(observer.load_failed());
196 ASSERT_TRUE(observer.finished_load()); 213 ASSERT_TRUE(observer.finished_load());
197 ASSERT_EQ(url, observer.validated_url()); 214 ASSERT_EQ(url, observer.validated_url());
198 // Ensure no bindings. 215 // Ensure no bindings.
199 const content::RenderViewHost* render_view_host = observer.render_view_host(); 216 const content::RenderViewHost* render_view_host = observer.render_view_host();
200 ASSERT_EQ(0, render_view_host->GetEnabledBindings()); 217 ASSERT_EQ(0, render_view_host->GetEnabledBindings());
201 // The MIME-type should always be text/html for the distilled articles. 218 // The MIME-type should always be text/html for the distilled articles.
(...skipping 26 matching lines...) Expand all
228 ASSERT_TRUE(observer.finished_load()); 245 ASSERT_TRUE(observer.finished_load());
229 ASSERT_EQ(url, observer.validated_url()); 246 ASSERT_EQ(url, observer.validated_url());
230 // Ensure no bindings. 247 // Ensure no bindings.
231 const content::RenderViewHost* render_view_host = observer.render_view_host(); 248 const content::RenderViewHost* render_view_host = observer.render_view_host();
232 ASSERT_EQ(0, render_view_host->GetEnabledBindings()); 249 ASSERT_EQ(0, render_view_host->GetEnabledBindings());
233 // The MIME-type should always be text/css for the CSS resources. 250 // The MIME-type should always be text/css for the CSS resources.
234 EXPECT_EQ("text/css", observer.web_contents()->GetContentsMimeType()); 251 EXPECT_EQ("text/css", observer.web_contents()->GetContentsMimeType());
235 } 252 }
236 253
237 } // namespace dom_distiller 254 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « build/ios/grit_whitelist.txt ('k') | components/components_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698