OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 TestFullscreen::TestFullscreen(TestingInstance* instance) | 52 TestFullscreen::TestFullscreen(TestingInstance* instance) |
53 : TestCase(instance), | 53 : TestCase(instance), |
54 error_(), | 54 error_(), |
55 screen_mode_(instance), | 55 screen_mode_(instance), |
56 painted_color_(0), | 56 painted_color_(0), |
57 fullscreen_pending_(false), | 57 fullscreen_pending_(false), |
58 normal_pending_(false), | 58 normal_pending_(false), |
59 set_fullscreen_true_callback_(instance->pp_instance()), | 59 fullscreen_event_(instance->pp_instance()), |
60 fullscreen_callback_(instance->pp_instance()), | 60 normal_event_(instance->pp_instance()) { |
61 normal_callback_(instance->pp_instance()) { | |
62 screen_mode_.GetScreenSize(&screen_size_); | 61 screen_mode_.GetScreenSize(&screen_size_); |
63 } | 62 } |
64 | 63 |
65 bool TestFullscreen::Init() { | 64 bool TestFullscreen::Init() { |
66 if (screen_size_.IsEmpty()) { | 65 if (screen_size_.IsEmpty()) { |
67 instance_->AppendError("Failed to initialize screen_size_"); | 66 instance_->AppendError("Failed to initialize screen_size_"); |
68 return false; | 67 return false; |
69 } | 68 } |
70 graphics2d_ = pp::Graphics2D(instance_, screen_size_, true); | 69 graphics2d_ = pp::Graphics2D(instance_, screen_size_, true); |
71 if (!instance_->BindGraphics(graphics2d_)) { | 70 if (!instance_->BindGraphics(graphics2d_)) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 107 |
109 // 1. Switch to fullscreen. | 108 // 1. Switch to fullscreen. |
110 // This is only allowed within a context of a user gesture (e.g. mouse click). | 109 // This is only allowed within a context of a user gesture (e.g. mouse click). |
111 if (screen_mode_.SetFullscreen(true)) | 110 if (screen_mode_.SetFullscreen(true)) |
112 return ReportError("SetFullscreen(true) outside of user gesture", true); | 111 return ReportError("SetFullscreen(true) outside of user gesture", true); |
113 // Trigger another call to SetFullscreen(true) from HandleInputEvent(). | 112 // Trigger another call to SetFullscreen(true) from HandleInputEvent(). |
114 // The transition is asynchronous and ends at the next DidChangeView(). | 113 // The transition is asynchronous and ends at the next DidChangeView(). |
115 instance_->RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); | 114 instance_->RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); |
116 SimulateUserGesture(); | 115 SimulateUserGesture(); |
117 // DidChangeView() will call the callback once in fullscreen mode. | 116 // DidChangeView() will call the callback once in fullscreen mode. |
118 fullscreen_callback_.WaitForResult(); | 117 fullscreen_event_.Wait(); |
119 if (GotError()) | 118 if (GotError()) |
120 return Error(); | 119 return Error(); |
121 if (fullscreen_pending_) | 120 if (fullscreen_pending_) |
122 return "fullscreen_pending_ has not been reset"; | 121 return "fullscreen_pending_ has not been reset"; |
123 if (!screen_mode_.IsFullscreen()) | 122 if (!screen_mode_.IsFullscreen()) |
124 return ReportError("IsFullscreen() in fullscreen", false); | 123 return ReportError("IsFullscreen() in fullscreen", false); |
125 | 124 |
126 // 2. Stay in fullscreen. No change. | 125 // 2. Stay in fullscreen. No change. |
127 if (screen_mode_.SetFullscreen(true)) | 126 if (screen_mode_.SetFullscreen(true)) |
128 return ReportError("SetFullscreen(true) in fullscreen", true); | 127 return ReportError("SetFullscreen(true) in fullscreen", true); |
129 if (!screen_mode_.IsFullscreen()) | 128 if (!screen_mode_.IsFullscreen()) |
130 return ReportError("IsFullscreen() in fullscreen^2", false); | 129 return ReportError("IsFullscreen() in fullscreen^2", false); |
131 | 130 |
132 // 3. Switch to normal. | 131 // 3. Switch to normal. |
133 // The transition is asynchronous and ends at DidChangeView(). | 132 // The transition is asynchronous and ends at DidChangeView(). |
134 // No graphics devices can be bound while in transition. | 133 // No graphics devices can be bound while in transition. |
135 normal_pending_ = true; | 134 normal_pending_ = true; |
136 if (!screen_mode_.SetFullscreen(false)) | 135 if (!screen_mode_.SetFullscreen(false)) |
137 return ReportError("SetFullscreen(false) in fullscreen", false); | 136 return ReportError("SetFullscreen(false) in fullscreen", false); |
138 // DidChangeView() will call the callback once out of fullscreen mode. | 137 // DidChangeView() will signal once out of fullscreen mode. |
139 normal_callback_.WaitForResult(); | 138 normal_event_.Wait(); |
140 if (GotError()) | 139 if (GotError()) |
141 return Error(); | 140 return Error(); |
142 if (normal_pending_) | 141 if (normal_pending_) |
143 return "normal_pending_ has not been reset"; | 142 return "normal_pending_ has not been reset"; |
144 if (screen_mode_.IsFullscreen()) | 143 if (screen_mode_.IsFullscreen()) |
145 return ReportError("IsFullscreen() in normal", true); | 144 return ReportError("IsFullscreen() in normal", true); |
146 | 145 |
147 // 4. Stay in normal. No change. | 146 // 4. Stay in normal. No change. |
148 if (screen_mode_.SetFullscreen(false)) | 147 if (screen_mode_.SetFullscreen(false)) |
149 return ReportError("SetFullscreen(false) in normal", true); | 148 return ReportError("SetFullscreen(false) in normal", true); |
(...skipping 17 matching lines...) Expand all Loading... |
167 plugin_center, | 166 plugin_center, |
168 1, // click_count | 167 1, // click_count |
169 mouse_movement); | 168 mouse_movement); |
170 | 169 |
171 testing_interface_->SimulateInputEvent(instance_->pp_instance(), | 170 testing_interface_->SimulateInputEvent(instance_->pp_instance(), |
172 input_event.pp_resource()); | 171 input_event.pp_resource()); |
173 } | 172 } |
174 | 173 |
175 void TestFullscreen::FailFullscreenTest(const std::string& error) { | 174 void TestFullscreen::FailFullscreenTest(const std::string& error) { |
176 error_ = error; | 175 error_ = error; |
177 pp::Module::Get()->core()->CallOnMainThread(0, fullscreen_callback_); | 176 fullscreen_event_.Signal(); |
178 } | 177 } |
179 | 178 |
180 void TestFullscreen::FailNormalTest(const std::string& error) { | 179 void TestFullscreen::FailNormalTest(const std::string& error) { |
181 error_ = error; | 180 error_ = error; |
182 pp::Module::Get()->core()->CallOnMainThread(0, normal_callback_); | 181 normal_event_.Signal(); |
183 } | 182 } |
184 | 183 |
185 void TestFullscreen::PassFullscreenTest() { | 184 void TestFullscreen::PassFullscreenTest() { |
186 pp::Module::Get()->core()->CallOnMainThread(0, fullscreen_callback_); | 185 fullscreen_event_.Signal(); |
187 } | 186 } |
188 | 187 |
189 void TestFullscreen::PassNormalTest() { | 188 void TestFullscreen::PassNormalTest() { |
190 pp::Module::Get()->core()->CallOnMainThread(0, normal_callback_); | 189 normal_event_.Signal(); |
191 } | 190 } |
192 | 191 |
193 // Transition to fullscreen can only happen when processing a user gesture. | 192 // Transition to fullscreen can only happen when processing a user gesture. |
194 bool TestFullscreen::HandleInputEvent(const pp::InputEvent& event) { | 193 bool TestFullscreen::HandleInputEvent(const pp::InputEvent& event) { |
195 // We only let mouse events through and only mouse clicks count. | 194 // We only let mouse events through and only mouse clicks count. |
196 if (event.GetType() != PP_INPUTEVENT_TYPE_MOUSEDOWN && | 195 if (event.GetType() != PP_INPUTEVENT_TYPE_MOUSEDOWN && |
197 event.GetType() != PP_INPUTEVENT_TYPE_MOUSEUP) | 196 event.GetType() != PP_INPUTEVENT_TYPE_MOUSEUP) |
198 return false; | 197 return false; |
199 // We got the gesture. No need to handle any more events. | 198 // We got the gesture. No need to handle any more events. |
200 instance_->ClearInputEventRequest(PP_INPUTEVENT_CLASS_MOUSE); | 199 instance_->ClearInputEventRequest(PP_INPUTEVENT_CLASS_MOUSE); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } else if (normal_pending_ && !is_fullscreen) { | 296 } else if (normal_pending_ && !is_fullscreen) { |
298 normal_pending_ = false; | 297 normal_pending_ = false; |
299 if (screen_mode_.IsFullscreen()) | 298 if (screen_mode_.IsFullscreen()) |
300 FailNormalTest("DidChangeview is in fullscreen"); | 299 FailNormalTest("DidChangeview is in fullscreen"); |
301 else if (!instance_->BindGraphics(graphics2d_)) | 300 else if (!instance_->BindGraphics(graphics2d_)) |
302 FailNormalTest("Failed to BindGraphics() in normal"); | 301 FailNormalTest("Failed to BindGraphics() in normal"); |
303 else if (!PaintPlugin(position.size(), kSheerBlue)) | 302 else if (!PaintPlugin(position.size(), kSheerBlue)) |
304 FailNormalTest("Failed to paint plugin image in normal"); | 303 FailNormalTest("Failed to paint plugin image in normal"); |
305 } | 304 } |
306 } | 305 } |
OLD | NEW |