summaryrefslogtreecommitdiffstats
path: root/ppapi/tests
diff options
context:
space:
mode:
authorgeorgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-17 01:33:01 +0000
committergeorgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-17 01:33:01 +0000
commit07effdb513a6dd2700a5647b10280787925cabee (patch)
treecf4b73f83bf616c469eee6e29d3c1f82fc58f880 /ppapi/tests
parentfd3c36fe7a490a71609806706a61648c1ff6e195 (diff)
downloadchromium_src-07effdb513a6dd2700a5647b10280787925cabee.zip
chromium_src-07effdb513a6dd2700a5647b10280787925cabee.tar.gz
chromium_src-07effdb513a6dd2700a5647b10280787925cabee.tar.bz2
Revert 114881 - PPB_Fullscreen test: Merge the NaCl version of the test into ppapi/tests compiled with gyp.
The two tests were written at around the same time and using the same test cases, so the only piece missing was the binding and paintig of the graphics device. BUG=none TEST=ui_tests Review URL: http://codereview.chromium.org/8954008 TBR=polina@google.com Review URL: http://codereview.chromium.org/8976016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114889 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r--ppapi/tests/test_fullscreen.cc145
-rw-r--r--ppapi/tests/test_fullscreen.h11
2 files changed, 27 insertions, 129 deletions
diff --git a/ppapi/tests/test_fullscreen.cc b/ppapi/tests/test_fullscreen.cc
index 2d78f3c..77320e2 100644
--- a/ppapi/tests/test_fullscreen.cc
+++ b/ppapi/tests/test_fullscreen.cc
@@ -10,7 +10,6 @@
#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/ppb_fullscreen.h"
-#include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
@@ -22,31 +21,12 @@ REGISTER_TEST_CASE(Fullscreen);
namespace {
-const ColorPremul kOpaqueWhite = { 0xFF, 0xFF, 0xFF, 0xFF };
-const ColorPremul kSheerRed = { 0x88, 0x88, 0x00, 0x00 };
-const ColorPremul kSheerBlue = { 0x88, 0x00, 0x00, 0x88 };
-const ColorPremul kOpaqueYellow = { 0xFF, 0xFF, 0xFF, 0x00 };
-const int kBytesPerPixel = sizeof(uint32_t); // 4 bytes for BGRA or RGBA.
-
-uint32_t FormatColor(PP_ImageDataFormat format, ColorPremul color) {
- if (format == PP_IMAGEDATAFORMAT_BGRA_PREMUL)
- return (color.A << 24) | (color.R << 16) | (color.G << 8) | (color.B);
- else if (format == PP_IMAGEDATAFORMAT_RGBA_PREMUL)
- return (color.A << 24) | (color.B << 16) | (color.G << 8) | (color.R);
- else
- NOTREACHED();
- return 0;
-}
-
bool HasMidScreen(const pp::Rect& position, const pp::Size& screen_size) {
static int32_t mid_x = screen_size.width() / 2;
static int32_t mid_y = screen_size.height() / 2;
return (position.Contains(mid_x, mid_y));
}
-void FlushCallback(void* user_data, int32_t result) {
-}
-
} // namespace
TestFullscreen::TestFullscreen(TestingInstance* instance)
@@ -56,6 +36,8 @@ TestFullscreen::TestFullscreen(TestingInstance* instance)
fullscreen_pending_(false),
normal_pending_(false),
saw_first_fullscreen_didchangeview(false),
+ graphics2d_fullscreen_(instance, pp::Size(10, 10), false),
+ graphics2d_normal_(instance, pp::Size(15, 15), false),
set_fullscreen_true_callback_(instance->pp_instance()),
fullscreen_callback_(instance->pp_instance()),
normal_callback_(instance->pp_instance()) {
@@ -63,15 +45,8 @@ TestFullscreen::TestFullscreen(TestingInstance* instance)
}
bool TestFullscreen::Init() {
- if (screen_size_.IsEmpty()) {
- instance_->AppendError("Failed to initialize screen_size_");
- return false;
- }
- graphics2d_ = pp::Graphics2D(instance_, screen_size_, true);
- if (!instance_->BindGraphics(graphics2d_)) {
- instance_->AppendError("Failed to initialize graphics2d_");
+ if (graphics2d_fullscreen_.is_null() && graphics2d_normal_.is_null())
return false;
- }
return InitTestingInterface();
}
@@ -90,9 +65,6 @@ std::string TestFullscreen::Error() {
return last_error;
}
-// TODO(polina): consider adding custom logic to JS for this test to
-// get screen.width and screen.height and postMessage those to this code,
-// so the dimensions can be checked exactly.
std::string TestFullscreen::TestGetScreenSize() {
if (screen_size_.width() < 320 || screen_size_.width() > 2560)
return ReportError("screen_size.width()", screen_size_.width());
@@ -110,10 +82,11 @@ std::string TestFullscreen::TestNormalToFullscreenToNormal() {
// This is only allowed within a context of a user gesture (e.g. mouse click).
if (screen_mode_.SetFullscreen(true))
return ReportError("SetFullscreen(true) outside of user gesture", true);
- // Trigger another call to SetFullscreen(true) from HandleInputEvent().
// The transition is asynchronous and ends at the next DidChangeView().
+ // No graphics devices can be bound while in transition.
instance_->RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
SimulateUserGesture();
+ // HandleInputEvent() will call SetFullscreen(true).
// DidChangeView() will call the callback once in fullscreen mode.
fullscreen_callback_.WaitForResult();
if (GotError())
@@ -122,6 +95,8 @@ std::string TestFullscreen::TestNormalToFullscreenToNormal() {
return "fullscreen_pending_ has not been reset";
if (!screen_mode_.IsFullscreen())
return ReportError("IsFullscreen() in fullscreen", false);
+ if (!instance_->BindGraphics(graphics2d_fullscreen_))
+ return ReportError("BindGraphics() in fullscreen", false);
// 2. Stay in fullscreen. No change.
if (screen_mode_.SetFullscreen(true))
@@ -140,17 +115,18 @@ std::string TestFullscreen::TestNormalToFullscreenToNormal() {
return ReportError("SetFullscreen(false) in normal pending", true);
if (screen_mode_.SetFullscreen(true))
return ReportError("SetFullscreen(true) in normal pending", true);
+ if (instance_->BindGraphics(graphics2d_normal_))
+ return ReportError("BindGraphics() in normal transition", true);
if (!screen_mode_.IsFullscreen())
return ReportError("IsFullscreen() in normal transition", false);
- // No graphics devices can be bound while in transition.
- if (instance_->BindGraphics(graphics2d_))
- return ReportError("BindGraphics() in normal transition", true);
// DidChangeView() will call the callback once out of fullscreen mode.
normal_callback_.WaitForResult();
if (normal_pending_)
return "normal_pending_ has not been reset";
if (screen_mode_.IsFullscreen())
return ReportError("IsFullscreen() in normal", true);
+ if (!instance_->BindGraphics(graphics2d_fullscreen_))
+ return ReportError("BindGraphics() in normal", false);
// 4. Stay in normal. No change.
if (screen_mode_.SetFullscreen(false))
@@ -187,22 +163,6 @@ void TestFullscreen::FailFullscreenTest(const std::string& error) {
pp::Module::Get()->core()->CallOnMainThread(0, fullscreen_callback_);
}
-void TestFullscreen::FailNormalTest(const std::string& error) {
- normal_pending_ = false;
- error_ = error;
- pp::Module::Get()->core()->CallOnMainThread(0, normal_callback_);
-}
-
-void TestFullscreen::PassFullscreenTest() {
- fullscreen_pending_ = false;
- pp::Module::Get()->core()->CallOnMainThread(0, fullscreen_callback_);
-}
-
-void TestFullscreen::PassNormalTest() {
- normal_pending_ = false;
- pp::Module::Get()->core()->CallOnMainThread(0, normal_callback_);
-}
-
// Transition to fullscreen can only happen when processing a user gesture.
bool TestFullscreen::HandleInputEvent(const pp::InputEvent& event) {
// We only let mouse events through and only mouse clicks count.
@@ -211,11 +171,6 @@ bool TestFullscreen::HandleInputEvent(const pp::InputEvent& event) {
return false;
// We got the gesture. No need to handle any more events.
instance_->ClearInputEventRequest(PP_INPUTEVENT_CLASS_MOUSE);
- if (screen_mode_.IsFullscreen()) {
- FailFullscreenTest(
- ReportError("IsFullscreen() before fullscreen transtion", true));
- return false;
- }
fullscreen_pending_ = true;
if (!screen_mode_.SetFullscreen(true)) {
FailFullscreenTest(ReportError("SetFullscreen(true) in normal", false));
@@ -231,87 +186,44 @@ bool TestFullscreen::HandleInputEvent(const pp::InputEvent& event) {
FailFullscreenTest(
ReportError("SetFullscreen(false) in fullscreen pending", true));
}
- if (screen_mode_.IsFullscreen()) {
+ // No graphics devices can be bound while in transition.
+ if (instance_->BindGraphics(graphics2d_fullscreen_)) {
FailFullscreenTest(
- ReportError("IsFullscreen() in fullscreen transtion", true));
+ ReportError("BindGraphics() in fullscreen transition", true));
return false;
}
- // No graphics devices can be bound while in transition.
- if (instance_->BindGraphics(graphics2d_)) {
+ if (screen_mode_.IsFullscreen()) {
FailFullscreenTest(
- ReportError("BindGraphics() in fullscreen transition", true));
+ ReportError("IsFullscreen() in fullscreen transtion", true));
return false;
}
// DidChangeView() will complete the transition to fullscreen.
return false;
}
-bool TestFullscreen::PaintPlugin(pp::Size size, ColorPremul color) {
- PP_ImageDataFormat image_format = pp::ImageData::GetNativeImageDataFormat();
- uint32_t pixel_color = FormatColor(image_format, color);
- pp::Point origin(0, 0);
-
- pp::ImageData image(instance_, image_format, size, false);
- if (image.is_null())
- return false;
- uint32_t* pixels = static_cast<uint32_t*>(image.data());
- int num_pixels = image.stride() / kBytesPerPixel * image.size().height();
- for (int i = 0; i < num_pixels; i++)
- pixels[i] = pixel_color;
- graphics2d_.PaintImageData(image, origin);
- pp::CompletionCallback cc(FlushCallback, NULL);
- if (graphics2d_.Flush(cc) != PP_OK_COMPLETIONPENDING)
- return false;
-
- // Confirm that painting was successful.
- pp::ImageData readback(instance_, image_format, graphics2d_.size(), false);
- if (readback.is_null())
- return false;
- if (PP_TRUE != testing_interface_->ReadImageData(graphics2d_.pp_resource(),
- readback.pp_resource(),
- &origin.pp_point()))
- return false;
- bool error = false;
- for (int y = 0; y < size.height() && !error; y++) {
- for (int x = 0; x < size.width() && !error; x++) {
- uint32_t* readback_color = readback.GetAddr32(pp::Point(x, y));
- if (pixel_color != *readback_color)
- return false;
- }
- }
- return true;
-}
-
// Transitions to/from fullscreen is asynchornous ending at DidChangeView.
// When going to fullscreen, two DidChangeView calls are generated:
// one for moving the plugin to the middle of window and one for stretching
// the window and placing the plugin in the middle of the screen.
-// This is not something we advertise to users and not something they should
-// rely on. But the test checks for these, so we know when the underlying
-// implementation changes.
-//
// WebKit does not change the plugin size, but Pepper does explicitly set
// it to screen width and height when SetFullscreen(true) is called and
// resets it back when ViewChanged is received indicating that we exited
// fullscreen.
-//
-// NOTE: The number of DidChangeView calls for <object> might be different.
+// NOTE: The number of DidChangeView calls for <object> might be different.
void TestFullscreen::DidChangeView(const pp::Rect& position,
const pp::Rect& clip) {
- if (normal_position_.IsEmpty()) {
+ if (normal_position_.IsEmpty())
normal_position_ = position;
- if (!PaintPlugin(position.size(), kSheerRed))
- error_ = "Failed to initialize plugin image";
- }
if (fullscreen_pending_ && !saw_first_fullscreen_didchangeview) {
saw_first_fullscreen_didchangeview = true;
if (screen_mode_.IsFullscreen())
FailFullscreenTest("DidChangeView1 is in fullscreen");
- else if (position.size() != screen_size_)
+ if (position.size() != screen_size_)
FailFullscreenTest("DidChangeView1 does not have screen size");
// Wait for the 2nd DidChangeView.
} else if (fullscreen_pending_) {
+ fullscreen_pending_ = false;
saw_first_fullscreen_didchangeview = false;
if (!screen_mode_.IsFullscreen())
FailFullscreenTest("DidChangeView2 is not in fullscreen");
@@ -321,23 +233,14 @@ void TestFullscreen::DidChangeView(const pp::Rect& position,
FailFullscreenTest("DidChangeView2 does not have screen size");
// NOTE: we cannot reliably test for clip size being equal to the screen
// because it might be affected by JS console, info bars, etc.
- else if (!instance_->BindGraphics(graphics2d_))
- FailFullscreenTest("Failed to BindGraphics() in fullscreen");
- else if (!PaintPlugin(position.size(), kOpaqueYellow))
- FailFullscreenTest("Failed to paint plugin image in fullscreen");
else
- PassFullscreenTest();
+ pp::Module::Get()->core()->CallOnMainThread(0, fullscreen_callback_);
} else if (normal_pending_) {
normal_pending_ = false;
if (screen_mode_.IsFullscreen())
- FailNormalTest("DidChangeview is in fullscreen");
+ error_ = "DidChangeview is in fullscreen";
else if (position != normal_position_)
- FailNormalTest("DidChangeView position is not normal");
- else if (!instance_->BindGraphics(graphics2d_))
- FailNormalTest("Failed to BindGraphics() in normal");
- else if (!PaintPlugin(position.size(), kSheerBlue))
- FailNormalTest("Failed to paint plugin image in normal");
- else
- PassNormalTest();
+ error_ = "DidChangeView position is not normal";
+ pp::Module::Get()->core()->CallOnMainThread(0, normal_callback_);
}
}
diff --git a/ppapi/tests/test_fullscreen.h b/ppapi/tests/test_fullscreen.h
index a022f75..f326bc9 100644
--- a/ppapi/tests/test_fullscreen.h
+++ b/ppapi/tests/test_fullscreen.h
@@ -7,7 +7,6 @@
#include <string>
-#include "base/logging.h"
#include "ppapi/cpp/fullscreen.h"
#include "ppapi/cpp/graphics_2d.h"
#include "ppapi/cpp/rect.h"
@@ -19,8 +18,6 @@ namespace pp {
class InputEvent;
} // namespace pp
-struct ColorPremul { uint32_t A, R, G, B; }; // Use premultipled Alpha.
-
class TestFullscreen : public TestCase {
public:
explicit TestFullscreen(TestingInstance* instance);
@@ -36,11 +33,8 @@ class TestFullscreen : public TestCase {
std::string TestNormalToFullscreenToNormal();
void SimulateUserGesture();
+
void FailFullscreenTest(const std::string& error);
- void FailNormalTest(const std::string& error);
- void PassFullscreenTest();
- void PassNormalTest();
- bool PaintPlugin(pp::Size size, ColorPremul color);
bool GotError();
std::string Error();
@@ -54,7 +48,8 @@ class TestFullscreen : public TestCase {
bool fullscreen_pending_;
bool normal_pending_;
bool saw_first_fullscreen_didchangeview;
- pp::Graphics2D graphics2d_;
+ pp::Graphics2D graphics2d_fullscreen_;
+ pp::Graphics2D graphics2d_normal_;
TestCompletionCallback set_fullscreen_true_callback_;
TestCompletionCallback fullscreen_callback_;
TestCompletionCallback normal_callback_;