Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/tests/test_fullscreen.h" | 5 #include "ppapi/tests/test_fullscreen.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "ppapi/c/dev/ppb_testing_dev.h" | 11 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 12 #include "ppapi/c/dev/ppb_fullscreen_dev.h" | 12 #include "ppapi/c/dev/ppb_fullscreen_dev.h" |
| 13 #include "ppapi/cpp/dev/fullscreen_dev.h" | 13 #include "ppapi/cpp/input_event.h" |
| 14 #include "ppapi/cpp/graphics_2d.h" | |
| 15 #include "ppapi/cpp/instance.h" | 14 #include "ppapi/cpp/instance.h" |
| 16 #include "ppapi/cpp/module.h" | 15 #include "ppapi/cpp/module.h" |
| 17 #include "ppapi/cpp/point.h" | 16 #include "ppapi/cpp/point.h" |
| 18 #include "ppapi/cpp/rect.h" | |
| 19 #include "ppapi/cpp/size.h" | |
| 20 #include "ppapi/tests/test_utils.h" | 17 #include "ppapi/tests/test_utils.h" |
| 21 #include "ppapi/tests/testing_instance.h" | 18 #include "ppapi/tests/testing_instance.h" |
| 22 | 19 |
| 23 REGISTER_TEST_CASE(Fullscreen); | 20 REGISTER_TEST_CASE(Fullscreen); |
| 24 | 21 |
| 25 namespace { | 22 namespace { |
| 26 | 23 |
| 27 bool IsFullscreenView(const pp::Rect& position, | 24 bool HasMidScreen(const pp::Rect& position, const pp::Size& screen_size) { |
| 28 const pp::Rect& clip, | 25 static int32_t mid_x = screen_size.width() / 2; |
| 29 const pp::Size& screen_size) { | 26 static int32_t mid_y = screen_size.height() / 2; |
| 30 return (position.point() == pp::Point(0, 0) && | 27 return (position.Contains(mid_x, mid_y)); |
| 31 position.size() == screen_size && | |
| 32 clip.point() == pp::Point(0, 0) && | |
| 33 clip.size() == screen_size); | |
| 34 } | 28 } |
| 35 | 29 |
| 36 } // namespace | 30 } // namespace |
| 37 | 31 |
| 38 TestFullscreen::TestFullscreen(TestingInstance* instance) | 32 TestFullscreen::TestFullscreen(TestingInstance* instance) |
| 39 : TestCase(instance), | 33 : TestCase(instance), |
| 34 error_(""), | |
|
brettw
2011/09/27 00:04:20
Just use error_() (the "" version requires more wo
polina
2011/09/27 00:49:08
Done.
| |
| 40 screen_mode_(instance), | 35 screen_mode_(instance), |
| 41 fullscreen_pending_(false), | 36 fullscreen_pending_(false), |
| 42 normal_pending_(false), | 37 normal_pending_(false), |
| 38 saw_first_fullscreen_didchangeview(false), | |
| 39 graphics2d_fullscreen_(instance, pp::Size(10, 10), false), | |
| 40 graphics2d_normal_(instance, pp::Size(15, 15), false), | |
| 41 set_fullscreen_true_callback_(instance->pp_instance()), | |
| 43 fullscreen_callback_(instance->pp_instance()), | 42 fullscreen_callback_(instance->pp_instance()), |
| 44 normal_callback_(instance->pp_instance()) { | 43 normal_callback_(instance->pp_instance()) { |
| 45 screen_mode_.GetScreenSize(&screen_size_); | 44 screen_mode_.GetScreenSize(&screen_size_); |
| 46 } | 45 } |
| 47 | 46 |
| 48 bool TestFullscreen::Init() { | 47 bool TestFullscreen::Init() { |
| 48 if (graphics2d_fullscreen_.is_null() && graphics2d_normal_.is_null()) | |
| 49 return false; | |
| 49 return InitTestingInterface(); | 50 return InitTestingInterface(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void TestFullscreen::RunTest() { | 53 void TestFullscreen::RunTest() { |
| 53 RUN_TEST(GetScreenSize); | 54 RUN_TEST(GetScreenSize); |
| 54 RUN_TEST(NormalToFullscreenToNormal); | 55 RUN_TEST(NormalToFullscreenToNormal); |
| 55 } | 56 } |
| 56 | 57 |
| 58 bool TestFullscreen::GotError() { | |
| 59 return !error_.empty(); | |
| 60 } | |
| 61 | |
| 62 std::string TestFullscreen::Error() { | |
| 63 std::string last_error = error_; | |
| 64 error_ = ""; | |
|
brettw
2011/09/27 00:04:20
error_.clear()?
polina
2011/09/27 00:49:08
Done.
| |
| 65 return last_error; | |
| 66 } | |
| 67 | |
| 57 std::string TestFullscreen::TestGetScreenSize() { | 68 std::string TestFullscreen::TestGetScreenSize() { |
| 58 if (screen_size_.width() < 320 || screen_size_.width() > 2560) | 69 if (screen_size_.width() < 320 || screen_size_.width() > 2560) |
| 59 return ReportError("screen_size.width()", screen_size_.width()); | 70 return ReportError("screen_size.width()", screen_size_.width()); |
| 60 if (screen_size_.height() < 200 || screen_size_.height() > 2048) | 71 if (screen_size_.height() < 200 || screen_size_.height() > 2048) |
| 61 return ReportError("screen_size.height()", screen_size_.height()); | 72 return ReportError("screen_size.height()", screen_size_.height()); |
| 62 PASS(); | 73 PASS(); |
| 63 } | 74 } |
| 64 | 75 |
| 65 std::string TestFullscreen::TestNormalToFullscreenToNormal() { | 76 std::string TestFullscreen::TestNormalToFullscreenToNormal() { |
| 66 // 0. Start in normal mode. | 77 // 0. Start in normal mode. |
| 67 if (screen_mode_.IsFullscreen()) | 78 if (screen_mode_.IsFullscreen()) |
| 68 return ReportError("IsFullscreen() at start", true); | 79 return ReportError("IsFullscreen() at start", true); |
| 69 | 80 |
| 70 // 1. Switch to fullscreen. | 81 // 1. Switch to fullscreen. |
| 82 // This is only allowed within a context of a user gesture (e.g. mouse click). | |
| 71 // The transition is asynchronous and ends at the next DidChangeView(). | 83 // The transition is asynchronous and ends at the next DidChangeView(). |
| 72 // No graphics devices can be bound while in transition. | 84 // No graphics devices can be bound while in transition. |
| 73 fullscreen_pending_ = true; | 85 instance_->RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); |
| 74 if (!screen_mode_.SetFullscreen(true)) | 86 // HandleInputEvent() will call SetFullscreen(true). |
| 75 return ReportError("SetFullscreen(true) in normal", false); | |
| 76 pp::Graphics2D graphics2d_fullscreen(instance_, pp::Size(10, 10), false); | |
| 77 if (graphics2d_fullscreen.is_null()) | |
| 78 return "Failed to create graphics2d_fullscreen"; | |
| 79 if (instance_->BindGraphics(graphics2d_fullscreen)) | |
| 80 return ReportError("BindGraphics() in fullscreen transition", true); | |
| 81 if (screen_mode_.IsFullscreen()) | |
| 82 return ReportError("IsFullscreen() in fullscreen transtion", true); | |
| 83 | |
| 84 // DidChangeView() will call the callback once in fullscreen mode. | 87 // DidChangeView() will call the callback once in fullscreen mode. |
| 85 fullscreen_callback_.WaitForResult(); | 88 fullscreen_callback_.WaitForResult(); |
| 89 if (GotError()) | |
| 90 return Error(); | |
| 86 if (fullscreen_pending_) | 91 if (fullscreen_pending_) |
| 87 return "fullscreen_pending_ has not been reset"; | 92 return "fullscreen_pending_ has not been reset"; |
| 88 if (!screen_mode_.IsFullscreen()) | 93 if (!screen_mode_.IsFullscreen()) |
| 89 return ReportError("IsFullscreen() in fullscreen", false); | 94 return ReportError("IsFullscreen() in fullscreen", false); |
| 90 if (!instance_->BindGraphics(graphics2d_fullscreen)) | 95 if (!instance_->BindGraphics(graphics2d_fullscreen_)) |
| 91 return ReportError("BindGraphics() in fullscreen", false); | 96 return ReportError("BindGraphics() in fullscreen", false); |
| 92 | 97 |
| 93 // 2. Stay in fullscreen. No change. | 98 // 2. Stay in fullscreen. No change. |
| 94 if (!screen_mode_.SetFullscreen(true)) | 99 if (!screen_mode_.SetFullscreen(true)) |
| 95 return ReportError("SetFullscreen(true) in fullscreen", false); | 100 return ReportError("SetFullscreen(true) in fullscreen", false); |
| 96 if (!screen_mode_.IsFullscreen()) | 101 if (!screen_mode_.IsFullscreen()) |
| 97 return ReportError("IsFullscreen() in fullscreen^2", false); | 102 return ReportError("IsFullscreen() in fullscreen^2", false); |
| 98 | 103 |
| 99 // 3. Switch to normal. | 104 // 3. Switch to normal. |
| 100 // The transition is synchronous in-process and asynchornous out-of-process | 105 // The transition is asynchronous and ends at DidChangeView(). |
| 101 // because proxied IsFullscreen saves a roundtrip by relying on information | 106 // No graphics devices can be bound while in transition. |
| 102 // communicated via a previous call to DidChangeView. | |
| 103 // Graphics devices can be bound right away. | |
| 104 normal_pending_ = true; | 107 normal_pending_ = true; |
| 105 if (!screen_mode_.SetFullscreen(false)) | 108 if (!screen_mode_.SetFullscreen(false)) |
| 106 return ReportError("SetFullscreen(false) in fullscreen", false); | 109 return ReportError("SetFullscreen(false) in fullscreen", false); |
| 107 pp::Graphics2D graphics2d_normal(instance_, pp::Size(15, 15), false); | 110 if (instance_->BindGraphics(graphics2d_normal_)) |
| 108 if (graphics2d_normal.is_null()) | 111 return ReportError("BindGraphics() in normal transition", true); |
| 109 return "Failed to create graphics2d_normal"; | 112 if (!screen_mode_.IsFullscreen()) |
| 110 if (!instance_->BindGraphics(graphics2d_normal)) | 113 return ReportError("IsFullscreen() in normal transition", false); |
| 111 return ReportError("BindGraphics() in normal transition", false); | 114 // DidChangeView() will call the callback once out of fullscreen mode. |
| 112 if (testing_interface_->IsOutOfProcess()) { | 115 normal_callback_.WaitForResult(); |
| 113 if (!screen_mode_.IsFullscreen()) | 116 if (normal_pending_) |
| 114 return ReportError("IsFullscreen() in normal transition", false); | 117 return "normal_pending_ has not been reset"; |
| 115 normal_callback_.WaitForResult(); | |
| 116 if (normal_pending_) | |
| 117 return "normal_pending_ has not been reset"; | |
| 118 } | |
| 119 if (screen_mode_.IsFullscreen()) | 118 if (screen_mode_.IsFullscreen()) |
| 120 return ReportError("IsFullscreen() in normal", true); | 119 return ReportError("IsFullscreen() in normal", true); |
| 120 if (!instance_->BindGraphics(graphics2d_fullscreen_)) | |
| 121 return ReportError("BindGraphics() in normal", false); | |
| 121 | 122 |
| 122 // 4. Stay in normal. No change. | 123 // 4. Stay in normal. No change. |
| 123 if (!screen_mode_.SetFullscreen(false)) | 124 if (!screen_mode_.SetFullscreen(false)) |
| 124 return ReportError("SetFullscreen(false) in normal", false); | 125 return ReportError("SetFullscreen(false) in normal", false); |
| 125 if (screen_mode_.IsFullscreen()) | 126 if (screen_mode_.IsFullscreen()) |
| 126 return ReportError("IsFullscreen() in normal^2", true); | 127 return ReportError("IsFullscreen() in normal^2", true); |
| 127 | 128 |
| 128 PASS(); | 129 PASS(); |
| 129 } | 130 } |
| 130 | 131 |
| 131 // Transition to fullscreen is asynchornous ending at DidChangeView. | 132 void TestFullscreen::FailFullscreenTest(const std::string& error) { |
| 132 // Transition to normal is synchronous in-process and asynchronous | 133 screen_mode_.SetFullscreen(false); |
| 133 // out-of-process ending at DidChangeView. | 134 fullscreen_pending_ = false; |
| 135 error_ = error; | |
| 136 pp::Module::Get()->core()->CallOnMainThread(0, fullscreen_callback_); | |
| 137 } | |
| 138 | |
| 139 // Transition to fullscreen can only happen after a user gesture. | |
| 140 bool TestFullscreen::HandleInputEvent(const pp::InputEvent& event) { | |
| 141 // We only let mouse events through and only mouse clicks count. | |
| 142 if (event.GetType() != PP_INPUTEVENT_TYPE_MOUSEDOWN && | |
| 143 event.GetType() != PP_INPUTEVENT_TYPE_MOUSEUP) | |
| 144 return false; | |
| 145 // We got the gesture. No need to handle any more events. | |
| 146 instance_->ClearInputEventRequest(PP_INPUTEVENT_CLASS_MOUSE); | |
| 147 fullscreen_pending_ = true; | |
| 148 if (!screen_mode_.SetFullscreen(true)) { | |
| 149 FailFullscreenTest(ReportError("SetFullscreen(true) in normal", false)); | |
| 150 return false; | |
| 151 } | |
| 152 // No graphics devices can be bound while in transition. | |
| 153 if (instance_->BindGraphics(graphics2d_fullscreen_)) { | |
| 154 FailFullscreenTest( | |
| 155 ReportError("BindGraphics() in fullscreen transition", true)); | |
| 156 return false; | |
| 157 } | |
| 158 if (screen_mode_.IsFullscreen()) { | |
| 159 FailFullscreenTest( | |
| 160 ReportError("IsFullscreen() in fullscreen transtion", true)); | |
| 161 return false; | |
| 162 } | |
| 163 // DidChangeView() will complete the transition to fullscreen. | |
| 164 return false; | |
| 165 } | |
| 166 | |
| 167 // Transitions to/from fullscreen is asynchornous ending at DidChangeView. | |
| 168 // When going to fullscreen, You actually get two DidChangeView calls: | |
| 169 // one for moving the plugin to the middle of window and one for placing | |
| 170 // the plugin in the middle of the screen. Plugin size does not change. | |
| 134 void TestFullscreen::DidChangeView(const pp::Rect& position, | 171 void TestFullscreen::DidChangeView(const pp::Rect& position, |
| 135 const pp::Rect& clip) { | 172 const pp::Rect& clip) { |
| 136 if (fullscreen_pending_ && IsFullscreenView(position, clip, screen_size_)) { | 173 if (normal_position_.IsEmpty()) |
| 174 normal_position_ = position; | |
| 175 | |
| 176 if (fullscreen_pending_ && !saw_first_fullscreen_didchangeview) { | |
| 177 saw_first_fullscreen_didchangeview = true; | |
| 178 if (!screen_mode_.IsFullscreen()) | |
| 179 FailFullscreenTest("1st DidChangeView is not in fullscreen"); | |
| 180 } else if (fullscreen_pending_) { | |
| 137 fullscreen_pending_ = false; | 181 fullscreen_pending_ = false; |
| 138 pp::Module::Get()->core()->CallOnMainThread(0, fullscreen_callback_); | 182 if (!screen_mode_.IsFullscreen()) |
| 139 } else if (normal_pending_ && | 183 FailFullscreenTest("2nd DidChangeView is not in fullscreen"); |
| 140 !IsFullscreenView(position, clip, screen_size_)) { | 184 else if (!HasMidScreen(position, screen_size_)) |
| 185 FailFullscreenTest("DidChangeView is not in the middle of the screen"); | |
| 186 else if (position.size() != normal_position_.size()) | |
| 187 FailFullscreenTest("DidChangeView has different plugin size"); | |
| 188 else | |
| 189 pp::Module::Get()->core()->CallOnMainThread(0, fullscreen_callback_); | |
| 190 } else if (normal_pending_) { | |
| 141 normal_pending_ = false; | 191 normal_pending_ = false; |
| 142 if (testing_interface_->IsOutOfProcess()) | 192 if (screen_mode_.IsFullscreen()) |
| 143 pp::Module::Get()->core()->CallOnMainThread(0, normal_callback_); | 193 error_ = "DidChangeview is in fullscreen"; |
| 194 else if (position != normal_position_) | |
| 195 error_ = "DidChangeView position is not normal"; | |
| 196 pp::Module::Get()->core()->CallOnMainThread(0, normal_callback_); | |
| 144 } | 197 } |
| 145 } | 198 } |
| OLD | NEW |