2008-03-12 14:28:04 +01:00
/*
* URL Cache Tests
*
* Copyright 2008 Robert Shearman for CodeWeavers
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , USA
*/
2019-01-09 05:50:23 +01:00
# define NONAMELESSUNION
# define NONAMELESSSTRUCT
2008-03-12 14:28:04 +01:00
# include <stdarg.h>
# include <stdio.h>
# include <stdlib.h>
# include "windef.h"
# include "winbase.h"
2013-04-01 13:48:23 +02:00
# include "winnls.h"
2008-03-12 14:28:04 +01:00
# include "wininet.h"
2009-05-13 14:01:18 +02:00
# include "winineti.h"
2019-01-09 05:50:23 +01:00
# include "shlobj.h"
2008-03-12 14:28:04 +01:00
# include "wine/test.h"
2012-09-25 17:31:55 +02:00
static const char test_url [ ] = " http://urlcachetest.winehq.org/index.html " ;
static const WCHAR test_urlW [ ] = { ' h ' , ' t ' , ' t ' , ' p ' , ' : ' , ' / ' , ' / ' , ' u ' , ' r ' , ' l ' , ' c ' , ' a ' , ' c ' , ' h ' , ' e ' , ' t ' , ' e ' , ' s ' , ' t ' , ' . ' ,
' w ' , ' i ' , ' n ' , ' e ' , ' h ' , ' q ' , ' . ' , ' o ' , ' r ' , ' g ' , ' / ' , ' i ' , ' n ' , ' d ' , ' e ' , ' x ' , ' . ' , ' h ' , ' t ' , ' m ' , ' l ' , 0 } ;
static const char test_url1 [ ] = " Visited: user@http://urlcachetest.winehq.org/index.html " ;
static const char test_hash_collisions1 [ ] = " Visited: http://winehq.org/doc0.html " ;
static const char test_hash_collisions2 [ ] = " Visited: http://winehq.org/doc75651909.html " ;
2008-03-12 14:28:04 +01:00
2008-05-22 10:38:29 +02:00
static BOOL ( WINAPI * pDeleteUrlCacheEntryA ) ( LPCSTR ) ;
static BOOL ( WINAPI * pUnlockUrlCacheEntryFileA ) ( LPCSTR , DWORD ) ;
2008-04-30 16:24:40 +02:00
static char filenameA [ MAX_PATH + 1 ] ;
2009-09-25 12:01:35 +02:00
static char filenameA1 [ MAX_PATH + 1 ] ;
2012-10-03 12:29:15 +02:00
static BOOL old_ie = FALSE ;
2013-11-18 09:58:13 +01:00
static BOOL ie10_cache = FALSE ;
2008-04-30 16:24:40 +02:00
2013-10-24 12:15:43 +02:00
static void check_cache_entry_infoA ( const char * returnedfrom , INTERNET_CACHE_ENTRY_INFOA * lpCacheEntryInfo )
2008-04-30 16:24:40 +02:00
{
ok ( lpCacheEntryInfo - > dwStructSize = = sizeof ( * lpCacheEntryInfo ) , " %s: dwStructSize was %d \n " , returnedfrom , lpCacheEntryInfo - > dwStructSize ) ;
2012-09-25 17:31:55 +02:00
ok ( ! strcmp ( lpCacheEntryInfo - > lpszSourceUrlName , test_url ) , " %s: lpszSourceUrlName should be %s instead of %s \n " , returnedfrom , test_url , lpCacheEntryInfo - > lpszSourceUrlName ) ;
2008-04-30 16:24:40 +02:00
ok ( ! strcmp ( lpCacheEntryInfo - > lpszLocalFileName , filenameA ) , " %s: lpszLocalFileName should be %s instead of %s \n " , returnedfrom , filenameA , lpCacheEntryInfo - > lpszLocalFileName ) ;
ok ( ! strcmp ( lpCacheEntryInfo - > lpszFileExtension , " html " ) , " %s: lpszFileExtension should be html instead of %s \n " , returnedfrom , lpCacheEntryInfo - > lpszFileExtension ) ;
}
static void test_find_url_cache_entriesA ( void )
2008-03-12 14:28:04 +01:00
{
BOOL ret ;
2008-03-12 14:29:47 +01:00
HANDLE hEnumHandle ;
BOOL found = FALSE ;
2008-04-30 16:24:40 +02:00
DWORD cbCacheEntryInfo ;
DWORD cbCacheEntryInfoSaved ;
2013-10-24 12:15:43 +02:00
INTERNET_CACHE_ENTRY_INFOA * lpCacheEntryInfo ;
2008-03-12 14:28:04 +01:00
2008-03-12 14:29:47 +01:00
cbCacheEntryInfo = 0 ;
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
hEnumHandle = FindFirstUrlCacheEntryA ( NULL , NULL , & cbCacheEntryInfo ) ;
2008-03-12 14:29:47 +01:00
ok ( ! hEnumHandle , " FindFirstUrlCacheEntry should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " FindFirstUrlCacheEntry should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d \n " , GetLastError ( ) ) ;
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo * sizeof ( char ) ) ;
cbCacheEntryInfoSaved = cbCacheEntryInfo ;
2013-10-24 12:15:43 +02:00
hEnumHandle = FindFirstUrlCacheEntryA ( NULL , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
2008-03-12 14:29:47 +01:00
ok ( hEnumHandle ! = NULL , " FindFirstUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
while ( TRUE )
{
2012-09-25 17:31:55 +02:00
if ( ! strcmp ( lpCacheEntryInfo - > lpszSourceUrlName , test_url ) )
2008-03-12 14:29:47 +01:00
{
found = TRUE ;
2012-04-09 10:44:58 +02:00
ret = TRUE ;
2008-03-12 14:29:47 +01:00
break ;
}
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2008-03-12 14:29:47 +01:00
cbCacheEntryInfo = cbCacheEntryInfoSaved ;
2013-10-24 12:15:43 +02:00
ret = FindNextUrlCacheEntryA ( hEnumHandle , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
2008-03-12 14:29:47 +01:00
if ( ! ret )
{
if ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER )
{
lpCacheEntryInfo = HeapReAlloc ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo , cbCacheEntryInfo ) ;
cbCacheEntryInfoSaved = cbCacheEntryInfo ;
2013-10-24 12:15:43 +02:00
ret = FindNextUrlCacheEntryA ( hEnumHandle , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
2008-03-12 14:29:47 +01:00
}
}
if ( ! ret )
break ;
}
2012-04-09 10:44:58 +02:00
ok ( ret , " FindNextUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
2012-03-31 12:38:32 +02:00
ok ( found , " Committed url cache entry not found during enumeration \n " ) ;
2008-03-12 14:29:47 +01:00
ret = FindCloseUrlCache ( hEnumHandle ) ;
ok ( ret , " FindCloseUrlCache failed with error %d \n " , GetLastError ( ) ) ;
2014-05-30 04:44:03 +02:00
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
2008-04-30 16:24:40 +02:00
}
static void test_GetUrlCacheEntryInfoExA ( void )
{
BOOL ret ;
2011-03-08 20:34:23 +01:00
DWORD cbCacheEntryInfo , cbRedirectUrl ;
2013-10-24 12:15:43 +02:00
INTERNET_CACHE_ENTRY_INFOA * lpCacheEntryInfo ;
2008-04-30 16:24:40 +02:00
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoExA ( NULL , NULL , NULL , NULL , NULL , NULL , 0 ) ;
2008-04-30 16:24:40 +02:00
ok ( ! ret , " GetUrlCacheEntryInfoEx with NULL URL and NULL args should have failed \n " ) ;
2009-09-25 12:01:35 +02:00
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER ,
" GetUrlCacheEntryInfoEx with NULL URL and NULL args should have set last error to ERROR_INVALID_PARAMETER instead of %d \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
cbCacheEntryInfo = sizeof ( INTERNET_CACHE_ENTRY_INFOA ) ;
2009-09-25 12:01:35 +02:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoExA ( " " , NULL , & cbCacheEntryInfo , NULL , NULL , NULL , 0 ) ;
2009-09-25 12:01:35 +02:00
ok ( ! ret , " GetUrlCacheEntryInfoEx with zero-length buffer should fail \n " ) ;
ok ( GetLastError ( ) = = ERROR_FILE_NOT_FOUND ,
" GetUrlCacheEntryInfoEx should have set last error to ERROR_FILE_NOT_FOUND instead of %d \n " , GetLastError ( ) ) ;
2008-04-30 16:24:40 +02:00
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoExA ( test_url , NULL , NULL , NULL , NULL , NULL , 0 ) ;
2008-04-30 16:24:40 +02:00
ok ( ret , " GetUrlCacheEntryInfoEx with NULL args failed with error %d \n " , GetLastError ( ) ) ;
cbCacheEntryInfo = 0 ;
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoExA ( test_url , NULL , & cbCacheEntryInfo , NULL , NULL , NULL , 0 ) ;
2008-04-30 16:24:40 +02:00
ok ( ! ret , " GetUrlCacheEntryInfoEx with zero-length buffer should fail \n " ) ;
2009-09-25 12:01:35 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" GetUrlCacheEntryInfoEx should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d \n " , GetLastError ( ) ) ;
2008-04-30 16:24:40 +02:00
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
2009-09-25 12:01:35 +02:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoExA ( test_url , NULL , NULL , NULL , NULL , NULL , 0x200 /*GET_INSTALLED_ENTRY*/ ) ;
2013-11-18 09:58:13 +01:00
ok ( ret = = ie10_cache , " GetUrlCacheEntryInfoEx returned %x \n " , ret ) ;
if ( ! ret ) ok ( GetLastError ( ) = = ERROR_FILE_NOT_FOUND ,
" GetUrlCacheEntryInfoEx should have set last error to ERROR_FILE_NOT_FOUND instead of %d \n " , GetLastError ( ) ) ;
2009-09-25 12:01:35 +02:00
2012-09-25 17:31:55 +02:00
/* Unicode version of function seems to ignore 0x200 flag */
ret = GetUrlCacheEntryInfoExW ( test_urlW , NULL , NULL , NULL , NULL , NULL , 0x200 /*GET_INSTALLED_ENTRY*/ ) ;
2012-10-03 12:29:15 +02:00
ok ( ret | | broken ( old_ie & & ! ret ) , " GetUrlCacheEntryInfoExW failed with error %d \n " , GetLastError ( ) ) ;
2012-09-25 17:31:55 +02:00
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoExA ( test_url , lpCacheEntryInfo , & cbCacheEntryInfo , NULL , NULL , NULL , 0 ) ;
2008-04-30 16:24:40 +02:00
ok ( ret , " GetUrlCacheEntryInfoEx failed with error %d \n " , GetLastError ( ) ) ;
2011-09-09 15:57:59 +02:00
if ( ret ) check_cache_entry_infoA ( " GetUrlCacheEntryInfoEx " , lpCacheEntryInfo ) ;
2008-04-30 16:24:40 +02:00
2012-09-25 17:31:55 +02:00
lpCacheEntryInfo - > CacheEntryType | = 0x10000000 ; /* INSTALLED_CACHE_ENTRY */
ret = SetUrlCacheEntryInfoA ( test_url , lpCacheEntryInfo , CACHE_ENTRY_ATTRIBUTE_FC ) ;
ok ( ret , " SetUrlCacheEntryInfoA failed with error %d \n " , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoExA ( test_url , NULL , NULL , NULL , NULL , NULL , 0x200 /*GET_INSTALLED_ENTRY*/ ) ;
2012-09-25 17:31:55 +02:00
ok ( ret , " GetUrlCacheEntryInfoEx failed with error %d \n " , GetLastError ( ) ) ;
2008-10-03 13:57:57 +02:00
cbCacheEntryInfo = 100000 ;
2008-10-07 16:39:33 +02:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoExA ( test_url , NULL , & cbCacheEntryInfo , NULL , NULL , NULL , 0 ) ;
2008-10-03 13:57:57 +02:00
ok ( ! ret , " GetUrlCacheEntryInfoEx with zero-length buffer should fail \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " GetUrlCacheEntryInfoEx should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d \n " , GetLastError ( ) ) ;
2008-04-30 16:24:40 +02:00
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
2011-03-08 20:34:23 +01:00
/* Querying the redirect URL fails with ERROR_INVALID_PARAMETER */
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoExA ( test_url , NULL , NULL , NULL , & cbRedirectUrl , NULL , 0 ) ;
2011-07-26 04:07:08 +02:00
ok ( ! ret , " GetUrlCacheEntryInfoEx should have failed \n " ) ;
2011-03-08 20:34:23 +01:00
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER ,
" expected ERROR_INVALID_PARAMETER, got %d \n " , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoExA ( test_url , NULL , & cbCacheEntryInfo , NULL , & cbRedirectUrl , NULL , 0 ) ;
2011-07-26 04:07:08 +02:00
ok ( ! ret , " GetUrlCacheEntryInfoEx should have failed \n " ) ;
2011-03-08 20:34:23 +01:00
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER ,
" expected ERROR_INVALID_PARAMETER, got %d \n " , GetLastError ( ) ) ;
2008-04-30 16:24:40 +02:00
}
2008-10-07 16:39:33 +02:00
static void test_RetrieveUrlCacheEntryA ( void )
{
BOOL ret ;
DWORD cbCacheEntryInfo ;
cbCacheEntryInfo = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = RetrieveUrlCacheEntryFileA ( NULL , NULL , & cbCacheEntryInfo , 0 ) ;
2008-10-07 16:39:33 +02:00
ok ( ! ret , " RetrieveUrlCacheEntryFile should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_PARAMETER instead of %d \n " , GetLastError ( ) ) ;
2008-10-08 17:39:37 +02:00
if ( 0 )
{
/* Crashes on Win9x, NT4 and W2K */
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = RetrieveUrlCacheEntryFileA ( test_url , NULL , NULL , 0 ) ;
2008-10-08 17:39:37 +02:00
ok ( ! ret , " RetrieveUrlCacheEntryFile should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_PARAMETER instead of %d \n " , GetLastError ( ) ) ;
}
2008-10-07 16:39:33 +02:00
SetLastError ( 0xdeadbeef ) ;
cbCacheEntryInfo = 100000 ;
2013-10-24 12:15:43 +02:00
ret = RetrieveUrlCacheEntryFileA ( NULL , NULL , & cbCacheEntryInfo , 0 ) ;
2008-10-07 16:39:33 +02:00
ok ( ! ret , " RetrieveUrlCacheEntryFile should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_PARAMETER instead of %d \n " , GetLastError ( ) ) ;
}
2011-03-08 19:39:37 +01:00
static void test_IsUrlCacheEntryExpiredA ( void )
{
static const char uncached_url [ ] =
" What's the airspeed velocity of an unladen swallow? " ;
BOOL ret ;
FILETIME ft ;
DWORD size ;
2013-10-24 12:15:43 +02:00
INTERNET_CACHE_ENTRY_INFOA * info ;
2011-03-08 19:39:37 +01:00
ULARGE_INTEGER exp_time ;
/* The function returns TRUE when the output time is NULL or the tested URL
* is NULL .
*/
ret = IsUrlCacheEntryExpiredA ( NULL , 0 , NULL ) ;
2015-04-12 23:04:32 +02:00
ok ( ret ! = ie10_cache , " IsUrlCacheEntryExpiredA returned %x \n " , ret ) ;
2011-03-08 19:39:37 +01:00
ft . dwLowDateTime = 0xdeadbeef ;
ft . dwHighDateTime = 0xbaadf00d ;
ret = IsUrlCacheEntryExpiredA ( NULL , 0 , & ft ) ;
2015-04-12 23:04:32 +02:00
ok ( ret ! = ie10_cache , " IsUrlCacheEntryExpiredA returned %x \n " , ret ) ;
2011-03-08 19:39:37 +01:00
ok ( ft . dwLowDateTime = = 0xdeadbeef & & ft . dwHighDateTime = = 0xbaadf00d ,
" expected time to be unchanged, got (%u,%u) \n " ,
ft . dwLowDateTime , ft . dwHighDateTime ) ;
2012-09-25 17:31:55 +02:00
ret = IsUrlCacheEntryExpiredA ( test_url , 0 , NULL ) ;
2015-04-12 23:04:32 +02:00
ok ( ret ! = ie10_cache , " IsUrlCacheEntryExpiredA returned %x \n " , ret ) ;
2011-03-08 19:39:37 +01:00
/* The return value should indicate whether the URL is expired,
* and the filetime indicates the last modified time , but a cache entry
* with a zero expire time is " not expired " .
*/
ft . dwLowDateTime = 0xdeadbeef ;
ft . dwHighDateTime = 0xbaadf00d ;
2012-09-25 17:31:55 +02:00
ret = IsUrlCacheEntryExpiredA ( test_url , 0 , & ft ) ;
2011-03-08 19:39:37 +01:00
ok ( ! ret , " expected FALSE \n " ) ;
ok ( ! ft . dwLowDateTime & & ! ft . dwHighDateTime ,
" expected time (0,0), got (%u,%u) \n " ,
ft . dwLowDateTime , ft . dwHighDateTime ) ;
/* Same behavior with bogus flags. */
ft . dwLowDateTime = 0xdeadbeef ;
ft . dwHighDateTime = 0xbaadf00d ;
2012-09-25 17:31:55 +02:00
ret = IsUrlCacheEntryExpiredA ( test_url , 0xffffffff , & ft ) ;
2011-03-08 19:39:37 +01:00
ok ( ! ret , " expected FALSE \n " ) ;
ok ( ! ft . dwLowDateTime & & ! ft . dwHighDateTime ,
" expected time (0,0), got (%u,%u) \n " ,
ft . dwLowDateTime , ft . dwHighDateTime ) ;
/* Set the expire time to a point in the past.. */
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url , NULL , & size ) ;
2011-03-08 19:39:37 +01:00
ok ( ! ret , " GetUrlCacheEntryInfo should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" expected ERROR_INSUFFICIENT_BUFFER, got %d \n " , GetLastError ( ) ) ;
info = HeapAlloc ( GetProcessHeap ( ) , 0 , size ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url , info , & size ) ;
2011-07-26 04:07:08 +02:00
ok ( ret , " GetUrlCacheEntryInfo failed: %d \n " , GetLastError ( ) ) ;
2011-03-08 19:39:37 +01:00
GetSystemTimeAsFileTime ( & info - > ExpireTime ) ;
2011-03-17 18:06:03 +01:00
exp_time . u . LowPart = info - > ExpireTime . dwLowDateTime ;
exp_time . u . HighPart = info - > ExpireTime . dwHighDateTime ;
2011-03-08 19:39:37 +01:00
exp_time . QuadPart - = 10 * 60 * ( ULONGLONG ) 10000000 ;
2011-03-17 18:06:03 +01:00
info - > ExpireTime . dwLowDateTime = exp_time . u . LowPart ;
info - > ExpireTime . dwHighDateTime = exp_time . u . HighPart ;
2013-10-24 12:15:43 +02:00
ret = SetUrlCacheEntryInfoA ( test_url , info , CACHE_ENTRY_EXPTIME_FC ) ;
2011-03-08 19:39:37 +01:00
ok ( ret , " SetUrlCacheEntryInfo failed: %d \n " , GetLastError ( ) ) ;
ft . dwLowDateTime = 0xdeadbeef ;
ft . dwHighDateTime = 0xbaadf00d ;
/* and the entry should be expired. */
2012-09-25 17:31:55 +02:00
ret = IsUrlCacheEntryExpiredA ( test_url , 0 , & ft ) ;
2011-03-08 19:39:37 +01:00
ok ( ret , " expected TRUE \n " ) ;
/* The modified time returned is 0. */
ok ( ! ft . dwLowDateTime & & ! ft . dwHighDateTime ,
" expected time (0,0), got (%u,%u) \n " ,
ft . dwLowDateTime , ft . dwHighDateTime ) ;
/* Set the expire time to a point in the future.. */
exp_time . QuadPart + = 20 * 60 * ( ULONGLONG ) 10000000 ;
2011-03-17 18:06:03 +01:00
info - > ExpireTime . dwLowDateTime = exp_time . u . LowPart ;
info - > ExpireTime . dwHighDateTime = exp_time . u . HighPart ;
2013-10-24 12:15:43 +02:00
ret = SetUrlCacheEntryInfoA ( test_url , info , CACHE_ENTRY_EXPTIME_FC ) ;
2011-03-08 19:39:37 +01:00
ok ( ret , " SetUrlCacheEntryInfo failed: %d \n " , GetLastError ( ) ) ;
ft . dwLowDateTime = 0xdeadbeef ;
ft . dwHighDateTime = 0xbaadf00d ;
/* and the entry should no longer be expired. */
2012-09-25 17:31:55 +02:00
ret = IsUrlCacheEntryExpiredA ( test_url , 0 , & ft ) ;
2011-03-08 19:39:37 +01:00
ok ( ! ret , " expected FALSE \n " ) ;
/* The modified time returned is still 0. */
ok ( ! ft . dwLowDateTime & & ! ft . dwHighDateTime ,
" expected time (0,0), got (%u,%u) \n " ,
ft . dwLowDateTime , ft . dwHighDateTime ) ;
/* Set the modified time... */
GetSystemTimeAsFileTime ( & info - > LastModifiedTime ) ;
2013-10-24 12:15:43 +02:00
ret = SetUrlCacheEntryInfoA ( test_url , info , CACHE_ENTRY_MODTIME_FC ) ;
2011-03-08 19:39:37 +01:00
ok ( ret , " SetUrlCacheEntryInfo failed: %d \n " , GetLastError ( ) ) ;
/* and the entry should still be unexpired.. */
2012-09-25 17:31:55 +02:00
ret = IsUrlCacheEntryExpiredA ( test_url , 0 , & ft ) ;
2011-03-08 19:39:37 +01:00
ok ( ! ret , " expected FALSE \n " ) ;
/* but the modified time returned is the last modified time just set. */
ok ( ft . dwLowDateTime = = info - > LastModifiedTime . dwLowDateTime & &
ft . dwHighDateTime = = info - > LastModifiedTime . dwHighDateTime ,
" expected time (%u,%u), got (%u,%u) \n " ,
info - > LastModifiedTime . dwLowDateTime ,
info - > LastModifiedTime . dwHighDateTime ,
ft . dwLowDateTime , ft . dwHighDateTime ) ;
HeapFree ( GetProcessHeap ( ) , 0 , info ) ;
/* An uncached URL is implicitly expired, but with unknown time. */
ft . dwLowDateTime = 0xdeadbeef ;
ft . dwHighDateTime = 0xbaadf00d ;
ret = IsUrlCacheEntryExpiredA ( uncached_url , 0 , & ft ) ;
2015-04-12 23:04:32 +02:00
ok ( ret ! = ie10_cache , " IsUrlCacheEntryExpiredA returned %x \n " , ret ) ;
2011-03-08 19:39:37 +01:00
ok ( ! ft . dwLowDateTime & & ! ft . dwHighDateTime ,
" expected time (0,0), got (%u,%u) \n " ,
ft . dwLowDateTime , ft . dwHighDateTime ) ;
}
2011-03-07 23:50:14 +01:00
static void _check_file_exists ( LONG l , LPCSTR filename )
{
HANDLE file ;
file = CreateFileA ( filename , GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_WRITE ,
NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL ) ;
ok_ ( __FILE__ , l ) ( file ! = INVALID_HANDLE_VALUE ,
" expected file to exist, CreateFile failed with error %d \n " ,
GetLastError ( ) ) ;
CloseHandle ( file ) ;
}
# define check_file_exists(f) _check_file_exists(__LINE__, f)
static void _check_file_not_exists ( LONG l , LPCSTR filename )
{
HANDLE file ;
file = CreateFileA ( filename , GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_WRITE ,
NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL ) ;
ok_ ( __FILE__ , l ) ( file = = INVALID_HANDLE_VALUE ,
" expected file not to exist \n " ) ;
if ( file ! = INVALID_HANDLE_VALUE )
CloseHandle ( file ) ;
}
# define check_file_not_exists(f) _check_file_not_exists(__LINE__, f)
static void create_and_write_file ( LPCSTR filename , void * data , DWORD len )
{
HANDLE file ;
DWORD written ;
BOOL ret ;
file = CreateFileA ( filename , GENERIC_WRITE ,
FILE_SHARE_READ | FILE_SHARE_WRITE , NULL , CREATE_ALWAYS ,
FILE_ATTRIBUTE_NORMAL , NULL ) ;
ok ( file ! = INVALID_HANDLE_VALUE , " CreateFileA failed with error %d \n " , GetLastError ( ) ) ;
ret = WriteFile ( file , data , len , & written , NULL ) ;
ok ( ret , " WriteFile failed with error %d \n " , GetLastError ( ) ) ;
CloseHandle ( file ) ;
}
2008-04-30 16:24:40 +02:00
static void test_urlcacheA ( void )
{
2015-06-19 08:58:55 +02:00
static char long_url [ 300 ] = " http://www.winehq.org/ " ;
2011-03-07 23:50:14 +01:00
static char ok_header [ ] = " HTTP/1.0 200 OK \r \n \r \n " ;
2008-04-30 16:24:40 +02:00
BOOL ret ;
HANDLE hFile ;
BYTE zero_byte = 0 ;
2013-10-24 12:15:43 +02:00
INTERNET_CACHE_ENTRY_INFOA * lpCacheEntryInfo ;
INTERNET_CACHE_ENTRY_INFOA * lpCacheEntryInfo2 ;
2008-04-30 16:24:40 +02:00
DWORD cbCacheEntryInfo ;
static const FILETIME filetime_zero ;
2011-03-07 23:50:14 +01:00
FILETIME now ;
2015-06-19 08:58:55 +02:00
int len ;
2008-04-30 16:24:40 +02:00
2013-10-24 12:15:43 +02:00
ret = CreateUrlCacheEntryA ( test_url , 0 , " html " , filenameA , 0 ) ;
2008-04-30 16:24:40 +02:00
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
ret = CreateUrlCacheEntryA ( test_url , 0 , " html " , filenameA1 , 0 ) ;
2009-09-25 12:01:35 +02:00
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
2012-09-18 14:44:51 +02:00
check_file_exists ( filenameA1 ) ;
DeleteFileA ( filenameA1 ) ;
2009-09-25 12:01:35 +02:00
ok ( lstrcmpiA ( filenameA , filenameA1 ) , " expected a different file name \n " ) ;
2011-03-07 23:50:14 +01:00
create_and_write_file ( filenameA , & zero_byte , sizeof ( zero_byte ) ) ;
2008-04-30 16:24:40 +02:00
2013-10-24 12:15:43 +02:00
ret = CommitUrlCacheEntryA ( test_url1 , NULL , filetime_zero , filetime_zero , NORMAL_CACHE_ENTRY , NULL , 0 , " html " , NULL ) ;
2009-09-25 12:01:35 +02:00
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
2011-03-07 23:50:14 +01:00
cbCacheEntryInfo = 0 ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url1 , NULL , & cbCacheEntryInfo ) ;
2011-03-07 23:50:14 +01:00
ok ( ! ret , " GetUrlCacheEntryInfo should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" GetUrlCacheEntryInfo should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d \n " , GetLastError ( ) ) ;
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url1 , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
2011-03-07 23:50:14 +01:00
ok ( ret , " GetUrlCacheEntryInfo failed with error %d \n " , GetLastError ( ) ) ;
ok ( ! memcmp ( & lpCacheEntryInfo - > ExpireTime , & filetime_zero , sizeof ( FILETIME ) ) ,
" expected zero ExpireTime \n " ) ;
ok ( ! memcmp ( & lpCacheEntryInfo - > LastModifiedTime , & filetime_zero , sizeof ( FILETIME ) ) ,
" expected zero LastModifiedTime \n " ) ;
ok ( lpCacheEntryInfo - > CacheEntryType = = ( NORMAL_CACHE_ENTRY | URLHISTORY_CACHE_ENTRY ) | |
broken ( lpCacheEntryInfo - > CacheEntryType = = NORMAL_CACHE_ENTRY /* NT4/W2k */ ) ,
" expected type NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY, got %08x \n " ,
lpCacheEntryInfo - > CacheEntryType ) ;
2011-03-17 18:06:03 +01:00
ok ( ! U ( * lpCacheEntryInfo ) . dwExemptDelta , " expected dwExemptDelta 0, got %d \n " ,
U ( * lpCacheEntryInfo ) . dwExemptDelta ) ;
2009-09-25 12:01:35 +02:00
2012-03-25 18:45:33 +02:00
/* Make sure there is a notable change in timestamps */
Sleep ( 1000 ) ;
/* A subsequent commit with a different time/type doesn't change most of the entry */
2011-03-07 23:50:14 +01:00
GetSystemTimeAsFileTime ( & now ) ;
2013-10-24 12:15:43 +02:00
ret = CommitUrlCacheEntryA ( test_url1 , NULL , now , now , NORMAL_CACHE_ENTRY ,
2011-03-07 23:50:14 +01:00
( LPBYTE ) ok_header , strlen ( ok_header ) , NULL , NULL ) ;
2009-09-25 12:01:35 +02:00
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
2011-03-07 23:50:14 +01:00
cbCacheEntryInfo = 0 ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url1 , NULL , & cbCacheEntryInfo ) ;
2011-03-07 23:50:14 +01:00
ok ( ! ret , " GetUrlCacheEntryInfo should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" expected ERROR_INSUFFICIENT_BUFFER, got %d \n " , GetLastError ( ) ) ;
2012-03-25 18:45:33 +02:00
lpCacheEntryInfo2 = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url1 , lpCacheEntryInfo2 , & cbCacheEntryInfo ) ;
2011-03-07 23:50:14 +01:00
ok ( ret , " GetUrlCacheEntryInfo failed with error %d \n " , GetLastError ( ) ) ;
/* but it does change the time.. */
2012-03-25 18:45:33 +02:00
ok ( memcmp ( & lpCacheEntryInfo2 - > ExpireTime , & filetime_zero , sizeof ( FILETIME ) ) ,
2011-03-07 23:50:14 +01:00
" expected positive ExpireTime \n " ) ;
2012-03-25 18:45:33 +02:00
ok ( memcmp ( & lpCacheEntryInfo2 - > LastModifiedTime , & filetime_zero , sizeof ( FILETIME ) ) ,
2011-03-07 23:50:14 +01:00
" expected positive LastModifiedTime \n " ) ;
2012-03-25 18:45:33 +02:00
ok ( lpCacheEntryInfo2 - > CacheEntryType = = ( NORMAL_CACHE_ENTRY | URLHISTORY_CACHE_ENTRY ) | |
broken ( lpCacheEntryInfo2 - > CacheEntryType = = NORMAL_CACHE_ENTRY /* NT4/W2k */ ) ,
2011-03-07 23:50:14 +01:00
" expected type NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY, got %08x \n " ,
2012-03-25 18:45:33 +02:00
lpCacheEntryInfo2 - > CacheEntryType ) ;
2011-03-07 23:50:14 +01:00
/* and set the headers. */
2012-03-25 18:45:33 +02:00
ok ( lpCacheEntryInfo2 - > dwHeaderInfoSize = = 19 ,
" expected headers size 19, got %d \n " ,
lpCacheEntryInfo2 - > dwHeaderInfoSize ) ;
/* Hit rate gets incremented by 1 */
ok ( ( lpCacheEntryInfo - > dwHitRate + 1 ) = = lpCacheEntryInfo2 - > dwHitRate ,
" HitRate not incremented by one on commit \n " ) ;
/* Last access time should be updated */
ok ( ! ( lpCacheEntryInfo - > LastAccessTime . dwHighDateTime = = lpCacheEntryInfo2 - > LastAccessTime . dwHighDateTime & &
lpCacheEntryInfo - > LastAccessTime . dwLowDateTime = = lpCacheEntryInfo2 - > LastAccessTime . dwLowDateTime ) ,
" Last accessed time was not updated by commit \n " ) ;
/* File extension should be unset */
ok ( lpCacheEntryInfo2 - > lpszFileExtension = = NULL ,
" Fileextension isn't unset: %s \n " ,
lpCacheEntryInfo2 - > lpszFileExtension ) ;
2011-03-07 23:50:14 +01:00
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
2012-03-25 18:45:33 +02:00
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo2 ) ;
2009-09-25 12:01:35 +02:00
2013-10-24 12:15:43 +02:00
ret = CommitUrlCacheEntryA ( test_url , filenameA , filetime_zero , filetime_zero , NORMAL_CACHE_ENTRY , NULL , 0 , " html " , NULL ) ;
2008-04-30 16:24:40 +02:00
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
cbCacheEntryInfo = 0 ;
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = RetrieveUrlCacheEntryFileA ( test_url , NULL , & cbCacheEntryInfo , 0 ) ;
2008-04-30 16:24:40 +02:00
ok ( ! ret , " RetrieveUrlCacheEntryFile should have failed \n " ) ;
2009-09-25 12:01:35 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" RetrieveUrlCacheEntryFile should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d \n " , GetLastError ( ) ) ;
2008-04-30 16:24:40 +02:00
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
2013-10-24 12:15:43 +02:00
ret = RetrieveUrlCacheEntryFileA ( test_url , lpCacheEntryInfo , & cbCacheEntryInfo , 0 ) ;
2008-04-30 16:24:40 +02:00
ok ( ret , " RetrieveUrlCacheEntryFile failed with error %d \n " , GetLastError ( ) ) ;
2011-09-09 15:57:59 +02:00
if ( ret ) check_cache_entry_infoA ( " RetrieveUrlCacheEntryFile " , lpCacheEntryInfo ) ;
2008-04-30 16:24:40 +02:00
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
2009-09-25 12:01:35 +02:00
cbCacheEntryInfo = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = RetrieveUrlCacheEntryFileA ( test_url1 , NULL , & cbCacheEntryInfo , 0 ) ;
2009-09-25 12:01:35 +02:00
ok ( ! ret , " RetrieveUrlCacheEntryFile should have failed \n " ) ;
2013-11-18 09:58:13 +01:00
ok ( GetLastError ( ) = = ERROR_INVALID_DATA | | GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
2009-09-25 12:01:35 +02:00
" RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_DATA instead of %d \n " , GetLastError ( ) ) ;
2008-05-22 10:38:29 +02:00
if ( pUnlockUrlCacheEntryFileA )
{
2012-09-25 17:31:55 +02:00
ret = pUnlockUrlCacheEntryFileA ( test_url , 0 ) ;
2008-05-22 10:38:29 +02:00
ok ( ret , " UnlockUrlCacheEntryFileA failed with error %d \n " , GetLastError ( ) ) ;
}
2008-04-30 16:24:40 +02:00
/* test Find*UrlCacheEntry functions */
test_find_url_cache_entriesA ( ) ;
2008-03-12 14:29:47 +01:00
2008-04-30 16:24:40 +02:00
test_GetUrlCacheEntryInfoExA ( ) ;
2008-10-07 16:39:33 +02:00
test_RetrieveUrlCacheEntryA ( ) ;
2011-03-08 19:39:37 +01:00
test_IsUrlCacheEntryExpiredA ( ) ;
2008-03-12 14:29:47 +01:00
2008-05-22 10:38:29 +02:00
if ( pDeleteUrlCacheEntryA )
{
2012-09-25 17:31:55 +02:00
ret = pDeleteUrlCacheEntryA ( test_url ) ;
2008-05-22 10:38:29 +02:00
ok ( ret , " DeleteUrlCacheEntryA failed with error %d \n " , GetLastError ( ) ) ;
2012-09-25 17:31:55 +02:00
ret = pDeleteUrlCacheEntryA ( test_url1 ) ;
2009-09-25 12:01:35 +02:00
ok ( ret , " DeleteUrlCacheEntryA failed with error %d \n " , GetLastError ( ) ) ;
2008-05-22 10:38:29 +02:00
}
2008-03-12 14:28:04 +01:00
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = DeleteFileA ( filenameA ) ;
2008-03-12 14:28:04 +01:00
ok ( ! ret & & GetLastError ( ) = = ERROR_FILE_NOT_FOUND , " local file should no longer exist \n " ) ;
2011-03-07 23:50:14 +01:00
/* Creating two entries with the same URL */
2013-10-24 12:15:43 +02:00
ret = CreateUrlCacheEntryA ( test_url , 0 , " html " , filenameA , 0 ) ;
2011-03-07 23:50:14 +01:00
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
ret = CreateUrlCacheEntryA ( test_url , 0 , " html " , filenameA1 , 0 ) ;
2011-03-07 23:50:14 +01:00
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
ok ( lstrcmpiA ( filenameA , filenameA1 ) , " expected a different file name \n " ) ;
create_and_write_file ( filenameA , & zero_byte , sizeof ( zero_byte ) ) ;
create_and_write_file ( filenameA1 , & zero_byte , sizeof ( zero_byte ) ) ;
check_file_exists ( filenameA ) ;
check_file_exists ( filenameA1 ) ;
2013-10-24 12:15:43 +02:00
ret = CommitUrlCacheEntryA ( test_url , filenameA , filetime_zero ,
2011-03-07 23:50:14 +01:00
filetime_zero , NORMAL_CACHE_ENTRY , ( LPBYTE ) ok_header ,
strlen ( ok_header ) , " html " , NULL ) ;
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
check_file_exists ( filenameA ) ;
check_file_exists ( filenameA1 ) ;
2013-10-24 12:15:43 +02:00
ret = CommitUrlCacheEntryA ( test_url , filenameA1 , filetime_zero ,
2011-03-07 23:50:14 +01:00
filetime_zero , COOKIE_CACHE_ENTRY , NULL , 0 , " html " , NULL ) ;
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
/* By committing the same URL a second time, the prior entry is
* overwritten . . .
*/
cbCacheEntryInfo = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url , NULL , & cbCacheEntryInfo ) ;
2012-03-31 12:38:32 +02:00
ok ( ! ret , " GetUrlCacheEntryInfo should have failed \n " ) ;
2011-03-07 23:50:14 +01:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" expected ERROR_INSUFFICIENT_BUFFER, got %d \n " , GetLastError ( ) ) ;
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
2011-03-07 23:50:14 +01:00
ok ( ret , " GetUrlCacheEntryInfo failed with error %d \n " , GetLastError ( ) ) ;
/* with the previous entry type retained.. */
ok ( lpCacheEntryInfo - > CacheEntryType & NORMAL_CACHE_ENTRY ,
" expected cache entry type NORMAL_CACHE_ENTRY, got %d (0x%08x) \n " ,
lpCacheEntryInfo - > CacheEntryType , lpCacheEntryInfo - > CacheEntryType ) ;
/* and the headers overwritten.. */
ok ( ! lpCacheEntryInfo - > dwHeaderInfoSize , " expected headers size 0, got %d \n " ,
lpCacheEntryInfo - > dwHeaderInfoSize ) ;
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
/* and the previous filename shouldn't exist. */
check_file_not_exists ( filenameA ) ;
check_file_exists ( filenameA1 ) ;
if ( pDeleteUrlCacheEntryA )
{
2012-09-25 17:31:55 +02:00
ret = pDeleteUrlCacheEntryA ( test_url ) ;
2011-03-07 23:50:14 +01:00
ok ( ret , " DeleteUrlCacheEntryA failed with error %d \n " , GetLastError ( ) ) ;
check_file_not_exists ( filenameA ) ;
check_file_not_exists ( filenameA1 ) ;
/* Just in case, clean up files */
DeleteFileA ( filenameA1 ) ;
DeleteFileA ( filenameA ) ;
}
/* Check whether a retrieved cache entry can be deleted before it's
* unlocked :
*/
2013-10-24 12:15:43 +02:00
ret = CreateUrlCacheEntryA ( test_url , 0 , " html " , filenameA , 0 ) ;
2011-03-07 23:50:14 +01:00
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
ret = CommitUrlCacheEntryA ( test_url , filenameA , filetime_zero , filetime_zero ,
2011-03-07 23:50:14 +01:00
NORMAL_CACHE_ENTRY , NULL , 0 , " html " , NULL ) ;
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
cbCacheEntryInfo = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = RetrieveUrlCacheEntryFileA ( test_url , NULL , & cbCacheEntryInfo , 0 ) ;
2011-03-07 23:50:14 +01:00
ok ( ! ret , " RetrieveUrlCacheEntryFile should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" expected ERROR_INSUFFICIENT_BUFFER, got %d \n " , GetLastError ( ) ) ;
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
2013-10-24 12:15:43 +02:00
ret = RetrieveUrlCacheEntryFileA ( test_url , lpCacheEntryInfo ,
2011-03-07 23:50:14 +01:00
& cbCacheEntryInfo , 0 ) ;
ok ( ret , " RetrieveUrlCacheEntryFile failed with error %d \n " , GetLastError ( ) ) ;
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
if ( pDeleteUrlCacheEntryA )
{
2012-09-25 17:31:55 +02:00
ret = pDeleteUrlCacheEntryA ( test_url ) ;
2011-03-07 23:50:14 +01:00
ok ( ! ret , " Expected failure \n " ) ;
ok ( GetLastError ( ) = = ERROR_SHARING_VIOLATION ,
" Expected ERROR_SHARING_VIOLATION, got %d \n " , GetLastError ( ) ) ;
check_file_exists ( filenameA ) ;
}
2012-03-25 18:45:33 +02:00
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
memset ( lpCacheEntryInfo , 0 , cbCacheEntryInfo ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
2012-03-25 18:45:33 +02:00
ok ( ret , " GetUrlCacheEntryInfo failed with error %d \n " , GetLastError ( ) ) ;
2012-09-18 14:43:12 +02:00
ok ( lpCacheEntryInfo - > CacheEntryType & 0x400000 ,
" CacheEntryType hasn't PENDING_DELETE_CACHE_ENTRY set, (flags %08x) \n " ,
2012-03-25 18:45:33 +02:00
lpCacheEntryInfo - > CacheEntryType ) ;
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
2011-03-07 23:50:14 +01:00
if ( pUnlockUrlCacheEntryFileA )
{
check_file_exists ( filenameA ) ;
2012-09-25 17:31:55 +02:00
ret = pUnlockUrlCacheEntryFileA ( test_url , 0 ) ;
2011-03-07 23:50:14 +01:00
ok ( ret , " UnlockUrlCacheEntryFileA failed: %d \n " , GetLastError ( ) ) ;
/* By unlocking the already-deleted cache entry, the file associated
* with it is deleted . .
*/
check_file_not_exists ( filenameA ) ;
/* (just in case, delete file) */
DeleteFileA ( filenameA ) ;
}
if ( pDeleteUrlCacheEntryA )
{
/* and a subsequent deletion should fail. */
2012-09-25 17:31:55 +02:00
ret = pDeleteUrlCacheEntryA ( test_url ) ;
2011-03-07 23:50:14 +01:00
ok ( ! ret , " Expected failure \n " ) ;
ok ( GetLastError ( ) = = ERROR_FILE_NOT_FOUND ,
" expected ERROR_FILE_NOT_FOUND, got %d \n " , GetLastError ( ) ) ;
}
/* Test whether preventing a file from being deleted causes
* DeleteUrlCacheEntryA to fail .
*/
2013-10-24 12:15:43 +02:00
ret = CreateUrlCacheEntryA ( test_url , 0 , " html " , filenameA , 0 ) ;
2011-03-07 23:50:14 +01:00
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
create_and_write_file ( filenameA , & zero_byte , sizeof ( zero_byte ) ) ;
check_file_exists ( filenameA ) ;
2013-10-24 12:15:43 +02:00
ret = CommitUrlCacheEntryA ( test_url , filenameA , filetime_zero ,
2011-03-07 23:50:14 +01:00
filetime_zero , NORMAL_CACHE_ENTRY , ( LPBYTE ) ok_header ,
strlen ( ok_header ) , " html " , NULL ) ;
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
check_file_exists ( filenameA ) ;
hFile = CreateFileA ( filenameA , GENERIC_READ , 0 , NULL , OPEN_EXISTING ,
FILE_ATTRIBUTE_NORMAL , NULL ) ;
ok ( hFile ! = INVALID_HANDLE_VALUE , " CreateFileA failed: %d \n " ,
GetLastError ( ) ) ;
if ( pDeleteUrlCacheEntryA )
{
/* DeleteUrlCacheEntryA should succeed.. */
2012-09-25 17:31:55 +02:00
ret = pDeleteUrlCacheEntryA ( test_url ) ;
2011-03-07 23:50:14 +01:00
ok ( ret , " DeleteUrlCacheEntryA failed with error %d \n " , GetLastError ( ) ) ;
}
CloseHandle ( hFile ) ;
if ( pDeleteUrlCacheEntryA )
{
/* and a subsequent deletion should fail.. */
2012-09-25 17:31:55 +02:00
ret = pDeleteUrlCacheEntryA ( test_url ) ;
2011-03-07 23:50:14 +01:00
ok ( ! ret , " Expected failure \n " ) ;
ok ( GetLastError ( ) = = ERROR_FILE_NOT_FOUND ,
" expected ERROR_FILE_NOT_FOUND, got %d \n " , GetLastError ( ) ) ;
}
/* and the file should be untouched. */
check_file_exists ( filenameA ) ;
DeleteFileA ( filenameA ) ;
2011-03-08 02:18:50 +01:00
/* Try creating a sticky entry. Unlike non-sticky entries, the filename
* must have been set already .
*/
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = CommitUrlCacheEntryA ( test_url , NULL , filetime_zero , filetime_zero ,
2011-03-08 02:18:50 +01:00
STICKY_CACHE_ENTRY , ( LPBYTE ) ok_header , strlen ( ok_header ) , " html " ,
NULL ) ;
2013-11-18 09:58:13 +01:00
ok ( ret = = ie10_cache , " CommitUrlCacheEntryA returned %x \n " , ret ) ;
if ( ! ret ) ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER ,
" expected ERROR_INVALID_PARAMETER, got %d \n " , GetLastError ( ) ) ;
2011-03-08 02:18:50 +01:00
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = CommitUrlCacheEntryA ( test_url , NULL , filetime_zero , filetime_zero ,
2011-03-08 02:18:50 +01:00
NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY ,
( LPBYTE ) ok_header , strlen ( ok_header ) , " html " , NULL ) ;
2013-11-18 09:58:13 +01:00
ok ( ret = = ie10_cache , " CommitUrlCacheEntryA returned %x \n " , ret ) ;
if ( ! ret ) ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER ,
" expected ERROR_INVALID_PARAMETER, got %d \n " , GetLastError ( ) ) ;
2012-03-25 18:45:33 +02:00
2013-10-24 12:15:43 +02:00
ret = CreateUrlCacheEntryA ( test_url , 0 , " html " , filenameA , 0 ) ;
2011-03-08 02:18:50 +01:00
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
create_and_write_file ( filenameA , & zero_byte , sizeof ( zero_byte ) ) ;
2013-10-24 12:15:43 +02:00
ret = CommitUrlCacheEntryA ( test_url , filenameA , filetime_zero , filetime_zero ,
2011-03-08 02:18:50 +01:00
NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY ,
( LPBYTE ) ok_header , strlen ( ok_header ) , " html " , NULL ) ;
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
cbCacheEntryInfo = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url , NULL , & cbCacheEntryInfo ) ;
2012-03-31 12:38:32 +02:00
ok ( ! ret , " GetUrlCacheEntryInfo should have failed \n " ) ;
2011-03-08 02:18:50 +01:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" expected ERROR_INSUFFICIENT_BUFFER, got %d \n " , GetLastError ( ) ) ;
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
2011-03-08 02:18:50 +01:00
ok ( ret , " GetUrlCacheEntryInfo failed with error %d \n " , GetLastError ( ) ) ;
ok ( lpCacheEntryInfo - > CacheEntryType & ( NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY ) ,
" expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x) \n " ,
lpCacheEntryInfo - > CacheEntryType , lpCacheEntryInfo - > CacheEntryType ) ;
2011-03-17 18:06:03 +01:00
ok ( U ( * lpCacheEntryInfo ) . dwExemptDelta = = 86400 ,
2012-03-31 12:38:32 +02:00
" expected dwExemptDelta 86400, got %d \n " ,
2011-03-17 18:06:03 +01:00
U ( * lpCacheEntryInfo ) . dwExemptDelta ) ;
2011-03-08 02:18:50 +01:00
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
if ( pDeleteUrlCacheEntryA )
{
2012-09-25 17:31:55 +02:00
ret = pDeleteUrlCacheEntryA ( test_url ) ;
2011-03-08 02:18:50 +01:00
ok ( ret , " DeleteUrlCacheEntryA failed with error %d \n " , GetLastError ( ) ) ;
/* When explicitly deleting the cache entry, the file is also deleted */
check_file_not_exists ( filenameA ) ;
}
/* Test once again, setting the exempt delta via SetUrlCacheEntryInfo */
2013-10-24 12:15:43 +02:00
ret = CreateUrlCacheEntryA ( test_url , 0 , " html " , filenameA , 0 ) ;
2011-03-08 02:18:50 +01:00
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
create_and_write_file ( filenameA , & zero_byte , sizeof ( zero_byte ) ) ;
2013-10-24 12:15:43 +02:00
ret = CommitUrlCacheEntryA ( test_url , filenameA , filetime_zero , filetime_zero ,
2011-03-08 02:18:50 +01:00
NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY ,
( LPBYTE ) ok_header , strlen ( ok_header ) , " html " , NULL ) ;
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
cbCacheEntryInfo = 0 ;
SetLastError ( 0xdeadbeef ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url , NULL , & cbCacheEntryInfo ) ;
2012-03-31 12:38:32 +02:00
ok ( ! ret , " GetUrlCacheEntryInfo should have failed \n " ) ;
2011-03-08 02:18:50 +01:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" expected ERROR_INSUFFICIENT_BUFFER, got %d \n " , GetLastError ( ) ) ;
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
2011-03-08 02:18:50 +01:00
ok ( ret , " GetUrlCacheEntryInfo failed with error %d \n " , GetLastError ( ) ) ;
ok ( lpCacheEntryInfo - > CacheEntryType & ( NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY ) ,
" expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x) \n " ,
lpCacheEntryInfo - > CacheEntryType , lpCacheEntryInfo - > CacheEntryType ) ;
2011-03-17 18:06:03 +01:00
ok ( U ( * lpCacheEntryInfo ) . dwExemptDelta = = 86400 ,
2012-03-31 12:38:32 +02:00
" expected dwExemptDelta 86400, got %d \n " ,
2011-03-17 18:06:03 +01:00
U ( * lpCacheEntryInfo ) . dwExemptDelta ) ;
U ( * lpCacheEntryInfo ) . dwExemptDelta = 0 ;
2012-09-25 17:31:55 +02:00
ret = SetUrlCacheEntryInfoA ( test_url , lpCacheEntryInfo ,
2011-03-08 02:18:50 +01:00
CACHE_ENTRY_EXEMPT_DELTA_FC ) ;
ok ( ret , " SetUrlCacheEntryInfo failed: %d \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
2011-03-08 02:18:50 +01:00
ok ( ret , " GetUrlCacheEntryInfo failed with error %d \n " , GetLastError ( ) ) ;
2011-03-17 18:06:03 +01:00
ok ( ! U ( * lpCacheEntryInfo ) . dwExemptDelta , " expected dwExemptDelta 0, got %d \n " ,
U ( * lpCacheEntryInfo ) . dwExemptDelta ) ;
2011-03-08 02:18:50 +01:00
/* See whether a sticky cache entry has the flag cleared once the exempt
* delta is meaningless .
*/
ok ( lpCacheEntryInfo - > CacheEntryType & ( NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY ) ,
" expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x) \n " ,
lpCacheEntryInfo - > CacheEntryType , lpCacheEntryInfo - > CacheEntryType ) ;
2012-03-25 18:45:33 +02:00
/* Recommit of Url entry keeps dwExemptDelta */
U ( * lpCacheEntryInfo ) . dwExemptDelta = 8600 ;
2012-09-25 17:31:55 +02:00
ret = SetUrlCacheEntryInfoA ( test_url , lpCacheEntryInfo ,
2012-03-25 18:45:33 +02:00
CACHE_ENTRY_EXEMPT_DELTA_FC ) ;
ok ( ret , " SetUrlCacheEntryInfo failed: %d \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
ret = CreateUrlCacheEntryA ( test_url , 0 , " html " , filenameA1 , 0 ) ;
2012-03-25 18:45:33 +02:00
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
create_and_write_file ( filenameA1 , & zero_byte , sizeof ( zero_byte ) ) ;
2013-10-24 12:15:43 +02:00
ret = CommitUrlCacheEntryA ( test_url , filenameA1 , filetime_zero , filetime_zero ,
2012-03-25 18:45:33 +02:00
NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY ,
( LPBYTE ) ok_header , strlen ( ok_header ) , " html " , NULL ) ;
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_url , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
2012-03-25 18:45:33 +02:00
ok ( ret , " GetUrlCacheEntryInfo failed with error %d \n " , GetLastError ( ) ) ;
2013-11-18 09:58:13 +01:00
ok ( U ( * lpCacheEntryInfo ) . dwExemptDelta = = 8600 | | ( ie10_cache & & U ( * lpCacheEntryInfo ) . dwExemptDelta = = 86400 ) ,
" expected dwExemptDelta 8600, got %d \n " , U ( * lpCacheEntryInfo ) . dwExemptDelta ) ;
2012-03-25 18:45:33 +02:00
2011-03-08 02:18:50 +01:00
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
2012-03-25 18:45:33 +02:00
2011-03-08 02:18:50 +01:00
if ( pDeleteUrlCacheEntryA )
{
2012-09-25 17:31:55 +02:00
ret = pDeleteUrlCacheEntryA ( test_url ) ;
2011-03-08 02:18:50 +01:00
ok ( ret , " DeleteUrlCacheEntryA failed with error %d \n " , GetLastError ( ) ) ;
check_file_not_exists ( filenameA ) ;
}
2012-09-24 14:56:56 +02:00
/* Test if files with identical hash keys are handled correctly */
2012-09-25 17:31:55 +02:00
ret = CommitUrlCacheEntryA ( test_hash_collisions1 , NULL , filetime_zero , filetime_zero , NORMAL_CACHE_ENTRY , NULL , 0 , " html " , NULL ) ;
2012-09-24 14:56:56 +02:00
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
2012-09-25 17:31:55 +02:00
ret = CommitUrlCacheEntryA ( test_hash_collisions2 , NULL , filetime_zero , filetime_zero , NORMAL_CACHE_ENTRY , NULL , 0 , " html " , NULL ) ;
2012-09-24 14:56:56 +02:00
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
cbCacheEntryInfo = 0 ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_hash_collisions1 , NULL , & cbCacheEntryInfo ) ;
2012-09-24 14:56:56 +02:00
ok ( ! ret , " GetUrlCacheEntryInfo should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" expected ERROR_INSUFFICIENT_BUFFER, got %d \n " , GetLastError ( ) ) ;
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_hash_collisions1 , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
2012-09-24 14:56:56 +02:00
ok ( ret , " GetUrlCacheEntryInfo failed with error %d \n " , GetLastError ( ) ) ;
2012-09-25 17:31:55 +02:00
ok ( ! strcmp ( lpCacheEntryInfo - > lpszSourceUrlName , test_hash_collisions1 ) ,
2012-09-24 14:56:56 +02:00
" got incorrect entry: %s \n " , lpCacheEntryInfo - > lpszSourceUrlName ) ;
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
cbCacheEntryInfo = 0 ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_hash_collisions2 , NULL , & cbCacheEntryInfo ) ;
2012-09-24 14:56:56 +02:00
ok ( ! ret , " GetUrlCacheEntryInfo should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" expected ERROR_INSUFFICIENT_BUFFER, got %d \n " , GetLastError ( ) ) ;
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
2013-10-24 12:15:43 +02:00
ret = GetUrlCacheEntryInfoA ( test_hash_collisions2 , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
2012-09-24 14:56:56 +02:00
ok ( ret , " GetUrlCacheEntryInfo failed with error %d \n " , GetLastError ( ) ) ;
2012-09-25 17:31:55 +02:00
ok ( ! strcmp ( lpCacheEntryInfo - > lpszSourceUrlName , test_hash_collisions2 ) ,
2012-09-24 14:56:56 +02:00
" got incorrect entry: %s \n " , lpCacheEntryInfo - > lpszSourceUrlName ) ;
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
if ( pDeleteUrlCacheEntryA ) {
2012-09-25 17:31:55 +02:00
ret = pDeleteUrlCacheEntryA ( test_hash_collisions1 ) ;
2012-09-24 14:56:56 +02:00
ok ( ret , " DeleteUrlCacheEntry failed: %d \n " , GetLastError ( ) ) ;
2012-09-25 17:31:55 +02:00
ret = pDeleteUrlCacheEntryA ( test_hash_collisions2 ) ;
2012-09-24 14:56:56 +02:00
ok ( ret , " DeleteUrlCacheEntry failed: %d \n " , GetLastError ( ) ) ;
}
2015-06-19 08:58:55 +02:00
len = strlen ( long_url ) ;
memset ( long_url + len , ' a ' , sizeof ( long_url ) - len ) ;
long_url [ sizeof ( long_url ) - 1 ] = 0 ;
ret = CreateUrlCacheEntryA ( long_url , 0 , NULL , filenameA , 0 ) ;
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
check_file_exists ( filenameA ) ;
DeleteFileA ( filenameA ) ;
ret = CreateUrlCacheEntryA ( long_url , 0 , " extension " , filenameA , 0 ) ;
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
check_file_exists ( filenameA ) ;
DeleteFileA ( filenameA ) ;
long_url [ 250 ] = 0 ;
ret = CreateUrlCacheEntryA ( long_url , 0 , NULL , filenameA , 0 ) ;
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
check_file_exists ( filenameA ) ;
DeleteFileA ( filenameA ) ;
ret = CreateUrlCacheEntryA ( long_url , 0 , " extension " , filenameA , 0 ) ;
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
check_file_exists ( filenameA ) ;
DeleteFileA ( filenameA ) ;
2008-03-12 14:28:04 +01:00
}
2013-04-01 13:48:23 +02:00
static void test_urlcacheW ( void )
{
static struct test_data
{
DWORD err ;
WCHAR url [ 128 ] ;
char encoded_url [ 128 ] ;
WCHAR extension [ 32 ] ;
WCHAR header_info [ 128 ] ;
} urls [ ] = {
{
0 , { ' h ' , ' t ' , ' t ' , ' p ' , ' : ' , ' / ' , ' / ' , ' T ' , ' . ' , ' p ' , ' l ' , ' / ' , ' t ' , 0 } ,
" http://T.pl/t " , { 0 } , { 0 }
} ,
{
0 , { ' w ' , ' w ' , ' w ' , ' . ' , ' T ' , ' . ' , ' p ' , ' l ' , ' / ' , ' t ' , 0 } ,
" www.T.pl/t " , { 0 } , { 0 }
} ,
{
0 , { ' h ' , ' t ' , ' t ' , ' p ' , ' : ' , ' / ' , ' / ' , ' w ' , ' w ' , ' w ' , ' . ' , ' t ' , ' e ' , ' s ' , ' t ' , 0x15b , 0x107 ,
' . ' , ' o ' , ' r ' , ' g ' , ' / ' , ' t ' , ' e ' , ' s ' , ' t ' , ' . ' , ' h ' , ' t ' , ' m ' , ' l ' , 0 } ,
" http://www.xn--test-ota71c.org/test.html " , { ' t ' , ' x ' , ' t ' , 0 } , { 0 }
} ,
{
0 , { ' w ' , ' w ' , ' w ' , ' . ' , ' T ' , ' e ' , ' s ' , ' t ' , 0x15b , 0x107 , ' . ' , ' o ' , ' r ' , ' g ' ,
' / ' , ' t ' , ' e ' , ' s ' , ' t ' , ' . ' , ' h ' , ' t ' , ' m ' , ' l ' , 0 } ,
" www.Test \xc5 \x9b \xc4 \x87 .org/test.html " , { ' a ' , 0x106 , ' a ' , 0 } , { ' b ' , 0x106 , ' b ' , 0 }
} ,
{
0 , { ' H ' , ' t ' , ' t ' , ' p ' , ' s ' , ' : ' , ' / ' , ' / ' , 0x15b , 0x15b , 0x107 , ' / ' , ' t ' , 0x107 , ' / ' ,
' t ' , ' e ' , ' s ' , ' t ' , ' ? ' , ' a ' , ' = ' , ' % ' , ' 2 ' , ' 0 ' , 0x106 , 0 } ,
" Https://xn--4da1oa/t \xc4 \x87 /test?a=%20 \xc4 \x86 " , { ' a ' , 0x15b , ' a ' , 0 } , { ' b ' , 0x15b , ' b ' , 0 }
} ,
{
12005 , { ' h ' , ' t ' , ' t ' , ' p ' , ' s ' , ' : ' , ' / ' , ' / ' , ' / ' , ' / ' , 0x107 , ' . ' , ' o ' , ' r ' , ' g ' , ' / ' , ' t ' , ' e ' , ' s ' , ' t ' , 0 } ,
" " , { 0 } , { 0 }
} ,
{
2019-10-24 11:22:55 +02:00
0 , { ' C ' , ' o ' , ' o ' , ' k ' , ' i ' , ' e ' , ' : ' , ' ' , ' u ' , ' s ' , ' e ' , ' r ' , ' @ ' , ' t ' , ' e ' , ' s ' , ' t ' , ' . ' , ' o ' , ' r ' , ' g ' , ' / ' , 0 } ,
" Cookie: user@test.org/ " , { 0 } , { 0 }
2013-04-01 13:48:23 +02:00
}
} ;
static const FILETIME filetime_zero ;
WCHAR bufW [ MAX_PATH ] ;
DWORD i ;
BOOL ret ;
if ( old_ie ) {
win_skip ( " urlcache unicode functions \n " ) ;
return ;
}
2018-06-21 23:06:10 +02:00
for ( i = 0 ; i < ARRAY_SIZE ( urls ) ; i + + ) {
2013-04-01 13:48:23 +02:00
INTERNET_CACHE_ENTRY_INFOA * entry_infoA ;
INTERNET_CACHE_ENTRY_INFOW * entry_infoW ;
DWORD size ;
SetLastError ( 0xdeadbeef ) ;
ret = CreateUrlCacheEntryW ( urls [ i ] . url , 0 , NULL , bufW , 0 ) ;
if ( urls [ i ] . err ! = 0 ) {
ok ( ! ret , " %d) CreateUrlCacheEntryW succeeded \n " , i ) ;
ok ( urls [ i ] . err = = GetLastError ( ) , " %d) GetLastError() = %d \n " , i , GetLastError ( ) ) ;
continue ;
}
ok ( ret , " %d) CreateUrlCacheEntryW failed: %d \n " , i , GetLastError ( ) ) ;
/* dwHeaderSize is ignored, pass 0 to prove it */
ret = CommitUrlCacheEntryW ( urls [ i ] . url , bufW , filetime_zero , filetime_zero ,
NORMAL_CACHE_ENTRY , urls [ i ] . header_info , 0 , urls [ i ] . extension , NULL ) ;
ok ( ret , " %d) CommitUrlCacheEntryW failed: %d \n " , i , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
size = 0 ;
ret = GetUrlCacheEntryInfoW ( urls [ i ] . url , NULL , & size ) ;
ok ( ! ret & & GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" %d) GetLastError() = %d \n " , i , GetLastError ( ) ) ;
entry_infoW = HeapAlloc ( GetProcessHeap ( ) , 0 , size ) ;
ret = GetUrlCacheEntryInfoW ( urls [ i ] . url , entry_infoW , & size ) ;
ok ( ret , " %d) GetUrlCacheEntryInfoW failed: %d \n " , i , GetLastError ( ) ) ;
ret = GetUrlCacheEntryInfoA ( urls [ i ] . encoded_url , NULL , & size ) ;
ok ( ! ret & & GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" %d) GetLastError() = %d \n " , i , GetLastError ( ) ) ;
entry_infoA = HeapAlloc ( GetProcessHeap ( ) , 0 , size ) ;
ret = GetUrlCacheEntryInfoA ( urls [ i ] . encoded_url , entry_infoA , & size ) ;
ok ( ret , " %d) GetUrlCacheEntryInfoA failed: %d \n " , i , GetLastError ( ) ) ;
ok ( entry_infoW - > dwStructSize = = entry_infoA - > dwStructSize ,
" %d) entry_infoW->dwStructSize = %d, expected %d \n " ,
i , entry_infoW - > dwStructSize , entry_infoA - > dwStructSize ) ;
ok ( ! lstrcmpW ( urls [ i ] . url , entry_infoW - > lpszSourceUrlName ) ,
" %d) entry_infoW->lpszSourceUrlName = %s \n " ,
i , wine_dbgstr_w ( entry_infoW - > lpszSourceUrlName ) ) ;
ok ( ! lstrcmpA ( urls [ i ] . encoded_url , entry_infoA - > lpszSourceUrlName ) ,
" %d) entry_infoA->lpszSourceUrlName = %s \n " ,
i , entry_infoA - > lpszSourceUrlName ) ;
ok ( entry_infoW - > CacheEntryType = = entry_infoA - > CacheEntryType ,
" %d) entry_infoW->CacheEntryType = %x, expected %x \n " ,
i , entry_infoW - > CacheEntryType , entry_infoA - > CacheEntryType ) ;
ok ( entry_infoW - > dwUseCount = = entry_infoA - > dwUseCount ,
" %d) entry_infoW->dwUseCount = %d, expected %d \n " ,
i , entry_infoW - > dwUseCount , entry_infoA - > dwUseCount ) ;
ok ( entry_infoW - > dwHitRate = = entry_infoA - > dwHitRate ,
" %d) entry_infoW->dwHitRate = %d, expected %d \n " ,
i , entry_infoW - > dwHitRate , entry_infoA - > dwHitRate ) ;
ok ( entry_infoW - > dwSizeLow = = entry_infoA - > dwSizeLow ,
" %d) entry_infoW->dwSizeLow = %d, expected %d \n " ,
i , entry_infoW - > dwSizeLow , entry_infoA - > dwSizeLow ) ;
ok ( entry_infoW - > dwSizeHigh = = entry_infoA - > dwSizeHigh ,
" %d) entry_infoW->dwSizeHigh = %d, expected %d \n " ,
i , entry_infoW - > dwSizeHigh , entry_infoA - > dwSizeHigh ) ;
ok ( ! memcmp ( & entry_infoW - > LastModifiedTime , & entry_infoA - > LastModifiedTime , sizeof ( FILETIME ) ) ,
" %d) entry_infoW->LastModifiedTime is incorrect \n " , i ) ;
ok ( ! memcmp ( & entry_infoW - > ExpireTime , & entry_infoA - > ExpireTime , sizeof ( FILETIME ) ) ,
" %d) entry_infoW->ExpireTime is incorrect \n " , i ) ;
ok ( ! memcmp ( & entry_infoW - > LastAccessTime , & entry_infoA - > LastAccessTime , sizeof ( FILETIME ) ) ,
" %d) entry_infoW->LastAccessTime is incorrect \n " , i ) ;
ok ( ! memcmp ( & entry_infoW - > LastSyncTime , & entry_infoA - > LastSyncTime , sizeof ( FILETIME ) ) ,
" %d) entry_infoW->LastSyncTime is incorrect \n " , i ) ;
MultiByteToWideChar ( CP_ACP , 0 , entry_infoA - > lpszLocalFileName , - 1 , bufW , MAX_PATH ) ;
ok ( ! lstrcmpW ( entry_infoW - > lpszLocalFileName , bufW ) ,
" %d) entry_infoW->lpszLocalFileName = %s, expected %s \n " ,
i , wine_dbgstr_w ( entry_infoW - > lpszLocalFileName ) , wine_dbgstr_w ( bufW ) ) ;
if ( ! urls [ i ] . header_info [ 0 ] ) {
ok ( ! entry_infoW - > lpHeaderInfo , " entry_infoW->lpHeaderInfo != NULL \n " ) ;
} else {
ok ( ! lstrcmpW ( ( WCHAR * ) entry_infoW - > lpHeaderInfo , urls [ i ] . header_info ) ,
" %d) entry_infoW->lpHeaderInfo = %s \n " ,
i , wine_dbgstr_w ( ( WCHAR * ) entry_infoW - > lpHeaderInfo ) ) ;
}
if ( ! urls [ i ] . extension [ 0 ] ) {
2013-11-18 09:58:13 +01:00
ok ( ! entry_infoW - > lpszFileExtension | | ( ie10_cache & & ! entry_infoW - > lpszFileExtension [ 0 ] ) ,
" %d) entry_infoW->lpszFileExtension = %s \n " ,
i , wine_dbgstr_w ( entry_infoW - > lpszFileExtension ) ) ;
2013-04-01 13:48:23 +02:00
} else {
MultiByteToWideChar ( CP_ACP , 0 , entry_infoA - > lpszFileExtension , - 1 , bufW , MAX_PATH ) ;
2013-11-18 09:58:13 +01:00
ok ( ! lstrcmpW ( entry_infoW - > lpszFileExtension , bufW ) | |
( ie10_cache & & ! lstrcmpW ( entry_infoW - > lpszFileExtension , urls [ i ] . extension ) ) ,
2013-04-01 13:48:23 +02:00
" %d) entry_infoW->lpszFileExtension = %s, expected %s \n " ,
i , wine_dbgstr_w ( entry_infoW - > lpszFileExtension ) , wine_dbgstr_w ( bufW ) ) ;
}
HeapFree ( GetProcessHeap ( ) , 0 , entry_infoW ) ;
HeapFree ( GetProcessHeap ( ) , 0 , entry_infoA ) ;
if ( pDeleteUrlCacheEntryA ) {
ret = pDeleteUrlCacheEntryA ( urls [ i ] . encoded_url ) ;
ok ( ret , " %d) DeleteUrlCacheEntryW failed: %d \n " , i , GetLastError ( ) ) ;
}
}
}
2008-05-08 20:14:41 +02:00
static void test_FindCloseUrlCache ( void )
{
BOOL r ;
DWORD err ;
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2008-05-08 20:14:41 +02:00
r = FindCloseUrlCache ( NULL ) ;
err = GetLastError ( ) ;
ok ( 0 = = r , " expected 0, got %d \n " , r ) ;
ok ( ERROR_INVALID_HANDLE = = err , " expected %d, got %d \n " , ERROR_INVALID_HANDLE , err ) ;
}
2009-05-13 14:01:18 +02:00
static void test_GetDiskInfoA ( void )
{
BOOL ret ;
DWORD error , cluster_size ;
DWORDLONG free , total ;
char path [ MAX_PATH ] , * p ;
GetSystemDirectoryA ( path , MAX_PATH ) ;
if ( ( p = strchr ( path , ' \\ ' ) ) ) * + + p = 0 ;
ret = GetDiskInfoA ( path , & cluster_size , & free , & total ) ;
ok ( ret , " GetDiskInfoA failed %u \n " , GetLastError ( ) ) ;
ret = GetDiskInfoA ( path , & cluster_size , & free , NULL ) ;
ok ( ret , " GetDiskInfoA failed %u \n " , GetLastError ( ) ) ;
ret = GetDiskInfoA ( path , & cluster_size , NULL , NULL ) ;
ok ( ret , " GetDiskInfoA failed %u \n " , GetLastError ( ) ) ;
ret = GetDiskInfoA ( path , NULL , NULL , NULL ) ;
ok ( ret , " GetDiskInfoA failed %u \n " , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
strcpy ( p , " \\ non \\ existing \\ path " ) ;
ret = GetDiskInfoA ( path , NULL , NULL , NULL ) ;
error = GetLastError ( ) ;
2009-05-13 20:50:36 +02:00
ok ( ! ret | |
2012-10-03 12:29:15 +02:00
broken ( old_ie & & ret ) , /* < IE7 */
2009-05-13 20:50:36 +02:00
" GetDiskInfoA succeeded \n " ) ;
ok ( error = = ERROR_PATH_NOT_FOUND | |
2012-10-03 12:29:15 +02:00
broken ( old_ie & & error = = 0xdeadbeef ) , /* < IE7 */
2009-05-13 20:50:36 +02:00
" got %u expected ERROR_PATH_NOT_FOUND \n " , error ) ;
2009-05-13 14:01:18 +02:00
SetLastError ( 0xdeadbeef ) ;
ret = GetDiskInfoA ( NULL , NULL , NULL , NULL ) ;
error = GetLastError ( ) ;
ok ( ! ret , " GetDiskInfoA succeeded \n " ) ;
ok ( error = = ERROR_INVALID_PARAMETER , " got %u expected ERROR_INVALID_PARAMETER \n " , error ) ;
}
2014-07-16 11:06:24 +02:00
static BOOL cache_entry_exists ( const char * url )
{
static char buf [ 10000 ] ;
DWORD size = sizeof ( buf ) ;
BOOL ret ;
ret = GetUrlCacheEntryInfoA ( url , ( void * ) buf , & size ) ;
ok ( ret | | GetLastError ( ) = = ERROR_FILE_NOT_FOUND , " GetUrlCacheEntryInfoA returned %x (%u) \n " , ret , GetLastError ( ) ) ;
return ret ;
}
static void test_trailing_slash ( void )
{
char filename [ MAX_PATH ] ;
BYTE zero_byte = 0 ;
BOOL ret ;
static const FILETIME filetime_zero ;
static char url_with_slash [ ] = " http://testing.cache.com/ " ;
ret = CreateUrlCacheEntryA ( url_with_slash , 0 , " html " , filename , 0 ) ;
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
2015-11-12 18:22:27 +01:00
create_and_write_file ( filename , & zero_byte , sizeof ( zero_byte ) ) ;
2014-07-16 11:06:24 +02:00
ret = CommitUrlCacheEntryA ( " Visited: http://testing.cache.com/ " , NULL , filetime_zero , filetime_zero ,
NORMAL_CACHE_ENTRY , NULL , 0 , " html " , NULL ) ;
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
ok ( cache_entry_exists ( " Visited: http://testing.cache.com/ " ) , " cache entry does not exist \n " ) ;
ok ( ! cache_entry_exists ( " Visited: http://testing.cache.com " ) , " cache entry exists \n " ) ;
ret = DeleteUrlCacheEntryA ( " Visited: http://testing.cache.com/ " ) ;
ok ( ret , " DeleteCacheEntryA failed \n " ) ;
DeleteFileA ( filename ) ;
}
2019-01-09 05:50:23 +01:00
static void get_cache_path ( DWORD flags , char path [ MAX_PATH ] , char path_win8 [ MAX_PATH ] )
{
BOOL ret ;
int folder = - 1 ;
const char * suffix = " " ;
const char * suffix_win8 = " " ;
switch ( flags )
{
case 0 :
case CACHE_CONFIG_CONTENT_PATHS_FC :
folder = CSIDL_INTERNET_CACHE ;
suffix = " \\ Content.IE5 \\ " ;
suffix_win8 = " \\ IE \\ " ;
break ;
case CACHE_CONFIG_COOKIES_PATHS_FC :
folder = CSIDL_COOKIES ;
suffix = " \\ " ;
suffix_win8 = " \\ " ;
break ;
case CACHE_CONFIG_HISTORY_PATHS_FC :
folder = CSIDL_HISTORY ;
suffix = " \\ History.IE5 \\ " ;
suffix_win8 = " \\ History.IE5 \\ " ;
break ;
default :
ok ( 0 , " unexpected flags %#x \n " , flags ) ;
break ;
}
ret = SHGetSpecialFolderPathA ( 0 , path , folder , FALSE ) ;
ok ( ret , " SHGetSpecialFolderPath error %u \n " , GetLastError ( ) ) ;
strcpy ( path_win8 , path ) ;
strcat ( path_win8 , suffix_win8 ) ;
strcat ( path , suffix ) ;
}
static void test_GetUrlCacheConfigInfo ( void )
{
INTERNET_CACHE_CONFIG_INFOA info ;
struct
{
INTERNET_CACHE_CONFIG_INFOA * info ;
DWORD dwStructSize ;
DWORD flags ;
BOOL ret ;
DWORD error ;
} td [ ] =
{
#if 0 /* crashes under Vista */
{ NULL , 0 , 0 , FALSE , ERROR_INVALID_PARAMETER } ,
# endif
{ & info , 0 , 0 , TRUE } ,
{ & info , sizeof ( info ) - 1 , 0 , TRUE } ,
{ & info , sizeof ( info ) + 1 , 0 , TRUE } ,
{ & info , 0 , CACHE_CONFIG_CONTENT_PATHS_FC , TRUE } ,
{ & info , sizeof ( info ) , CACHE_CONFIG_CONTENT_PATHS_FC , TRUE } ,
{ & info , 0 , CACHE_CONFIG_COOKIES_PATHS_FC , TRUE } ,
{ & info , sizeof ( info ) , CACHE_CONFIG_COOKIES_PATHS_FC , TRUE } ,
{ & info , 0 , CACHE_CONFIG_HISTORY_PATHS_FC , TRUE } ,
{ & info , sizeof ( info ) , CACHE_CONFIG_HISTORY_PATHS_FC , TRUE } ,
} ;
int i ;
BOOL ret ;
for ( i = 0 ; i < ARRAY_SIZE ( td ) ; i + + )
{
if ( td [ i ] . info )
{
memset ( & info , 0 , sizeof ( * td [ i ] . info ) ) ;
info . dwStructSize = td [ i ] . dwStructSize ;
}
SetLastError ( 0xdeadbeef ) ;
ret = GetUrlCacheConfigInfoA ( td [ i ] . info , NULL , td [ i ] . flags ) ;
ok ( ret = = td [ i ] . ret , " %d: expected %d, got %d \n " , i , td [ i ] . ret , ret ) ;
if ( ! ret )
ok ( GetLastError ( ) = = td [ i ] . error , " %d: expected %u, got %u \n " , i , td [ i ] . error , GetLastError ( ) ) ;
else
{
char path [ MAX_PATH ] , path_win8 [ MAX_PATH ] ;
get_cache_path ( td [ i ] . flags , path , path_win8 ) ;
ok ( info . dwStructSize = = td [ i ] . dwStructSize , " got %u \n " , info . dwStructSize ) ;
ok ( ! lstrcmpA ( info . u . s . CachePath , path ) | | ! lstrcmpA ( info . u . s . CachePath , path_win8 ) ,
" %d: expected %s or %s, got %s \n " , i , path , path_win8 , info . u . s . CachePath ) ;
}
}
}
2008-03-12 14:28:04 +01:00
START_TEST ( urlcache )
{
2008-05-22 10:38:29 +02:00
HMODULE hdll ;
hdll = GetModuleHandleA ( " wininet.dll " ) ;
2010-10-19 10:44:03 +02:00
if ( ! GetProcAddress ( hdll , " InternetGetCookieExW " ) ) {
win_skip ( " Too old IE (older than 6.0) \n " ) ;
return ;
}
2012-10-03 12:29:15 +02:00
if ( ! GetProcAddress ( hdll , " InternetGetSecurityInfoByURL " ) ) /* < IE7 */
old_ie = TRUE ;
2010-10-19 10:44:03 +02:00
2013-11-18 09:58:13 +01:00
if ( GetProcAddress ( hdll , " CreateUrlCacheEntryExW " ) ) {
trace ( " Running tests on IE10 or newer \n " ) ;
ie10_cache = TRUE ;
}
2008-05-22 10:38:29 +02:00
pDeleteUrlCacheEntryA = ( void * ) GetProcAddress ( hdll , " DeleteUrlCacheEntryA " ) ;
pUnlockUrlCacheEntryFileA = ( void * ) GetProcAddress ( hdll , " UnlockUrlCacheEntryFileA " ) ;
2008-03-12 14:28:04 +01:00
test_urlcacheA ( ) ;
2013-04-01 13:48:23 +02:00
test_urlcacheW ( ) ;
2008-05-08 20:14:41 +02:00
test_FindCloseUrlCache ( ) ;
2009-05-13 14:01:18 +02:00
test_GetDiskInfoA ( ) ;
2014-07-16 11:06:24 +02:00
test_trailing_slash ( ) ;
2019-01-09 05:50:23 +01:00
test_GetUrlCacheConfigInfo ( ) ;
2008-03-12 14:28:04 +01:00
}