| 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 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 TestFullscreen::TestFullscreen(TestingInstance* instance) | 51 TestFullscreen::TestFullscreen(TestingInstance* instance) |
| 52 : TestCase(instance), | 52 : TestCase(instance), |
| 53 error_(), | 53 error_(), |
| 54 screen_mode_(instance), | 54 screen_mode_(instance), |
| 55 fullscreen_pending_(false), | 55 fullscreen_pending_(false), |
| 56 normal_pending_(false), | 56 normal_pending_(false), |
| 57 saw_first_fullscreen_didchangeview(false), | |
| 58 set_fullscreen_true_callback_(instance->pp_instance()), | 57 set_fullscreen_true_callback_(instance->pp_instance()), |
| 59 fullscreen_callback_(instance->pp_instance()), | 58 fullscreen_callback_(instance->pp_instance()), |
| 60 normal_callback_(instance->pp_instance()) { | 59 normal_callback_(instance->pp_instance()) { |
| 61 screen_mode_.GetScreenSize(&screen_size_); | 60 screen_mode_.GetScreenSize(&screen_size_); |
| 62 } | 61 } |
| 63 | 62 |
| 64 bool TestFullscreen::Init() { | 63 bool TestFullscreen::Init() { |
| 65 if (screen_size_.IsEmpty()) { | 64 if (screen_size_.IsEmpty()) { |
| 66 instance_->AppendError("Failed to initialize screen_size_"); | 65 instance_->AppendError("Failed to initialize screen_size_"); |
| 67 return false; | 66 return false; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 return ReportError("SetFullscreen(true) in fullscreen", true); | 126 return ReportError("SetFullscreen(true) in fullscreen", true); |
| 128 if (!screen_mode_.IsFullscreen()) | 127 if (!screen_mode_.IsFullscreen()) |
| 129 return ReportError("IsFullscreen() in fullscreen^2", false); | 128 return ReportError("IsFullscreen() in fullscreen^2", false); |
| 130 | 129 |
| 131 // 3. Switch to normal. | 130 // 3. Switch to normal. |
| 132 // The transition is asynchronous and ends at DidChangeView(). | 131 // The transition is asynchronous and ends at DidChangeView(). |
| 133 // No graphics devices can be bound while in transition. | 132 // No graphics devices can be bound while in transition. |
| 134 normal_pending_ = true; | 133 normal_pending_ = true; |
| 135 if (!screen_mode_.SetFullscreen(false)) | 134 if (!screen_mode_.SetFullscreen(false)) |
| 136 return ReportError("SetFullscreen(false) in fullscreen", false); | 135 return ReportError("SetFullscreen(false) in fullscreen", false); |
| 137 // Normal is now pending, so additional requests should fail. | |
| 138 if (screen_mode_.SetFullscreen(false)) | |
| 139 return ReportError("SetFullscreen(false) in normal pending", true); | |
| 140 if (screen_mode_.SetFullscreen(true)) | |
| 141 return ReportError("SetFullscreen(true) in normal pending", true); | |
| 142 if (!screen_mode_.IsFullscreen()) | |
| 143 return ReportError("IsFullscreen() in normal transition", false); | |
| 144 // No graphics devices can be bound while in transition. | |
| 145 if (instance_->BindGraphics(graphics2d_)) | |
| 146 return ReportError("BindGraphics() in normal transition", true); | |
| 147 // DidChangeView() will call the callback once out of fullscreen mode. | 136 // DidChangeView() will call the callback once out of fullscreen mode. |
| 148 normal_callback_.WaitForResult(); | 137 normal_callback_.WaitForResult(); |
| 149 if (normal_pending_) | 138 if (normal_pending_) |
| 150 return "normal_pending_ has not been reset"; | 139 return "normal_pending_ has not been reset"; |
| 151 if (screen_mode_.IsFullscreen()) | 140 if (screen_mode_.IsFullscreen()) |
| 152 return ReportError("IsFullscreen() in normal", true); | 141 return ReportError("IsFullscreen() in normal", true); |
| 153 | 142 |
| 154 // 4. Stay in normal. No change. | 143 // 4. Stay in normal. No change. |
| 155 if (screen_mode_.SetFullscreen(false)) | 144 if (screen_mode_.SetFullscreen(false)) |
| 156 return ReportError("SetFullscreen(false) in normal", true); | 145 return ReportError("SetFullscreen(false) in normal", true); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 173 PP_INPUTEVENT_MOUSEBUTTON_LEFT, | 162 PP_INPUTEVENT_MOUSEBUTTON_LEFT, |
| 174 plugin_center, | 163 plugin_center, |
| 175 1, // click_count | 164 1, // click_count |
| 176 mouse_movement); | 165 mouse_movement); |
| 177 | 166 |
| 178 testing_interface_->SimulateInputEvent(instance_->pp_instance(), | 167 testing_interface_->SimulateInputEvent(instance_->pp_instance(), |
| 179 input_event.pp_resource()); | 168 input_event.pp_resource()); |
| 180 } | 169 } |
| 181 | 170 |
| 182 void TestFullscreen::FailFullscreenTest(const std::string& error) { | 171 void TestFullscreen::FailFullscreenTest(const std::string& error) { |
| 183 screen_mode_.SetFullscreen(false); | |
| 184 fullscreen_pending_ = false; | |
| 185 error_ = error; | 172 error_ = error; |
| 186 pp::Module::Get()->core()->CallOnMainThread(0, fullscreen_callback_); | 173 pp::Module::Get()->core()->CallOnMainThread(0, fullscreen_callback_); |
| 187 } | 174 } |
| 188 | 175 |
| 189 void TestFullscreen::FailNormalTest(const std::string& error) { | 176 void TestFullscreen::FailNormalTest(const std::string& error) { |
| 190 normal_pending_ = false; | |
| 191 error_ = error; | 177 error_ = error; |
| 192 pp::Module::Get()->core()->CallOnMainThread(0, normal_callback_); | 178 pp::Module::Get()->core()->CallOnMainThread(0, normal_callback_); |
| 193 } | 179 } |
| 194 | 180 |
| 195 void TestFullscreen::PassFullscreenTest() { | 181 void TestFullscreen::PassFullscreenTest() { |
| 196 fullscreen_pending_ = false; | |
| 197 pp::Module::Get()->core()->CallOnMainThread(0, fullscreen_callback_); | 182 pp::Module::Get()->core()->CallOnMainThread(0, fullscreen_callback_); |
| 198 } | 183 } |
| 199 | 184 |
| 200 void TestFullscreen::PassNormalTest() { | 185 void TestFullscreen::PassNormalTest() { |
| 201 normal_pending_ = false; | |
| 202 pp::Module::Get()->core()->CallOnMainThread(0, normal_callback_); | 186 pp::Module::Get()->core()->CallOnMainThread(0, normal_callback_); |
| 203 } | 187 } |
| 204 | 188 |
| 205 // Transition to fullscreen can only happen when processing a user gesture. | 189 // Transition to fullscreen can only happen when processing a user gesture. |
| 206 bool TestFullscreen::HandleInputEvent(const pp::InputEvent& event) { | 190 bool TestFullscreen::HandleInputEvent(const pp::InputEvent& event) { |
| 207 // We only let mouse events through and only mouse clicks count. | 191 // We only let mouse events through and only mouse clicks count. |
| 208 if (event.GetType() != PP_INPUTEVENT_TYPE_MOUSEDOWN && | 192 if (event.GetType() != PP_INPUTEVENT_TYPE_MOUSEDOWN && |
| 209 event.GetType() != PP_INPUTEVENT_TYPE_MOUSEUP) | 193 event.GetType() != PP_INPUTEVENT_TYPE_MOUSEUP) |
| 210 return false; | 194 return false; |
| 211 // We got the gesture. No need to handle any more events. | 195 // We got the gesture. No need to handle any more events. |
| 212 instance_->ClearInputEventRequest(PP_INPUTEVENT_CLASS_MOUSE); | 196 instance_->ClearInputEventRequest(PP_INPUTEVENT_CLASS_MOUSE); |
| 213 if (screen_mode_.IsFullscreen()) { | 197 if (screen_mode_.IsFullscreen()) { |
| 214 FailFullscreenTest( | 198 FailFullscreenTest( |
| 215 ReportError("IsFullscreen() before fullscreen transition", true)); | 199 ReportError("IsFullscreen() before fullscreen transition", true)); |
| 216 return false; | 200 return false; |
| 217 } | 201 } |
| 218 fullscreen_pending_ = true; | 202 fullscreen_pending_ = true; |
| 219 if (!screen_mode_.SetFullscreen(true)) { | 203 if (!screen_mode_.SetFullscreen(true)) { |
| 220 FailFullscreenTest(ReportError("SetFullscreen(true) in normal", false)); | 204 FailFullscreenTest(ReportError("SetFullscreen(true) in normal", false)); |
| 221 return false; | 205 return false; |
| 222 } | 206 } |
| 223 // Fullscreen is now pending, so additional requests should fail. | |
| 224 if (screen_mode_.SetFullscreen(true)) { | |
| 225 FailFullscreenTest( | |
| 226 ReportError("SetFullscreen(true) in fullscreen pending", true)); | |
| 227 return false; | |
| 228 } | |
| 229 if (screen_mode_.SetFullscreen(false)) { | |
| 230 FailFullscreenTest( | |
| 231 ReportError("SetFullscreen(false) in fullscreen pending", true)); | |
| 232 } | |
| 233 if (screen_mode_.IsFullscreen()) { | |
| 234 FailFullscreenTest( | |
| 235 ReportError("IsFullscreen() in fullscreen transition", true)); | |
| 236 return false; | |
| 237 } | |
| 238 // No graphics devices can be bound while in transition. | |
| 239 if (instance_->BindGraphics(graphics2d_)) { | |
| 240 FailFullscreenTest( | |
| 241 ReportError("BindGraphics() in fullscreen transition", true)); | |
| 242 return false; | |
| 243 } | |
| 244 // DidChangeView() will complete the transition to fullscreen. | 207 // DidChangeView() will complete the transition to fullscreen. |
| 245 return false; | 208 return false; |
| 246 } | 209 } |
| 247 | 210 |
| 248 bool TestFullscreen::PaintPlugin(pp::Size size, ColorPremul color) { | 211 bool TestFullscreen::PaintPlugin(pp::Size size, ColorPremul color) { |
| 249 PP_ImageDataFormat image_format = pp::ImageData::GetNativeImageDataFormat(); | 212 PP_ImageDataFormat image_format = pp::ImageData::GetNativeImageDataFormat(); |
| 250 uint32_t pixel_color = FormatColor(image_format, color); | 213 uint32_t pixel_color = FormatColor(image_format, color); |
| 251 if (pixel_color == 0) | 214 if (pixel_color == 0) |
| 252 return false; | 215 return false; |
| 253 pp::Point origin(0, 0); | 216 pp::Point origin(0, 0); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 276 for (int y = 0; y < size.height() && !error; y++) { | 239 for (int y = 0; y < size.height() && !error; y++) { |
| 277 for (int x = 0; x < size.width() && !error; x++) { | 240 for (int x = 0; x < size.width() && !error; x++) { |
| 278 uint32_t* readback_color = readback.GetAddr32(pp::Point(x, y)); | 241 uint32_t* readback_color = readback.GetAddr32(pp::Point(x, y)); |
| 279 if (pixel_color != *readback_color) | 242 if (pixel_color != *readback_color) |
| 280 return false; | 243 return false; |
| 281 } | 244 } |
| 282 } | 245 } |
| 283 return true; | 246 return true; |
| 284 } | 247 } |
| 285 | 248 |
| 286 // Transitions to/from fullscreen is asynchornous ending at DidChangeView. | 249 // Transitions to/from fullscreen is asynchronous ending at DidChangeView. |
| 287 // When going to fullscreen, two DidChangeView calls are generated: | 250 // The number of calls to DidChangeView during fullscreen / normal transitions |
| 288 // one for moving the plugin to the middle of window and one for stretching | 251 // isn't specified by the API. The test waits until it the screen has |
| 289 // the window and placing the plugin in the middle of the screen. | 252 // transitioned to the desired state. |
| 290 // This is not something we advertise to users and not something they should | |
| 291 // rely on. But the test checks for these, so we know when the underlying | |
| 292 // implementation changes. | |
| 293 // | 253 // |
| 294 // WebKit does not change the plugin size, but Pepper does explicitly set | 254 // WebKit does not change the plugin size, but Pepper does explicitly set |
| 295 // it to screen width and height when SetFullscreen(true) is called and | 255 // it to screen width and height when SetFullscreen(true) is called and |
| 296 // resets it back when ViewChanged is received indicating that we exited | 256 // resets it back when ViewChanged is received indicating that we exited |
| 297 // fullscreen. | 257 // fullscreen. |
| 298 // | 258 // |
| 299 // NOTE: The number of DidChangeView calls for <object> might be different. | 259 // NOTE: The number of DidChangeView calls for <object> might be different. |
| 300 void TestFullscreen::DidChangeView(const pp::View& view) { | 260 void TestFullscreen::DidChangeView(const pp::View& view) { |
| 301 pp::Rect position = view.GetRect(); | 261 pp::Rect position = view.GetRect(); |
| 302 pp::Rect clip = view.GetClipRect(); | 262 pp::Rect clip = view.GetClipRect(); |
| 303 | 263 |
| 304 if (normal_position_.IsEmpty()) { | 264 if (normal_position_.IsEmpty()) { |
| 305 normal_position_ = position; | 265 normal_position_ = position; |
| 306 if (!PaintPlugin(position.size(), kSheerRed)) | 266 if (!PaintPlugin(position.size(), kSheerRed)) |
| 307 error_ = "Failed to initialize plugin image"; | 267 error_ = "Failed to initialize plugin image"; |
| 308 } | 268 } |
| 309 | 269 |
| 310 if (fullscreen_pending_ && !saw_first_fullscreen_didchangeview) { | 270 bool is_fullscreen = screen_mode_.IsFullscreen(); |
| 311 saw_first_fullscreen_didchangeview = true; | 271 if (fullscreen_pending_ && is_fullscreen) { |
| 312 if (screen_mode_.IsFullscreen()) | 272 fullscreen_pending_ = false; |
| 313 FailFullscreenTest("DidChangeView1 is in fullscreen"); | 273 if (!HasMidScreen(position, screen_size_)) |
| 274 FailFullscreenTest("DidChangeView is not in the middle of the screen"); |
| 314 else if (position.size() != screen_size_) | 275 else if (position.size() != screen_size_) |
| 315 FailFullscreenTest("DidChangeView1 does not have screen size"); | 276 FailFullscreenTest("DidChangeView does not have screen size"); |
| 316 // Wait for the 2nd DidChangeView. | |
| 317 } else if (fullscreen_pending_) { | |
| 318 saw_first_fullscreen_didchangeview = false; | |
| 319 if (!screen_mode_.IsFullscreen()) | |
| 320 FailFullscreenTest("DidChangeView2 is not in fullscreen"); | |
| 321 else if (!HasMidScreen(position, screen_size_)) | |
| 322 FailFullscreenTest("DidChangeView2 is not in the middle of the screen"); | |
| 323 else if (position.size() != screen_size_) | |
| 324 FailFullscreenTest("DidChangeView2 does not have screen size"); | |
| 325 // NOTE: we cannot reliably test for clip size being equal to the screen | 277 // NOTE: we cannot reliably test for clip size being equal to the screen |
| 326 // because it might be affected by JS console, info bars, etc. | 278 // because it might be affected by JS console, info bars, etc. |
| 327 else if (!instance_->BindGraphics(graphics2d_)) | 279 else if (!instance_->BindGraphics(graphics2d_)) |
| 328 FailFullscreenTest("Failed to BindGraphics() in fullscreen"); | 280 FailFullscreenTest("Failed to BindGraphics() in fullscreen"); |
| 329 else if (!PaintPlugin(position.size(), kOpaqueYellow)) | 281 else if (!PaintPlugin(position.size(), kOpaqueYellow)) |
| 330 FailFullscreenTest("Failed to paint plugin image in fullscreen"); | 282 FailFullscreenTest("Failed to paint plugin image in fullscreen"); |
| 331 else | 283 else |
| 332 PassFullscreenTest(); | 284 PassFullscreenTest(); |
| 333 } else if (normal_pending_) { | 285 } else if (normal_pending_ && !is_fullscreen) { |
| 334 normal_pending_ = false; | 286 normal_pending_ = false; |
| 335 if (screen_mode_.IsFullscreen()) | 287 if (screen_mode_.IsFullscreen()) |
| 336 FailNormalTest("DidChangeview is in fullscreen"); | 288 FailNormalTest("DidChangeview is in fullscreen"); |
| 337 else if (position != normal_position_) | 289 else if (position != normal_position_) |
| 338 FailNormalTest("DidChangeView position is not normal"); | 290 FailNormalTest("DidChangeView position is not normal"); |
| 339 else if (!instance_->BindGraphics(graphics2d_)) | 291 else if (!instance_->BindGraphics(graphics2d_)) |
| 340 FailNormalTest("Failed to BindGraphics() in normal"); | 292 FailNormalTest("Failed to BindGraphics() in normal"); |
| 341 else if (!PaintPlugin(position.size(), kSheerBlue)) | 293 else if (!PaintPlugin(position.size(), kSheerBlue)) |
| 342 FailNormalTest("Failed to paint plugin image in normal"); | 294 FailNormalTest("Failed to paint plugin image in normal"); |
| 343 else | 295 else |
| 344 PassNormalTest(); | 296 PassNormalTest(); |
| 345 } | 297 } |
| 346 } | 298 } |
| OLD | NEW |