- Fix incorrect result in CefBytesReader::Seek() when SEEK_END argument is specified.
- Return 0 from CefBytesReader::Seek() on success to be consistent with fseek().
- Set URLRequestStatus error code to net::ERR_ABORTED in browser_resource_loader_bridge.cc when HandleBeforeResourceLoad returns RV_HANDLED to avoid a WebKit assert.

unittests:
- Add unit testing framework.
- Add initial unit tests for request, stream and V8.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@52 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2009-10-08 01:26:56 +00:00
parent 0800cba74d
commit 144e15c966
13 changed files with 1580 additions and 16 deletions

39
cef.gyp
View File

@ -1,6 +1,6 @@
# Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
# reserved. Use of this source code is governed by a BSD-style license that
# can be found in the LICENSE file.
# Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
# reserved. Use of this source code is governed by a BSD-style license that
# can be found in the LICENSE file.
{
'variables': {
@ -74,6 +74,31 @@
}],
],
},
{
'target_name': 'cef_unittests',
'type': 'executable',
'msvs_guid': '8500027C-B11A-11DE-A16E-B80256D89593',
'dependencies': [
'../base/base.gyp:base',
'../testing/gtest.gyp:gtest',
'../third_party/icu/icu.gyp:icui18n',
'../third_party/icu/icu.gyp:icuuc',
'libcef',
'libcef_dll_wrapper',
],
'sources': [
'tests/unittests/request_unittest.cc',
'tests/unittests/run_all_unittests.cc',
'tests/unittests/stream_unittest.cc',
'tests/unittests/test_handler.h',
'tests/unittests/test_suite.h',
'tests/unittests/v8_unittest.cc',
],
'include_dirs': [
'.',
'..',
],
},
{
'target_name': 'patcher',
'type': 'none',
@ -117,10 +142,10 @@
'../third_party/modp_b64/modp_b64.gyp:modp_b64',
'../third_party/WebKit/JavaScriptCore/JavaScriptCore.gyp/JavaScriptCore.gyp:pcre',
'../third_party/WebKit/JavaScriptCore/JavaScriptCore.gyp/JavaScriptCore.gyp:wtf',
'../third_party/WebKit/WebCore/WebCore.gyp/WebCore.gyp:webcore',
'../third_party/WebKit/WebCore/WebCore.gyp/WebCore.gyp:webcore',
'../third_party/zlib/zlib.gyp:zlib',
'../webkit/webkit.gyp:appcache',
'../webkit/webkit.gyp:database',
'../webkit/webkit.gyp:database',
'../webkit/webkit.gyp:glue',
'../webkit/webkit.gyp:webkit',
'../webkit/webkit.gyp:webkit_resources',
@ -272,10 +297,10 @@
'../third_party/modp_b64/modp_b64.gyp:modp_b64',
'../third_party/WebKit/JavaScriptCore/JavaScriptCore.gyp/JavaScriptCore.gyp:pcre',
'../third_party/WebKit/JavaScriptCore/JavaScriptCore.gyp/JavaScriptCore.gyp:wtf',
'../third_party/WebKit/WebCore/WebCore.gyp/WebCore.gyp:webcore',
'../third_party/WebKit/WebCore/WebCore.gyp/WebCore.gyp:webcore',
'../third_party/zlib/zlib.gyp:zlib',
'../webkit/webkit.gyp:appcache',
'../webkit/webkit.gyp:database',
'../webkit/webkit.gyp:database',
'../webkit/webkit.gyp:glue',
'../webkit/webkit.gyp:webkit',
'../webkit/webkit.gyp:webkit_resources',

36
cef.sln
View File

@ -30,6 +30,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "(net)", "net", "{96A8EC63-8
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "(temp_gyp)", "build\temp_gyp", "{299D9456-929B-5224-943D-BFC2576C69EA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "(testing)", "testing", "{EAC80D00-01D2-3F49-A377-20B7154947F3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "(third_party)", "third_party", "{89C816A7-DD31-D54C-C69C-5A80E0C49B77}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "(tools)", "v8\tools", "{E95778BD-E4AC-C3D0-84EF-83684E04593A}"
@ -66,6 +68,16 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "breakpad_handler", "..\brea
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bzip2", "..\third_party\bzip2\bzip2.vcproj", "{2A70CBF0-847E-4E3A-B926-542A656DC7FE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cef_unittests", "cef_unittests.vcproj", "{8500027C-B11A-11DE-A16E-B80256D89593}"
ProjectSection(ProjectDependencies) = postProject
{1832A374-8A74-4F9E-B536-69A699B3E165} = {1832A374-8A74-4F9E-B536-69A699B3E165}
{BFE8E2A7-3B3B-43B0-A994-3058B852DB8B} = {BFE8E2A7-3B3B-43B0-A994-3058B852DB8B}
{14E7F2BB-B8FC-4DC1-B04D-31C06BDFA1D9} = {14E7F2BB-B8FC-4DC1-B04D-31C06BDFA1D9}
{9E2EFAAB-02B7-4A82-B664-1E98DF6D1953} = {9E2EFAAB-02B7-4A82-B664-1E98DF6D1953}
{C13650D5-CF1A-4259-BE45-B1EBA6280E47} = {C13650D5-CF1A-4259-BE45-B1EBA6280E47}
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9} = {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cefclient", "cefclient.vcproj", "{6617FED9-C5D4-4907-BF55-A90062A6683F}"
ProjectSection(ProjectDependencies) = postProject
{1DEB72EA-4793-B0D6-383E-DE389E057BAF} = {1DEB72EA-4793-B0D6-383E-DE389E057BAF}
@ -112,6 +124,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "googleurl", "..\build\temp_
{D3A97815-3309-44F8-B9BB-CBBE2393A454} = {D3A97815-3309-44F8-B9BB-CBBE2393A454}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest", "..\testing\gtest.vcproj", "{BFE8E2A7-3B3B-43B0-A994-3058B852DB8B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icudata", "..\third_party\icu\icudata.vcproj", "{D3A97815-3309-44F8-B9BB-CBBE2393A454}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icui18n", "..\third_party\icu\icui18n.vcproj", "{14E7F2BB-B8FC-4DC1-B04D-31C06BDFA1D9}"
@ -511,6 +525,14 @@ Global
{8423AF0D-4B88-4EBF-94E1-E4D00D00E21C}.Purify|Win32.Build.0 = Purify|Win32
{8423AF0D-4B88-4EBF-94E1-E4D00D00E21C}.Release|Win32.ActiveCfg = Release|Win32
{8423AF0D-4B88-4EBF-94E1-E4D00D00E21C}.Release|Win32.Build.0 = Release|Win32
{8500027C-B11A-11DE-A16E-B80256D89593}.Release - no tcmalloc|Win32.ActiveCfg = Release - no tcmalloc|Win32
{8500027C-B11A-11DE-A16E-B80256D89593}.Release - no tcmalloc|Win32.Build.0 = Release - no tcmalloc|Win32
{8500027C-B11A-11DE-A16E-B80256D89593}.Debug|Win32.ActiveCfg = Debug|Win32
{8500027C-B11A-11DE-A16E-B80256D89593}.Debug|Win32.Build.0 = Debug|Win32
{8500027C-B11A-11DE-A16E-B80256D89593}.Purify|Win32.ActiveCfg = Purify|Win32
{8500027C-B11A-11DE-A16E-B80256D89593}.Purify|Win32.Build.0 = Purify|Win32
{8500027C-B11A-11DE-A16E-B80256D89593}.Release|Win32.ActiveCfg = Release|Win32
{8500027C-B11A-11DE-A16E-B80256D89593}.Release|Win32.Build.0 = Release|Win32
{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}.Release - no tcmalloc|Win32.ActiveCfg = Release - no tcmalloc|Win32
{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}.Release - no tcmalloc|Win32.Build.0 = Release - no tcmalloc|Win32
{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}.Debug|Win32.ActiveCfg = Debug|Win32
@ -599,6 +621,14 @@ Global
{BC2C97B3-E3CB-FAD5-2749-4A55FC6E56D3}.Purify|Win32.Build.0 = Purify|Win32
{BC2C97B3-E3CB-FAD5-2749-4A55FC6E56D3}.Release|Win32.ActiveCfg = Release|Win32
{BC2C97B3-E3CB-FAD5-2749-4A55FC6E56D3}.Release|Win32.Build.0 = Release|Win32
{BFE8E2A7-3B3B-43B0-A994-3058B852DB8B}.Release - no tcmalloc|Win32.ActiveCfg = Release - no tcmalloc|Win32
{BFE8E2A7-3B3B-43B0-A994-3058B852DB8B}.Release - no tcmalloc|Win32.Build.0 = Release - no tcmalloc|Win32
{BFE8E2A7-3B3B-43B0-A994-3058B852DB8B}.Debug|Win32.ActiveCfg = Debug|Win32
{BFE8E2A7-3B3B-43B0-A994-3058B852DB8B}.Debug|Win32.Build.0 = Debug|Win32
{BFE8E2A7-3B3B-43B0-A994-3058B852DB8B}.Purify|Win32.ActiveCfg = Purify|Win32
{BFE8E2A7-3B3B-43B0-A994-3058B852DB8B}.Purify|Win32.Build.0 = Purify|Win32
{BFE8E2A7-3B3B-43B0-A994-3058B852DB8B}.Release|Win32.ActiveCfg = Release|Win32
{BFE8E2A7-3B3B-43B0-A994-3058B852DB8B}.Release|Win32.Build.0 = Release|Win32
{C13650D5-CF1A-4259-BE45-B1EBA6280E47}.Release - no tcmalloc|Win32.ActiveCfg = Release - no tcmalloc|Win32
{C13650D5-CF1A-4259-BE45-B1EBA6280E47}.Release - no tcmalloc|Win32.Build.0 = Release - no tcmalloc|Win32
{C13650D5-CF1A-4259-BE45-B1EBA6280E47}.Debug|Win32.ActiveCfg = Debug|Win32
@ -732,10 +762,11 @@ Global
{B55CA863-B374-4BAF-95AC-539E4FA4C90C} = {42F0DECB-2C02-ABBA-B565-D2CE9FF519D0}
{E8172FD5-71EF-020B-71B0-9838CD43BF8E} = {BC1FC5DA-9C54-7D77-0BFF-DEDDFD7A8F6C}
{299D9456-929B-5224-943D-BFC2576C69EA} = {BC1FC5DA-9C54-7D77-0BFF-DEDDFD7A8F6C}
{C13650D5-CF1A-4259-BE45-B1EBA6280E47} = {3FB44A30-A004-0316-4D72-550C5B558AAD}
{A6D0953E-899E-4C60-AB6B-CAE75A44B8E6} = {3FB44A30-A004-0316-4D72-550C5B558AAD}
{6617FED9-C5D4-4907-BF55-A90062A6683F} = {3FB44A30-A004-0316-4D72-550C5B558AAD}
{A6D0953E-899E-4C60-AB6B-CAE75A44B8E6} = {3FB44A30-A004-0316-4D72-550C5B558AAD}
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9} = {3FB44A30-A004-0316-4D72-550C5B558AAD}
{8500027C-B11A-11DE-A16E-B80256D89593} = {3FB44A30-A004-0316-4D72-550C5B558AAD}
{C13650D5-CF1A-4259-BE45-B1EBA6280E47} = {3FB44A30-A004-0316-4D72-550C5B558AAD}
{FA39524D-3067-4141-888D-28A86C66F2B9} = {3FB44A30-A004-0316-4D72-550C5B558AAD}
{D7A94F58-576A-45D9-A45F-EB87C63ABBB0} = {F8FCF6CD-4DE1-16F6-65CB-5E6194E8495C}
{4E4070E1-EFD9-4EF1-8634-3960956F6F10} = {F8FCF6CD-4DE1-16F6-65CB-5E6194E8495C}
@ -752,6 +783,7 @@ Global
{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942} = {96A8EC63-88DB-B85C-EEBC-43667C60DEB3}
{E13045CD-7E1F-4A41-9B18-8D288B2E7B41} = {96A8EC63-88DB-B85C-EEBC-43667C60DEB3}
{EF5E94AB-B646-4E5B-A058-52EF07B8351C} = {299D9456-929B-5224-943D-BFC2576C69EA}
{BFE8E2A7-3B3B-43B0-A994-3058B852DB8B} = {EAC80D00-01D2-3F49-A377-20B7154947F3}
{6EAD4A4B-2BBC-4974-8E45-BB5C16CC2AC9} = {89C816A7-DD31-D54C-C69C-5A80E0C49B77}
{F8FCF6CD-4DE1-16F6-65CB-5E6194E8495C} = {89C816A7-DD31-D54C-C69C-5A80E0C49B77}
{238CE175-76CE-4A25-A676-69D115885601} = {89C816A7-DD31-D54C-C69C-5A80E0C49B77}

52
cef_unittests.vcproj Normal file
View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject Keyword="Win32Proj" Name="cef_unittests" ProjectGUID="{8500027C-B11A-11DE-A16E-B80256D89593}" ProjectType="Visual C++" RootNamespace="cef_unittests" Version="8.00">
<Platforms>
<Platform Name="Win32"/>
</Platforms>
<ToolFiles/>
<Configurations>
<Configuration CharacterSet="1" ConfigurationType="1" InheritedPropertySheets="" IntermediateDirectory="$(OutDir)\obj\$(ProjectName)" Name="Debug|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)">
<Tool AdditionalIncludeDirectories="..\third_party\icu\public\common;..\third_party\icu\public\i18n;.;..;..\testing\gtest\include;..\third_party\platformsdk_win2008_6_1\files\Include;$(VSInstallDir)\VC\atlmfc\include" AdditionalOptions="/MP" BasicRuntimeChecks="3" BufferSecurityCheck="true" DebugInformationFormat="3" DisableSpecificWarnings="4396;4503;4819" EnableFunctionLevelLinking="true" ExceptionHandling="0" MinimalRebuild="false" Name="VCCLCompilerTool" Optimization="0" PreprocessorDefinitions="_DEBUG;_WIN32_WINNT=0x0600;WINVER=0x0600;WIN32;_WINDOWS;_HAS_EXCEPTIONS=0;NOMINMAX;_CRT_RAND_S;CERT_CHAIN_PARA_HAS_EXTRA_FIELDS;WIN32_LEAN_AND_MEAN;_SECURE_ATL;_HAS_TR1=0;__STDC_FORMAT_MACROS;CHROMIUM_BUILD;UNIT_TEST;U_STATIC_IMPLEMENTATION" ProgramDataBaseFileName="$(IntDir)\$(ProjectName)\vc80.pdb" RuntimeLibrary="1" RuntimeTypeInfo="false" WarnAsError="true" WarningLevel="3"/>
<Tool AdditionalIncludeDirectories="..;..\third_party\icu\public\common;..\third_party\icu\public\i18n;.;..;..\testing\gtest\include;..\third_party\platformsdk_win2008_6_1\files\Include;$(VSInstallDir)\VC\atlmfc\include" Culture="1033" Name="VCResourceCompilerTool" PreprocessorDefinitions="_DEBUG;_WIN32_WINNT=0x0600;WINVER=0x0600;WIN32;_WINDOWS;_HAS_EXCEPTIONS=0;NOMINMAX;_CRT_RAND_S;CERT_CHAIN_PARA_HAS_EXTRA_FIELDS;WIN32_LEAN_AND_MEAN;_SECURE_ATL;_HAS_TR1=0;__STDC_FORMAT_MACROS;CHROMIUM_BUILD;UNIT_TEST;U_STATIC_IMPLEMENTATION"/>
<Tool DLLDataFileName="dlldata.c" GenerateStublessProxies="true" HeaderFileName="$(InputName).h" InterfaceIdentifierFileName="$(InputName)_i.c" Name="VCMIDLTool" OutputDirectory="$(IntDir)" ProxyFileName="$(InputName)_p.c" TypeLibraryName="$(InputName).tlb"/>
<Tool AdditionalLibraryDirectories="../third_party/platformsdk_win2008_6_1/files/Lib" AdditionalOptions="/ignore:4221" Name="VCLibrarianTool"/>
<Tool AdditionalDependencies="wininet.lib version.lib msimg32.lib ws2_32.lib usp10.lib psapi.lib dbghelp.lib $(OutDir)/lib/avcodec-52.lib $(OutDir)/lib/avformat-52.lib $(OutDir)/lib/avutil-50.lib" AdditionalLibraryDirectories="../third_party/platformsdk_win2008_6_1/files/Lib" AdditionalOptions="/safeseh /dynamicbase /ignore:4199 /ignore:4221 /nxcompat" DelayLoadDLLs="dbghelp.dll;dwmapi.dll;uxtheme.dll;avcodec-52.dll;avformat-52.dll;avutil-50.dll" FixedBaseAddress="1" GenerateDebugInformation="true" ImportLibrary="$(OutDir)\lib\$(TargetName).lib" LinkIncremental="2" MapFileName="$(OutDir)\$(TargetName).map" Name="VCLinkerTool" OutputFile="$(OutDir)\$(ProjectName).exe" SubSystem="1" TargetMachine="1"/>
</Configuration>
<Configuration CharacterSet="1" ConfigurationType="1" InheritedPropertySheets="..\build\release.vsprops" IntermediateDirectory="$(OutDir)\obj\$(ProjectName)" Name="Release|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)">
<Tool AdditionalIncludeDirectories="..\third_party\icu\public\common;..\third_party\icu\public\i18n;.;..;..\testing\gtest\include;..\third_party\platformsdk_win2008_6_1\files\Include;$(VSInstallDir)\VC\atlmfc\include" AdditionalOptions="/MP" BufferSecurityCheck="true" DebugInformationFormat="3" DisableSpecificWarnings="4396;4503;4819" EnableFunctionLevelLinking="true" ExceptionHandling="0" MinimalRebuild="false" Name="VCCLCompilerTool" PreprocessorDefinitions="_WIN32_WINNT=0x0600;WINVER=0x0600;WIN32;_WINDOWS;_HAS_EXCEPTIONS=0;NOMINMAX;_CRT_RAND_S;CERT_CHAIN_PARA_HAS_EXTRA_FIELDS;WIN32_LEAN_AND_MEAN;_SECURE_ATL;_HAS_TR1=0;__STDC_FORMAT_MACROS;CHROMIUM_BUILD;UNIT_TEST;U_STATIC_IMPLEMENTATION;NDEBUG;NVALGRIND" ProgramDataBaseFileName="$(IntDir)\$(ProjectName)\vc80.pdb" RuntimeTypeInfo="false" WarnAsError="true" WarningLevel="3"/>
<Tool AdditionalIncludeDirectories="..;..\third_party\icu\public\common;..\third_party\icu\public\i18n;.;..;..\testing\gtest\include;..\third_party\platformsdk_win2008_6_1\files\Include;$(VSInstallDir)\VC\atlmfc\include" Culture="1033" Name="VCResourceCompilerTool" PreprocessorDefinitions="_WIN32_WINNT=0x0600;WINVER=0x0600;WIN32;_WINDOWS;_HAS_EXCEPTIONS=0;NOMINMAX;_CRT_RAND_S;CERT_CHAIN_PARA_HAS_EXTRA_FIELDS;WIN32_LEAN_AND_MEAN;_SECURE_ATL;_HAS_TR1=0;__STDC_FORMAT_MACROS;CHROMIUM_BUILD;UNIT_TEST;U_STATIC_IMPLEMENTATION;NDEBUG;NVALGRIND"/>
<Tool DLLDataFileName="dlldata.c" GenerateStublessProxies="true" HeaderFileName="$(InputName).h" InterfaceIdentifierFileName="$(InputName)_i.c" Name="VCMIDLTool" OutputDirectory="$(IntDir)" ProxyFileName="$(InputName)_p.c" TypeLibraryName="$(InputName).tlb"/>
<Tool AdditionalLibraryDirectories="../third_party/platformsdk_win2008_6_1/files/Lib" AdditionalOptions="/ignore:4221" Name="VCLibrarianTool"/>
<Tool AdditionalDependencies="wininet.lib version.lib msimg32.lib ws2_32.lib usp10.lib psapi.lib dbghelp.lib $(OutDir)/lib/avcodec-52.lib $(OutDir)/lib/avformat-52.lib $(OutDir)/lib/avutil-50.lib" AdditionalLibraryDirectories="../third_party/platformsdk_win2008_6_1/files/Lib" AdditionalOptions="/safeseh /dynamicbase /ignore:4199 /ignore:4221 /nxcompat" DelayLoadDLLs="dbghelp.dll;dwmapi.dll;uxtheme.dll;avcodec-52.dll;avformat-52.dll;avutil-50.dll" FixedBaseAddress="1" GenerateDebugInformation="true" ImportLibrary="$(OutDir)\lib\$(TargetName).lib" LinkIncremental="1" MapFileName="$(OutDir)\$(TargetName).map" Name="VCLinkerTool" OutputFile="$(OutDir)\$(ProjectName).exe" SubSystem="1" TargetMachine="1"/>
</Configuration>
<Configuration CharacterSet="1" ConfigurationType="1" InheritedPropertySheets="..\build\release.vsprops" IntermediateDirectory="$(OutDir)\obj\$(ProjectName)" Name="Purify|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)">
<Tool AdditionalIncludeDirectories="..\third_party\icu\public\common;..\third_party\icu\public\i18n;.;..;..\testing\gtest\include;..\third_party\platformsdk_win2008_6_1\files\Include;$(VSInstallDir)\VC\atlmfc\include" AdditionalOptions="/MP" BufferSecurityCheck="false" DebugInformationFormat="3" DisableSpecificWarnings="4396;4503;4819" EnableFunctionLevelLinking="true" ExceptionHandling="0" MinimalRebuild="false" Name="VCCLCompilerTool" Optimization="0" PreprocessorDefinitions="_WIN32_WINNT=0x0600;WINVER=0x0600;WIN32;_WINDOWS;_HAS_EXCEPTIONS=0;NOMINMAX;_CRT_RAND_S;CERT_CHAIN_PARA_HAS_EXTRA_FIELDS;WIN32_LEAN_AND_MEAN;_SECURE_ATL;_HAS_TR1=0;__STDC_FORMAT_MACROS;CHROMIUM_BUILD;UNIT_TEST;U_STATIC_IMPLEMENTATION;NDEBUG;PURIFY;NO_TCMALLOC" ProgramDataBaseFileName="$(IntDir)\$(ProjectName)\vc80.pdb" RuntimeLibrary="0" RuntimeTypeInfo="false" WarnAsError="true" WarningLevel="3"/>
<Tool AdditionalIncludeDirectories="..;..\third_party\icu\public\common;..\third_party\icu\public\i18n;.;..;..\testing\gtest\include;..\third_party\platformsdk_win2008_6_1\files\Include;$(VSInstallDir)\VC\atlmfc\include" Culture="1033" Name="VCResourceCompilerTool" PreprocessorDefinitions="_WIN32_WINNT=0x0600;WINVER=0x0600;WIN32;_WINDOWS;_HAS_EXCEPTIONS=0;NOMINMAX;_CRT_RAND_S;CERT_CHAIN_PARA_HAS_EXTRA_FIELDS;WIN32_LEAN_AND_MEAN;_SECURE_ATL;_HAS_TR1=0;__STDC_FORMAT_MACROS;CHROMIUM_BUILD;UNIT_TEST;U_STATIC_IMPLEMENTATION;NDEBUG;PURIFY;NO_TCMALLOC"/>
<Tool DLLDataFileName="dlldata.c" GenerateStublessProxies="true" HeaderFileName="$(InputName).h" InterfaceIdentifierFileName="$(InputName)_i.c" Name="VCMIDLTool" OutputDirectory="$(IntDir)" ProxyFileName="$(InputName)_p.c" TypeLibraryName="$(InputName).tlb"/>
<Tool AdditionalLibraryDirectories="../third_party/platformsdk_win2008_6_1/files/Lib" AdditionalOptions="/ignore:4221" Name="VCLibrarianTool"/>
<Tool AdditionalDependencies="wininet.lib version.lib msimg32.lib ws2_32.lib usp10.lib psapi.lib dbghelp.lib $(OutDir)/lib/avcodec-52.lib $(OutDir)/lib/avformat-52.lib $(OutDir)/lib/avutil-50.lib" AdditionalLibraryDirectories="../third_party/platformsdk_win2008_6_1/files/Lib" AdditionalOptions="/safeseh /dynamicbase /ignore:4199 /ignore:4221 /nxcompat" DelayLoadDLLs="dbghelp.dll;dwmapi.dll;uxtheme.dll;avcodec-52.dll;avformat-52.dll;avutil-50.dll" EnableCOMDATFolding="1" FixedBaseAddress="1" GenerateDebugInformation="true" ImportLibrary="$(OutDir)\lib\$(TargetName).lib" LinkIncremental="1" MapFileName="$(OutDir)\$(TargetName).map" Name="VCLinkerTool" OutputFile="$(OutDir)\$(ProjectName).exe" SubSystem="1" TargetMachine="1"/>
</Configuration>
<Configuration CharacterSet="1" ConfigurationType="1" InheritedPropertySheets="..\build\release.vsprops" IntermediateDirectory="$(OutDir)\obj\$(ProjectName)" Name="Release - no tcmalloc|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)">
<Tool AdditionalIncludeDirectories="..\third_party\icu\public\common;..\third_party\icu\public\i18n;.;..;..\testing\gtest\include;..\third_party\platformsdk_win2008_6_1\files\Include;$(VSInstallDir)\VC\atlmfc\include" AdditionalOptions="/MP" BufferSecurityCheck="true" DebugInformationFormat="3" DisableSpecificWarnings="4396;4503;4819" EnableFunctionLevelLinking="true" ExceptionHandling="0" MinimalRebuild="false" Name="VCCLCompilerTool" PreprocessorDefinitions="_WIN32_WINNT=0x0600;WINVER=0x0600;WIN32;_WINDOWS;_HAS_EXCEPTIONS=0;NOMINMAX;_CRT_RAND_S;CERT_CHAIN_PARA_HAS_EXTRA_FIELDS;WIN32_LEAN_AND_MEAN;_SECURE_ATL;_HAS_TR1=0;__STDC_FORMAT_MACROS;CHROMIUM_BUILD;UNIT_TEST;U_STATIC_IMPLEMENTATION;NDEBUG;NO_TCMALLOC" ProgramDataBaseFileName="$(IntDir)\$(ProjectName)\vc80.pdb" RuntimeTypeInfo="false" WarnAsError="true" WarningLevel="3"/>
<Tool AdditionalIncludeDirectories="..;..\third_party\icu\public\common;..\third_party\icu\public\i18n;.;..;..\testing\gtest\include;..\third_party\platformsdk_win2008_6_1\files\Include;$(VSInstallDir)\VC\atlmfc\include" Culture="1033" Name="VCResourceCompilerTool" PreprocessorDefinitions="_WIN32_WINNT=0x0600;WINVER=0x0600;WIN32;_WINDOWS;_HAS_EXCEPTIONS=0;NOMINMAX;_CRT_RAND_S;CERT_CHAIN_PARA_HAS_EXTRA_FIELDS;WIN32_LEAN_AND_MEAN;_SECURE_ATL;_HAS_TR1=0;__STDC_FORMAT_MACROS;CHROMIUM_BUILD;UNIT_TEST;U_STATIC_IMPLEMENTATION;NDEBUG;NO_TCMALLOC"/>
<Tool DLLDataFileName="dlldata.c" GenerateStublessProxies="true" HeaderFileName="$(InputName).h" InterfaceIdentifierFileName="$(InputName)_i.c" Name="VCMIDLTool" OutputDirectory="$(IntDir)" ProxyFileName="$(InputName)_p.c" TypeLibraryName="$(InputName).tlb"/>
<Tool AdditionalLibraryDirectories="../third_party/platformsdk_win2008_6_1/files/Lib" AdditionalOptions="/ignore:4221" Name="VCLibrarianTool"/>
<Tool AdditionalDependencies="wininet.lib version.lib msimg32.lib ws2_32.lib usp10.lib psapi.lib dbghelp.lib $(OutDir)/lib/avcodec-52.lib $(OutDir)/lib/avformat-52.lib $(OutDir)/lib/avutil-50.lib" AdditionalLibraryDirectories="../third_party/platformsdk_win2008_6_1/files/Lib" AdditionalOptions="/safeseh /dynamicbase /ignore:4199 /ignore:4221 /nxcompat" DelayLoadDLLs="dbghelp.dll;dwmapi.dll;uxtheme.dll;avcodec-52.dll;avformat-52.dll;avutil-50.dll" FixedBaseAddress="1" GenerateDebugInformation="true" ImportLibrary="$(OutDir)\lib\$(TargetName).lib" LinkIncremental="1" MapFileName="$(OutDir)\$(TargetName).map" Name="VCLinkerTool" OutputFile="$(OutDir)\$(ProjectName).exe" SubSystem="1" TargetMachine="1"/>
</Configuration>
</Configurations>
<References/>
<Files>
<File RelativePath="cef.gyp"/>
<Filter Name="tests">
<Filter Name="unittests">
<File RelativePath="tests\unittests\stream_unittest.cc"/>
<File RelativePath="tests\unittests\test_suite.h"/>
<File RelativePath="tests\unittests\test_handler.h"/>
<File RelativePath="tests\unittests\v8_unittest.cc"/>
<File RelativePath="tests\unittests\run_all_unittests.cc"/>
<File RelativePath="tests\unittests\request_unittest.cc"/>
</Filter>
</Filter>
</Files>
<Globals/>
</VisualStudioProject>

View File

@ -787,7 +787,8 @@ public:
virtual size_t Read(void* ptr, size_t size, size_t n) =0;
// Seek to the specified offset position. |whence| may be any one of
// SEEK_CUR, SEEK_END or SEEK_SET.
// SEEK_CUR, SEEK_END or SEEK_SET. Returns zero on success and non-zero on
// failure.
/*--cef()--*/
virtual int Seek(long offset, int whence) =0;

View File

@ -635,7 +635,7 @@ typedef struct _cef_stream_reader_t
size_t size, size_t n);
// Seek to the specified offset position. |whence| may be any one of SEEK_CUR,
// SEEK_END or SEEK_SET.
// SEEK_END or SEEK_SET. Returns zero on success and non-zero on failure.
int (CEF_CALLBACK *seek)(struct _cef_stream_reader_t* self, long offset,
int whence);

View File

@ -250,8 +250,9 @@ class RequestProxy : public URLRequest::Delegate,
if(rv == RV_HANDLED) {
// cancel the resource load
handled = true;
OnCompletedRequest(URLRequestStatus(URLRequestStatus::CANCELED, 0),
std::string());
OnCompletedRequest(
URLRequestStatus(URLRequestStatus::CANCELED, net::ERR_ABORTED),
std::string());
} else if(!redirectUrl.empty()) {
// redirect to the specified URL
params->url = GURL(WideToUTF8(redirectUrl));

View File

@ -192,20 +192,21 @@ int CefBytesReader::Seek(long offset, int whence)
break;
}
offset_ += offset;
rv = offset_;
rv = 0;
break;
case SEEK_END:
if(offset > (int)datasize_) {
break;
}
offset_ = datasize_ - offset;
rv = offset_;
rv = 0;
break;
case SEEK_SET:
if(offset > (int)datasize_) {
break;
}
offset_ = offset;
rv = offset_;
rv = 0;
break;
}
Unlock();

View File

@ -0,0 +1,424 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/cef.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "test_handler.h"
// Verify that CefRequest::HeaderMap objects are equal
// If |allowExtras| is true then additional header fields will be allowed in
// |map2|.
static void VerifyMapEqual(CefRequest::HeaderMap &map1,
CefRequest::HeaderMap &map2,
bool allowExtras)
{
if(!allowExtras)
ASSERT_EQ(map1.size(), map2.size());
CefRequest::HeaderMap::const_iterator it1, it2;
for(it1 = map1.begin(); it1 != map1.end(); ++it1) {
it2 = map2.find(it1->first);
ASSERT_TRUE(it2 != map2.end());
ASSERT_EQ(it1->second, it2->second);
}
}
// Verify that CefPostDataElement objects are equal
static void VerifyPostDataElementEqual(CefRefPtr<CefPostDataElement> elem1,
CefRefPtr<CefPostDataElement> elem2)
{
ASSERT_EQ(elem1->GetType(), elem2->GetType());
switch(elem1->GetType()) {
case PDE_TYPE_BYTES: {
ASSERT_EQ(elem1->GetBytesCount(), elem2->GetBytesCount());
char *buff1, *buff2;
size_t bytesCt = elem1->GetBytesCount();
buff1 = new char[bytesCt];
buff2 = new char[bytesCt];
elem1->GetBytes(bytesCt, buff1);
elem2->GetBytes(bytesCt, buff2);
ASSERT_TRUE(!memcmp(buff1, buff2, bytesCt));
delete [] buff1;
delete [] buff2;
} break;
case PDE_TYPE_FILE:
ASSERT_EQ(elem1->GetFile(), elem2->GetFile());
break;
}
}
// Verify that CefPostData objects are equal
static void VerifyPostDataEqual(CefRefPtr<CefPostData> postData1,
CefRefPtr<CefPostData> postData2)
{
ASSERT_TRUE(!(postData1.get()) == !(postData2.get()));
ASSERT_EQ(postData1->GetElementCount(), postData2->GetElementCount());
CefPostData::ElementVector ev1, ev2;
postData1->GetElements(ev1);
postData1->GetElements(ev2);
ASSERT_EQ(ev1.size(), ev2.size());
CefPostData::ElementVector::const_iterator it1 = ev1.begin();
CefPostData::ElementVector::const_iterator it2 = ev2.begin();
for(; it1 != ev1.end() && it2 != ev2.end(); ++it1, ++it2)
VerifyPostDataElementEqual((*it1), (*it2));
}
// Verify that CefRequest objects are equal
// If |allowExtras| is true then additional header fields will be allowed in
// |request2|.
static void VerifyRequestEqual(CefRefPtr<CefRequest> request1,
CefRefPtr<CefRequest> request2,
bool allowExtras)
{
ASSERT_EQ(request1->GetURL(), request2->GetURL());
ASSERT_EQ(request1->GetMethod(), request2->GetMethod());
CefRequest::HeaderMap headers1, headers2;
request1->GetHeaderMap(headers1);
request2->GetHeaderMap(headers2);
VerifyMapEqual(headers1, headers2, allowExtras);
VerifyPostDataEqual(request1->GetPostData(), request2->GetPostData());
}
// Verify Set/Get methods for CefRequest, CefPostData and CefPostDataElement.
TEST(RequestTest, SetGet)
{
// CefRequest CreateRequest
CefRefPtr<CefRequest> request(CefRequest::CreateRequest());
ASSERT_TRUE(request.get() != NULL);
std::wstring url = L"http://tests/run.html";
std::wstring method = L"POST";
CefRequest::HeaderMap setHeaders, getHeaders;
setHeaders.insert(std::make_pair(L"HeaderA", L"ValueA"));
setHeaders.insert(std::make_pair(L"HeaderB", L"ValueB"));
// CefPostData CreatePostData
CefRefPtr<CefPostData> postData(CefPostData::CreatePostData());
ASSERT_TRUE(postData.get() != NULL);
// CefPostDataElement CreatePostDataElement
CefRefPtr<CefPostDataElement> element1(
CefPostDataElement::CreatePostDataElement());
ASSERT_TRUE(element1.get() != NULL);
CefRefPtr<CefPostDataElement> element2(
CefPostDataElement::CreatePostDataElement());
ASSERT_TRUE(element2.get() != NULL);
// CefPostDataElement SetToFile
std::wstring file = L"c:\\path\\to\\file.ext";
element1->SetToFile(file);
ASSERT_EQ(PDE_TYPE_FILE, element1->GetType());
ASSERT_EQ(file, element1->GetFile());
// CefPostDataElement SetToBytes
char bytes[] = "Test Bytes";
element2->SetToBytes(sizeof(bytes), bytes);
ASSERT_EQ(PDE_TYPE_BYTES, element2->GetType());
ASSERT_EQ(sizeof(bytes), element2->GetBytesCount());
char bytesOut[sizeof(bytes)];
element2->GetBytes(sizeof(bytes), bytesOut);
ASSERT_TRUE(!memcmp(bytes, bytesOut, sizeof(bytes)));
// CefPostData AddElement
postData->AddElement(element1);
postData->AddElement(element2);
ASSERT_EQ(2, postData->GetElementCount());
// CefPostData RemoveElement
postData->RemoveElement(element1);
ASSERT_EQ(1, postData->GetElementCount());
// CefPostData RemoveElements
postData->RemoveElements();
ASSERT_EQ(0, postData->GetElementCount());
postData->AddElement(element1);
postData->AddElement(element2);
ASSERT_EQ(2, postData->GetElementCount());
CefPostData::ElementVector elements;
postData->GetElements(elements);
CefPostData::ElementVector::const_iterator it = elements.begin();
for(size_t i = 0; it != elements.end(); ++it, ++i) {
if(i == 0)
VerifyPostDataElementEqual(element1, (*it).get());
else if(i == 1)
VerifyPostDataElementEqual(element2, (*it).get());
}
// CefRequest SetURL
request->SetURL(url);
ASSERT_EQ(url, request->GetURL());
// CefRequest SetMethod
request->SetMethod(method);
ASSERT_EQ(method, request->GetMethod());
// CefRequest SetHeaderMap
request->SetHeaderMap(setHeaders);
request->GetHeaderMap(getHeaders);
VerifyMapEqual(setHeaders, getHeaders, false);
getHeaders.clear();
// CefRequest SetPostData
request->SetPostData(postData);
VerifyPostDataEqual(postData, request->GetPostData());
request = CefRequest::CreateRequest();
ASSERT_TRUE(request.get() != NULL);
// CefRequest Set
request->Set(url, method, postData, setHeaders);
ASSERT_EQ(url, request->GetURL());
ASSERT_EQ(method, request->GetMethod());
request->GetHeaderMap(getHeaders);
VerifyMapEqual(setHeaders, getHeaders, false);
getHeaders.clear();
VerifyPostDataEqual(postData, request->GetPostData());
}
static void CreateRequest(CefRefPtr<CefRequest>& request)
{
request = CefRequest::CreateRequest();
ASSERT_TRUE(request.get() != NULL);
request->SetURL(L"http://tests/run.html");
request->SetMethod(L"POST");
CefRequest::HeaderMap headers;
headers.insert(std::make_pair(L"HeaderA", L"ValueA"));
headers.insert(std::make_pair(L"HeaderB", L"ValueB"));
request->SetHeaderMap(headers);
CefRefPtr<CefPostData> postData(CefPostData::CreatePostData());
ASSERT_TRUE(postData.get() != NULL);
CefRefPtr<CefPostDataElement> element1(
CefPostDataElement::CreatePostDataElement());
ASSERT_TRUE(element1.get() != NULL);
element1->SetToFile(L"c:\\path\\to\\file.ext");
postData->AddElement(element1);
CefRefPtr<CefPostDataElement> element2(
CefPostDataElement::CreatePostDataElement());
ASSERT_TRUE(element2.get() != NULL);
char bytes[] = "Test Bytes";
element2->SetToBytes(sizeof(bytes), bytes);
postData->AddElement(element2);
request->SetPostData(postData);
}
bool g_RequestSendRecvTestHandlerHandleBeforeBrowseCalled;
bool g_RequestSendRecvTestHandlerHandleBeforeResourceLoadCalled;
class RequestSendRecvTestHandler : public TestHandler
{
public:
RequestSendRecvTestHandler() {}
virtual void RunTest()
{
// Create the test request
CreateRequest(request_);
// Create the browser
CreateBrowser(std::wstring());
}
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser)
{
TestHandler::HandleAfterCreated(browser);
// Load the test request
browser->GetMainFrame()->LoadRequest(request_);
return RV_CONTINUE;
}
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType, bool isRedirect)
{
g_RequestSendRecvTestHandlerHandleBeforeBrowseCalled = true;
// Verify that the request is the same
VerifyRequestEqual(request_, request, true);
return RV_CONTINUE;
}
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefRequest> request,
std::wstring& redirectUrl,
CefRefPtr<CefStreamReader>& resourceStream,
std::wstring& mimeType,
int loadFlags)
{
g_RequestSendRecvTestHandlerHandleBeforeResourceLoadCalled = true;
// Verify that the request is the same
VerifyRequestEqual(request_, request, true);
// No results
return RV_HANDLED;
}
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame)
{
if(!browser->IsPopup() && !frame.get())
NotifyTestComplete();
return RV_CONTINUE;
}
CefRefPtr<CefRequest> request_;
};
// Verify send and recieve
TEST(RequestTest, SendRecv)
{
g_RequestSendRecvTestHandlerHandleBeforeBrowseCalled = false;
g_RequestSendRecvTestHandlerHandleBeforeResourceLoadCalled = false;
RequestSendRecvTestHandler* handler = new RequestSendRecvTestHandler();
handler->ExecuteTest();
ASSERT_TRUE(g_RequestSendRecvTestHandlerHandleBeforeBrowseCalled);
ASSERT_TRUE(g_RequestSendRecvTestHandlerHandleBeforeResourceLoadCalled);
}
bool g_RequestHistoryNavTestDidLoadRequest;
bool g_RequestHistoryNavTestDidReloadRequest;
class RequestHistoryNavTestHandler : public TestHandler
{
public:
RequestHistoryNavTestHandler() : navigated_(false) {}
virtual void RunTest()
{
// Create the test request
CreateRequest(request_);
// Add the resource that we will navigate to/from
AddResource(L"http://tests/goto.html", "<html>To</html>", L"text/html");
// Create the browser
CreateBrowser(std::wstring());
}
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser)
{
TestHandler::HandleAfterCreated(browser);
// Load the test request
browser->GetMainFrame()->LoadRequest(request_);
return RV_CONTINUE;
}
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType, bool isRedirect)
{
std::wstring url = request->GetURL();
if(url == L"http://tests/run.html")
{
// Verify that the request is the same
VerifyRequestEqual(request_, request, true);
}
return RV_CONTINUE;
}
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefRequest> request,
std::wstring& redirectUrl,
CefRefPtr<CefStreamReader>& resourceStream,
std::wstring& mimeType,
int loadFlags)
{
std::wstring url = request->GetURL();
if(url == L"http://tests/run.html")
{
// Verify that the request is the same
VerifyRequestEqual(request_, request, true);
if(!navigated_)
{
// Loading the request for the 1st time
g_RequestHistoryNavTestDidLoadRequest = true;
}
else
{
// Re-loading the request
g_RequestHistoryNavTestDidReloadRequest = true;
}
// Return dummy results
std::string output = "<html>Request</html>";
resourceStream = CefStreamReader::CreateForData((void*)output.c_str(),
output.length());
mimeType = L"text/html";
return RV_CONTINUE;
}
else
{
// Pass to the default handler to return the to/from page
return TestHandler::HandleBeforeResourceLoad(browser, request,
redirectUrl, resourceStream, mimeType, loadFlags);
}
}
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame)
{
if(!browser->IsPopup() && !frame.get())
{
std::wstring url = browser->GetMainFrame()->GetURL();
if(url == L"http://tests/run.html")
{
if(!navigated_)
{
// First resource load, go to the next page
navigated_ = true;
browser->GetMainFrame()->LoadURL(L"http://tests/goto.html");
}
else
{
// Resource re-load, end the test
NotifyTestComplete();
}
}
else
{
// To/from page load, go back the the request page
browser->GoBack();
}
}
return RV_CONTINUE;
}
CefRefPtr<CefRequest> request_;
bool navigated_;
};
// Verify history navigation
// This test will only pass if the patches for issue #42 are applied.
TEST(RequestTest, HistoryNav)
{
g_RequestHistoryNavTestDidLoadRequest = false;
g_RequestHistoryNavTestDidReloadRequest = false;
RequestHistoryNavTestHandler* handler = new RequestHistoryNavTestHandler();
handler->ExecuteTest();
ASSERT_TRUE(g_RequestHistoryNavTestDidLoadRequest);
ASSERT_TRUE(g_RequestHistoryNavTestDidReloadRequest);
}

View File

@ -0,0 +1,9 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "test_suite.h"
int main(int argc, char** argv) {
return CefTestSuite(argc, argv).Run();
}

View File

@ -0,0 +1,347 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/cef.h"
#include "testing/gtest/include/gtest/gtest.h"
#define min(a,b) ((a)<(b)?(a):(b))
static void VerifyStreamReadBehavior(CefRefPtr<CefStreamReader> stream,
const std::string& contents)
{
int contentSize = static_cast<int>(contents.size());
const char* contentStr = contents.c_str();
// Move to the beginning of the stream
ASSERT_EQ(0, stream->Seek(0, SEEK_SET));
ASSERT_EQ(0, stream->Tell());
// Move to the end of the stream
ASSERT_EQ(0, stream->Seek(0, SEEK_END));
ASSERT_EQ(contentSize, stream->Tell());
// Move to the beginning of the stream
ASSERT_EQ(0, stream->Seek(-contentSize, SEEK_CUR));
ASSERT_EQ(0, stream->Tell());
// Read 10 characters at a time and verify the result
char buff[10];
int res, read, offset = 0;
do {
read = min(sizeof(buff), contentSize-offset);
res = stream->Read(buff, 1, read);
ASSERT_EQ(read, res);
ASSERT_TRUE(!memcmp(contentStr+offset, buff, res));
offset += res;
} while(offset < contentSize);
// Read past the end of the file
stream->Read(buff, 1, 1);
ASSERT_TRUE(stream->Eof());
}
static void VerifyStreamWriteBehavior(CefRefPtr<CefStreamWriter> stream,
const std::string& contents)
{
int contentSize = static_cast<int>(contents.size());
const char* contentStr = contents.c_str();
// Write 10 characters at a time and verify the result
int res, write, offset = 0;
do {
write = min(10, contentSize-offset);
res = stream->Write(contentStr+offset, 1, write);
ASSERT_EQ(write, res);
offset += res;
ASSERT_EQ(offset, stream->Tell());
} while(offset < contentSize);
// Move to the beginning of the stream
ASSERT_EQ(0, stream->Seek(-contentSize, SEEK_CUR));
ASSERT_EQ(0, stream->Tell());
// Move to the end of the stream
ASSERT_EQ(0, stream->Seek(0, SEEK_END));
ASSERT_EQ(contentSize, stream->Tell());
// Move to the beginning of the stream
ASSERT_EQ(0, stream->Seek(0, SEEK_SET));
ASSERT_EQ(0, stream->Tell());
}
TEST(StreamTest, ReadFile)
{
std::wstring fileName = L"StreamTest.VerifyReadFile.txt";
std::string contents = "This is my test\ncontents for the file";
// Create the file
FILE* f = NULL;
_wfopen_s(&f, fileName.c_str(), L"wb");
ASSERT_TRUE(f != NULL);
ASSERT_EQ(1, fwrite(contents.c_str(), contents.size(), 1, f));
fclose(f);
// Test the stream
CefRefPtr<CefStreamReader> stream(CefStreamReader::CreateForFile(fileName));
ASSERT_TRUE(stream.get() != NULL);
VerifyStreamReadBehavior(stream, contents);
// Release the file pointer
stream = NULL;
// Delete the file
ASSERT_EQ(0, _wunlink(fileName.c_str()));
}
TEST(StreamTest, ReadData)
{
std::string contents = "This is my test\ncontents for the file";
// Test the stream
CefRefPtr<CefStreamReader> stream(
CefStreamReader::CreateForData((void*)contents.c_str(), contents.size()));
ASSERT_TRUE(stream.get() != NULL);
VerifyStreamReadBehavior(stream, contents);
}
TEST(StreamTest, WriteFile)
{
std::wstring fileName = L"StreamTest.VerifyWriteFile.txt";
std::string contents = "This is my test\ncontents for the file";
// Test the stream
CefRefPtr<CefStreamWriter> stream(CefStreamWriter::CreateForFile(fileName));
ASSERT_TRUE(stream.get() != NULL);
VerifyStreamWriteBehavior(stream, contents);
// Release the file pointer
stream = NULL;
// Read the file that was written
FILE* f = NULL;
char* buff = new char[contents.size()];
_wfopen_s(&f, fileName.c_str(), L"rb");
ASSERT_TRUE(f != NULL);
ASSERT_EQ(1, fread(buff, contents.size(), 1, f));
// Read past the end of the file
fgetc(f);
ASSERT_TRUE(feof(f));
fclose(f);
// Verify the file contents
ASSERT_TRUE(!memcmp(contents.c_str(), buff, contents.size()));
delete [] buff;
// Delete the file
ASSERT_EQ(0, _wunlink(fileName.c_str()));
}
bool g_ReadHandlerTesterDeleted = false;
class ReadHandlerTester : public CefThreadSafeBase<CefReadHandler>
{
public:
ReadHandlerTester()
: read_called_(false), read_ptr_(NULL), read_size_(0), read_n_(0),
seek_called_(false), seek_offset_(0), seek_whence_(0),
tell_called_(false), eof_called_(false)
{
}
virtual ~ReadHandlerTester()
{
g_ReadHandlerTesterDeleted = true;
}
virtual size_t Read(void* ptr, size_t size, size_t n)
{
read_called_ = true;
read_ptr_ = ptr;
read_size_ = size;
read_n_ = n;
return 10;
}
virtual int Seek(long offset, int whence)
{
seek_called_ = true;
seek_offset_ = offset;
seek_whence_ = whence;
return 10;
}
virtual long Tell()
{
tell_called_ = true;
return 10;
}
virtual int Eof()
{
eof_called_ = true;
return 10;
}
bool read_called_;
const void* read_ptr_;
size_t read_size_;
size_t read_n_;
bool seek_called_;
long seek_offset_;
int seek_whence_;
bool tell_called_;
bool eof_called_;
};
TEST(StreamTest, ReadHandler)
{
ReadHandlerTester* handler = new ReadHandlerTester();
ASSERT_TRUE(handler != NULL);
CefRefPtr<CefStreamReader> stream(CefStreamReader::CreateForHandler(handler));
ASSERT_TRUE(stream.get() != NULL);
// CefReadHandler Read
char* read_ptr = "My data";
size_t read_size = sizeof(read_ptr);
size_t read_n = 1;
size_t read_res = stream->Read(read_ptr, read_size, read_n);
ASSERT_TRUE(handler->read_called_);
ASSERT_EQ(10, read_res);
ASSERT_EQ(read_ptr, handler->read_ptr_);
ASSERT_EQ(read_size, handler->read_size_);
ASSERT_EQ(read_n, handler->read_n_);
// CefReadHandler Seek
long seek_offset = 10;
int seek_whence = SEEK_CUR;
int seek_res = stream->Seek(seek_offset, seek_whence);
ASSERT_TRUE(handler->seek_called_);
ASSERT_EQ(10, seek_res);
ASSERT_EQ(seek_offset, handler->seek_offset_);
ASSERT_EQ(seek_whence, handler->seek_whence_);
// CefReadHandler Tell
long tell_res = stream->Tell();
ASSERT_TRUE(handler->tell_called_);
ASSERT_EQ(10, tell_res);
// CefReadHandler Eof
int eof_res = stream->Eof();
ASSERT_TRUE(handler->eof_called_);
ASSERT_EQ(10, eof_res);
// Delete the stream
stream = NULL;
// Verify that the handler object was deleted
ASSERT_TRUE(g_ReadHandlerTesterDeleted);
}
bool g_WriteHandlerTesterDeleted = false;
class WriteHandlerTester : public CefThreadSafeBase<CefWriteHandler>
{
public:
WriteHandlerTester()
: write_called_(false), write_ptr_(NULL), write_size_(0), write_n_(0),
seek_called_(false), seek_offset_(0), seek_whence_(0),
tell_called_(false), flush_called_(false)
{
}
virtual ~WriteHandlerTester()
{
g_WriteHandlerTesterDeleted = true;
}
virtual size_t Write(const void* ptr, size_t size, size_t n)
{
write_called_ = true;
write_ptr_ = ptr;
write_size_ = size;
write_n_ = n;
return 10;
}
virtual int Seek(long offset, int whence)
{
seek_called_ = true;
seek_offset_ = offset;
seek_whence_ = whence;
return 10;
}
virtual long Tell()
{
tell_called_ = true;
return 10;
}
virtual int Flush()
{
flush_called_ = true;
return 10;
}
bool write_called_;
const void* write_ptr_;
size_t write_size_;
size_t write_n_;
bool seek_called_;
long seek_offset_;
int seek_whence_;
bool tell_called_;
bool flush_called_;
};
TEST(StreamTest, WriteHandler)
{
WriteHandlerTester* handler = new WriteHandlerTester();
ASSERT_TRUE(handler != NULL);
CefRefPtr<CefStreamWriter> stream(CefStreamWriter::CreateForHandler(handler));
ASSERT_TRUE(stream.get() != NULL);
// CefWriteHandler Write
char* write_ptr = "My data";
size_t write_size = sizeof(write_ptr);
size_t write_n = 1;
size_t write_res = stream->Write(write_ptr, write_size, write_n);
ASSERT_TRUE(handler->write_called_);
ASSERT_EQ(10, write_res);
ASSERT_EQ(write_ptr, handler->write_ptr_);
ASSERT_EQ(write_size, handler->write_size_);
ASSERT_EQ(write_n, handler->write_n_);
// CefWriteHandler Seek
long seek_offset = 10;
int seek_whence = SEEK_CUR;
int seek_res = stream->Seek(seek_offset, seek_whence);
ASSERT_TRUE(handler->seek_called_);
ASSERT_EQ(10, seek_res);
ASSERT_EQ(seek_offset, handler->seek_offset_);
ASSERT_EQ(seek_whence, handler->seek_whence_);
// CefWriteHandler Tell
long tell_res = stream->Tell();
ASSERT_TRUE(handler->tell_called_);
ASSERT_EQ(10, tell_res);
// CefWriteHandler Flush
int flush_res = stream->Flush();
ASSERT_TRUE(handler->flush_called_);
ASSERT_EQ(10, flush_res);
// Delete the stream
stream = NULL;
// Verify that the handler object was deleted
ASSERT_TRUE(g_WriteHandlerTesterDeleted);
}

View File

@ -0,0 +1,290 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _TEST_HANDLER_H
#define _TEST_HANDLER_H
#include "include/cef.h"
#include "testing/gtest/include/gtest/gtest.h"
// Base implementation of CefHandler for unit tests.
class TestHandler : public CefThreadSafeBase<CefHandler>
{
public:
TestHandler() : browser_hwnd_(NULL), completion_event_(NULL)
{
}
virtual ~TestHandler()
{
}
// Implement this method to run the test
virtual void RunTest() =0;
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& createInfo, bool popup,
CefRefPtr<CefHandler>& handler,
std::wstring& url)
{
return RV_CONTINUE;
}
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser)
{
Lock();
if(!browser->IsPopup())
{
// Keep the main child window, but not popup windows
browser_ = browser;
browser_hwnd_ = browser->GetWindowHandle();
}
Unlock();
return RV_CONTINUE;
}
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& url)
{
return RV_CONTINUE;
}
virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser,
const std::wstring& title)
{
return RV_CONTINUE;
}
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
NavType navType, bool isRedirect)
{
return RV_CONTINUE;
}
virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame)
{
return RV_CONTINUE;
}
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame)
{
return RV_CONTINUE;
}
virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const std::wstring& failedUrl,
std::wstring& errorText)
{
return RV_CONTINUE;
}
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefRequest> request,
std::wstring& redirectUrl,
CefRefPtr<CefStreamReader>& resourceStream,
std::wstring& mimeType,
int loadFlags)
{
Lock();
if(resource_map_.size() > 0) {
std::wstring url = request->GetURL();
ResourceMap::const_iterator it = resource_map_.find(url);
if(it != resource_map_.end()) {
// Return the previously mapped resource
resourceStream = CefStreamReader::CreateForData(
(void*)it->second.first.c_str(), it->second.first.length());
mimeType = it->second.second;
}
}
Unlock();
return RV_CONTINUE;
}
virtual RetVal HandleBeforeMenu(CefRefPtr<CefBrowser> browser,
const MenuInfo& menuInfo)
{
return RV_CONTINUE;
}
virtual RetVal HandleGetMenuLabel(CefRefPtr<CefBrowser> browser,
MenuId menuId, std::wstring& label)
{
return RV_CONTINUE;
}
virtual RetVal HandleMenuAction(CefRefPtr<CefBrowser> browser,
MenuId menuId)
{
return RV_CONTINUE;
}
virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefPrintInfo& printInfo,
const std::wstring& url,
const std::wstring& title,
int currentPage, int maxPages,
std::wstring& topLeft,
std::wstring& topCenter,
std::wstring& topRight,
std::wstring& bottomLeft,
std::wstring& bottomCenter,
std::wstring& bottomRight)
{
return RV_CONTINUE;
}
virtual RetVal HandleJSAlert(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message)
{
return RV_CONTINUE;
}
virtual RetVal HandleJSConfirm(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message, bool& retval)
{
return RV_CONTINUE;
}
virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::wstring& message,
const std::wstring& defaultValue,
bool& retval,
std::wstring& result)
{
return RV_CONTINUE;
}
virtual RetVal HandleBeforeWindowClose(CefRefPtr<CefBrowser> browser)
{
Lock();
if(browser_hwnd_ == browser->GetWindowHandle())
{
// Free the browser pointer so that the browser can be destroyed
browser_ = NULL;
browser_hwnd_ = NULL;
// Just in case it wasn't called already
NotifyTestComplete();
}
Unlock();
return RV_CONTINUE;
}
virtual RetVal HandleTakeFocus(CefRefPtr<CefBrowser> browser, bool reverse)
{
return RV_CONTINUE;
}
virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object)
{
return RV_CONTINUE;
}
virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser,
bool isWidget)
{
return RV_CONTINUE;
}
CefRefPtr<CefBrowser> GetBrowser()
{
return browser_;
}
HWND GetBrowserHwnd()
{
return browser_hwnd_;
}
// Called by the test function to execute the test. This method blocks until
// the test is complete. Do not reference the object after this method
// returns.
void ExecuteTest()
{
// Add a reference
AddRef();
// Create the notification event
Lock();
completion_event_ = CreateEvent(NULL, TRUE, FALSE, NULL);
ASSERT_TRUE(completion_event_ != NULL);
Unlock();
// Run the test
RunTest();
// Wait for the test to complete
WaitForSingleObject(completion_event_, INFINITE);
Lock();
CloseHandle(completion_event_);
completion_event_ = NULL;
Unlock();
// Remove the reference
Release();
}
protected:
// Called by the implementing class when the test is complete
void NotifyTestComplete()
{
// Notify that the test is complete
Lock();
if(completion_event_ != NULL)
SetEvent(completion_event_);
if(browser_hwnd_ != NULL)
PostMessage(browser_hwnd_, WM_CLOSE, 0, 0);
Unlock();
}
void CreateBrowser(const std::wstring& url)
{
CefWindowInfo windowInfo;
windowInfo.SetAsPopup(NULL, L"CefUnitTest");
windowInfo.m_dwStyle |= WS_VISIBLE;
CefBrowser::CreateBrowser(windowInfo, false, this, url);
}
void AddResource(const std::wstring& key, const std::string& value,
const std::wstring& mimeType)
{
resource_map_.insert(std::make_pair(key, std::make_pair(value, mimeType)));
}
void ClearResources()
{
resource_map_.clear();
}
private:
// The child browser window
CefRefPtr<CefBrowser> browser_;
// The browser window handle
HWND browser_hwnd_;
// Handle used to notify when the test is complete
HANDLE completion_event_;
// Map of resources that can be automatically loaded
typedef std::map<std::wstring, std::pair<std::string, std::wstring>> ResourceMap;
ResourceMap resource_map_;
};
#endif // _TEST_HANDLER_H

View File

@ -0,0 +1,30 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef _CEF_TEST_SUITE_H
#define _CEF_TEST_SUITE_H
#include "build/build_config.h"
#include "base/test_suite.h"
#include "include/cef.h"
class CefTestSuite : public TestSuite {
public:
CefTestSuite(int argc, char** argv) : TestSuite(argc, argv) {
}
protected:
virtual void Initialize() {
TestSuite::Initialize();
CefInitialize(true, std::wstring());
}
virtual void Shutdown() {
CefShutdown();
TestSuite::Shutdown();
}
};
#endif // _CEF_TEST_SUITE_H

View File

@ -0,0 +1,352 @@
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/cef.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "test_handler.h"
bool g_V8TestV8HandlerExecuteCalled;
bool g_V8TestV8HandlerExecute2Called;
class V8TestV8Handler : public CefThreadSafeBase<CefV8Handler>
{
public:
V8TestV8Handler(bool bindingTest) { binding_test_ = bindingTest; }
virtual bool Execute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
TestExecute(name, object, arguments, retval, exception);
return true;
}
void TestExecute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
if(name == L"execute") {
g_V8TestV8HandlerExecuteCalled = true;
ASSERT_EQ(8, arguments.size());
int argct = 0;
// basic types
ASSERT_TRUE(arguments[argct]->IsInt());
ASSERT_EQ(5, arguments[argct]->GetIntValue());
argct++;
ASSERT_TRUE(arguments[argct]->IsDouble());
ASSERT_EQ(6.543, arguments[argct]->GetDoubleValue());
argct++;
ASSERT_TRUE(arguments[argct]->IsBool());
ASSERT_EQ(true, arguments[argct]->GetBoolValue());
argct++;
ASSERT_TRUE(arguments[argct]->IsString());
ASSERT_EQ(L"test string", arguments[argct]->GetStringValue());
argct++;
CefRefPtr<CefV8Value> value;
// array
ASSERT_TRUE(arguments[argct]->IsArray());
ASSERT_EQ(4, arguments[argct]->GetArrayLength());
{
int subargct = 0;
value = arguments[argct]->GetValue(subargct);
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsInt());
ASSERT_EQ(7, value->GetIntValue());
subargct++;
value = arguments[argct]->GetValue(subargct);
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsDouble());
ASSERT_EQ(5.432, value->GetDoubleValue());
subargct++;
value = arguments[argct]->GetValue(subargct);
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsBool());
ASSERT_EQ(false, value->GetBoolValue());
subargct++;
value = arguments[argct]->GetValue(subargct);
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsString());
ASSERT_EQ(L"another string", value->GetStringValue());
subargct++;
}
argct++;
// object
ASSERT_TRUE(arguments[argct]->IsObject());
{
value = arguments[argct]->GetValue(L"arg0");
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsInt());
ASSERT_EQ(2, value->GetIntValue());
value = arguments[argct]->GetValue(L"arg1");
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsDouble());
ASSERT_EQ(3.433, value->GetDoubleValue());
value = arguments[argct]->GetValue(L"arg2");
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsBool());
ASSERT_EQ(true, value->GetBoolValue());
value = arguments[argct]->GetValue(L"arg3");
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsString());
ASSERT_EQ(L"some string", value->GetStringValue());
}
argct++;
// function that returns a value
ASSERT_TRUE(arguments[argct]->IsFunction());
{
CefV8ValueList args;
args.push_back(CefV8Value::CreateInt(5));
args.push_back(CefV8Value::CreateDouble(3.5));
args.push_back(CefV8Value::CreateBool(true));
args.push_back(CefV8Value::CreateString(L"10"));
CefRefPtr<CefV8Value> rv;
std::wstring exception;
ASSERT_TRUE(arguments[argct]->ExecuteFunction(
arguments[argct], args, rv, exception));
ASSERT_TRUE(rv.get() != NULL);
ASSERT_TRUE(rv->IsDouble());
ASSERT_EQ(19.5, rv->GetDoubleValue());
}
argct++;
// function that throws an exception
ASSERT_TRUE(arguments[argct]->IsFunction());
{
CefV8ValueList args;
args.push_back(CefV8Value::CreateDouble(5));
args.push_back(CefV8Value::CreateDouble(0));
CefRefPtr<CefV8Value> rv;
std::wstring exception;
ASSERT_TRUE(arguments[argct]->ExecuteFunction(
arguments[argct], args, rv, exception));
ASSERT_EQ(L"Uncaught My Exception", exception);
}
argct++;
if(binding_test_)
{
// values
value = object->GetValue(L"intVal");
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsInt());
ASSERT_EQ(12, value->GetIntValue());
value = object->GetValue(L"doubleVal");
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsDouble());
ASSERT_EQ(5.432, value->GetDoubleValue());
value = object->GetValue(L"boolVal");
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsBool());
ASSERT_EQ(true, value->GetBoolValue());
value = object->GetValue(L"stringVal");
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsString());
ASSERT_EQ(L"the string", value->GetStringValue());
value = object->GetValue(L"arrayVal");
ASSERT_TRUE(value.get() != NULL);
ASSERT_TRUE(value->IsArray());
{
CefRefPtr<CefV8Value> value2;
int subargct = 0;
value2 = value->GetValue(subargct);
ASSERT_TRUE(value2.get() != NULL);
ASSERT_TRUE(value2->IsInt());
ASSERT_EQ(4, value2->GetIntValue());
subargct++;
value2 = value->GetValue(subargct);
ASSERT_TRUE(value2.get() != NULL);
ASSERT_TRUE(value2->IsDouble());
ASSERT_EQ(120.43, value2->GetDoubleValue());
subargct++;
value2 = value->GetValue(subargct);
ASSERT_TRUE(value2.get() != NULL);
ASSERT_TRUE(value2->IsBool());
ASSERT_EQ(true, value2->GetBoolValue());
subargct++;
value2 = value->GetValue(subargct);
ASSERT_TRUE(value2.get() != NULL);
ASSERT_TRUE(value2->IsString());
ASSERT_EQ(L"a string", value2->GetStringValue());
subargct++;
}
}
retval = CefV8Value::CreateInt(5);
} else if(name == L"execute2") {
g_V8TestV8HandlerExecute2Called = true;
// check the result of calling the "execute" function
ASSERT_EQ(1, arguments.size());
ASSERT_TRUE(arguments[0]->IsInt());
ASSERT_EQ(5, arguments[0]->GetIntValue());
}
}
bool binding_test_;
};
class V8TestHandler : public TestHandler
{
public:
V8TestHandler(bool bindingTest) { binding_test_ = bindingTest; }
virtual void RunTest()
{
std::string object;
if(binding_test_) {
// binding uses the window object
object = "window.test";
} else {
// extension uses a global object
object = "test";
}
std::stringstream testHtml;
testHtml <<
"<html><body>"
"<script language=\"JavaScript\">"
"function func(a,b,c,d) { return a+b+(c?1:0)+parseFloat(d); }"
"function func2(a,b) { throw('My Exception'); }"
<< object << ".execute2("
" " << object << ".execute(5, 6.543, true, \"test string\","
" [7, 5.432, false, \"another string\"],"
" {arg0:2, arg1:3.433, arg2:true, arg3:\"some string\"}, func, func2)"
");"
"</script>"
"</body></html>";
AddResource(L"http://tests/run.html", testHtml.str(), L"text/html");
CreateBrowser(L"http://tests/run.html");
}
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame)
{
if(!browser->IsPopup() && !frame.get())
NotifyTestComplete();
return RV_CONTINUE;
}
virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object)
{
if(binding_test_) {
TestHandleJSBinding(browser, frame, object);
return RV_HANDLED;
}
return RV_CONTINUE;
}
void TestHandleJSBinding(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object)
{
// Create the new V8 object
CefRefPtr<CefV8Value> testObj = CefV8Value::CreateObject(NULL);
ASSERT_TRUE(testObj.get() != NULL);
ASSERT_TRUE(object->SetValue(L"test", testObj));
// Create an instance of V8ExecuteV8Handler
CefRefPtr<CefV8Handler> testHandler(new V8TestV8Handler(true));
ASSERT_TRUE(testHandler.get() != NULL);
// Add the functions
CefRefPtr<CefV8Value> testFunc;
testFunc = CefV8Value::CreateFunction(L"execute", testHandler);
ASSERT_TRUE(testFunc.get() != NULL);
ASSERT_TRUE(testObj->SetValue(L"execute", testFunc));
testFunc = CefV8Value::CreateFunction(L"execute2", testHandler);
ASSERT_TRUE(testFunc.get() != NULL);
ASSERT_TRUE(testObj->SetValue(L"execute2", testFunc));
// Add the values
ASSERT_TRUE(testObj->SetValue(L"intVal",
CefV8Value::CreateInt(12)));
ASSERT_TRUE(testObj->SetValue(L"doubleVal",
CefV8Value::CreateDouble(5.432)));
ASSERT_TRUE(testObj->SetValue(L"boolVal",
CefV8Value::CreateBool(true)));
ASSERT_TRUE(testObj->SetValue(L"stringVal",
CefV8Value::CreateString(L"the string")));
CefRefPtr<CefV8Value> testArray(CefV8Value::CreateArray());
ASSERT_TRUE(testArray.get() != NULL);
ASSERT_TRUE(testObj->SetValue(L"arrayVal", testArray));
ASSERT_TRUE(testArray->SetValue(0, CefV8Value::CreateInt(4)));
ASSERT_TRUE(testArray->SetValue(1, CefV8Value::CreateDouble(120.43)));
ASSERT_TRUE(testArray->SetValue(2, CefV8Value::CreateBool(true)));
ASSERT_TRUE(testArray->SetValue(3, CefV8Value::CreateString(L"a string")));
}
bool binding_test_;
};
// Verify window binding
TEST(V8Test, Binding)
{
g_V8TestV8HandlerExecuteCalled = false;
g_V8TestV8HandlerExecute2Called = false;
V8TestHandler* handler = new V8TestHandler(true);
handler->ExecuteTest();
ASSERT_TRUE(g_V8TestV8HandlerExecuteCalled);
ASSERT_TRUE(g_V8TestV8HandlerExecute2Called);
}
// Verify extensions
TEST(V8Test, Extension)
{
g_V8TestV8HandlerExecuteCalled = false;
g_V8TestV8HandlerExecute2Called = false;
std::wstring extensionCode =
L"var test;"
L"if (!test)"
L" test = {};"
L"(function() {"
L" test.execute = function(a,b,c,d,e,f,g,h) {"
L" native function execute();"
L" return execute(a,b,c,d,e,f,g,h);"
L" };"
L" test.execute2 = function(a) {"
L" native function execute2();"
L" return execute2(a);"
L" };"
L"})();";
CefRegisterExtension(L"v8/test", extensionCode, new V8TestV8Handler(false));
V8TestHandler* handler = new V8TestHandler(false);
handler->ExecuteTest();
ASSERT_TRUE(g_V8TestV8HandlerExecuteCalled);
ASSERT_TRUE(g_V8TestV8HandlerExecute2Called);
}