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

Side by Side Diff: components/dom_distiller/content/distiller_page_web_contents_browsertest.cc

Issue 396503003: DomDistiller: fix 0 document width (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: resolve patch conflicts Created 6 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/memory/weak_ptr.h" 5 #include "base/memory/weak_ptr.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "components/dom_distiller/content/distiller_page_web_contents.h" 9 #include "components/dom_distiller/content/distiller_page_web_contents.h"
10 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" 10 #include "components/dom_distiller/content/web_contents_main_frame_observer.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 base::Closure quit_closure_; 82 base::Closure quit_closure_;
83 scoped_ptr<DistilledPageInfo> page_info_; 83 scoped_ptr<DistilledPageInfo> page_info_;
84 }; 84 };
85 85
86 // Use this class to be able to leak the WebContents, which is needed for when 86 // Use this class to be able to leak the WebContents, which is needed for when
87 // the current WebContents is used for distillation. 87 // the current WebContents is used for distillation.
88 class TestDistillerPageWebContents : public DistillerPageWebContents { 88 class TestDistillerPageWebContents : public DistillerPageWebContents {
89 public: 89 public:
90 TestDistillerPageWebContents( 90 TestDistillerPageWebContents(
91 content::BrowserContext* browser_context, 91 content::BrowserContext* browser_context,
92 const gfx::Size& render_view_size,
92 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle, 93 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle,
93 bool expect_new_web_contents) 94 bool expect_new_web_contents)
94 : DistillerPageWebContents(browser_context, 95 : DistillerPageWebContents(browser_context, render_view_size,
95 optional_web_contents_handle.Pass()), 96 optional_web_contents_handle.Pass()),
96 expect_new_web_contents_(expect_new_web_contents), 97 expect_new_web_contents_(expect_new_web_contents),
97 new_web_contents_created_(false) {} 98 new_web_contents_created_(false) {}
98 99
99 virtual void CreateNewWebContents(const GURL& url) OVERRIDE { 100 virtual void CreateNewWebContents(const GURL& url) OVERRIDE {
100 ASSERT_EQ(true, expect_new_web_contents_); 101 ASSERT_EQ(true, expect_new_web_contents_);
101 new_web_contents_created_ = true; 102 new_web_contents_created_ = true;
102 // DistillerPageWebContents::CreateNewWebContents resets the scoped_ptr to 103 // DistillerPageWebContents::CreateNewWebContents resets the scoped_ptr to
103 // the WebContents, so intentionally leak WebContents here, since it is 104 // the WebContents, so intentionally leak WebContents here, since it is
104 // owned by the shell. 105 // owned by the shell.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 155 }
155 156
156 private: 157 private:
157 base::Closure callback_; 158 base::Closure callback_;
158 bool wait_for_document_loaded_; 159 bool wait_for_document_loaded_;
159 }; 160 };
160 161
161 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, BasicDistillationWorks) { 162 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, BasicDistillationWorks) {
162 DistillerPageWebContents distiller_page( 163 DistillerPageWebContents distiller_page(
163 shell()->web_contents()->GetBrowserContext(), 164 shell()->web_contents()->GetBrowserContext(),
165 shell()->web_contents()->GetContainerBounds().size(),
164 scoped_ptr<SourcePageHandleWebContents>()); 166 scoped_ptr<SourcePageHandleWebContents>());
165 distiller_page_ = &distiller_page; 167 distiller_page_ = &distiller_page;
166 168
167 base::RunLoop run_loop; 169 base::RunLoop run_loop;
168 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); 170 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath);
169 run_loop.Run(); 171 run_loop.Run();
170 172
171 EXPECT_EQ("Test Page Title", page_info_.get()->title); 173 EXPECT_EQ("Test Page Title", page_info_.get()->title);
172 EXPECT_THAT(page_info_.get()->html, HasSubstr("Lorem ipsum")); 174 EXPECT_THAT(page_info_.get()->html, HasSubstr("Lorem ipsum"));
173 EXPECT_THAT(page_info_.get()->html, Not(HasSubstr("questionable content"))); 175 EXPECT_THAT(page_info_.get()->html, Not(HasSubstr("questionable content")));
174 EXPECT_EQ("", page_info_.get()->next_page_url); 176 EXPECT_EQ("", page_info_.get()->next_page_url);
175 EXPECT_EQ("", page_info_.get()->prev_page_url); 177 EXPECT_EQ("", page_info_.get()->prev_page_url);
176 } 178 }
177 179
178 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeLinks) { 180 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeLinks) {
179 DistillerPageWebContents distiller_page( 181 DistillerPageWebContents distiller_page(
180 shell()->web_contents()->GetBrowserContext(), 182 shell()->web_contents()->GetBrowserContext(),
183 shell()->web_contents()->GetContainerBounds().size(),
181 scoped_ptr<SourcePageHandleWebContents>()); 184 scoped_ptr<SourcePageHandleWebContents>());
182 distiller_page_ = &distiller_page; 185 distiller_page_ = &distiller_page;
183 186
184 base::RunLoop run_loop; 187 base::RunLoop run_loop;
185 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); 188 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath);
186 run_loop.Run(); 189 run_loop.Run();
187 190
188 // A relative link should've been updated. 191 // A relative link should've been updated.
189 EXPECT_THAT(page_info_.get()->html, 192 EXPECT_THAT(page_info_.get()->html,
190 ContainsRegex("href=\"http://127.0.0.1:.*/relativelink.html\"")); 193 ContainsRegex("href=\"http://127.0.0.1:.*/relativelink.html\""));
191 EXPECT_THAT(page_info_.get()->html, 194 EXPECT_THAT(page_info_.get()->html,
192 HasSubstr("href=\"http://www.google.com/absolutelink.html\"")); 195 HasSubstr("href=\"http://www.google.com/absolutelink.html\""));
193 } 196 }
194 197
195 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeImages) { 198 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeImages) {
196 DistillerPageWebContents distiller_page( 199 DistillerPageWebContents distiller_page(
197 shell()->web_contents()->GetBrowserContext(), 200 shell()->web_contents()->GetBrowserContext(),
201 shell()->web_contents()->GetContainerBounds().size(),
198 scoped_ptr<SourcePageHandleWebContents>()); 202 scoped_ptr<SourcePageHandleWebContents>());
199 distiller_page_ = &distiller_page; 203 distiller_page_ = &distiller_page;
200 204
201 base::RunLoop run_loop; 205 base::RunLoop run_loop;
202 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); 206 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath);
203 run_loop.Run(); 207 run_loop.Run();
204 208
205 // A relative link should've been updated. 209 // A relative link should've been updated.
206 EXPECT_THAT(page_info_.get()->html, 210 EXPECT_THAT(page_info_.get()->html,
207 ContainsRegex("src=\"http://127.0.0.1:.*/relativeimage.png\"")); 211 ContainsRegex("src=\"http://127.0.0.1:.*/relativeimage.png\""));
208 EXPECT_THAT(page_info_.get()->html, 212 EXPECT_THAT(page_info_.get()->html,
209 HasSubstr("src=\"http://www.google.com/absoluteimage.png\"")); 213 HasSubstr("src=\"http://www.google.com/absoluteimage.png\""));
210 } 214 }
211 215
212 216
213 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeVideos) { 217 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeVideos) {
214 DistillerPageWebContents distiller_page( 218 DistillerPageWebContents distiller_page(
215 shell()->web_contents()->GetBrowserContext(), 219 shell()->web_contents()->GetBrowserContext(),
220 shell()->web_contents()->GetContainerBounds().size(),
216 scoped_ptr<SourcePageHandleWebContents>()); 221 scoped_ptr<SourcePageHandleWebContents>());
217 distiller_page_ = &distiller_page; 222 distiller_page_ = &distiller_page;
218 223
219 base::RunLoop run_loop; 224 base::RunLoop run_loop;
220 DistillPage(run_loop.QuitClosure(), kVideoArticlePath); 225 DistillPage(run_loop.QuitClosure(), kVideoArticlePath);
221 run_loop.Run(); 226 run_loop.Run();
222 227
223 // A relative source/track should've been updated. 228 // A relative source/track should've been updated.
224 EXPECT_THAT( 229 EXPECT_THAT(
225 page_info_.get()->html, 230 page_info_.get()->html,
226 ContainsRegex("src=\"http://127.0.0.1:.*/relative_video.mp4\"")); 231 ContainsRegex("src=\"http://127.0.0.1:.*/relative_video.mp4\""));
227 EXPECT_THAT( 232 EXPECT_THAT(
228 page_info_.get()->html, 233 page_info_.get()->html,
229 ContainsRegex("src=\"http://127.0.0.1:.*/relative_track_en.vtt\"")); 234 ContainsRegex("src=\"http://127.0.0.1:.*/relative_track_en.vtt\""));
230 EXPECT_THAT( 235 EXPECT_THAT(
231 page_info_.get()->html, 236 page_info_.get()->html,
232 HasSubstr("src=\"http://www.google.com/absolute_video.ogg\"")); 237 HasSubstr("src=\"http://www.google.com/absolute_video.ogg\""));
233 EXPECT_THAT( 238 EXPECT_THAT(
234 page_info_.get()->html, 239 page_info_.get()->html,
235 HasSubstr("src=\"http://www.google.com/absolute_track_fr.vtt\"")); 240 HasSubstr("src=\"http://www.google.com/absolute_track_fr.vtt\""));
236 } 241 }
237 242
238 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, VisibilityDetection) { 243 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, VisibilityDetection) {
239 DistillerPageWebContents distiller_page( 244 DistillerPageWebContents distiller_page(
240 shell()->web_contents()->GetBrowserContext(), 245 shell()->web_contents()->GetBrowserContext(),
246 shell()->web_contents()->GetContainerBounds().size(),
241 scoped_ptr<SourcePageHandleWebContents>()); 247 scoped_ptr<SourcePageHandleWebContents>());
242 distiller_page_ = &distiller_page; 248 distiller_page_ = &distiller_page;
243 249
244 // visble_style.html and invisible_style.html only differ by the visibility 250 // visble_style.html and invisible_style.html only differ by the visibility
245 // internal stylesheet. 251 // internal stylesheet.
246 252
247 { 253 {
248 base::RunLoop run_loop; 254 base::RunLoop run_loop;
249 DistillPage(run_loop.QuitClosure(), "/visible_style.html"); 255 DistillPage(run_loop.QuitClosure(), "/visible_style.html");
250 run_loop.Run(); 256 run_loop.Run();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 content::PAGE_TRANSITION_TYPED, 333 content::PAGE_TRANSITION_TYPED,
328 std::string()); 334 std::string());
329 url_loaded_runner.Run(); 335 url_loaded_runner.Run();
330 336
331 scoped_ptr<content::WebContents> old_web_contents_sptr(current_web_contents); 337 scoped_ptr<content::WebContents> old_web_contents_sptr(current_web_contents);
332 scoped_ptr<SourcePageHandleWebContents> source_page_handle( 338 scoped_ptr<SourcePageHandleWebContents> source_page_handle(
333 new SourcePageHandleWebContents(old_web_contents_sptr.Pass())); 339 new SourcePageHandleWebContents(old_web_contents_sptr.Pass()));
334 340
335 TestDistillerPageWebContents distiller_page( 341 TestDistillerPageWebContents distiller_page(
336 shell()->web_contents()->GetBrowserContext(), 342 shell()->web_contents()->GetBrowserContext(),
343 shell()->web_contents()->GetContainerBounds().size(),
337 source_page_handle.Pass(), 344 source_page_handle.Pass(),
338 expect_new_web_contents); 345 expect_new_web_contents);
339 distiller_page_ = &distiller_page; 346 distiller_page_ = &distiller_page;
340 347
341 base::RunLoop run_loop; 348 base::RunLoop run_loop;
342 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); 349 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath);
343 run_loop.Run(); 350 run_loop.Run();
344 351
345 // Sanity check of distillation process. 352 // Sanity check of distillation process.
346 EXPECT_EQ(expect_new_web_contents, distiller_page.new_web_contents_created()); 353 EXPECT_EQ(expect_new_web_contents, distiller_page.new_web_contents_created());
347 EXPECT_EQ("Test Page Title", page_info_.get()->title); 354 EXPECT_EQ("Test Page Title", page_info_.get()->title);
348 } 355 }
349 356
350 } // namespace dom_distiller 357 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698