| 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 // Tests PPB_Fullscreen_Dev. | 5 // Tests PPB_Fullscreen. |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "native_client/src/shared/platform/nacl_check.h" | 9 #include "native_client/src/shared/platform/nacl_check.h" |
| 10 #include "native_client/tests/ppapi_test_lib/get_browser_interface.h" | 10 #include "native_client/tests/ppapi_test_lib/get_browser_interface.h" |
| 11 #include "native_client/tests/ppapi_test_lib/test_interface.h" | 11 #include "native_client/tests/ppapi_test_lib/test_interface.h" |
| 12 #include "native_client/tests/ppapi_test_lib/testable_callback.h" | 12 #include "native_client/tests/ppapi_test_lib/testable_callback.h" |
| 13 | 13 |
| 14 #include "ppapi/c/dev/ppb_fullscreen_dev.h" | |
| 15 #include "ppapi/c/ppb_core.h" | 14 #include "ppapi/c/ppb_core.h" |
| 15 #include "ppapi/c/ppb_fullscreen.h" |
| 16 #include "ppapi/c/ppb_graphics_2d.h" | 16 #include "ppapi/c/ppb_graphics_2d.h" |
| 17 #include "ppapi/c/ppb_input_event.h" | 17 #include "ppapi/c/ppb_input_event.h" |
| 18 #include "ppapi/c/ppb_instance.h" | 18 #include "ppapi/c/ppb_instance.h" |
| 19 #include "ppapi/c/ppp_input_event.h" | 19 #include "ppapi/c/ppp_input_event.h" |
| 20 #include "ppapi/c/ppp_instance.h" | 20 #include "ppapi/c/ppp_instance.h" |
| 21 #include "ppapi/c/pp_errors.h" | 21 #include "ppapi/c/pp_errors.h" |
| 22 #include "ppapi/c/pp_rect.h" | 22 #include "ppapi/c/pp_rect.h" |
| 23 #include "ppapi/c/pp_size.h" | 23 #include "ppapi/c/pp_size.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 PP_Bool not_always_opaque = PP_FALSE; | 59 PP_Bool not_always_opaque = PP_FALSE; |
| 60 *graphics2d = | 60 *graphics2d = |
| 61 PPBGraphics2D()->Create(pp_instance(), &size, not_always_opaque); | 61 PPBGraphics2D()->Create(pp_instance(), &size, not_always_opaque); |
| 62 return (*graphics2d != kInvalidResource); | 62 return (*graphics2d != kInvalidResource); |
| 63 } | 63 } |
| 64 | 64 |
| 65 //////////////////////////////////////////////////////////////////////////////// | 65 //////////////////////////////////////////////////////////////////////////////// |
| 66 // Test cases | 66 // Test cases |
| 67 //////////////////////////////////////////////////////////////////////////////// | 67 //////////////////////////////////////////////////////////////////////////////// |
| 68 | 68 |
| 69 // Test for the availability of PPB_FULLSCREEN_DEV_INTERFACE. | |
| 70 void TestGetInterface() { | |
| 71 printf("--- TestGetInterface\n"); | |
| 72 EXPECT(PPBFullscreenDev() != NULL); | |
| 73 TEST_PASSED; | |
| 74 } | |
| 75 | |
| 76 // Test | 69 // Test |
| 77 // PP_Bool (*IsFullscreen)(PP_Instance instance); | 70 // PP_Bool (*IsFullscreen)(PP_Instance instance); |
| 78 void TestIsFullscreenTrue() { | 71 void TestIsFullscreenTrue() { |
| 79 printf("--- TestIsFullscreenTrue\n"); | 72 printf("--- TestIsFullscreenTrue\n"); |
| 80 EXPECT(PPBFullscreenDev()->IsFullscreen(pp_instance()) == PP_TRUE); | 73 EXPECT(PPBFullscreen()->IsFullscreen(pp_instance()) == PP_TRUE); |
| 81 TEST_PASSED; | 74 TEST_PASSED; |
| 82 } | 75 } |
| 83 | 76 |
| 84 void TestIsFullscreenFalse() { | 77 void TestIsFullscreenFalse() { |
| 85 printf("--- TestIsFullscreenFalse\n"); | 78 printf("--- TestIsFullscreenFalse\n"); |
| 86 EXPECT(PPBFullscreenDev()->IsFullscreen(pp_instance()) == PP_FALSE); | 79 EXPECT(PPBFullscreen()->IsFullscreen(pp_instance()) == PP_FALSE); |
| 87 TEST_PASSED; | 80 TEST_PASSED; |
| 88 } | 81 } |
| 89 | 82 |
| 90 // Test | 83 // Test |
| 91 // PP_Bool (*SetFullscreen)(PP_Instance instance, PP_Bool fullscreen); | 84 // PP_Bool (*SetFullscreen)(PP_Instance instance, PP_Bool fullscreen); |
| 92 bool g_fullscreen_pending = false; | 85 bool g_fullscreen_pending = false; |
| 93 bool g_normal_pending = false; | 86 bool g_normal_pending = false; |
| 94 | 87 |
| 95 void TestSetFullscreenTrue() { | 88 void TestSetFullscreenTrue() { |
| 96 printf("--- TestSetFullscreenTrue\n"); | 89 printf("--- TestSetFullscreenTrue\n"); |
| 97 const PPB_Fullscreen_Dev* ppb = PPBFullscreenDev(); | 90 const PPB_Fullscreen* ppb = PPBFullscreen(); |
| 98 if (ppb->IsFullscreen(pp_instance()) == PP_FALSE) { | 91 if (ppb->IsFullscreen(pp_instance()) == PP_FALSE) { |
| 99 // Transition to fullscreen. | 92 // Transition to fullscreen. |
| 100 // This can only be done when processing a user gesture - | 93 // This can only be done when processing a user gesture - |
| 101 // see HandleInputEvent(). | 94 // see HandleInputEvent(). |
| 102 EXPECT(ppb->SetFullscreen(pp_instance(), PP_TRUE) == PP_FALSE); | 95 EXPECT(ppb->SetFullscreen(pp_instance(), PP_TRUE) == PP_FALSE); |
| 103 EXPECT(PPBInputEvent()-> | 96 EXPECT(PPBInputEvent()-> |
| 104 RequestInputEvents(pp_instance(), | 97 RequestInputEvents(pp_instance(), |
| 105 PP_INPUTEVENT_CLASS_MOUSE) == PP_OK); | 98 PP_INPUTEVENT_CLASS_MOUSE) == PP_OK); |
| 106 } else { | 99 } else { |
| 107 // No change. | 100 // No change. |
| 108 EXPECT(ppb->SetFullscreen(pp_instance(), PP_TRUE) == PP_FALSE); | 101 EXPECT(ppb->SetFullscreen(pp_instance(), PP_TRUE) == PP_FALSE); |
| 109 EXPECT(ppb->IsFullscreen(pp_instance()) == PP_TRUE); | 102 EXPECT(ppb->IsFullscreen(pp_instance()) == PP_TRUE); |
| 110 TEST_PASSED; | 103 TEST_PASSED; |
| 111 } | 104 } |
| 112 } | 105 } |
| 113 | 106 |
| 114 void TestSetFullscreenFalse() { | 107 void TestSetFullscreenFalse() { |
| 115 printf("--- TestSetFullscreenFalse\n"); | 108 printf("--- TestSetFullscreenFalse\n"); |
| 116 const PPB_Fullscreen_Dev* ppb = PPBFullscreenDev(); | 109 const PPB_Fullscreen* ppb = PPBFullscreen(); |
| 117 if (ppb->IsFullscreen(pp_instance()) == PP_TRUE) { | 110 if (ppb->IsFullscreen(pp_instance()) == PP_TRUE) { |
| 118 // Transition out of fullscreen. | 111 // Transition out of fullscreen. |
| 119 EXPECT(CreateGraphics2D(&g_graphics2d)); | 112 EXPECT(CreateGraphics2D(&g_graphics2d)); |
| 120 // The transition is asynchronous and ends at the next DidChangeView(). | 113 // The transition is asynchronous and ends at the next DidChangeView(). |
| 121 EXPECT(ppb->SetFullscreen(pp_instance(), PP_FALSE) == PP_TRUE); | 114 EXPECT(ppb->SetFullscreen(pp_instance(), PP_FALSE) == PP_TRUE); |
| 122 g_normal_pending = true; | 115 g_normal_pending = true; |
| 123 // Transition is pending, so additional requests fail. | 116 // Transition is pending, so additional requests fail. |
| 124 EXPECT(ppb->SetFullscreen(pp_instance(), PP_FALSE) == PP_FALSE); | 117 EXPECT(ppb->SetFullscreen(pp_instance(), PP_FALSE) == PP_FALSE); |
| 125 EXPECT(ppb->SetFullscreen(pp_instance(), PP_TRUE) == PP_FALSE); | 118 EXPECT(ppb->SetFullscreen(pp_instance(), PP_TRUE) == PP_FALSE); |
| 126 EXPECT(ppb->IsFullscreen(pp_instance()) == PP_TRUE); | 119 EXPECT(ppb->IsFullscreen(pp_instance()) == PP_TRUE); |
| 127 // No 2D or 3D device can be bound during transition. | 120 // No 2D or 3D device can be bound during transition. |
| 128 EXPECT(PPBGraphics2D()->IsGraphics2D(g_graphics2d) == PP_TRUE); | 121 EXPECT(PPBGraphics2D()->IsGraphics2D(g_graphics2d) == PP_TRUE); |
| 129 EXPECT(PPBInstance()->BindGraphics(pp_instance(), g_graphics2d) == | 122 EXPECT(PPBInstance()->BindGraphics(pp_instance(), g_graphics2d) == |
| 130 PP_FALSE); | 123 PP_FALSE); |
| 131 // The transition ends at the next DidChangeView(). | 124 // The transition ends at the next DidChangeView(). |
| 132 } else { | 125 } else { |
| 133 // No change. | 126 // No change. |
| 134 EXPECT(ppb->SetFullscreen(pp_instance(), PP_FALSE) == PP_FALSE); | 127 EXPECT(ppb->SetFullscreen(pp_instance(), PP_FALSE) == PP_FALSE); |
| 135 EXPECT(ppb->IsFullscreen(pp_instance()) == PP_FALSE); | 128 EXPECT(ppb->IsFullscreen(pp_instance()) == PP_FALSE); |
| 136 TEST_PASSED; | 129 TEST_PASSED; |
| 137 } | 130 } |
| 138 } | 131 } |
| 139 | 132 |
| 140 // Test | 133 // Test |
| 141 // PP_Bool (*GetScreenSize)(PP_Instance instance, struct PP_Size* size); | 134 // PP_Bool (*GetScreenSize)(PP_Instance instance, struct PP_Size* size); |
| 142 | 135 |
| 143 void TestGetScreenSizeHelper(PP_Size min_size, PP_Size max_size) { | 136 void TestGetScreenSizeHelper(PP_Size min_size, PP_Size max_size) { |
| 144 PP_Size size = PP_MakeSize(0, 0); | 137 PP_Size size = PP_MakeSize(0, 0); |
| 145 EXPECT(PPBFullscreenDev()->GetScreenSize(pp_instance(), &size) == PP_TRUE); | 138 EXPECT(PPBFullscreen()->GetScreenSize(pp_instance(), &size) == PP_TRUE); |
| 146 EXPECT(IsSizeInRange(size, min_size, max_size)); | 139 EXPECT(IsSizeInRange(size, min_size, max_size)); |
| 147 } | 140 } |
| 148 | 141 |
| 149 void TestGetScreenSize() { | 142 void TestGetScreenSize() { |
| 150 printf("--- TestGetScreenSize\n"); | 143 printf("--- TestGetScreenSize\n"); |
| 151 TestGetScreenSizeHelper(kSize320x200, kSize2560x2048); | 144 TestGetScreenSizeHelper(kSize320x200, kSize2560x2048); |
| 152 TEST_PASSED; | 145 TEST_PASSED; |
| 153 } | 146 } |
| 154 | 147 |
| 155 void TestGetScreenSize2560x1600() { | 148 void TestGetScreenSize2560x1600() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 172 // gesture (e.g. mouse click). | 165 // gesture (e.g. mouse click). |
| 173 PP_Bool HandleInputEvent(PP_Instance instance, PP_Resource event) { | 166 PP_Bool HandleInputEvent(PP_Instance instance, PP_Resource event) { |
| 174 PP_InputEvent_Type event_type = PPBInputEvent()->GetType(event); | 167 PP_InputEvent_Type event_type = PPBInputEvent()->GetType(event); |
| 175 if (event_type != PP_INPUTEVENT_TYPE_MOUSEDOWN && | 168 if (event_type != PP_INPUTEVENT_TYPE_MOUSEDOWN && |
| 176 event_type != PP_INPUTEVENT_TYPE_MOUSEUP) | 169 event_type != PP_INPUTEVENT_TYPE_MOUSEUP) |
| 177 return PP_FALSE; // Not a mouse click. | 170 return PP_FALSE; // Not a mouse click. |
| 178 printf("--- PPP_InputEvent::HandleInputEvent\n"); | 171 printf("--- PPP_InputEvent::HandleInputEvent\n"); |
| 179 // We got the user gesture we needed, no need to handle events anymore. | 172 // We got the user gesture we needed, no need to handle events anymore. |
| 180 PPBInputEvent()->ClearInputEventRequest(pp_instance(), | 173 PPBInputEvent()->ClearInputEventRequest(pp_instance(), |
| 181 PP_INPUTEVENT_CLASS_MOUSE); | 174 PP_INPUTEVENT_CLASS_MOUSE); |
| 182 EXPECT(PPBFullscreenDev()->IsFullscreen(pp_instance()) == PP_FALSE); | 175 EXPECT(PPBFullscreen()->IsFullscreen(pp_instance()) == PP_FALSE); |
| 183 EXPECT(CreateGraphics2D(&g_graphics2d)); | 176 EXPECT(CreateGraphics2D(&g_graphics2d)); |
| 184 EXPECT(PPBFullscreenDev()->SetFullscreen(pp_instance(), PP_TRUE) == PP_TRUE); | 177 EXPECT(PPBFullscreen()->SetFullscreen(pp_instance(), PP_TRUE) == PP_TRUE); |
| 185 g_fullscreen_pending = true; | 178 g_fullscreen_pending = true; |
| 186 // Transition is pending, so additional requests fail. | 179 // Transition is pending, so additional requests fail. |
| 187 EXPECT(PPBFullscreenDev()->SetFullscreen(pp_instance(), PP_TRUE) == PP_FALSE); | 180 EXPECT(PPBFullscreen()->SetFullscreen(pp_instance(), PP_TRUE) == PP_FALSE); |
| 188 EXPECT(PPBFullscreenDev()->SetFullscreen(pp_instance(), PP_FALSE) == | 181 EXPECT(PPBFullscreen()->SetFullscreen(pp_instance(), PP_FALSE) == |
| 189 PP_FALSE); | 182 PP_FALSE); |
| 190 EXPECT(PPBFullscreenDev()->IsFullscreen(pp_instance()) == PP_FALSE); | 183 EXPECT(PPBFullscreen()->IsFullscreen(pp_instance()) == PP_FALSE); |
| 191 // No 2D or 3D device can be bound during transition. | 184 // No 2D or 3D device can be bound during transition. |
| 192 EXPECT(PPBGraphics2D()->IsGraphics2D(g_graphics2d) == PP_TRUE); | 185 EXPECT(PPBGraphics2D()->IsGraphics2D(g_graphics2d) == PP_TRUE); |
| 193 EXPECT(PPBInstance()->BindGraphics(pp_instance(), g_graphics2d) == | 186 EXPECT(PPBInstance()->BindGraphics(pp_instance(), g_graphics2d) == |
| 194 PP_FALSE); | 187 PP_FALSE); |
| 195 // The transition ends at the next DidChangeView(). | 188 // The transition ends at the next DidChangeView(). |
| 196 return PP_FALSE; | 189 return PP_FALSE; |
| 197 } | 190 } |
| 198 | 191 |
| 199 const PPP_InputEvent ppp_input_event_interface = { | 192 const PPP_InputEvent ppp_input_event_interface = { |
| 200 &HandleInputEvent | 193 &HandleInputEvent |
| 201 }; | 194 }; |
| 202 | 195 |
| 203 //////////////////////////////////////////////////////////////////////////////// | 196 //////////////////////////////////////////////////////////////////////////////// |
| 204 // PPP_Instance | 197 // PPP_Instance |
| 205 //////////////////////////////////////////////////////////////////////////////// | 198 //////////////////////////////////////////////////////////////////////////////// |
| 206 | 199 |
| 207 PP_Size GetScreenSize() { | 200 PP_Size GetScreenSize() { |
| 208 PP_Size screen_size = PP_MakeSize(0, 0); | 201 PP_Size screen_size = PP_MakeSize(0, 0); |
| 209 CHECK(PPBFullscreenDev()->GetScreenSize(pp_instance(), &screen_size)); | 202 CHECK(PPBFullscreen()->GetScreenSize(pp_instance(), &screen_size)); |
| 210 return screen_size; | 203 return screen_size; |
| 211 } | 204 } |
| 212 | 205 |
| 213 bool HasMidScreen(const PP_Rect* position) { | 206 bool HasMidScreen(const PP_Rect* position) { |
| 214 static PP_Size screen_size = GetScreenSize(); | 207 static PP_Size screen_size = GetScreenSize(); |
| 215 static int32_t mid_x = screen_size.width / 2; | 208 static int32_t mid_x = screen_size.width / 2; |
| 216 static int32_t mid_y = screen_size.height / 2; | 209 static int32_t mid_y = screen_size.height / 2; |
| 217 PP_Point origin = position->point; | 210 PP_Point origin = position->point; |
| 218 PP_Size size = position->size; | 211 PP_Size size = position->size; |
| 219 return (origin.x < mid_x && mid_x < origin.x + size.width && | 212 return (origin.x < mid_x && mid_x < origin.x + size.width && |
| (...skipping 18 matching lines...) Expand all Loading... |
| 238 // Remember the original position on the first DidChangeView. | 231 // Remember the original position on the first DidChangeView. |
| 239 if (g_normal_position.size.width == 0 && g_normal_position.size.height == 0) { | 232 if (g_normal_position.size.width == 0 && g_normal_position.size.height == 0) { |
| 240 g_normal_position = PP_MakeRectFromXYWH(position->point.x, | 233 g_normal_position = PP_MakeRectFromXYWH(position->point.x, |
| 241 position->point.y, | 234 position->point.y, |
| 242 position->size.width, | 235 position->size.width, |
| 243 position->size.height); | 236 position->size.height); |
| 244 } | 237 } |
| 245 | 238 |
| 246 const char* test = NULL; | 239 const char* test = NULL; |
| 247 PP_Size screen_size = GetScreenSize(); | 240 PP_Size screen_size = GetScreenSize(); |
| 248 if (g_fullscreen_pending && PPBFullscreenDev()->IsFullscreen(pp_instance())) { | 241 if (g_fullscreen_pending && PPBFullscreen()->IsFullscreen(pp_instance())) { |
| 249 test = "TestSetFullscreenTrue"; | 242 test = "TestSetFullscreenTrue"; |
| 250 g_fullscreen_pending = false; | 243 g_fullscreen_pending = false; |
| 251 EXPECT(IsSizeEqual(position->size, screen_size)); | 244 EXPECT(IsSizeEqual(position->size, screen_size)); |
| 252 // NOTE: we cannot reliably test for clip size being equal to the screen | 245 // NOTE: we cannot reliably test for clip size being equal to the screen |
| 253 // because it might be affected by JS console, info bars, etc. | 246 // because it might be affected by JS console, info bars, etc. |
| 254 } else if (g_normal_pending && | 247 } else if (g_normal_pending && |
| 255 !PPBFullscreenDev()->IsFullscreen(pp_instance())) { | 248 !PPBFullscreen()->IsFullscreen(pp_instance())) { |
| 256 test = "TestSetFullscreenFalse"; | 249 test = "TestSetFullscreenFalse"; |
| 257 g_normal_pending = false; | 250 g_normal_pending = false; |
| 258 EXPECT(IsRectEqual(*position, g_normal_position)); | 251 EXPECT(IsRectEqual(*position, g_normal_position)); |
| 259 } | 252 } |
| 260 if (test != NULL) { | 253 if (test != NULL) { |
| 261 // We should now be able to bind 2D and 3D devices. | 254 // We should now be able to bind 2D and 3D devices. |
| 262 EXPECT(PPBGraphics2D()->IsGraphics2D(g_graphics2d) == PP_TRUE); | 255 EXPECT(PPBGraphics2D()->IsGraphics2D(g_graphics2d) == PP_TRUE); |
| 263 EXPECT(PPBInstance()->BindGraphics(pp_instance(), g_graphics2d) == PP_TRUE); | 256 EXPECT(PPBInstance()->BindGraphics(pp_instance(), g_graphics2d) == PP_TRUE); |
| 264 PPBCore()->ReleaseResource(g_graphics2d); | 257 PPBCore()->ReleaseResource(g_graphics2d); |
| 265 PostTestMessage(test, "PASSED"); | 258 PostTestMessage(test, "PASSED"); |
| 266 } | 259 } |
| 267 } | 260 } |
| 268 | 261 |
| 269 const PPP_Instance ppp_instance_interface = { | 262 const PPP_Instance ppp_instance_interface = { |
| 270 DidCreateDefault, | 263 DidCreateDefault, |
| 271 DidDestroyDefault, | 264 DidDestroyDefault, |
| 272 DidChangeView, | 265 DidChangeView, |
| 273 DidChangeFocusDefault, | 266 DidChangeFocusDefault, |
| 274 HandleDocumentLoadDefault | 267 HandleDocumentLoadDefault |
| 275 }; | 268 }; |
| 276 | 269 |
| 277 } // namespace | 270 } // namespace |
| 278 | 271 |
| 279 void SetupTests() { | 272 void SetupTests() { |
| 280 RegisterTest("TestGetInterface", TestGetInterface); | |
| 281 RegisterTest("TestIsFullscreenTrue", TestIsFullscreenTrue); | 273 RegisterTest("TestIsFullscreenTrue", TestIsFullscreenTrue); |
| 282 RegisterTest("TestIsFullscreenFalse", TestIsFullscreenFalse); | 274 RegisterTest("TestIsFullscreenFalse", TestIsFullscreenFalse); |
| 283 RegisterTest("TestSetFullscreenTrue", TestSetFullscreenTrue); | 275 RegisterTest("TestSetFullscreenTrue", TestSetFullscreenTrue); |
| 284 RegisterTest("TestSetFullscreenFalse", TestSetFullscreenFalse); | 276 RegisterTest("TestSetFullscreenFalse", TestSetFullscreenFalse); |
| 285 RegisterTest("TestGetScreenSize", TestGetScreenSize); | 277 RegisterTest("TestGetScreenSize", TestGetScreenSize); |
| 286 RegisterTest("TestGetScreenSize2560x1600", TestGetScreenSize2560x1600); | 278 RegisterTest("TestGetScreenSize2560x1600", TestGetScreenSize2560x1600); |
| 287 RegisterTest("TestGetScreenSize1920x1200", TestGetScreenSize1920x1200); | 279 RegisterTest("TestGetScreenSize1920x1200", TestGetScreenSize1920x1200); |
| 288 } | 280 } |
| 289 | 281 |
| 290 void SetupPluginInterfaces() { | 282 void SetupPluginInterfaces() { |
| 291 RegisterPluginInterface(PPP_INSTANCE_INTERFACE, &ppp_instance_interface); | 283 RegisterPluginInterface(PPP_INSTANCE_INTERFACE, &ppp_instance_interface); |
| 292 RegisterPluginInterface(PPP_INPUT_EVENT_INTERFACE, | 284 RegisterPluginInterface(PPP_INPUT_EVENT_INTERFACE, |
| 293 &ppp_input_event_interface); | 285 &ppp_input_event_interface); |
| 294 } | 286 } |
| OLD | NEW |