Roll src/third_party/WebKit 75a2fa9:2546356 (svn 202272:202273)
[chromium-blink-merge.git] / ppapi / tests / test_graphics_2d.h
blobc905d8a2415d8a8b68997a0e2862037cf0bfb355
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.
5 #ifndef PPAPI_TESTS_TEST_GRAPHICS_2D_H_
6 #define PPAPI_TESTS_TEST_GRAPHICS_2D_H_
8 #include <string>
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"
15 namespace pp {
16 class Graphics2D;
17 class ImageData;
18 class Point;
19 class Rect;
22 class TestGraphics2D : public TestCase {
23 public:
24 explicit TestGraphics2D(TestingInstance* instance);
26 // TestCase implementation.
27 virtual void DidChangeView(const pp::View& view);
28 virtual bool Init();
29 virtual void RunTests(const std::string& filter);
31 void QuitMessageLoop();
33 private:
34 bool ReadImageData(const pp::Graphics2D& dc,
35 pp::ImageData* image,
36 const pp::Point& top_left) const;
38 void FillRectInImage(pp::ImageData* image,
39 const pp::Rect& rect,
40 uint32_t color) const;
42 // Fill image with gradient colors.
43 void FillImageWithGradient(pp::ImageData* image) const;
45 // Return true if images are the same.
46 bool CompareImages(const pp::ImageData& image1,
47 const pp::ImageData& image2);
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;
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;
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;
66 // Validates that the given device context is filled with the given color.
67 bool IsDCUniformColor(const pp::Graphics2D& dc, uint32_t color) const;
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);
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.
79 // Returns 0 on failure.
80 PP_Resource ReplaceContentsAndReturnID(pp::Graphics2D* dc,
81 const pp::Size& size);
83 // Resets the internal state of view change.
84 void ResetViewChangedState();
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();
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();
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_;
110 // Used to indicate that DidChangeView has happened, in order to make plugin
111 // and ui synchronous.
112 bool is_view_changed_;
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_;
120 #endif // PPAPI_TESTS_TEST_GRAPHICS_2D_H_