| 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 "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 10 matching lines...) Expand all Loading... |
| 21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 | 22 |
| 23 using content::ContentBrowserTest; | 23 using content::ContentBrowserTest; |
| 24 using testing::ContainsRegex; | 24 using testing::ContainsRegex; |
| 25 using testing::HasSubstr; | 25 using testing::HasSubstr; |
| 26 using testing::Not; | 26 using testing::Not; |
| 27 | 27 |
| 28 namespace dom_distiller { | 28 namespace dom_distiller { |
| 29 | 29 |
| 30 const char* kSimpleArticlePath = "/simple_article.html"; | 30 const char* kSimpleArticlePath = "/simple_article.html"; |
| 31 const char* kVideoArticlePath = "/video_article.html"; |
| 31 | 32 |
| 32 class DistillerPageWebContentsTest : public ContentBrowserTest { | 33 class DistillerPageWebContentsTest : public ContentBrowserTest { |
| 33 public: | 34 public: |
| 34 // ContentBrowserTest: | 35 // ContentBrowserTest: |
| 35 virtual void SetUpOnMainThread() OVERRIDE { | 36 virtual void SetUpOnMainThread() OVERRIDE { |
| 36 AddComponentsResources(); | 37 AddComponentsResources(); |
| 37 SetUpTestServer(); | 38 SetUpTestServer(); |
| 38 ContentBrowserTest::SetUpOnMainThread(); | 39 ContentBrowserTest::SetUpOnMainThread(); |
| 39 } | 40 } |
| 40 | 41 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); | 211 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); |
| 211 run_loop.Run(); | 212 run_loop.Run(); |
| 212 | 213 |
| 213 // A relative link should've been updated. | 214 // A relative link should've been updated. |
| 214 EXPECT_THAT(page_info_.get()->html, | 215 EXPECT_THAT(page_info_.get()->html, |
| 215 ContainsRegex("src=\"http://127.0.0.1:.*/relativeimage.png\"")); | 216 ContainsRegex("src=\"http://127.0.0.1:.*/relativeimage.png\"")); |
| 216 EXPECT_THAT(page_info_.get()->html, | 217 EXPECT_THAT(page_info_.get()->html, |
| 217 HasSubstr("src=\"http://www.google.com/absoluteimage.png\"")); | 218 HasSubstr("src=\"http://www.google.com/absoluteimage.png\"")); |
| 218 } | 219 } |
| 219 | 220 |
| 221 |
| 222 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeVideos) { |
| 223 DistillerPageWebContents distiller_page( |
| 224 shell()->web_contents()->GetBrowserContext(), |
| 225 scoped_ptr<SourcePageHandleWebContents>()); |
| 226 distiller_page_ = &distiller_page; |
| 227 |
| 228 base::RunLoop run_loop; |
| 229 DistillPage(run_loop.QuitClosure(), kVideoArticlePath); |
| 230 run_loop.Run(); |
| 231 |
| 232 // A relative source/track should've been updated. |
| 233 EXPECT_THAT( |
| 234 page_info_.get()->html, |
| 235 ContainsRegex("src=\"http://127.0.0.1:.*/relative_video.mp4\"")); |
| 236 EXPECT_THAT( |
| 237 page_info_.get()->html, |
| 238 ContainsRegex("src=\"http://127.0.0.1:.*/relative_track_en.vtt\"")); |
| 239 EXPECT_THAT( |
| 240 page_info_.get()->html, |
| 241 HasSubstr("src=\"http://www.google.com/absolute_video.ogg\"")); |
| 242 EXPECT_THAT( |
| 243 page_info_.get()->html, |
| 244 HasSubstr("src=\"http://www.google.com/absolute_track_fr.vtt\"")); |
| 245 } |
| 246 |
| 220 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, VisibilityDetection) { | 247 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, VisibilityDetection) { |
| 221 DistillerPageWebContents distiller_page( | 248 DistillerPageWebContents distiller_page( |
| 222 shell()->web_contents()->GetBrowserContext(), | 249 shell()->web_contents()->GetBrowserContext(), |
| 223 scoped_ptr<SourcePageHandleWebContents>()); | 250 scoped_ptr<SourcePageHandleWebContents>()); |
| 224 distiller_page_ = &distiller_page; | 251 distiller_page_ = &distiller_page; |
| 225 | 252 |
| 226 // visble_style.html and invisible_style.html only differ by the visibility | 253 // visble_style.html and invisible_style.html only differ by the visibility |
| 227 // internal stylesheet. | 254 // internal stylesheet. |
| 228 | 255 |
| 229 { | 256 { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 base::RunLoop run_loop; | 350 base::RunLoop run_loop; |
| 324 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); | 351 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); |
| 325 run_loop.Run(); | 352 run_loop.Run(); |
| 326 | 353 |
| 327 // Sanity check of distillation process. | 354 // Sanity check of distillation process. |
| 328 EXPECT_EQ(expect_new_web_contents, distiller_page.new_web_contents_created()); | 355 EXPECT_EQ(expect_new_web_contents, distiller_page.new_web_contents_created()); |
| 329 EXPECT_EQ("Test Page Title", page_info_.get()->title); | 356 EXPECT_EQ("Test Page Title", page_info_.get()->title); |
| 330 } | 357 } |
| 331 | 358 |
| 332 } // namespace dom_distiller | 359 } // namespace dom_distiller |
| OLD | NEW |