Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; 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 "TestDrawTargetBase.h" |
michael@0 | 7 | #include <sstream> |
michael@0 | 8 | |
michael@0 | 9 | using namespace mozilla; |
michael@0 | 10 | using namespace mozilla::gfx; |
michael@0 | 11 | using namespace std; |
michael@0 | 12 | |
michael@0 | 13 | TestDrawTargetBase::TestDrawTargetBase() |
michael@0 | 14 | { |
michael@0 | 15 | REGISTER_TEST(TestDrawTargetBase, Initialized); |
michael@0 | 16 | REGISTER_TEST(TestDrawTargetBase, FillCompletely); |
michael@0 | 17 | REGISTER_TEST(TestDrawTargetBase, FillRect); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | void |
michael@0 | 21 | TestDrawTargetBase::Initialized() |
michael@0 | 22 | { |
michael@0 | 23 | VERIFY(mDT); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | void |
michael@0 | 27 | TestDrawTargetBase::FillCompletely() |
michael@0 | 28 | { |
michael@0 | 29 | mDT->FillRect(Rect(0, 0, DT_WIDTH, DT_HEIGHT), ColorPattern(Color(0, 0.5f, 0, 1.0f))); |
michael@0 | 30 | |
michael@0 | 31 | RefreshSnapshot(); |
michael@0 | 32 | |
michael@0 | 33 | VerifyAllPixels(Color(0, 0.5f, 0, 1.0f)); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | void |
michael@0 | 37 | TestDrawTargetBase::FillRect() |
michael@0 | 38 | { |
michael@0 | 39 | mDT->FillRect(Rect(0, 0, DT_WIDTH, DT_HEIGHT), ColorPattern(Color(0, 0.5f, 0, 1.0f))); |
michael@0 | 40 | mDT->FillRect(Rect(50, 50, 50, 50), ColorPattern(Color(0.5f, 0, 0, 1.0f))); |
michael@0 | 41 | |
michael@0 | 42 | RefreshSnapshot(); |
michael@0 | 43 | |
michael@0 | 44 | VerifyPixel(IntPoint(49, 49), Color(0, 0.5f, 0, 1.0f)); |
michael@0 | 45 | VerifyPixel(IntPoint(50, 50), Color(0.5f, 0, 0, 1.0f)); |
michael@0 | 46 | VerifyPixel(IntPoint(99, 99), Color(0.5f, 0, 0, 1.0f)); |
michael@0 | 47 | VerifyPixel(IntPoint(100, 100), Color(0, 0.5f, 0, 1.0f)); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | void |
michael@0 | 51 | TestDrawTargetBase::RefreshSnapshot() |
michael@0 | 52 | { |
michael@0 | 53 | RefPtr<SourceSurface> snapshot = mDT->Snapshot(); |
michael@0 | 54 | mDataSnapshot = snapshot->GetDataSurface(); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | void |
michael@0 | 58 | TestDrawTargetBase::VerifyAllPixels(const Color &aColor) |
michael@0 | 59 | { |
michael@0 | 60 | uint32_t *colVal = (uint32_t*)mDataSnapshot->GetData(); |
michael@0 | 61 | |
michael@0 | 62 | uint32_t expected = RGBAPixelFromColor(aColor); |
michael@0 | 63 | |
michael@0 | 64 | for (int y = 0; y < DT_HEIGHT; y++) { |
michael@0 | 65 | for (int x = 0; x < DT_WIDTH; x++) { |
michael@0 | 66 | if (colVal[y * (mDataSnapshot->Stride() / 4) + x] != expected) { |
michael@0 | 67 | LogMessage("VerifyAllPixels Failed\n"); |
michael@0 | 68 | mTestFailed = true; |
michael@0 | 69 | return; |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | void |
michael@0 | 76 | TestDrawTargetBase::VerifyPixel(const IntPoint &aPoint, mozilla::gfx::Color &aColor) |
michael@0 | 77 | { |
michael@0 | 78 | uint32_t *colVal = (uint32_t*)mDataSnapshot->GetData(); |
michael@0 | 79 | |
michael@0 | 80 | uint32_t expected = RGBAPixelFromColor(aColor); |
michael@0 | 81 | uint32_t rawActual = colVal[aPoint.y * (mDataSnapshot->Stride() / 4) + aPoint.x]; |
michael@0 | 82 | |
michael@0 | 83 | if (rawActual != expected) { |
michael@0 | 84 | stringstream message; |
michael@0 | 85 | uint32_t actb = rawActual & 0xFF; |
michael@0 | 86 | uint32_t actg = (rawActual & 0xFF00) >> 8; |
michael@0 | 87 | uint32_t actr = (rawActual & 0xFF0000) >> 16; |
michael@0 | 88 | uint32_t acta = (rawActual & 0xFF000000) >> 24; |
michael@0 | 89 | uint32_t expb = expected & 0xFF; |
michael@0 | 90 | uint32_t expg = (expected & 0xFF00) >> 8; |
michael@0 | 91 | uint32_t expr = (expected & 0xFF0000) >> 16; |
michael@0 | 92 | uint32_t expa = (expected & 0xFF000000) >> 24; |
michael@0 | 93 | |
michael@0 | 94 | message << "Verify Pixel (" << aPoint.x << "x" << aPoint.y << ") Failed." |
michael@0 | 95 | " Expected (" << expr << "," << expg << "," << expb << "," << expa << ") " |
michael@0 | 96 | " Got (" << actr << "," << actg << "," << actb << "," << acta << ")\n"; |
michael@0 | 97 | |
michael@0 | 98 | LogMessage(message.str()); |
michael@0 | 99 | mTestFailed = true; |
michael@0 | 100 | return; |
michael@0 | 101 | } |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | uint32_t |
michael@0 | 105 | TestDrawTargetBase::RGBAPixelFromColor(const Color &aColor) |
michael@0 | 106 | { |
michael@0 | 107 | return uint8_t((aColor.b * 255) + 0.5f) | uint8_t((aColor.g * 255) + 0.5f) << 8 | |
michael@0 | 108 | uint8_t((aColor.r * 255) + 0.5f) << 16 | uint8_t((aColor.a * 255) + 0.5f) << 24; |
michael@0 | 109 | } |