Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * Test: |
michael@0 | 8 | */ |
michael@0 | 9 | |
michael@0 | 10 | #include "../TestHarness.h" |
michael@0 | 11 | #include "nsEmbedString.h" |
michael@0 | 12 | #include "nsILocalFileWin.h" |
michael@0 | 13 | #include <windows.h> |
michael@0 | 14 | |
michael@0 | 15 | #define BUFFSIZE 512 |
michael@0 | 16 | |
michael@0 | 17 | nsresult TestWinAttribs() |
michael@0 | 18 | { |
michael@0 | 19 | |
michael@0 | 20 | nsresult rv; |
michael@0 | 21 | |
michael@0 | 22 | // File variables |
michael@0 | 23 | HANDLE hIndexed; |
michael@0 | 24 | nsCOMPtr<nsIFile> localFile; |
michael@0 | 25 | WCHAR filePath[MAX_PATH]; |
michael@0 | 26 | |
michael@0 | 27 | // Create and open temporary file |
michael@0 | 28 | hIndexed = CreateFileW(L".\\indexbit.txt", |
michael@0 | 29 | GENERIC_READ | GENERIC_WRITE, |
michael@0 | 30 | 0, |
michael@0 | 31 | nullptr, |
michael@0 | 32 | CREATE_ALWAYS, |
michael@0 | 33 | FILE_ATTRIBUTE_NORMAL, //FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, not supported by cf |
michael@0 | 34 | nullptr); |
michael@0 | 35 | |
michael@0 | 36 | if(hIndexed == INVALID_HANDLE_VALUE) |
michael@0 | 37 | { |
michael@0 | 38 | fail("Test Win Attribs: Creating Test File"); |
michael@0 | 39 | return NS_ERROR_FAILURE; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | CloseHandle(hIndexed); |
michael@0 | 43 | |
michael@0 | 44 | GetFullPathNameW((LPCWSTR)L".\\indexbit.txt", |
michael@0 | 45 | MAX_PATH, filePath, nullptr); |
michael@0 | 46 | |
michael@0 | 47 | //wprintf(filePath); |
michael@0 | 48 | //wprintf(L"\n"); |
michael@0 | 49 | |
michael@0 | 50 | rv = NS_NewLocalFile(nsEmbedString(filePath), false, |
michael@0 | 51 | getter_AddRefs(localFile)); |
michael@0 | 52 | if (NS_FAILED(rv)) |
michael@0 | 53 | { |
michael@0 | 54 | fail("Test Win Attribs: Opening Test File"); |
michael@0 | 55 | DeleteFileW(filePath); |
michael@0 | 56 | return rv; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | nsCOMPtr<nsILocalFileWin> localFileWin(do_QueryInterface(localFile)); |
michael@0 | 60 | |
michael@0 | 61 | DWORD dwAttrs = GetFileAttributesW(filePath); |
michael@0 | 62 | if (dwAttrs == INVALID_FILE_ATTRIBUTES) |
michael@0 | 63 | { |
michael@0 | 64 | fail("Test Win Attribs: GetFileAttributesW - couldn't find our temp file."); |
michael@0 | 65 | DeleteFileW(filePath); |
michael@0 | 66 | return NS_ERROR_FAILURE; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | dwAttrs |= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; |
michael@0 | 70 | SetFileAttributesW(filePath, dwAttrs); |
michael@0 | 71 | |
michael@0 | 72 | uint32_t attribs = 0; |
michael@0 | 73 | rv = localFileWin->GetFileAttributesWin(&attribs); |
michael@0 | 74 | |
michael@0 | 75 | if (NS_FAILED(rv)) |
michael@0 | 76 | { |
michael@0 | 77 | fail("Test Win Attribs: GetFileAttributesWin failed to GET attributes. (1)"); |
michael@0 | 78 | DeleteFileW(filePath); |
michael@0 | 79 | return NS_ERROR_FAILURE; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | if (attribs & nsILocalFileWin::WFA_SEARCH_INDEXED) |
michael@0 | 83 | { |
michael@0 | 84 | fail("Test Win Attribs: GetFileAttributesWin attributed did not match. (2)"); |
michael@0 | 85 | DeleteFileW(filePath); |
michael@0 | 86 | return NS_ERROR_FAILURE; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | dwAttrs &= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; |
michael@0 | 90 | SetFileAttributesW(filePath, dwAttrs); |
michael@0 | 91 | |
michael@0 | 92 | rv = localFileWin->GetFileAttributesWin(&attribs); |
michael@0 | 93 | |
michael@0 | 94 | if (NS_FAILED(rv)) |
michael@0 | 95 | { |
michael@0 | 96 | fail("Test Win Attribs: GetFileAttributesWin failed to GET attributes. (3)"); |
michael@0 | 97 | DeleteFileW(filePath); |
michael@0 | 98 | return NS_ERROR_FAILURE; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | if (!(attribs & nsILocalFileWin::WFA_SEARCH_INDEXED)) |
michael@0 | 102 | { |
michael@0 | 103 | fail("Test Win Attribs: GetFileAttributesWin attributed did not match. (4)"); |
michael@0 | 104 | DeleteFileW(filePath); |
michael@0 | 105 | return NS_ERROR_FAILURE; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | dwAttrs &= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; |
michael@0 | 109 | SetFileAttributesW(filePath, dwAttrs); |
michael@0 | 110 | |
michael@0 | 111 | attribs = nsILocalFileWin::WFA_SEARCH_INDEXED; |
michael@0 | 112 | rv = localFileWin->SetFileAttributesWin(attribs); |
michael@0 | 113 | |
michael@0 | 114 | dwAttrs = GetFileAttributesW(filePath); |
michael@0 | 115 | |
michael@0 | 116 | if (NS_FAILED(rv)) |
michael@0 | 117 | { |
michael@0 | 118 | fail("Test Win Attribs: GetFileAttributesWin failed to SET attributes. (5)"); |
michael@0 | 119 | DeleteFileW(filePath); |
michael@0 | 120 | return NS_ERROR_FAILURE; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | if (dwAttrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) |
michael@0 | 124 | { |
michael@0 | 125 | fail("Test Win Attribs: SetFileAttributesWin attributed did not match. (6)"); |
michael@0 | 126 | DeleteFileW(filePath); |
michael@0 | 127 | return NS_ERROR_FAILURE; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | dwAttrs |= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; |
michael@0 | 131 | SetFileAttributesW(filePath, dwAttrs); |
michael@0 | 132 | |
michael@0 | 133 | attribs = 0; |
michael@0 | 134 | rv = localFileWin->SetFileAttributesWin(attribs); |
michael@0 | 135 | |
michael@0 | 136 | dwAttrs = GetFileAttributesW(filePath); |
michael@0 | 137 | |
michael@0 | 138 | if (NS_FAILED(rv)) |
michael@0 | 139 | { |
michael@0 | 140 | fail("Test Win Attribs: GetFileAttributesWin failed to SET attributes. (7)"); |
michael@0 | 141 | DeleteFileW(filePath); |
michael@0 | 142 | return NS_ERROR_FAILURE; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | if (!(dwAttrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)) |
michael@0 | 146 | { |
michael@0 | 147 | fail("Test Win Attribs: SetFileAttributesWin attributed did not match. (8)"); |
michael@0 | 148 | DeleteFileW(filePath); |
michael@0 | 149 | return NS_ERROR_FAILURE; |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | DeleteFileW(filePath); |
michael@0 | 153 | |
michael@0 | 154 | passed("Test Win Attribs: passed tests."); |
michael@0 | 155 | |
michael@0 | 156 | return NS_OK; |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | int main(int argc, char** argv) |
michael@0 | 160 | { |
michael@0 | 161 | ScopedXPCOM xpcom("WinFileAttributes"); |
michael@0 | 162 | if (xpcom.failed()) |
michael@0 | 163 | return 1; |
michael@0 | 164 | |
michael@0 | 165 | int rv = 0; |
michael@0 | 166 | |
michael@0 | 167 | if(NS_FAILED(TestWinAttribs())) |
michael@0 | 168 | rv = 1; |
michael@0 | 169 | |
michael@0 | 170 | return rv; |
michael@0 | 171 | |
michael@0 | 172 | } |
michael@0 | 173 |