Home | History | Annotate | Download | only in pdf
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_PDF_PDF_BROWSERTEST_BASE_H_
      6 #define CHROME_BROWSER_UI_PDF_PDF_BROWSERTEST_BASE_H_
      7 
      8 #include <string>
      9 
     10 #include "base/files/file_path.h"
     11 #include "chrome/test/base/in_process_browser_test.h"
     12 #include "content/public/browser/notification_observer.h"
     13 #include "net/test/embedded_test_server/embedded_test_server.h"
     14 
     15 namespace base {
     16 class CommandLine;
     17 }
     18 
     19 class SkBitmap;
     20 
     21 // This class is in its own separate file because it is used in both
     22 // browser_tests and interactive_ui_tests.
     23 class PDFBrowserTest : public InProcessBrowserTest,
     24                        public testing::WithParamInterface<int>,
     25                        public content::NotificationObserver {
     26  public:
     27   PDFBrowserTest();
     28   virtual ~PDFBrowserTest();
     29 
     30  protected:
     31   // Use our own TestServer so that we can serve files from the pdf directory.
     32   net::test_server::EmbeddedTestServer* pdf_test_server() {
     33     return &pdf_test_server_;
     34   }
     35 
     36   int load_stop_notification_count() const {
     37     return load_stop_notification_count_;
     38   }
     39 
     40   void Load();
     41   void WaitForResponse();
     42   bool VerifySnapshot(const std::string& expected_filename);
     43 
     44  private:
     45   void CopyFromBackingStoreCallback(bool success, const SkBitmap& bitmap);
     46 
     47   // content::NotificationObserver
     48   virtual void Observe(int type,
     49                        const content::NotificationSource& source,
     50                        const content::NotificationDetails& details) OVERRIDE;
     51 
     52   // InProcessBrowserTest
     53   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
     54 
     55   // True if the snapshot differed from the expected value.
     56   bool snapshot_different_;
     57   // Internal variable used to synchronize to the renderer.
     58   int next_dummy_search_value_;
     59   // The filename of the bitmap to compare the snapshot to.
     60   std::string expected_filename_;
     61   // If the snapshot is different, holds the location where it's saved.
     62   base::FilePath snapshot_filename_;
     63   // How many times we've seen chrome::LOAD_STOP.
     64   int load_stop_notification_count_;
     65 
     66   net::test_server::EmbeddedTestServer pdf_test_server_;
     67 
     68   DISALLOW_COPY_AND_ASSIGN(PDFBrowserTest);
     69 };
     70 
     71 #endif  // CHROME_BROWSER_UI_PDF_PDF_BROWSERTEST_BASE_H_
     72