Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / components / dom_distiller / content / distiller_page_web_contents_browsertest.cc
index e8c1efa..af3b96d 100644 (file)
@@ -89,9 +89,10 @@ class TestDistillerPageWebContents : public DistillerPageWebContents {
  public:
   TestDistillerPageWebContents(
       content::BrowserContext* browser_context,
+      const gfx::Size& render_view_size,
       scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle,
       bool expect_new_web_contents)
-      : DistillerPageWebContents(browser_context,
+      : DistillerPageWebContents(browser_context, render_view_size,
                                  optional_web_contents_handle.Pass()),
         expect_new_web_contents_(expect_new_web_contents),
         new_web_contents_created_(false) {}
@@ -131,38 +132,29 @@ class WebContentsMainFrameHelper : public content::WebContentsObserver {
   WebContentsMainFrameHelper(content::WebContents* web_contents,
                              const base::Closure& callback,
                              bool wait_for_document_loaded)
-      : web_contents_(web_contents),
+      : WebContentsObserver(web_contents),
         callback_(callback),
-        wait_for_document_loaded_(wait_for_document_loaded) {
-    content::WebContentsObserver::Observe(web_contents);
-  }
+        wait_for_document_loaded_(wait_for_document_loaded) {}
 
   virtual void DidCommitProvisionalLoadForFrame(
-      int64 frame_id,
-      const base::string16& frame_unique_name,
-      bool is_main_frame,
+      content::RenderFrameHost* render_frame_host,
       const GURL& url,
-      content::PageTransition transition_type,
-      content::RenderViewHost* render_view_host) OVERRIDE {
+      content::PageTransition transition_type) OVERRIDE {
     if (wait_for_document_loaded_)
       return;
-    if (is_main_frame)
+    if (!render_frame_host->GetParent())
       callback_.Run();
   }
 
   virtual void DocumentLoadedInFrame(
-      int64 frame_id,
-      content::RenderViewHost* render_view_host) OVERRIDE {
+      content::RenderFrameHost* render_frame_host) OVERRIDE {
     if (wait_for_document_loaded_) {
-      if (web_contents_ &&
-          frame_id == web_contents_->GetMainFrame()->GetRoutingID()) {
+      if (!render_frame_host->GetParent())
         callback_.Run();
-      }
     }
   }
 
  private:
-  content::WebContents* web_contents_;
   base::Closure callback_;
   bool wait_for_document_loaded_;
 };
@@ -170,6 +162,7 @@ class WebContentsMainFrameHelper : public content::WebContentsObserver {
 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, BasicDistillationWorks) {
   DistillerPageWebContents distiller_page(
       shell()->web_contents()->GetBrowserContext(),
+      shell()->web_contents()->GetContainerBounds().size(),
       scoped_ptr<SourcePageHandleWebContents>());
   distiller_page_ = &distiller_page;
 
@@ -187,6 +180,7 @@ IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, BasicDistillationWorks) {
 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeLinks) {
   DistillerPageWebContents distiller_page(
       shell()->web_contents()->GetBrowserContext(),
+      shell()->web_contents()->GetContainerBounds().size(),
       scoped_ptr<SourcePageHandleWebContents>());
   distiller_page_ = &distiller_page;
 
@@ -204,6 +198,7 @@ IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeLinks) {
 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeImages) {
   DistillerPageWebContents distiller_page(
       shell()->web_contents()->GetBrowserContext(),
+      shell()->web_contents()->GetContainerBounds().size(),
       scoped_ptr<SourcePageHandleWebContents>());
   distiller_page_ = &distiller_page;
 
@@ -222,6 +217,7 @@ IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeImages) {
 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeVideos) {
   DistillerPageWebContents distiller_page(
       shell()->web_contents()->GetBrowserContext(),
+      shell()->web_contents()->GetContainerBounds().size(),
       scoped_ptr<SourcePageHandleWebContents>());
   distiller_page_ = &distiller_page;
 
@@ -247,6 +243,7 @@ IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, HandlesRelativeVideos) {
 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, VisibilityDetection) {
   DistillerPageWebContents distiller_page(
       shell()->web_contents()->GetBrowserContext(),
+      shell()->web_contents()->GetContainerBounds().size(),
       scoped_ptr<SourcePageHandleWebContents>());
   distiller_page_ = &distiller_page;
 
@@ -343,6 +340,7 @@ void DistillerPageWebContentsTest::RunUseCurrentWebContentsTest(
 
   TestDistillerPageWebContents distiller_page(
       shell()->web_contents()->GetBrowserContext(),
+      shell()->web_contents()->GetContainerBounds().size(),
       source_page_handle.Pass(),
       expect_new_web_contents);
   distiller_page_ = &distiller_page;
@@ -356,4 +354,54 @@ void DistillerPageWebContentsTest::RunUseCurrentWebContentsTest(
   EXPECT_EQ("Test Page Title", page_info_.get()->title);
 }
 
+IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, MarkupInfo) {
+  DistillerPageWebContents distiller_page(
+      shell()->web_contents()->GetBrowserContext(),
+      shell()->web_contents()->GetContainerBounds().size(),
+      scoped_ptr<SourcePageHandleWebContents>());
+  distiller_page_ = &distiller_page;
+
+  base::RunLoop run_loop;
+  DistillPage(run_loop.QuitClosure(), "/markup_article.html");
+  run_loop.Run();
+
+  EXPECT_THAT(page_info_.get()->html, HasSubstr("Lorem ipsum"));
+  EXPECT_EQ("Marked-up Markup Test Page Title", page_info_.get()->title);
+
+  const DistilledPageInfo::MarkupInfo& markup_info = page_info_->markup_info;
+  EXPECT_EQ("Marked-up Markup Test Page Title", markup_info.title);
+  EXPECT_EQ("Article", markup_info.type);
+  EXPECT_EQ("http://test/markup.html", markup_info.url);
+  EXPECT_EQ("This page tests Markup Info.", markup_info.description);
+  EXPECT_EQ("Whoever Published", markup_info.publisher);
+  EXPECT_EQ("Copyright 2000-2014 Whoever Copyrighted", markup_info.copyright);
+  EXPECT_EQ("Whoever Authored", markup_info.author);
+
+  const DistilledPageInfo::MarkupArticle& markup_article = markup_info.article;
+  EXPECT_EQ("Whatever Section", markup_article.section);
+  EXPECT_EQ("July 23, 2014", markup_article.published_time);
+  EXPECT_EQ("2014-07-23T23:59", markup_article.modified_time);
+  EXPECT_EQ("", markup_article.expiration_time);
+  ASSERT_EQ(1U, markup_article.authors.size());
+  EXPECT_EQ("Whoever Authored", markup_article.authors[0]);
+
+  ASSERT_EQ(2U, markup_info.images.size());
+
+  const DistilledPageInfo::MarkupImage& markup_image1 = markup_info.images[0];
+  EXPECT_EQ("http://test/markup1.jpeg", markup_image1.url);
+  EXPECT_EQ("https://test/markup1.jpeg", markup_image1.secure_url);
+  EXPECT_EQ("jpeg", markup_image1.type);
+  EXPECT_EQ("", markup_image1.caption);
+  EXPECT_EQ(600, markup_image1.width);
+  EXPECT_EQ(400, markup_image1.height);
+
+  const DistilledPageInfo::MarkupImage& markup_image2 = markup_info.images[1];
+  EXPECT_EQ("http://test/markup2.gif", markup_image2.url);
+  EXPECT_EQ("https://test/markup2.gif", markup_image2.secure_url);
+  EXPECT_EQ("gif", markup_image2.type);
+  EXPECT_EQ("", markup_image2.caption);
+  EXPECT_EQ(1000, markup_image2.width);
+  EXPECT_EQ(600, markup_image2.height);
+}
+
 }  // namespace dom_distiller