| OLD | NEW |
| 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 "components/dom_distiller/content/browser/distiller_page_web_contents.h
" | 5 #include "components/dom_distiller/content/browser/distiller_page_web_contents.h
" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 DistillerPageWebContents::CreateNewWebContents(url); | 175 DistillerPageWebContents::CreateNewWebContents(url); |
| 176 } | 176 } |
| 177 | 177 |
| 178 bool new_web_contents_created() { return new_web_contents_created_; } | 178 bool new_web_contents_created() { return new_web_contents_created_; } |
| 179 | 179 |
| 180 private: | 180 private: |
| 181 bool expect_new_web_contents_; | 181 bool expect_new_web_contents_; |
| 182 bool new_web_contents_created_; | 182 bool new_web_contents_created_; |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, BasicDistillationWorks) { | 185 // Consistently failing for no obvious reason on Android. |
| 186 // See: crbug.com/728960. |
| 187 #if defined(OS_ANDROID) |
| 188 #define MAYBE_BasicDistillationWorks DISABLED_BasicDistillationWorks |
| 189 #else |
| 190 #define MAYBE_BasicDistillationWorks BasicDistillationWorks |
| 191 #endif |
| 192 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, |
| 193 MAYBE_BasicDistillationWorks) { |
| 186 DistillerPageWebContents distiller_page( | 194 DistillerPageWebContents distiller_page( |
| 187 shell()->web_contents()->GetBrowserContext(), | 195 shell()->web_contents()->GetBrowserContext(), |
| 188 shell()->web_contents()->GetContainerBounds().size(), | 196 shell()->web_contents()->GetContainerBounds().size(), |
| 189 std::unique_ptr<SourcePageHandleWebContents>()); | 197 std::unique_ptr<SourcePageHandleWebContents>()); |
| 190 distiller_page_ = &distiller_page; | 198 distiller_page_ = &distiller_page; |
| 191 | 199 |
| 192 base::RunLoop run_loop; | 200 base::RunLoop run_loop; |
| 193 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); | 201 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); |
| 194 run_loop.Run(); | 202 run_loop.Run(); |
| 195 | 203 |
| 196 EXPECT_EQ("Test Page Title", distiller_result_->title()); | 204 EXPECT_EQ("Test Page Title", distiller_result_->title()); |
| 197 EXPECT_THAT(distiller_result_->distilled_content().html(), | 205 EXPECT_THAT(distiller_result_->distilled_content().html(), |
| 198 HasSubstr("Lorem ipsum")); | 206 HasSubstr("Lorem ipsum")); |
| 199 EXPECT_THAT(distiller_result_->distilled_content().html(), | 207 EXPECT_THAT(distiller_result_->distilled_content().html(), |
| 200 Not(HasSubstr("questionable content"))); | 208 Not(HasSubstr("questionable content"))); |
| 201 EXPECT_EQ("", distiller_result_->pagination_info().next_page()); | 209 EXPECT_EQ("", distiller_result_->pagination_info().next_page()); |
| 202 EXPECT_EQ("", distiller_result_->pagination_info().prev_page()); | 210 EXPECT_EQ("", distiller_result_->pagination_info().prev_page()); |
| 203 } | 211 } |
| 204 | 212 |
| 205 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeLinks) { | 213 // Consistently failing for no obvious reason on Android. |
| 214 // See: crbug.com/728960. |
| 215 #if defined(OS_ANDROID) |
| 216 #define MAYBE_HandlesRelativeLinks DISABLED_HandlesRelativeLinks |
| 217 #else |
| 218 #define MAYBE_HandlesRelativeLinks HandlesRelativeLinks |
| 219 #endif |
| 220 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, |
| 221 MAYBE_HandlesRelativeLinks) { |
| 206 DistillerPageWebContents distiller_page( | 222 DistillerPageWebContents distiller_page( |
| 207 shell()->web_contents()->GetBrowserContext(), | 223 shell()->web_contents()->GetBrowserContext(), |
| 208 shell()->web_contents()->GetContainerBounds().size(), | 224 shell()->web_contents()->GetContainerBounds().size(), |
| 209 std::unique_ptr<SourcePageHandleWebContents>()); | 225 std::unique_ptr<SourcePageHandleWebContents>()); |
| 210 distiller_page_ = &distiller_page; | 226 distiller_page_ = &distiller_page; |
| 211 | 227 |
| 212 base::RunLoop run_loop; | 228 base::RunLoop run_loop; |
| 213 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); | 229 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); |
| 214 run_loop.Run(); | 230 run_loop.Run(); |
| 215 | 231 |
| 216 // A relative link should've been updated. | 232 // A relative link should've been updated. |
| 217 EXPECT_THAT(distiller_result_->distilled_content().html(), | 233 EXPECT_THAT(distiller_result_->distilled_content().html(), |
| 218 ContainsRegex("href=\"http://127.0.0.1:.*/relativelink.html\"")); | 234 ContainsRegex("href=\"http://127.0.0.1:.*/relativelink.html\"")); |
| 219 EXPECT_THAT(distiller_result_->distilled_content().html(), | 235 EXPECT_THAT(distiller_result_->distilled_content().html(), |
| 220 HasSubstr("href=\"http://www.google.com/absolutelink.html\"")); | 236 HasSubstr("href=\"http://www.google.com/absolutelink.html\"")); |
| 221 } | 237 } |
| 222 | 238 |
| 223 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeImages) { | 239 // Consistently failing for no obvious reason on Android. |
| 240 // See: crbug.com/728960. |
| 241 #if defined(OS_ANDROID) |
| 242 #define MAYBE_HandlesRelativeImages DISABLED_HandlesRelativeImages |
| 243 #else |
| 244 #define MAYBE_HandlesRelativeImages HandlesRelativeImages |
| 245 #endif |
| 246 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, |
| 247 MAYBE_HandlesRelativeImages) { |
| 224 DistillerPageWebContents distiller_page( | 248 DistillerPageWebContents distiller_page( |
| 225 shell()->web_contents()->GetBrowserContext(), | 249 shell()->web_contents()->GetBrowserContext(), |
| 226 shell()->web_contents()->GetContainerBounds().size(), | 250 shell()->web_contents()->GetContainerBounds().size(), |
| 227 std::unique_ptr<SourcePageHandleWebContents>()); | 251 std::unique_ptr<SourcePageHandleWebContents>()); |
| 228 distiller_page_ = &distiller_page; | 252 distiller_page_ = &distiller_page; |
| 229 | 253 |
| 230 base::RunLoop run_loop; | 254 base::RunLoop run_loop; |
| 231 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); | 255 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); |
| 232 run_loop.Run(); | 256 run_loop.Run(); |
| 233 | 257 |
| 234 // A relative link should've been updated. | 258 // A relative link should've been updated. |
| 235 EXPECT_THAT(distiller_result_->distilled_content().html(), | 259 EXPECT_THAT(distiller_result_->distilled_content().html(), |
| 236 ContainsRegex("src=\"http://127.0.0.1:.*/relativeimage.png\"")); | 260 ContainsRegex("src=\"http://127.0.0.1:.*/relativeimage.png\"")); |
| 237 EXPECT_THAT(distiller_result_->distilled_content().html(), | 261 EXPECT_THAT(distiller_result_->distilled_content().html(), |
| 238 HasSubstr("src=\"http://www.google.com/absoluteimage.png\"")); | 262 HasSubstr("src=\"http://www.google.com/absoluteimage.png\"")); |
| 239 } | 263 } |
| 240 | 264 |
| 241 | 265 // Consistently failing for no obvious reason on Android. |
| 242 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeVideos) { | 266 // See: crbug.com/728960. |
| 267 #if defined(OS_ANDROID) |
| 268 #define MAYBE_HandlesRelativeVideos DISABLED_HandlesRelativeVideos |
| 269 #else |
| 270 #define MAYBE_HandlesRelativeVideos HandlesRelativeVideos |
| 271 #endif |
| 272 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, |
| 273 MAYBE_HandlesRelativeVideos) { |
| 243 DistillerPageWebContents distiller_page( | 274 DistillerPageWebContents distiller_page( |
| 244 shell()->web_contents()->GetBrowserContext(), | 275 shell()->web_contents()->GetBrowserContext(), |
| 245 shell()->web_contents()->GetContainerBounds().size(), | 276 shell()->web_contents()->GetContainerBounds().size(), |
| 246 std::unique_ptr<SourcePageHandleWebContents>()); | 277 std::unique_ptr<SourcePageHandleWebContents>()); |
| 247 distiller_page_ = &distiller_page; | 278 distiller_page_ = &distiller_page; |
| 248 | 279 |
| 249 base::RunLoop run_loop; | 280 base::RunLoop run_loop; |
| 250 DistillPage(run_loop.QuitClosure(), kVideoArticlePath); | 281 DistillPage(run_loop.QuitClosure(), kVideoArticlePath); |
| 251 run_loop.Run(); | 282 run_loop.Run(); |
| 252 | 283 |
| 253 // A relative source/track should've been updated. | 284 // A relative source/track should've been updated. |
| 254 EXPECT_THAT(distiller_result_->distilled_content().html(), | 285 EXPECT_THAT(distiller_result_->distilled_content().html(), |
| 255 ContainsRegex("src=\"http://127.0.0.1:.*/relative_video.webm\"")); | 286 ContainsRegex("src=\"http://127.0.0.1:.*/relative_video.webm\"")); |
| 256 EXPECT_THAT( | 287 EXPECT_THAT( |
| 257 distiller_result_->distilled_content().html(), | 288 distiller_result_->distilled_content().html(), |
| 258 ContainsRegex("src=\"http://127.0.0.1:.*/relative_track_en.vtt\"")); | 289 ContainsRegex("src=\"http://127.0.0.1:.*/relative_track_en.vtt\"")); |
| 259 EXPECT_THAT(distiller_result_->distilled_content().html(), | 290 EXPECT_THAT(distiller_result_->distilled_content().html(), |
| 260 HasSubstr("src=\"http://www.google.com/absolute_video.ogg\"")); | 291 HasSubstr("src=\"http://www.google.com/absolute_video.ogg\"")); |
| 261 EXPECT_THAT(distiller_result_->distilled_content().html(), | 292 EXPECT_THAT(distiller_result_->distilled_content().html(), |
| 262 HasSubstr("src=\"http://www.google.com/absolute_track_fr.vtt\"")); | 293 HasSubstr("src=\"http://www.google.com/absolute_track_fr.vtt\"")); |
| 263 } | 294 } |
| 264 | 295 |
| 265 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, VisibilityDetection) { | 296 // Consistently failing for no obvious reason on Android. |
| 297 // See: crbug.com/728960. |
| 298 #if defined(OS_ANDROID) |
| 299 #define MAYBE_VisibilityDetection DISABLED_VisibilityDetection |
| 300 #else |
| 301 #define MAYBE_VisibilityDetection VisibilityDetection |
| 302 #endif |
| 303 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, |
| 304 MAYBE_VisibilityDetection) { |
| 266 DistillerPageWebContents distiller_page( | 305 DistillerPageWebContents distiller_page( |
| 267 shell()->web_contents()->GetBrowserContext(), | 306 shell()->web_contents()->GetBrowserContext(), |
| 268 shell()->web_contents()->GetContainerBounds().size(), | 307 shell()->web_contents()->GetContainerBounds().size(), |
| 269 std::unique_ptr<SourcePageHandleWebContents>()); | 308 std::unique_ptr<SourcePageHandleWebContents>()); |
| 270 distiller_page_ = &distiller_page; | 309 distiller_page_ = &distiller_page; |
| 271 | 310 |
| 272 // visble_style.html and invisible_style.html only differ by the visibility | 311 // visble_style.html and invisible_style.html only differ by the visibility |
| 273 // internal stylesheet. | 312 // internal stylesheet. |
| 274 | 313 |
| 275 { | 314 { |
| 276 base::RunLoop run_loop; | 315 base::RunLoop run_loop; |
| 277 DistillPage(run_loop.QuitClosure(), "/visible_style.html"); | 316 DistillPage(run_loop.QuitClosure(), "/visible_style.html"); |
| 278 run_loop.Run(); | 317 run_loop.Run(); |
| 279 EXPECT_THAT(distiller_result_->distilled_content().html(), | 318 EXPECT_THAT(distiller_result_->distilled_content().html(), |
| 280 HasSubstr("Lorem ipsum")); | 319 HasSubstr("Lorem ipsum")); |
| 281 } | 320 } |
| 282 | 321 |
| 283 { | 322 { |
| 284 base::RunLoop run_loop; | 323 base::RunLoop run_loop; |
| 285 DistillPage(run_loop.QuitClosure(), "/invisible_style.html"); | 324 DistillPage(run_loop.QuitClosure(), "/invisible_style.html"); |
| 286 run_loop.Run(); | 325 run_loop.Run(); |
| 287 EXPECT_THAT(distiller_result_->distilled_content().html(), | 326 EXPECT_THAT(distiller_result_->distilled_content().html(), |
| 288 Not(HasSubstr("Lorem ipsum"))); | 327 Not(HasSubstr("Lorem ipsum"))); |
| 289 } | 328 } |
| 290 } | 329 } |
| 291 | 330 |
| 331 // Consistently failing for no obvious reason on Android. |
| 332 // See: crbug.com/728960. |
| 333 #if defined(OS_ANDROID) |
| 334 #define MAYBE_UsingCurrentWebContentsWrongUrl \ |
| 335 DISABLED_UsingCurrentWebContentsWrongUrl |
| 336 #else |
| 337 #define MAYBE_UsingCurrentWebContentsWrongUrl UsingCurrentWebContentsWrongUrl |
| 338 #endif |
| 292 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, | 339 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, |
| 293 UsingCurrentWebContentsWrongUrl) { | 340 MAYBE_UsingCurrentWebContentsWrongUrl) { |
| 294 std::string url("/bogus"); | 341 std::string url("/bogus"); |
| 295 bool expect_new_web_contents = true; | 342 bool expect_new_web_contents = true; |
| 296 bool setup_main_frame_observer = true; | 343 bool setup_main_frame_observer = true; |
| 297 bool wait_for_document_loaded = true; | 344 bool wait_for_document_loaded = true; |
| 298 RunUseCurrentWebContentsTest(url, | 345 RunUseCurrentWebContentsTest(url, |
| 299 expect_new_web_contents, | 346 expect_new_web_contents, |
| 300 setup_main_frame_observer, | 347 setup_main_frame_observer, |
| 301 wait_for_document_loaded); | 348 wait_for_document_loaded); |
| 302 } | 349 } |
| 303 | 350 |
| 351 // Consistently failing for no obvious reason on Android. |
| 352 // See: crbug.com/728960. |
| 353 #if defined(OS_ANDROID) |
| 354 #define MAYBE_UsingCurrentWebContentsNoMainFrameObserver \ |
| 355 DISABLED_UsingCurrentWebContentsNoMainFrameObserver |
| 356 #else |
| 357 #define MAYBE_UsingCurrentWebContentsNoMainFrameObserver \ |
| 358 UsingCurrentWebContentsNoMainFrameObserver |
| 359 #endif |
| 304 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, | 360 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, |
| 305 UsingCurrentWebContentsNoMainFrameObserver) { | 361 MAYBE_UsingCurrentWebContentsNoMainFrameObserver) { |
| 306 std::string url(kSimpleArticlePath); | 362 std::string url(kSimpleArticlePath); |
| 307 bool expect_new_web_contents = true; | 363 bool expect_new_web_contents = true; |
| 308 bool setup_main_frame_observer = false; | 364 bool setup_main_frame_observer = false; |
| 309 bool wait_for_document_loaded = true; | 365 bool wait_for_document_loaded = true; |
| 310 RunUseCurrentWebContentsTest(url, | 366 RunUseCurrentWebContentsTest(url, |
| 311 expect_new_web_contents, | 367 expect_new_web_contents, |
| 312 setup_main_frame_observer, | 368 setup_main_frame_observer, |
| 313 wait_for_document_loaded); | 369 wait_for_document_loaded); |
| 314 } | 370 } |
| 315 | 371 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 // It can not crash the loop when returning the result. | 466 // It can not crash the loop when returning the result. |
| 411 delete distiller_page_; | 467 delete distiller_page_; |
| 412 | 468 |
| 413 // Make sure the test ends when it does not crash. | 469 // Make sure the test ends when it does not crash. |
| 414 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 470 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 415 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(2)); | 471 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(2)); |
| 416 | 472 |
| 417 run_loop.Run(); | 473 run_loop.Run(); |
| 418 } | 474 } |
| 419 | 475 |
| 420 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, MarkupInfo) { | 476 // Consistently failing for no obvious reason on Android. |
| 477 // See: crbug.com/728960. |
| 478 #if defined(OS_ANDROID) |
| 479 #define MAYBE_MarkupInfo DISABLED_MarkupInfo |
| 480 #else |
| 481 #define MAYBE_MarkupInfo MarkupInfo |
| 482 #endif |
| 483 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, MAYBE_MarkupInfo) { |
| 421 DistillerPageWebContents distiller_page( | 484 DistillerPageWebContents distiller_page( |
| 422 shell()->web_contents()->GetBrowserContext(), | 485 shell()->web_contents()->GetBrowserContext(), |
| 423 shell()->web_contents()->GetContainerBounds().size(), | 486 shell()->web_contents()->GetContainerBounds().size(), |
| 424 std::unique_ptr<SourcePageHandleWebContents>()); | 487 std::unique_ptr<SourcePageHandleWebContents>()); |
| 425 distiller_page_ = &distiller_page; | 488 distiller_page_ = &distiller_page; |
| 426 | 489 |
| 427 base::RunLoop run_loop; | 490 base::RunLoop run_loop; |
| 428 DistillPage(run_loop.QuitClosure(), "/markup_article.html"); | 491 DistillPage(run_loop.QuitClosure(), "/markup_article.html"); |
| 429 run_loop.Run(); | 492 run_loop.Run(); |
| 430 | 493 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 ASSERT_TRUE(js_result_); | 582 ASSERT_TRUE(js_result_); |
| 520 ASSERT_TRUE(js_result_->GetAsDictionary(&dict)); | 583 ASSERT_TRUE(js_result_->GetAsDictionary(&dict)); |
| 521 | 584 |
| 522 ASSERT_TRUE(dict->HasKey("success")); | 585 ASSERT_TRUE(dict->HasKey("success")); |
| 523 bool success; | 586 bool success; |
| 524 ASSERT_TRUE(dict->GetBoolean("success", &success)); | 587 ASSERT_TRUE(dict->GetBoolean("success", &success)); |
| 525 EXPECT_TRUE(success); | 588 EXPECT_TRUE(success); |
| 526 } | 589 } |
| 527 | 590 |
| 528 } // namespace dom_distiller | 591 } // namespace dom_distiller |
| OLD | NEW |