1 # Copyright (C) 2010 Apple Inc. All rights reserved. 2 # 3 # Redistribution and use in source and binary forms, with or without 4 # modification, are permitted provided that the following conditions 5 # are met: 6 # 1. Redistributions of source code must retain the above copyright 7 # notice, this list of conditions and the following disclaimer. 8 # 2. Redistributions in binary form must reproduce the above copyright 9 # notice, this list of conditions and the following disclaimer in the 10 # documentation and/or other materials provided with the distribution. 11 # 12 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND 13 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR 16 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 19 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 20 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 21 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 23 import unittest 24 from StringIO import StringIO 25 26 import messages 27 28 _messages_file_contents = """# Copyright (C) 2010 Apple Inc. All rights reserved. 29 # 30 # Redistribution and use in source and binary forms, with or without 31 # modification, are permitted provided that the following conditions 32 # are met: 33 # 1. Redistributions of source code must retain the above copyright 34 # notice, this list of conditions and the following disclaimer. 35 # 2. Redistributions in binary form must reproduce the above copyright 36 # notice, this list of conditions and the following disclaimer in the 37 # documentation and/or other materials provided with the distribution. 38 # 39 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND 40 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 41 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 42 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR 43 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 44 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 45 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 46 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 47 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 48 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 49 50 #include "config.h" 51 52 #if ENABLE(WEBKIT2) 53 54 messages -> WebPage { 55 LoadURL(WTF::String url) 56 #if ENABLE(TOUCH_EVENTS) 57 TouchEvent(WebKit::WebTouchEvent event) 58 #endif 59 DidReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction) 60 Close() 61 62 PreferencesDidChange(WebKit::WebPreferencesStore store) 63 SendDoubleAndFloat(double d, float f) 64 SendInts(Vector<uint64_t> ints, Vector<Vector<uint64_t> > intVectors) 65 66 CreatePlugin(uint64_t pluginInstanceID, WebKit::Plugin::Parameters parameters) -> (bool result) 67 RunJavaScriptAlert(uint64_t frameID, WTF::String message) -> () 68 GetPlugins(bool refresh) -> (Vector<WebCore::PluginInfo> plugins) DispatchOnConnectionQueue 69 GetPluginProcessConnection(WTF::String pluginPath) -> (CoreIPC::Connection::Handle connectionHandle) Delayed 70 71 TestMultipleAttributes() -> () DispatchOnConnectionQueue Delayed 72 73 #if PLATFORM(MAC) 74 DidCreateWebProcessConnection(CoreIPC::MachPort connectionIdentifier) 75 #endif 76 77 #if PLATFORM(MAC) 78 # Keyboard support 79 InterpretKeyEvent(uint32_t type) -> (Vector<WebCore::KeypressCommand> commandName) 80 #endif 81 } 82 83 #endif 84 """ 85 86 _expected_results = { 87 'name': 'WebPage', 88 'condition': 'ENABLE(WEBKIT2)', 89 'messages': ( 90 { 91 'name': 'LoadURL', 92 'parameters': ( 93 ('WTF::String', 'url'), 94 ), 95 'condition': None, 96 }, 97 { 98 'name': 'TouchEvent', 99 'parameters': ( 100 ('WebKit::WebTouchEvent', 'event'), 101 ), 102 'condition': 'ENABLE(TOUCH_EVENTS)', 103 }, 104 { 105 'name': 'DidReceivePolicyDecision', 106 'parameters': ( 107 ('uint64_t', 'frameID'), 108 ('uint64_t', 'listenerID'), 109 ('uint32_t', 'policyAction'), 110 ), 111 'condition': None, 112 }, 113 { 114 'name': 'Close', 115 'parameters': (), 116 'condition': None, 117 }, 118 { 119 'name': 'PreferencesDidChange', 120 'parameters': ( 121 ('WebKit::WebPreferencesStore', 'store'), 122 ), 123 'condition': None, 124 }, 125 { 126 'name': 'SendDoubleAndFloat', 127 'parameters': ( 128 ('double', 'd'), 129 ('float', 'f'), 130 ), 131 'condition': None, 132 }, 133 { 134 'name': 'SendInts', 135 'parameters': ( 136 ('Vector<uint64_t>', 'ints'), 137 ('Vector<Vector<uint64_t> >', 'intVectors') 138 ), 139 'condition': None, 140 }, 141 { 142 'name': 'CreatePlugin', 143 'parameters': ( 144 ('uint64_t', 'pluginInstanceID'), 145 ('WebKit::Plugin::Parameters', 'parameters') 146 ), 147 'reply_parameters': ( 148 ('bool', 'result'), 149 ), 150 'condition': None, 151 }, 152 { 153 'name': 'RunJavaScriptAlert', 154 'parameters': ( 155 ('uint64_t', 'frameID'), 156 ('WTF::String', 'message') 157 ), 158 'reply_parameters': (), 159 'condition': None, 160 }, 161 { 162 'name': 'GetPlugins', 163 'parameters': ( 164 ('bool', 'refresh'), 165 ), 166 'reply_parameters': ( 167 ('Vector<WebCore::PluginInfo>', 'plugins'), 168 ), 169 'condition': None, 170 }, 171 { 172 'name': 'GetPluginProcessConnection', 173 'parameters': ( 174 ('WTF::String', 'pluginPath'), 175 ), 176 'reply_parameters': ( 177 ('CoreIPC::Connection::Handle', 'connectionHandle'), 178 ), 179 'condition': None, 180 }, 181 { 182 'name': 'TestMultipleAttributes', 183 'parameters': ( 184 ), 185 'reply_parameters': ( 186 ), 187 'condition': None, 188 }, 189 { 190 'name': 'DidCreateWebProcessConnection', 191 'parameters': ( 192 ('CoreIPC::MachPort', 'connectionIdentifier'), 193 ), 194 'condition': 'PLATFORM(MAC)', 195 }, 196 { 197 'name': 'InterpretKeyEvent', 198 'parameters': ( 199 ('uint32_t', 'type'), 200 ), 201 'reply_parameters': ( 202 ('Vector<WebCore::KeypressCommand>', 'commandName'), 203 ), 204 'condition': 'PLATFORM(MAC)', 205 }, 206 ), 207 } 208 209 210 class MessagesTest(unittest.TestCase): 211 def setUp(self): 212 self.receiver = messages.MessageReceiver.parse(StringIO(_messages_file_contents)) 213 214 215 class ParsingTest(MessagesTest): 216 def check_message(self, message, expected_message): 217 self.assertEquals(message.name, expected_message['name']) 218 self.assertEquals(len(message.parameters), len(expected_message['parameters'])) 219 for index, parameter in enumerate(message.parameters): 220 self.assertEquals(parameter.type, expected_message['parameters'][index][0]) 221 self.assertEquals(parameter.name, expected_message['parameters'][index][1]) 222 if message.reply_parameters != None: 223 for index, parameter in enumerate(message.reply_parameters): 224 self.assertEquals(parameter.type, expected_message['reply_parameters'][index][0]) 225 self.assertEquals(parameter.name, expected_message['reply_parameters'][index][1]) 226 else: 227 self.assertFalse('reply_parameters' in expected_message) 228 self.assertEquals(message.condition, expected_message['condition']) 229 230 def test_receiver(self): 231 """Receiver should be parsed as expected""" 232 self.assertEquals(self.receiver.name, _expected_results['name']) 233 self.assertEquals(self.receiver.condition, _expected_results['condition']) 234 self.assertEquals(len(self.receiver.messages), len(_expected_results['messages'])) 235 for index, message in enumerate(self.receiver.messages): 236 self.check_message(message, _expected_results['messages'][index]) 237 238 _expected_header = """/* 239 * Copyright (C) 2010 Apple Inc. All rights reserved. 240 * 241 * Redistribution and use in source and binary forms, with or without 242 * modification, are permitted provided that the following conditions 243 * are met: 244 * 1. Redistributions of source code must retain the above copyright 245 * notice, this list of conditions and the following disclaimer. 246 * 2. Redistributions in binary form must reproduce the above copyright 247 * notice, this list of conditions and the following disclaimer in the 248 * documentation and/or other materials provided with the distribution. 249 * 250 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND 251 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 252 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 253 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR 254 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 255 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 256 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 257 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 258 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 259 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 260 */ 261 262 #ifndef WebPageMessages_h 263 #define WebPageMessages_h 264 265 #if ENABLE(WEBKIT2) 266 267 #include "Arguments.h" 268 #include "Connection.h" 269 #include "MessageID.h" 270 #include "Plugin.h" 271 #include <WebCore/KeyboardEvent.h> 272 #include <WebCore/PluginData.h> 273 #include <wtf/ThreadSafeRefCounted.h> 274 #include <wtf/Vector.h> 275 276 namespace CoreIPC { 277 class ArgumentEncoder; 278 class Connection; 279 class MachPort; 280 } 281 282 namespace WTF { 283 class String; 284 } 285 286 namespace WebKit { 287 struct WebPreferencesStore; 288 class WebTouchEvent; 289 } 290 291 namespace Messages { 292 293 namespace WebPage { 294 295 enum Kind { 296 LoadURLID, 297 #if ENABLE(TOUCH_EVENTS) 298 TouchEventID, 299 #endif 300 DidReceivePolicyDecisionID, 301 CloseID, 302 PreferencesDidChangeID, 303 SendDoubleAndFloatID, 304 SendIntsID, 305 CreatePluginID, 306 RunJavaScriptAlertID, 307 GetPluginsID, 308 GetPluginProcessConnectionID, 309 TestMultipleAttributesID, 310 #if PLATFORM(MAC) 311 DidCreateWebProcessConnectionID, 312 #endif 313 #if PLATFORM(MAC) 314 InterpretKeyEventID, 315 #endif 316 }; 317 318 struct LoadURL : CoreIPC::Arguments1<const WTF::String&> { 319 static const Kind messageID = LoadURLID; 320 typedef CoreIPC::Arguments1<const WTF::String&> DecodeType; 321 explicit LoadURL(const WTF::String& url) 322 : CoreIPC::Arguments1<const WTF::String&>(url) 323 { 324 } 325 }; 326 327 #if ENABLE(TOUCH_EVENTS) 328 struct TouchEvent : CoreIPC::Arguments1<const WebKit::WebTouchEvent&> { 329 static const Kind messageID = TouchEventID; 330 typedef CoreIPC::Arguments1<const WebKit::WebTouchEvent&> DecodeType; 331 explicit TouchEvent(const WebKit::WebTouchEvent& event) 332 : CoreIPC::Arguments1<const WebKit::WebTouchEvent&>(event) 333 { 334 } 335 }; 336 #endif 337 338 struct DidReceivePolicyDecision : CoreIPC::Arguments3<uint64_t, uint64_t, uint32_t> { 339 static const Kind messageID = DidReceivePolicyDecisionID; 340 typedef CoreIPC::Arguments3<uint64_t, uint64_t, uint32_t> DecodeType; 341 DidReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction) 342 : CoreIPC::Arguments3<uint64_t, uint64_t, uint32_t>(frameID, listenerID, policyAction) 343 { 344 } 345 }; 346 347 struct Close : CoreIPC::Arguments0 { 348 static const Kind messageID = CloseID; 349 typedef CoreIPC::Arguments0 DecodeType; 350 }; 351 352 struct PreferencesDidChange : CoreIPC::Arguments1<const WebKit::WebPreferencesStore&> { 353 static const Kind messageID = PreferencesDidChangeID; 354 typedef CoreIPC::Arguments1<const WebKit::WebPreferencesStore&> DecodeType; 355 explicit PreferencesDidChange(const WebKit::WebPreferencesStore& store) 356 : CoreIPC::Arguments1<const WebKit::WebPreferencesStore&>(store) 357 { 358 } 359 }; 360 361 struct SendDoubleAndFloat : CoreIPC::Arguments2<double, float> { 362 static const Kind messageID = SendDoubleAndFloatID; 363 typedef CoreIPC::Arguments2<double, float> DecodeType; 364 SendDoubleAndFloat(double d, float f) 365 : CoreIPC::Arguments2<double, float>(d, f) 366 { 367 } 368 }; 369 370 struct SendInts : CoreIPC::Arguments2<const Vector<uint64_t>&, const Vector<Vector<uint64_t> >&> { 371 static const Kind messageID = SendIntsID; 372 typedef CoreIPC::Arguments2<const Vector<uint64_t>&, const Vector<Vector<uint64_t> >&> DecodeType; 373 SendInts(const Vector<uint64_t>& ints, const Vector<Vector<uint64_t> >& intVectors) 374 : CoreIPC::Arguments2<const Vector<uint64_t>&, const Vector<Vector<uint64_t> >&>(ints, intVectors) 375 { 376 } 377 }; 378 379 struct CreatePlugin : CoreIPC::Arguments2<uint64_t, const WebKit::Plugin::Parameters&> { 380 static const Kind messageID = CreatePluginID; 381 typedef CoreIPC::Arguments1<bool&> Reply; 382 typedef CoreIPC::Arguments2<uint64_t, const WebKit::Plugin::Parameters&> DecodeType; 383 CreatePlugin(uint64_t pluginInstanceID, const WebKit::Plugin::Parameters& parameters) 384 : CoreIPC::Arguments2<uint64_t, const WebKit::Plugin::Parameters&>(pluginInstanceID, parameters) 385 { 386 } 387 }; 388 389 struct RunJavaScriptAlert : CoreIPC::Arguments2<uint64_t, const WTF::String&> { 390 static const Kind messageID = RunJavaScriptAlertID; 391 typedef CoreIPC::Arguments0 Reply; 392 typedef CoreIPC::Arguments2<uint64_t, const WTF::String&> DecodeType; 393 RunJavaScriptAlert(uint64_t frameID, const WTF::String& message) 394 : CoreIPC::Arguments2<uint64_t, const WTF::String&>(frameID, message) 395 { 396 } 397 }; 398 399 struct GetPlugins : CoreIPC::Arguments1<bool> { 400 static const Kind messageID = GetPluginsID; 401 typedef CoreIPC::Arguments1<Vector<WebCore::PluginInfo>&> Reply; 402 typedef CoreIPC::Arguments1<bool> DecodeType; 403 explicit GetPlugins(bool refresh) 404 : CoreIPC::Arguments1<bool>(refresh) 405 { 406 } 407 }; 408 409 struct GetPluginProcessConnection : CoreIPC::Arguments1<const WTF::String&> { 410 static const Kind messageID = GetPluginProcessConnectionID; 411 struct DelayedReply : public ThreadSafeRefCounted<DelayedReply> { 412 DelayedReply(PassRefPtr<CoreIPC::Connection>, PassOwnPtr<CoreIPC::ArgumentEncoder>); 413 ~DelayedReply(); 414 415 bool send(const CoreIPC::Connection::Handle& connectionHandle); 416 417 private: 418 RefPtr<CoreIPC::Connection> m_connection; 419 OwnPtr<CoreIPC::ArgumentEncoder> m_arguments; 420 }; 421 422 typedef CoreIPC::Arguments1<CoreIPC::Connection::Handle&> Reply; 423 typedef CoreIPC::Arguments1<const WTF::String&> DecodeType; 424 explicit GetPluginProcessConnection(const WTF::String& pluginPath) 425 : CoreIPC::Arguments1<const WTF::String&>(pluginPath) 426 { 427 } 428 }; 429 430 struct TestMultipleAttributes : CoreIPC::Arguments0 { 431 static const Kind messageID = TestMultipleAttributesID; 432 struct DelayedReply : public ThreadSafeRefCounted<DelayedReply> { 433 DelayedReply(PassRefPtr<CoreIPC::Connection>, PassOwnPtr<CoreIPC::ArgumentEncoder>); 434 ~DelayedReply(); 435 436 bool send(); 437 438 private: 439 RefPtr<CoreIPC::Connection> m_connection; 440 OwnPtr<CoreIPC::ArgumentEncoder> m_arguments; 441 }; 442 443 typedef CoreIPC::Arguments0 Reply; 444 typedef CoreIPC::Arguments0 DecodeType; 445 }; 446 447 #if PLATFORM(MAC) 448 struct DidCreateWebProcessConnection : CoreIPC::Arguments1<const CoreIPC::MachPort&> { 449 static const Kind messageID = DidCreateWebProcessConnectionID; 450 typedef CoreIPC::Arguments1<const CoreIPC::MachPort&> DecodeType; 451 explicit DidCreateWebProcessConnection(const CoreIPC::MachPort& connectionIdentifier) 452 : CoreIPC::Arguments1<const CoreIPC::MachPort&>(connectionIdentifier) 453 { 454 } 455 }; 456 #endif 457 458 #if PLATFORM(MAC) 459 struct InterpretKeyEvent : CoreIPC::Arguments1<uint32_t> { 460 static const Kind messageID = InterpretKeyEventID; 461 typedef CoreIPC::Arguments1<Vector<WebCore::KeypressCommand>&> Reply; 462 typedef CoreIPC::Arguments1<uint32_t> DecodeType; 463 explicit InterpretKeyEvent(uint32_t type) 464 : CoreIPC::Arguments1<uint32_t>(type) 465 { 466 } 467 }; 468 #endif 469 470 } // namespace WebPage 471 472 } // namespace Messages 473 474 namespace CoreIPC { 475 476 template<> struct MessageKindTraits<Messages::WebPage::Kind> { 477 static const MessageClass messageClass = MessageClassWebPage; 478 }; 479 480 } // namespace CoreIPC 481 482 #endif // ENABLE(WEBKIT2) 483 484 #endif // WebPageMessages_h 485 """ 486 487 _expected_receiver_implementation = """/* 488 * Copyright (C) 2010 Apple Inc. All rights reserved. 489 * 490 * Redistribution and use in source and binary forms, with or without 491 * modification, are permitted provided that the following conditions 492 * are met: 493 * 1. Redistributions of source code must retain the above copyright 494 * notice, this list of conditions and the following disclaimer. 495 * 2. Redistributions in binary form must reproduce the above copyright 496 * notice, this list of conditions and the following disclaimer in the 497 * documentation and/or other materials provided with the distribution. 498 * 499 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND 500 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 501 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 502 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR 503 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 504 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 505 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 506 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 507 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 508 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 509 */ 510 511 #include "config.h" 512 513 #if ENABLE(WEBKIT2) 514 515 #include "WebPage.h" 516 517 #if PLATFORM(MAC) 518 #include "ArgumentCoders.h" 519 #endif 520 #include "ArgumentDecoder.h" 521 #include "Connection.h" 522 #include "HandleMessage.h" 523 #if PLATFORM(MAC) 524 #include "MachPort.h" 525 #endif 526 #include "Plugin.h" 527 #if PLATFORM(MAC) 528 #include "WebCoreArgumentCoders.h" 529 #endif 530 #if ENABLE(TOUCH_EVENTS) 531 #include "WebEvent.h" 532 #endif 533 #include "WebPageMessages.h" 534 #include "WebPreferencesStore.h" 535 536 namespace Messages { 537 538 namespace WebPage { 539 540 GetPluginProcessConnection::DelayedReply::DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::ArgumentEncoder> arguments) 541 : m_connection(connection) 542 , m_arguments(arguments) 543 { 544 } 545 546 GetPluginProcessConnection::DelayedReply::~DelayedReply() 547 { 548 ASSERT(!m_connection); 549 } 550 551 bool GetPluginProcessConnection::DelayedReply::send(const CoreIPC::Connection::Handle& connectionHandle) 552 { 553 ASSERT(m_arguments); 554 m_arguments->encode(connectionHandle); 555 bool result = m_connection->sendSyncReply(m_arguments.release()); 556 m_connection = nullptr; 557 return result; 558 } 559 560 TestMultipleAttributes::DelayedReply::DelayedReply(PassRefPtr<CoreIPC::Connection> connection, PassOwnPtr<CoreIPC::ArgumentEncoder> arguments) 561 : m_connection(connection) 562 , m_arguments(arguments) 563 { 564 } 565 566 TestMultipleAttributes::DelayedReply::~DelayedReply() 567 { 568 ASSERT(!m_connection); 569 } 570 571 bool TestMultipleAttributes::DelayedReply::send() 572 { 573 ASSERT(m_arguments); 574 bool result = m_connection->sendSyncReply(m_arguments.release()); 575 m_connection = nullptr; 576 return result; 577 } 578 579 } // namespace WebPage 580 581 } // namespace Messages 582 583 namespace WebKit { 584 585 void WebPage::didReceiveWebPageMessage(CoreIPC::Connection*, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments) 586 { 587 switch (messageID.get<Messages::WebPage::Kind>()) { 588 case Messages::WebPage::LoadURLID: 589 CoreIPC::handleMessage<Messages::WebPage::LoadURL>(arguments, this, &WebPage::loadURL); 590 return; 591 #if ENABLE(TOUCH_EVENTS) 592 case Messages::WebPage::TouchEventID: 593 CoreIPC::handleMessage<Messages::WebPage::TouchEvent>(arguments, this, &WebPage::touchEvent); 594 return; 595 #endif 596 case Messages::WebPage::DidReceivePolicyDecisionID: 597 CoreIPC::handleMessage<Messages::WebPage::DidReceivePolicyDecision>(arguments, this, &WebPage::didReceivePolicyDecision); 598 return; 599 case Messages::WebPage::CloseID: 600 CoreIPC::handleMessage<Messages::WebPage::Close>(arguments, this, &WebPage::close); 601 return; 602 case Messages::WebPage::PreferencesDidChangeID: 603 CoreIPC::handleMessage<Messages::WebPage::PreferencesDidChange>(arguments, this, &WebPage::preferencesDidChange); 604 return; 605 case Messages::WebPage::SendDoubleAndFloatID: 606 CoreIPC::handleMessage<Messages::WebPage::SendDoubleAndFloat>(arguments, this, &WebPage::sendDoubleAndFloat); 607 return; 608 case Messages::WebPage::SendIntsID: 609 CoreIPC::handleMessage<Messages::WebPage::SendInts>(arguments, this, &WebPage::sendInts); 610 return; 611 #if PLATFORM(MAC) 612 case Messages::WebPage::DidCreateWebProcessConnectionID: 613 CoreIPC::handleMessage<Messages::WebPage::DidCreateWebProcessConnection>(arguments, this, &WebPage::didCreateWebProcessConnection); 614 return; 615 #endif 616 default: 617 break; 618 } 619 620 ASSERT_NOT_REACHED(); 621 } 622 623 CoreIPC::SyncReplyMode WebPage::didReceiveSyncWebPageMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply) 624 { 625 switch (messageID.get<Messages::WebPage::Kind>()) { 626 case Messages::WebPage::CreatePluginID: 627 CoreIPC::handleMessage<Messages::WebPage::CreatePlugin>(arguments, reply, this, &WebPage::createPlugin); 628 return CoreIPC::AutomaticReply; 629 case Messages::WebPage::RunJavaScriptAlertID: 630 CoreIPC::handleMessage<Messages::WebPage::RunJavaScriptAlert>(arguments, reply, this, &WebPage::runJavaScriptAlert); 631 return CoreIPC::AutomaticReply; 632 case Messages::WebPage::GetPluginsID: 633 CoreIPC::handleMessage<Messages::WebPage::GetPlugins>(arguments, reply, this, &WebPage::getPlugins); 634 return CoreIPC::AutomaticReply; 635 case Messages::WebPage::GetPluginProcessConnectionID: 636 CoreIPC::handleMessageDelayed<Messages::WebPage::GetPluginProcessConnection>(connection, arguments, reply, this, &WebPage::getPluginProcessConnection); 637 return CoreIPC::ManualReply; 638 case Messages::WebPage::TestMultipleAttributesID: 639 CoreIPC::handleMessageDelayed<Messages::WebPage::TestMultipleAttributes>(connection, arguments, reply, this, &WebPage::testMultipleAttributes); 640 return CoreIPC::ManualReply; 641 #if PLATFORM(MAC) 642 case Messages::WebPage::InterpretKeyEventID: 643 CoreIPC::handleMessage<Messages::WebPage::InterpretKeyEvent>(arguments, reply, this, &WebPage::interpretKeyEvent); 644 return CoreIPC::AutomaticReply; 645 #endif 646 default: 647 break; 648 } 649 650 ASSERT_NOT_REACHED(); 651 return CoreIPC::AutomaticReply; 652 } 653 654 } // namespace WebKit 655 656 #endif // ENABLE(WEBKIT2) 657 """ 658 659 660 class GeneratedFileContentsTest(unittest.TestCase): 661 def assertGeneratedFileContentsEqual(self, first, second): 662 first_list = first.split('\n') 663 second_list = second.split('\n') 664 665 for index, first_line in enumerate(first_list): 666 self.assertEquals(first_line, second_list[index]) 667 668 self.assertEquals(len(first_list), len(second_list)) 669 670 671 class HeaderTest(GeneratedFileContentsTest): 672 def test_header(self): 673 file_contents = messages.generate_messages_header(StringIO(_messages_file_contents)) 674 self.assertGeneratedFileContentsEqual(file_contents, _expected_header) 675 676 677 class ReceiverImplementationTest(GeneratedFileContentsTest): 678 def test_receiver_implementation(self): 679 file_contents = messages.generate_message_handler(StringIO(_messages_file_contents)) 680 self.assertGeneratedFileContentsEqual(file_contents, _expected_receiver_implementation) 681 682 683 if __name__ == '__main__': 684 unittest.main() 685