Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: webkit/tools/npapi_layout_test_plugin/PluginObject.cpp

Issue 393017: This CL fixes the document-open.html and window-open.html plugin layout tests... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 15 matching lines...) Expand all
26 #include "PluginObject.h" 26 #include "PluginObject.h"
27 27
28 #include "TestObject.h" 28 #include "TestObject.h"
29 #include <assert.h> 29 #include <assert.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <stdio.h> 31 #include <stdio.h>
32 #ifdef WIN32 32 #ifdef WIN32
33 #define snprintf sprintf_s 33 #define snprintf sprintf_s
34 #endif 34 #endif
35 35
36 static void logWithWindowObject(NPObject* windowObject, NPP instance, const char * message)
37 {
38 NPVariant consoleVariant;
39 if (!browser->getproperty(instance, windowObject, browser->getstringidentifi er("console"), &consoleVariant)) {
40 fprintf(stderr, "Failed to retrieve console object while logging: %s\n", message);
41 return;
42 }
43
44 NPObject* consoleObject = NPVARIANT_TO_OBJECT(consoleVariant);
45
46 NPVariant messageVariant;
47 STRINGZ_TO_NPVARIANT(message, messageVariant);
48
49 NPVariant result;
50 if (!browser->invoke(instance, consoleObject, browser->getstringidentifier(" log"), &messageVariant, 1, &result)) {
51 fprintf(stderr, "Failed to invoke console.log while logging: %s\n", mess age);
52 browser->releaseobject(consoleObject);
53 return;
54 }
55
56 browser->releasevariantvalue(&result);
57 browser->releaseobject(consoleObject);
58 }
59
60 static void logWithWindowObjectVariableArgs(NPObject* windowObject, NPP instance , const char* format, ...)
61 {
62 va_list args;
63 va_start(args, format);
64 char message[2048] = "PLUGIN: ";
65 vsprintf(message + strlen(message), format, args);
66 va_end(args);
67
68 logWithWindowObject(windowObject, instance, message);
69 }
70
71 void log(NPP instance, const char* format, ...)
72 {
73 va_list args;
74 va_start(args, format);
75 char message[2048] = "PLUGIN: ";
76 vsprintf(message + strlen(message), format, args);
77 va_end(args);
78
79 NPObject* windowObject = 0;
80 NPError error = browser->getvalue(instance, NPNVWindowNPObject, &windowObjec t);
81 if (error != NPERR_NO_ERROR) {
82 fprintf(stderr, "Failed to retrieve window object while logging: %s\n", message);
83 return;
84 }
85
86 logWithWindowObject(windowObject, instance, message);
87 browser->releaseobject(windowObject);
88 }
89
36 static void pluginInvalidate(NPObject*); 90 static void pluginInvalidate(NPObject*);
37 static bool pluginHasProperty(NPObject*, NPIdentifier name); 91 static bool pluginHasProperty(NPObject*, NPIdentifier name);
38 static bool pluginHasMethod(NPObject*, NPIdentifier name); 92 static bool pluginHasMethod(NPObject*, NPIdentifier name);
39 static bool pluginGetProperty(NPObject*, NPIdentifier name, NPVariant*); 93 static bool pluginGetProperty(NPObject*, NPIdentifier name, NPVariant*);
40 static bool pluginSetProperty(NPObject*, NPIdentifier name, const NPVariant*); 94 static bool pluginSetProperty(NPObject*, NPIdentifier name, const NPVariant*);
41 static bool pluginInvoke(NPObject*, NPIdentifier name, const NPVariant* args, ui nt32_t argCount, NPVariant* result); 95 static bool pluginInvoke(NPObject*, NPIdentifier name, const NPVariant* args, ui nt32_t argCount, NPVariant* result);
42 static bool pluginInvokeDefault(NPObject*, const NPVariant* args, uint32_t argCo unt, NPVariant* result); 96 static bool pluginInvokeDefault(NPObject*, const NPVariant* args, uint32_t argCo unt, NPVariant* result);
43 static NPObject* pluginAllocate(NPP npp, NPClass*); 97 static NPObject* pluginAllocate(NPP npp, NPClass*);
44 static void pluginDeallocate(NPObject*); 98 static void pluginDeallocate(NPObject*);
45 99
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 } 676 }
623 677
624 static bool testConstruct(PluginObject* obj, const NPVariant* args, uint32_t arg Count, NPVariant* result) 678 static bool testConstruct(PluginObject* obj, const NPVariant* args, uint32_t arg Count, NPVariant* result)
625 { 679 {
626 if (!argCount || !NPVARIANT_IS_OBJECT(args[0])) 680 if (!argCount || !NPVARIANT_IS_OBJECT(args[0]))
627 return false; 681 return false;
628 682
629 return browser->construct(obj->npp, NPVARIANT_TO_OBJECT(args[0]), args + 1, argCount - 1, result); 683 return browser->construct(obj->npp, NPVARIANT_TO_OBJECT(args[0]), args + 1, argCount - 1, result);
630 } 684 }
631 685
686 // Helper function to notify the layout test controller that the test completed.
687 void notifyTestCompletion(NPP npp, NPObject* object)
688 {
689 NPVariant result;
690 NPString script;
691 script.UTF8Characters = "javascript:window.layoutTestController.notifyDone() ;";
692 script.UTF8Length = strlen("javascript:window.layoutTestController.notifyDon e();");
693 browser->evaluate(npp, object, &script, &result);
694 browser->releasevariantvalue(&result);
695 }
696
697 bool testDocumentOpen(NPP npp)
698 {
699 NPIdentifier documentId = browser->getstringidentifier("document");
700 NPIdentifier openId = browser->getstringidentifier("open");
701
702 NPObject *windowObject = NULL;
703 browser->getvalue(npp, NPNVWindowNPObject, &windowObject);
704 if (!windowObject)
705 return false;
706
707 NPVariant docVariant;
708 browser->getproperty(npp, windowObject, documentId, &docVariant);
709 if (docVariant.type != NPVariantType_Object)
710 return false;
711
712 NPObject *documentObject = NPVARIANT_TO_OBJECT(docVariant);
713
714 NPVariant openArgs[2];
715 STRINGZ_TO_NPVARIANT("text/html", openArgs[0]);
716 STRINGZ_TO_NPVARIANT("_blank", openArgs[1]);
717
718 NPVariant result;
719 browser->invoke(npp, documentObject, openId, openArgs, 2, &result);
720 browser->releaseobject(documentObject);
721
722 if (result.type == NPVariantType_Object) {
723 logWithWindowObjectVariableArgs(windowObject, npp, "DOCUMENT OPEN SUCCES S");
724 notifyTestCompletion(npp, result.value.objectValue);
725 browser->releaseobject(result.value.objectValue);
726 return true;
727 }
728
729 return false;
730 }
731
732 bool testWindowOpen(NPP npp)
733 {
734 NPIdentifier openId = browser->getstringidentifier("open");
735
736 NPObject *windowObject = NULL;
737 browser->getvalue(npp, NPNVWindowNPObject, &windowObject);
738 if (!windowObject)
739 return false;
740
741 NPVariant openArgs[2];
742 STRINGZ_TO_NPVARIANT("about:blank", openArgs[0]);
743 STRINGZ_TO_NPVARIANT("_blank", openArgs[1]);
744
745 NPVariant result;
746 browser->invoke(npp, windowObject, openId, openArgs, 2, &result);
747 if (result.type == NPVariantType_Object) {
748 logWithWindowObjectVariableArgs(windowObject, npp, "WINDOW OPEN SUCCESS" );
749 notifyTestCompletion(npp, result.value.objectValue);
750 browser->releaseobject(result.value.objectValue);
751 return true;
752 }
753 return false;
754 }
755
632 static bool pluginInvoke(NPObject* header, NPIdentifier name, const NPVariant* a rgs, uint32_t argCount, NPVariant* result) 756 static bool pluginInvoke(NPObject* header, NPIdentifier name, const NPVariant* a rgs, uint32_t argCount, NPVariant* result)
633 { 757 {
634 PluginObject* plugin = reinterpret_cast<PluginObject*>(header); 758 PluginObject* plugin = reinterpret_cast<PluginObject*>(header);
635 if (name == pluginMethodIdentifiers[ID_TEST_CALLBACK_METHOD]) 759 if (name == pluginMethodIdentifiers[ID_TEST_CALLBACK_METHOD])
636 return testCallback(plugin, args, argCount, result); 760 return testCallback(plugin, args, argCount, result);
637 else if (name == pluginMethodIdentifiers[ID_TEST_GETURL]) 761 else if (name == pluginMethodIdentifiers[ID_TEST_GETURL])
638 return getURL(plugin, args, argCount, result); 762 return getURL(plugin, args, argCount, result);
639 else if (name == pluginMethodIdentifiers[ID_REMOVE_DEFAULT_METHOD]) 763 else if (name == pluginMethodIdentifiers[ID_REMOVE_DEFAULT_METHOD])
640 return removeDefaultMethod(plugin, args, argCount, result); 764 return removeDefaultMethod(plugin, args, argCount, result);
641 else if (name == pluginMethodIdentifiers[ID_TEST_DOM_ACCESS]) 765 else if (name == pluginMethodIdentifiers[ID_TEST_DOM_ACCESS])
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 newInstance->logDestroy = FALSE; 955 newInstance->logDestroy = FALSE;
832 newInstance->logSetWindow = FALSE; 956 newInstance->logSetWindow = FALSE;
833 newInstance->returnErrorFromNewStream = FALSE; 957 newInstance->returnErrorFromNewStream = FALSE;
834 newInstance->stream = 0; 958 newInstance->stream = 0;
835 959
836 newInstance->firstUrl = NULL; 960 newInstance->firstUrl = NULL;
837 newInstance->firstHeaders = NULL; 961 newInstance->firstHeaders = NULL;
838 newInstance->lastUrl = NULL; 962 newInstance->lastUrl = NULL;
839 newInstance->lastHeaders = NULL; 963 newInstance->lastHeaders = NULL;
840 964
965 newInstance->testDocumentOpenInDestroyStream = FALSE;
966 newInstance->testWindowOpen = FALSE;
967
841 return (NPObject*)newInstance; 968 return (NPObject*)newInstance;
842 } 969 }
843 970
844 static void pluginDeallocate(NPObject* header) 971 static void pluginDeallocate(NPObject* header)
845 { 972 {
846 PluginObject* plugin = reinterpret_cast<PluginObject*>(header); 973 PluginObject* plugin = reinterpret_cast<PluginObject*>(header);
847 browser->releaseobject(plugin->testObject); 974 browser->releaseobject(plugin->testObject);
848 975
849 free(plugin->firstUrl); 976 free(plugin->firstUrl);
850 free(plugin->firstHeaders); 977 free(plugin->firstHeaders);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 DOUBLE_TO_NPVARIANT(242.242, args[4]); 1047 DOUBLE_TO_NPVARIANT(242.242, args[4]);
921 STRINGZ_TO_NPVARIANT("Hello, World", args[5]); 1048 STRINGZ_TO_NPVARIANT("Hello, World", args[5]);
922 OBJECT_TO_NPVARIANT(windowScriptObject, args[6]); 1049 OBJECT_TO_NPVARIANT(windowScriptObject, args[6]);
923 1050
924 NPVariant result; 1051 NPVariant result;
925 if (browser->invoke(npp, windowScriptObject, testNPInvoke, args, 7, &result) ) 1052 if (browser->invoke(npp, windowScriptObject, testNPInvoke, args, 7, &result) )
926 browser->releasevariantvalue(&result); 1053 browser->releasevariantvalue(&result);
927 1054
928 browser->releaseobject(windowScriptObject); 1055 browser->releaseobject(windowScriptObject);
929 } 1056 }
OLDNEW
« no previous file with comments | « webkit/tools/npapi_layout_test_plugin/PluginObject.h ('k') | webkit/tools/npapi_layout_test_plugin/main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698