Home | History | Annotate | Download | only in tests
      1 // Copyright (c) 2012 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 PPAPI_TESTS_TEST_GRAPHICS_2D_H_
      6 #define PPAPI_TESTS_TEST_GRAPHICS_2D_H_
      7 
      8 #include <string>
      9 
     10 #include "ppapi/c/pp_stdint.h"
     11 #include "ppapi/c/ppb_graphics_2d.h"
     12 #include "ppapi/c/ppb_image_data.h"
     13 #include "ppapi/tests/test_case.h"
     14 
     15 namespace pp {
     16 class Graphics2D;
     17 class ImageData;
     18 class Point;
     19 class Rect;
     20 }
     21 
     22 class TestGraphics2D : public TestCase {
     23  public:
     24   explicit TestGraphics2D(TestingInstance* instance);
     25 
     26   // TestCase implementation.
     27   virtual void DidChangeView(const pp::View& view);
     28   virtual bool Init();
     29   virtual void RunTests(const std::string& filter);
     30 
     31   void QuitMessageLoop();
     32 
     33  private:
     34   bool ReadImageData(const pp::Graphics2D& dc,
     35                      pp::ImageData* image,
     36                      const pp::Point& top_left) const;
     37 
     38   void FillRectInImage(pp::ImageData* image,
     39                        const pp::Rect& rect,
     40                        uint32_t color) const;
     41 
     42   // Fill image with gradient colors.
     43   void FillImageWithGradient(pp::ImageData* image) const;
     44 
     45   // Return true if images are the same.
     46   bool CompareImages(const pp::ImageData& image1,
     47                      const pp::ImageData& image2);
     48 
     49   // Return true if images within specified rectangles are the same.
     50   bool CompareImageRect(const pp::ImageData& image1,
     51                         const pp::Rect& rc1,
     52                         const pp::ImageData& image2,
     53                         const pp::Rect& rc2) const;
     54 
     55   // Validates that the given image is a single color with a square of another
     56   // color inside it.
     57   bool IsSquareInImage(const pp::ImageData& image_data,
     58                        uint32_t background_color,
     59                        const pp::Rect& square, uint32_t square_color) const;
     60 
     61   // Validates that the given device context is a single color with a square of
     62   // another color inside it.
     63   bool IsSquareInDC(const pp::Graphics2D& dc, uint32_t background_color,
     64                     const pp::Rect& square, uint32_t square_color) const;
     65 
     66   // Validates that the given device context is filled with the given color.
     67   bool IsDCUniformColor(const pp::Graphics2D& dc, uint32_t color) const;
     68 
     69   // Issues a flush on the given device context and blocks until the flush
     70   // has issued its callback. Returns an empty string on success or an error
     71   // message on failure.
     72   std::string FlushAndWaitForDone(pp::Graphics2D* context);
     73 
     74   // Creates an image and replaces the contents of the Graphics2D with the
     75   // image, waiting for completion. This returns the resource ID of the image
     76   // data we created. This image data will be released by the time the call
     77   // completes, but it can be used for comparisons later.
     78   //
     79   // Returns 0 on failure.
     80   PP_Resource ReplaceContentsAndReturnID(pp::Graphics2D* dc,
     81                                          const pp::Size& size);
     82 
     83   // Resets the internal state of view change.
     84   void ResetViewChangedState();
     85 
     86   // Waits until we get a view change event. Note that it's possible to receive
     87   // an unexpected event, thus post_quit_on_view_changed_ is introduced so that
     88   // DidChangeView can check whether the event is from here.
     89   bool WaitUntilViewChanged();
     90 
     91   std::string TestInvalidResource();
     92   std::string TestInvalidSize();
     93   std::string TestHumongous();
     94   std::string TestInitToZero();
     95   std::string TestDescribe();
     96   std::string TestScale();
     97   std::string TestPaint();
     98   std::string TestScroll();
     99   std::string TestReplace();
    100   std::string TestFlush();
    101   std::string TestFlushOffscreenUpdate();
    102   std::string TestDev();
    103   std::string TestReplaceContentsCaching();
    104   std::string TestBindNull();
    105 
    106   // Used by the tests that access the C API directly.
    107   const PPB_Graphics2D_1_1* graphics_2d_interface_;
    108   const PPB_ImageData_1_0* image_data_interface_;
    109 
    110   // Used to indicate that DidChangeView has happened, in order to make plugin
    111   // and ui synchronous.
    112   bool is_view_changed_;
    113 
    114   // Set to true to request that the next invocation of DidChangeView should
    115   // post a quit to the message loop. DidChangeView will also reset the flag so
    116   // this will only happen once.
    117   bool post_quit_on_view_changed_;
    118 };
    119 
    120 #endif  // PPAPI_TESTS_TEST_GRAPHICS_2D_H_
    121