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 | #include "gtest/gtest.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "BufferUnrotate.h" |
michael@0 | 9 | |
michael@0 | 10 | static unsigned char* GenerateBuffer(int bytesPerPixel, |
michael@0 | 11 | int width, int height, |
michael@0 | 12 | int stride, int xBoundary, int yBoundary) |
michael@0 | 13 | { |
michael@0 | 14 | unsigned char* buffer = new unsigned char[stride*height]; |
michael@0 | 15 | for (int y = 0; y < height; y++) { |
michael@0 | 16 | for (int x = 0; x < width; x++) { |
michael@0 | 17 | int pos = ((yBoundary + y) % height) * stride + |
michael@0 | 18 | ((xBoundary + x) % width) * bytesPerPixel; |
michael@0 | 19 | for (int i = 0; i < bytesPerPixel; i++) { |
michael@0 | 20 | buffer[pos+i] = (x+y+i*2)%256; |
michael@0 | 21 | } |
michael@0 | 22 | } |
michael@0 | 23 | } |
michael@0 | 24 | return buffer; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | static bool CheckBuffer(unsigned char* buffer, int bytesPerPixel, |
michael@0 | 28 | int width, int height, int stride) |
michael@0 | 29 | { |
michael@0 | 30 | int xBoundary = 0; |
michael@0 | 31 | int yBoundary = 0; |
michael@0 | 32 | for (int y = 0; y < height; y++) { |
michael@0 | 33 | for (int x = 0; x < width; x++) { |
michael@0 | 34 | int pos = ((yBoundary + y) % height) * stride + |
michael@0 | 35 | ((xBoundary + x) % width) * bytesPerPixel; |
michael@0 | 36 | for (int i = 0; i < bytesPerPixel; i++) { |
michael@0 | 37 | if (buffer[pos+i] != (x+y+i*2)%256) { |
michael@0 | 38 | printf("Buffer differs at %i, %i, is %i\n", x, y, (int)buffer[pos+i]); |
michael@0 | 39 | return false; |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | } |
michael@0 | 44 | return true; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | TEST(Gfx, BufferUnrotateHorizontal) { |
michael@0 | 48 | const int NUM_OF_TESTS = 8; |
michael@0 | 49 | int bytesPerPixelList[2] = {2,4}; |
michael@0 | 50 | int width[NUM_OF_TESTS] = {100, 100, 99, 99, 100, 100, 99, 99}; |
michael@0 | 51 | int height[NUM_OF_TESTS] = {100, 99, 100, 99, 100, 99, 100, 99}; |
michael@0 | 52 | int xBoundary[NUM_OF_TESTS] = {30, 30, 30, 30, 31, 31, 31, 31}; |
michael@0 | 53 | int yBoundary[NUM_OF_TESTS] = {0, 0, 0, 0}; |
michael@0 | 54 | |
michael@0 | 55 | for (int bytesPerId = 0; bytesPerId < 2; bytesPerId++) { |
michael@0 | 56 | int bytesPerPixel = bytesPerPixelList[bytesPerId]; |
michael@0 | 57 | int stride = 256 * bytesPerPixel; |
michael@0 | 58 | for (int testId = 0; testId < NUM_OF_TESTS; testId++) { |
michael@0 | 59 | unsigned char* buffer = GenerateBuffer(bytesPerPixel, |
michael@0 | 60 | width[testId], height[testId], stride, |
michael@0 | 61 | xBoundary[testId], yBoundary[testId]); |
michael@0 | 62 | BufferUnrotate(buffer, |
michael@0 | 63 | width[testId] * bytesPerPixel, height[testId], stride, |
michael@0 | 64 | xBoundary[testId] * bytesPerPixel, yBoundary[testId]); |
michael@0 | 65 | |
michael@0 | 66 | EXPECT_TRUE(CheckBuffer(buffer, bytesPerPixel, |
michael@0 | 67 | width[testId], height[testId], stride)); |
michael@0 | 68 | delete[] buffer; |
michael@0 | 69 | } |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | TEST(Gfx, BufferUnrotateVertical) { |
michael@0 | 74 | const int NUM_OF_TESTS = 8; |
michael@0 | 75 | int bytesPerPixelList[2] = {2,4}; |
michael@0 | 76 | int width[NUM_OF_TESTS] = {100, 100, 99, 99, 100, 100, 99, 99}; |
michael@0 | 77 | int height[NUM_OF_TESTS] = {100, 99, 100, 99, 100, 99, 100, 99}; |
michael@0 | 78 | int xBoundary[NUM_OF_TESTS] = {0, 0, 0, 0}; |
michael@0 | 79 | int yBoundary[NUM_OF_TESTS] = {30, 30, 30, 30, 31, 31, 31, 31}; |
michael@0 | 80 | |
michael@0 | 81 | for (int bytesPerId = 0; bytesPerId < 2; bytesPerId++) { |
michael@0 | 82 | int bytesPerPixel = bytesPerPixelList[bytesPerId]; |
michael@0 | 83 | int stride = 256 * bytesPerPixel; |
michael@0 | 84 | for (int testId = 0; testId < NUM_OF_TESTS; testId++) { |
michael@0 | 85 | unsigned char* buffer = GenerateBuffer(bytesPerPixel, |
michael@0 | 86 | width[testId], height[testId], stride, |
michael@0 | 87 | xBoundary[testId], yBoundary[testId]); |
michael@0 | 88 | BufferUnrotate(buffer, width[testId] * bytesPerPixel, |
michael@0 | 89 | height[testId], stride, |
michael@0 | 90 | xBoundary[testId] * bytesPerPixel, yBoundary[testId]); |
michael@0 | 91 | |
michael@0 | 92 | EXPECT_TRUE(CheckBuffer(buffer, bytesPerPixel, |
michael@0 | 93 | width[testId], height[testId], stride)); |
michael@0 | 94 | delete[] buffer; |
michael@0 | 95 | } |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | |
michael@0 | 100 | TEST(Gfx, BufferUnrotateBoth) { |
michael@0 | 101 | const int NUM_OF_TESTS = 16; |
michael@0 | 102 | int bytesPerPixelList[2] = {2,4}; |
michael@0 | 103 | int width[NUM_OF_TESTS] = {100, 100, 99, 99, 100, 100, 99, 99, 100, 100, 99, 99, 100, 100, 99, 99}; |
michael@0 | 104 | int height[NUM_OF_TESTS] = {100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99, 100, 99}; |
michael@0 | 105 | int xBoundary[NUM_OF_TESTS] = {30, 30, 30, 30, 31, 31, 31, 31, 30, 30, 30, 30, 31, 31, 31, 31}; |
michael@0 | 106 | int yBoundary[NUM_OF_TESTS] = {30, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31}; |
michael@0 | 107 | |
michael@0 | 108 | for (int bytesPerId = 0; bytesPerId < 2; bytesPerId++) { |
michael@0 | 109 | int bytesPerPixel = bytesPerPixelList[bytesPerId]; |
michael@0 | 110 | int stride = 256 * bytesPerPixel; |
michael@0 | 111 | for (int testId = 0; testId < NUM_OF_TESTS; testId++) { |
michael@0 | 112 | unsigned char* buffer = GenerateBuffer(bytesPerPixel, |
michael@0 | 113 | width[testId], height[testId], stride, |
michael@0 | 114 | xBoundary[testId], yBoundary[testId]); |
michael@0 | 115 | BufferUnrotate(buffer, |
michael@0 | 116 | width[testId] * bytesPerPixel, height[testId], stride, |
michael@0 | 117 | xBoundary[testId] * bytesPerPixel, yBoundary[testId]); |
michael@0 | 118 | |
michael@0 | 119 | EXPECT_TRUE(CheckBuffer(buffer, bytesPerPixel, |
michael@0 | 120 | width[testId], height[testId], stride)); |
michael@0 | 121 | delete[] buffer; |
michael@0 | 122 | } |
michael@0 | 123 | } |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | TEST(Gfx, BufferUnrotateUneven) { |
michael@0 | 127 | const int NUM_OF_TESTS = 16; |
michael@0 | 128 | int bytesPerPixelList[2] = {2,4}; |
michael@0 | 129 | int width[NUM_OF_TESTS] = {10, 100, 99, 39, 100, 40, 99, 39, 100, 50, 39, 99, 74, 60, 99, 39}; |
michael@0 | 130 | int height[NUM_OF_TESTS] = {100, 39, 10, 99, 10, 99, 40, 99, 73, 39, 100, 39, 67, 99, 84, 99}; |
michael@0 | 131 | int xBoundary[NUM_OF_TESTS] = {0, 0, 30, 30, 99, 31, 0, 31, 30, 30, 30, 30, 31, 31, 31, 38}; |
michael@0 | 132 | int yBoundary[NUM_OF_TESTS] = {30, 30, 0, 30, 0, 30, 0, 30, 31, 31, 31, 31, 31, 31, 31, 98}; |
michael@0 | 133 | |
michael@0 | 134 | for (int bytesPerId = 0; bytesPerId < 2; bytesPerId++) { |
michael@0 | 135 | int bytesPerPixel = bytesPerPixelList[bytesPerId]; |
michael@0 | 136 | int stride = 256 * bytesPerPixel; |
michael@0 | 137 | for (int testId = 0; testId < NUM_OF_TESTS; testId++) { |
michael@0 | 138 | unsigned char* buffer = GenerateBuffer(bytesPerPixel, |
michael@0 | 139 | width[testId], height[testId], stride, |
michael@0 | 140 | xBoundary[testId], yBoundary[testId]); |
michael@0 | 141 | BufferUnrotate(buffer, |
michael@0 | 142 | width[testId]*bytesPerPixel, height[testId], stride, |
michael@0 | 143 | xBoundary[testId]*bytesPerPixel, yBoundary[testId]); |
michael@0 | 144 | |
michael@0 | 145 | EXPECT_TRUE(CheckBuffer(buffer, bytesPerPixel, width[testId], height[testId], stride)); |
michael@0 | 146 | delete[] buffer; |
michael@0 | 147 | } |
michael@0 | 148 | } |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 |