Upstream version 9.37.195.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / pdf / pdf_browsertest.cc
index aeb9683..ae83110 100644 (file)
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include "base/command_line.h"
 #include "base/file_util.h"
 #include "base/files/file.h"
 #include "base/files/file_enumerator.h"
@@ -21,6 +22,7 @@
 #include "content/public/browser/notification_observer.h"
 #include "content/public/browser/render_view_host.h"
 #include "content/public/browser/web_contents.h"
+#include "content/public/common/content_switches.h"
 #include "content/public/test/browser_test_utils.h"
 #include "net/test/embedded_test_server/embedded_test_server.h"
 #include "third_party/skia/include/core/SkBitmap.h"
@@ -51,7 +53,8 @@ class PDFBrowserTest : public InProcessBrowserTest,
         load_stop_notification_count_(0) {
     base::FilePath src_dir;
     EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir));
-    pdf_test_server_.ServeFilesFromDirectory(src_dir.AppendASCII("pdf/test"));
+    pdf_test_server_.ServeFilesFromDirectory(src_dir.AppendASCII(
+        "chrome/test/data/pdf_private"));
   }
 
  protected:
@@ -64,12 +67,6 @@ class PDFBrowserTest : public InProcessBrowserTest,
     return load_stop_notification_count_;
   }
 
-  base::FilePath GetPDFTestDir() {
-    return base::FilePath(base::FilePath::kCurrentDirectory).AppendASCII("..").
-        AppendASCII("..").AppendASCII("..").AppendASCII("pdf").
-        AppendASCII("test");
-  }
-
   void Load() {
     // Make sure to set the window size before rendering, as otherwise rendering
     // to a smaller window and then expanding leads to slight anti-aliasing
@@ -82,7 +79,7 @@ class PDFBrowserTest : public InProcessBrowserTest,
     browser()->window()->SetBounds(bounds);
 
     GURL url(ui_test_utils::GetTestUrl(
-        GetPDFTestDir(),
+        base::FilePath(FILE_PATH_LITERAL("pdf_private")),
         base::FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf"))));
     ui_test_utils::NavigateToURL(browser(), url);
   }
@@ -95,14 +92,17 @@ class PDFBrowserTest : public InProcessBrowserTest,
     DCHECK(web_contents);
 
     content::RenderWidgetHost* rwh = web_contents->GetRenderViewHost();
-    rwh->GetSnapshotFromRenderer(gfx::Rect(), base::Bind(
-        &PDFBrowserTest::GetSnapshotFromRendererCallback, this));
+    rwh->CopyFromBackingStore(
+        gfx::Rect(),
+        gfx::Size(),
+        base::Bind(&PDFBrowserTest::CopyFromBackingStoreCallback, this),
+        SkBitmap::kARGB_8888_Config);
 
     content::RunMessageLoop();
 
     if (snapshot_different_) {
       LOG(INFO) << "Rendering didn't match, see result " <<
-          snapshot_filename_.value().c_str();
+          snapshot_filename_.value();
     }
     return !snapshot_different_;
   }
@@ -126,12 +126,11 @@ class PDFBrowserTest : public InProcessBrowserTest,
   }
 
  private:
-  void GetSnapshotFromRendererCallback(bool success,
-                                       const SkBitmap& bitmap) {
+  void CopyFromBackingStoreCallback(bool success, const SkBitmap& bitmap) {
     base::MessageLoopForUI::current()->Quit();
     ASSERT_EQ(success, true);
     base::FilePath reference = ui_test_utils::GetTestFilePath(
-        GetPDFTestDir(),
+        base::FilePath(FILE_PATH_LITERAL("pdf_private")),
         base::FilePath().AppendASCII(expected_filename_));
     base::File::Info info;
     ASSERT_TRUE(base::GetFileInfo(reference, &info));
@@ -186,7 +185,7 @@ class PDFBrowserTest : public InProcessBrowserTest,
       std::vector<unsigned char> png_data;
       gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_data);
       if (base::CreateTemporaryFile(&snapshot_filename_)) {
-        file_util::WriteFile(snapshot_filename_,
+        base::WriteFile(snapshot_filename_,
             reinterpret_cast<char*>(&png_data[0]), png_data.size());
       }
     }
@@ -195,12 +194,21 @@ class PDFBrowserTest : public InProcessBrowserTest,
   // content::NotificationObserver
   virtual void Observe(int type,
                        const content::NotificationSource& source,
-                       const content::NotificationDetails& details) {
+                       const content::NotificationDetails& details) OVERRIDE {
     if (type == content::NOTIFICATION_LOAD_STOP) {
       load_stop_notification_count_++;
     }
   }
 
+  // InProcessBrowserTest
+  virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE {
+#if defined(OS_LINUX)
+    // Calling RenderWidgetHost::CopyFromBackingStore() with the GPU enabled
+    // fails on Linux.
+    command_line->AppendSwitch(switches::kDisableGpu);
+#endif
+  }
+
   // True if the snapshot differed from the expected value.
   bool snapshot_different_;
   // Internal variable used to synchronize to the renderer.
@@ -216,10 +224,14 @@ class PDFBrowserTest : public InProcessBrowserTest,
 };
 
 
-// TODO(thestig): http://crbug.com/79837
 // Tests basic PDF rendering.  This can be broken depending on bad merges with
 // the vendor, so it's important that we have basic sanity checking.
-IN_PROC_BROWSER_TEST_F(PDFBrowserTest, DISABLED_Basic) {
+#if defined(GOOGLE_CHROME_BUILD) && defined(OS_LINUX)
+#define MAYBE_Basic Basic
+#else
+#define MAYBE_Basic DISABLED_Basic
+#endif
+IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Basic) {
   ASSERT_NO_FATAL_FAILURE(Load());
   ASSERT_NO_FATAL_FAILURE(WaitForResponse());
   // OS X uses CoreText, and FreeType renders slightly different on Linux and
@@ -235,12 +247,11 @@ IN_PROC_BROWSER_TEST_F(PDFBrowserTest, DISABLED_Basic) {
 #endif
 }
 
-#if (!defined(GOOGLE_CHROME_BUILD) || defined(OS_CHROMEOS)) || \
-    (defined(OS_LINUX) || defined(OS_MACOSX))
-// TODO(sanjeevr): http://crbug.com/79837, http://crbug.com/332778
-#define MAYBE_Scroll DISABLED_Scroll
-#else
+#if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
 #define MAYBE_Scroll Scroll
+#else
+// TODO(thestig): http://crbug.com/79837, http://crbug.com/332778
+#define MAYBE_Scroll DISABLED_Scroll
 #endif
 // Tests that scrolling works.
 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Scroll) {
@@ -266,14 +277,14 @@ IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Scroll) {
   ASSERT_GT(y_offset, 0);
 }
 
-#if (!defined(GOOGLE_CHROME_BUILD) || defined(OS_CHROMEOS)) || \
-    (defined(OS_LINUX) || defined(OS_MACOSX))
+#if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
+#define MAYBE_FindAndCopy FindAndCopy
+#else
 // TODO(thestig): http://crbug.com/79837, http://crbug.com/329912
 #define MAYBE_FindAndCopy DISABLED_FindAndCopy
-#else
-#define MAYBE_FindAndCopy FindAndCopy
 #endif
-IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_FindAndCopy) {
+// flaky, disabling on branch
+IN_PROC_BROWSER_TEST_F(PDFBrowserTest, DISABLED_FindAndCopy) {
   ASSERT_NO_FATAL_FAILURE(Load());
   // Verifies that find in page works.
   ASSERT_EQ(3, ui_test_utils::FindInPage(
@@ -284,14 +295,9 @@ IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_FindAndCopy) {
   // Verify that copying selected text works.
   ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
   // Reset the clipboard first.
-  ui::Clipboard::ObjectMap objects;
-  ui::Clipboard::ObjectMapParams params;
-  params.push_back(std::vector<char>());
-  objects[ui::Clipboard::CBF_TEXT] = params;
-  clipboard->WriteObjects(ui::CLIPBOARD_TYPE_COPY_PASTE, objects);
-
-  browser()->tab_strip_model()->GetActiveWebContents()->
-      GetRenderViewHost()->Copy();
+  clipboard->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE);
+
+  browser()->tab_strip_model()->GetActiveWebContents()->Copy();
   ASSERT_NO_FATAL_FAILURE(WaitForResponse());
 
   std::string text;
@@ -305,10 +311,10 @@ const int kLoadingNumberOfParts = 10;
 // This also loads all documents that used to crash, to ensure we don't have
 // regressions.
 // If it flakes, reopen http://crbug.com/74548.
-#if !defined(GOOGLE_CHROME_BUILD)
-#define MAYBE_Loading DISABLED_Loading
-#else
+#if defined(GOOGLE_CHROME_BUILD)
 #define MAYBE_Loading Loading
+#else
+#define MAYBE_Loading DISABLED_Loading
 #endif
 IN_PROC_BROWSER_TEST_P(PDFBrowserTest, MAYBE_Loading) {
   ASSERT_TRUE(pdf_test_server()->InitializeAndWaitUntilReady());
@@ -322,7 +328,8 @@ IN_PROC_BROWSER_TEST_P(PDFBrowserTest, MAYBE_Loading) {
   std::string base_url = std::string("/");
 
   base::FileEnumerator file_enumerator(
-      ui_test_utils::GetTestFilePath(GetPDFTestDir(), base::FilePath()),
+      ui_test_utils::GetTestFilePath(
+          base::FilePath(FILE_PATH_LITERAL("pdf_private")), base::FilePath()),
       false,
       base::FileEnumerator::FILES,
       FILE_PATH_LITERAL("*.pdf"));
@@ -376,11 +383,11 @@ INSTANTIATE_TEST_CASE_P(PDFTestFiles,
                         PDFBrowserTest,
                         testing::Range(0, kLoadingNumberOfParts));
 
-#if !defined(GOOGLE_CHROME_BUILD) || defined(OS_MACOSX)
+#if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
+#define MAYBE_Action Action
+#else
 // http://crbug.com/315160
 #define MAYBE_Action DISABLED_Action
-#else
-#define MAYBE_Action Action
 #endif
 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Action) {
   ASSERT_NO_FATAL_FAILURE(Load());
@@ -408,26 +415,29 @@ IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Action) {
   ASSERT_NE(zoom1, zoom2);
 }
 
+#if defined(GOOGLE_CHROME_BUILD) && defined(OS_LINUX)
+#define MAYBE_OnLoadAndReload OnLoadAndReload
+#else
 // Flaky as per http://crbug.com/74549.
-IN_PROC_BROWSER_TEST_F(PDFBrowserTest, DISABLED_OnLoadAndReload) {
+#define MAYBE_OnLoadAndReload DISABLED_OnLoadAndReload
+#endif
+IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_OnLoadAndReload) {
   ASSERT_TRUE(pdf_test_server()->InitializeAndWaitUntilReady());
 
   GURL url = pdf_test_server()->GetURL("/onload_reload.html");
   ui_test_utils::NavigateToURL(browser(), url);
+  WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
 
   content::WindowedNotificationObserver observer(
       content::NOTIFICATION_LOAD_STOP,
       content::Source<NavigationController>(
-          &browser()->tab_strip_model()->GetActiveWebContents()->
-              GetController()));
+          &contents->GetController()));
   ASSERT_TRUE(content::ExecuteScript(
       browser()->tab_strip_model()->GetActiveWebContents(),
       "reloadPDF();"));
   observer.Wait();
 
-  ASSERT_EQ("success",
-            browser()->tab_strip_model()->GetActiveWebContents()->
-                GetURL().query());
+  ASSERT_EQ("success", contents->GetURL().query());
 }
 
 }  // namespace