From 43a42f108af6bcbd91f2672731c3047c26213af1 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 22 Oct 2012 15:40:17 +0200 Subject: Imported WebKit commit 302e7806bff028bd1167a1ec7c86a1ee00ecfb49 (http://svn.webkit.org/repository/webkit/trunk@132067) New snapshot that fixes build without QtWidgets --- .../chromium/tests/DeferredImageDecoderTest.cpp | 102 +++++++++++++++++++++ .../chromium/tests/IDBAbortOnCorruptTest.cpp | 1 + Source/WebKit/chromium/tests/IDBFakeBackingStore.h | 2 +- Source/WebKit/chromium/tests/LocaleMacTest.cpp | 52 +++++++++++ Source/WebKit/chromium/tests/LocaleWinTest.cpp | 29 ++++++ .../WebKit/chromium/tests/LocalizedDateICUTest.cpp | 48 ++++++++++ Source/WebKit/chromium/tests/MockImageDecoder.h | 61 ++++++++++++ 7 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 Source/WebKit/chromium/tests/DeferredImageDecoderTest.cpp create mode 100644 Source/WebKit/chromium/tests/MockImageDecoder.h (limited to 'Source/WebKit/chromium/tests') diff --git a/Source/WebKit/chromium/tests/DeferredImageDecoderTest.cpp b/Source/WebKit/chromium/tests/DeferredImageDecoderTest.cpp new file mode 100644 index 000000000..482549805 --- /dev/null +++ b/Source/WebKit/chromium/tests/DeferredImageDecoderTest.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2012 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "DeferredImageDecoder.h" + +#include "ImageDecodingStore.h" +#include "MockImageDecoder.h" +#include "NativeImageSkia.h" +#include "SkCanvas.h" +#include "SkDevice.h" +#include "SkPicture.h" +#include + +using namespace WebCore; + +namespace { + +class DeferredImageDecoderTest : public ::testing::Test { +public: + virtual void SetUp() + { + ImageDecodingStore::initializeOnMainThread(); + m_actualDecoder = new MockImageDecoder(); + m_actualDecoder->setSize(600, 613); + m_lazyDecoder = DeferredImageDecoder::createForTesting(adoptPtr(m_actualDecoder)); + m_canvas.setDevice(new SkDevice(SkBitmap::kARGB_8888_Config, 100, 100))->unref(); + } + + virtual void TearDown() + { + ImageDecodingStore::shutdown(); + } + +protected: + // Don't own this but saves the pointer to query states. + MockImageDecoder* m_actualDecoder; + OwnPtr m_lazyDecoder; + SkPicture m_picture; + SkCanvas m_canvas; +}; + +TEST_F(DeferredImageDecoderTest, drawIntoSkPicture) +{ + OwnPtr image(adoptPtr(m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage())); + EXPECT_EQ(m_actualDecoder->size().width(), image->bitmap().width()); + EXPECT_EQ(m_actualDecoder->size().height(), image->bitmap().height()); + EXPECT_FALSE(image->bitmap().isNull()); + EXPECT_TRUE(image->bitmap().isImmutable()); + + SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); + tempCanvas->drawBitmap(image->bitmap(), 0, 0); + m_picture.endRecording(); + EXPECT_EQ(0, m_actualDecoder->frameBufferRequestCount()); + + m_canvas.drawPicture(m_picture); + EXPECT_EQ(1, m_actualDecoder->frameBufferRequestCount()); +} + +TEST_F(DeferredImageDecoderTest, drawScaledIntoSkPicture) +{ + OwnPtr image(adoptPtr(m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage())); + SkBitmap scaledBitmap = image->resizedBitmap(SkISize::Make(50, 51), SkIRect::MakeWH(50, 51)); + EXPECT_FALSE(scaledBitmap.isNull()); + EXPECT_TRUE(scaledBitmap.isImmutable()); + EXPECT_EQ(50, scaledBitmap.width()); + EXPECT_EQ(51, scaledBitmap.height()); + EXPECT_EQ(0, m_actualDecoder->frameBufferRequestCount()); + + SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); + tempCanvas->drawBitmap(scaledBitmap, 0, 0); + m_picture.endRecording(); + EXPECT_EQ(0, m_actualDecoder->frameBufferRequestCount()); + + m_canvas.drawPicture(m_picture); + EXPECT_EQ(1, m_actualDecoder->frameBufferRequestCount()); +} + +} // namespace diff --git a/Source/WebKit/chromium/tests/IDBAbortOnCorruptTest.cpp b/Source/WebKit/chromium/tests/IDBAbortOnCorruptTest.cpp index cd2a07649..2be4e567e 100644 --- a/Source/WebKit/chromium/tests/IDBAbortOnCorruptTest.cpp +++ b/Source/WebKit/chromium/tests/IDBAbortOnCorruptTest.cpp @@ -24,6 +24,7 @@ */ #include "config.h" +#include "IDBCallbacks.h" #include "IDBCursorBackendInterface.h" #include "IDBDatabaseBackendInterface.h" #include "IDBDatabaseCallbacks.h" diff --git a/Source/WebKit/chromium/tests/IDBFakeBackingStore.h b/Source/WebKit/chromium/tests/IDBFakeBackingStore.h index c59dce675..45cdd1cb2 100644 --- a/Source/WebKit/chromium/tests/IDBFakeBackingStore.h +++ b/Source/WebKit/chromium/tests/IDBFakeBackingStore.h @@ -33,7 +33,7 @@ namespace WebCore { class IDBFakeBackingStore : public IDBBackingStore { public: virtual void getDatabaseNames(Vector& foundNames) OVERRIDE { } - virtual bool getIDBDatabaseMetaData(const String& name, String& foundStringVersion, int64_t& foundIntVersion, int64_t& foundId, int64_t& maxObjectStoreId) OVERRIDE { return false; } + virtual bool getIDBDatabaseMetaData(const String& name, IDBDatabaseMetadata*) OVERRIDE { return false; } virtual bool createIDBDatabaseMetaData(const String& name, const String& version, int64_t intVersion, int64_t& rowId) OVERRIDE { return true; } virtual bool updateIDBDatabaseMetaData(Transaction*, int64_t rowId, const String& version) OVERRIDE { return false; } virtual bool updateIDBDatabaseIntVersion(Transaction*, int64_t rowId, int64_t version) OVERRIDE { return false; } diff --git a/Source/WebKit/chromium/tests/LocaleMacTest.cpp b/Source/WebKit/chromium/tests/LocaleMacTest.cpp index 449776195..91482d94d 100644 --- a/Source/WebKit/chromium/tests/LocaleMacTest.cpp +++ b/Source/WebKit/chromium/tests/LocaleMacTest.cpp @@ -120,6 +120,12 @@ protected: #endif #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) + String monthFormat(const String& localeString) + { + OwnPtr locale = LocaleMac::create(localeString); + return locale->monthFormat(); + } + String timeFormat(const String& localeString) { OwnPtr locale = LocaleMac::create(localeString); @@ -132,6 +138,18 @@ protected: return locale->shortTimeFormat(); } + String shortMonthLabel(const String& localeString, unsigned index) + { + OwnPtr locale = LocaleMac::create(localeString); + return locale->shortMonthLabels()[index]; + } + + String shortStandAloneMonthLabel(const String& localeString, unsigned index) + { + OwnPtr locale = LocaleMac::create(localeString); + return locale->shortStandAloneMonthLabels()[index]; + } + String timeAMPMLabel(const String& localeString, unsigned index) { OwnPtr locale = LocaleMac::create(localeString); @@ -236,6 +254,16 @@ TEST_F(LocaleMacTest, isRTL) #endif #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) +TEST_F(LocaleMacTest, monthFormat) +{ + EXPECT_STREQ("MMM yyyy", monthFormat("en_US").utf8().data()); + EXPECT_STREQ("yyyy\xE5\xB9\xB4M\xE6\x9C\x88", monthFormat("ja_JP").utf8().data()); + + // fr_FR and ru return different results on OS versions. + // "MMM yyyy" "LLL yyyy" on 10.6 and 10.7 + // "MMM y" "LLL y" on 10.8 +} + TEST_F(LocaleMacTest, timeFormat) { EXPECT_STREQ("h:mm:ss a", timeFormat("en_US").utf8().data()); @@ -250,6 +278,30 @@ TEST_F(LocaleMacTest, shortTimeFormat) EXPECT_STREQ("H:mm", shortTimeFormat("ja_JP").utf8().data()); } +TEST_F(LocaleMacTest, shortMonthLabels) +{ + EXPECT_STREQ("Jan", shortMonthLabel("en_US", 0).utf8().data()); + EXPECT_STREQ("Jan", shortStandAloneMonthLabel("en_US", 0).utf8().data()); + EXPECT_STREQ("Dec", shortMonthLabel("en_US", 11).utf8().data()); + EXPECT_STREQ("Dec", shortStandAloneMonthLabel("en_US", 11).utf8().data()); + + EXPECT_STREQ("janv.", shortMonthLabel("fr_FR", 0).utf8().data()); + EXPECT_STREQ("janv.", shortStandAloneMonthLabel("fr_FR", 0).utf8().data()); + EXPECT_STREQ("d\xC3\xA9" "c.", shortMonthLabel("fr_FR", 11).utf8().data()); + EXPECT_STREQ("d\xC3\xA9" "c.", shortStandAloneMonthLabel("fr_FR", 11).utf8().data()); + + EXPECT_STREQ("1\xE6\x9C\x88", shortMonthLabel("ja_JP", 0).utf8().data()); + EXPECT_STREQ("1\xE6\x9C\x88", shortStandAloneMonthLabel("ja_JP", 0).utf8().data()); + EXPECT_STREQ("12\xE6\x9C\x88", shortMonthLabel("ja_JP", 11).utf8().data()); + EXPECT_STREQ("12\xE6\x9C\x88", shortStandAloneMonthLabel("ja_JP", 11).utf8().data()); + + EXPECT_STREQ("\xD0\xBC\xD0\xB0\xD1\x80\xD1\x82\xD0\xB0", shortMonthLabel("ru_RU", 2).utf8().data()); + EXPECT_STREQ("\xD0\xBC\xD0\xB0\xD1\x8F", shortMonthLabel("ru_RU", 4).utf8().data()); + // The ru_RU locale returns different stand-alone month labels on OS versions. + // "\xD0\xBC\xD0\xB0\xD1\x80\xD1\x82" "\xD0\xBC\xD0\xB0\xD0\xB9" on 10.6 and 10.7 + // "\xD0\x9C\xD0\xB0\xD1\x80\xD1\x82" "\xD0\x9C\xD0\xB0\xD0\xB9" on 10.8 +} + TEST_F(LocaleMacTest, timeAMPMLabels) { EXPECT_STREQ("AM", timeAMPMLabel("en_US", 0).utf8().data()); diff --git a/Source/WebKit/chromium/tests/LocaleWinTest.cpp b/Source/WebKit/chromium/tests/LocaleWinTest.cpp index 75af419dd..35f064aac 100644 --- a/Source/WebKit/chromium/tests/LocaleWinTest.cpp +++ b/Source/WebKit/chromium/tests/LocaleWinTest.cpp @@ -129,6 +129,12 @@ protected: #endif #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) + String monthFormat(LCID lcid) + { + OwnPtr locale = LocaleWin::create(lcid); + return locale->monthFormat(); + } + String timeFormat(LCID lcid) { OwnPtr locale = LocaleWin::create(lcid); @@ -141,6 +147,12 @@ protected: return locale->shortTimeFormat(); } + String shortMonthLabel(LCID lcid, unsigned index) + { + OwnPtr locale = LocaleWin::create(lcid); + return locale->shortMonthLabels()[index]; + } + String timeAMPMLabel(LCID lcid, unsigned index) { OwnPtr locale = LocaleWin::create(lcid); @@ -284,6 +296,13 @@ TEST_F(LocaleWinTest, dateFormat) EXPECT_STREQ("yyyy'-'''''MMMM'-'dd", LocaleWin::dateFormat("yyyy-''''MMMM-dd").utf8().data()); } +TEST_F(LocaleWinTest, monthFormat) +{ + EXPECT_STREQ("MMMM', 'yyyy", monthFormat(EnglishUS).utf8().data()); + EXPECT_STREQ("MMMM' 'yyyy", monthFormat(FrenchFR).utf8().data()); + EXPECT_STREQ("yyyy'\xE5\xB9\xB4'M'\xE6\x9C\x88'", monthFormat(JapaneseJP).utf8().data()); +} + TEST_F(LocaleWinTest, timeFormat) { EXPECT_STREQ("h:mm:ss a", timeFormat(EnglishUS).utf8().data()); @@ -298,6 +317,16 @@ TEST_F(LocaleWinTest, shortTimeFormat) EXPECT_STREQ("H:mm:ss", shortTimeFormat(JapaneseJP).utf8().data()); } +TEST_F(LocaleWinTest, shortMonthLabels) +{ + EXPECT_STREQ("Jan", shortMonthLabel(EnglishUS, 0).utf8().data()); + EXPECT_STREQ("Dec", shortMonthLabel(EnglishUS, 11).utf8().data()); + EXPECT_STREQ("janv.", shortMonthLabel(FrenchFR, 0).utf8().data()); + EXPECT_STREQ("d\xC3\xA9" "c.", shortMonthLabel(FrenchFR, 11).utf8().data()); + EXPECT_STREQ("1", shortMonthLabel(JapaneseJP, 0).utf8().data()); + EXPECT_STREQ("12", shortMonthLabel(JapaneseJP, 11).utf8().data()); +} + TEST_F(LocaleWinTest, timeAMPMLabels) { EXPECT_STREQ("AM", timeAMPMLabel(EnglishUS, 0).utf8().data()); diff --git a/Source/WebKit/chromium/tests/LocalizedDateICUTest.cpp b/Source/WebKit/chromium/tests/LocalizedDateICUTest.cpp index 771a3cbc0..88946e84d 100644 --- a/Source/WebKit/chromium/tests/LocalizedDateICUTest.cpp +++ b/Source/WebKit/chromium/tests/LocalizedDateICUTest.cpp @@ -88,6 +88,12 @@ protected: return Labels(labels); } + String monthFormat(const char* localeString) + { + OwnPtr locale = LocaleICU::create(localeString); + return locale->monthFormat(); + } + String localizedDateFormatText(const char* localeString) { OwnPtr locale = LocaleICU::create(localeString); @@ -100,6 +106,18 @@ protected: return locale->shortTimeFormat(); } + String shortMonthLabel(const char* localeString, unsigned index) + { + OwnPtr locale = LocaleICU::create(localeString); + return locale->shortMonthLabels()[index]; + } + + String shortStandAloneMonthLabel(const char* localeString, unsigned index) + { + OwnPtr locale = LocaleICU::create(localeString); + return locale->shortStandAloneMonthLabels()[index]; + } + Labels timeAMPMLabels(const char* localeString) { OwnPtr locale = LocaleICU::create(localeString); @@ -126,6 +144,13 @@ TEST_F(LocalizedDateICUTest, isRTL) EXPECT_FALSE(isRTL("**invalid**")); } +TEST_F(LocalizedDateICUTest, monthFormat) +{ + EXPECT_STREQ("MMM yyyy", monthFormat("en_US").utf8().data()); + EXPECT_STREQ("MMM yyyy", monthFormat("fr").utf8().data()); + EXPECT_STREQ("yyyy\xE5\xB9\xB4M\xE6\x9C\x88", monthFormat("ja").utf8().data()); +} + TEST_F(LocalizedDateICUTest, localizedDateFormatText) { // Note: EXPECT_EQ(String, String) doesn't print result as string. @@ -141,6 +166,29 @@ TEST_F(LocalizedDateICUTest, localizedShortDateFormatText) EXPECT_STREQ("H:mm", localizedShortDateFormatText("ja").utf8().data()); } +TEST_F(LocalizedDateICUTest, shortMonthLabels) +{ + EXPECT_STREQ("Jan", shortMonthLabel("en_US", 0).utf8().data()); + EXPECT_STREQ("Jan", shortStandAloneMonthLabel("en_US", 0).utf8().data()); + EXPECT_STREQ("Dec", shortMonthLabel("en_US", 11).utf8().data()); + EXPECT_STREQ("Dec", shortStandAloneMonthLabel("en_US", 11).utf8().data()); + + EXPECT_STREQ("janv.", shortMonthLabel("fr_FR", 0).utf8().data()); + EXPECT_STREQ("janv.", shortStandAloneMonthLabel("fr_FR", 0).utf8().data()); + EXPECT_STREQ("d\xC3\xA9" "c.", shortMonthLabel("fr_FR", 11).utf8().data()); + EXPECT_STREQ("d\xC3\xA9" "c.", shortStandAloneMonthLabel("fr_FR", 11).utf8().data()); + + EXPECT_STREQ("1\xE6\x9C\x88", shortMonthLabel("ja_JP", 0).utf8().data()); + EXPECT_STREQ("1\xE6\x9C\x88", shortStandAloneMonthLabel("ja_JP", 0).utf8().data()); + EXPECT_STREQ("12\xE6\x9C\x88", shortMonthLabel("ja_JP", 11).utf8().data()); + EXPECT_STREQ("12\xE6\x9C\x88", shortStandAloneMonthLabel("ja_JP", 11).utf8().data()); + + EXPECT_STREQ("\xD0\xBC\xD0\xB0\xD1\x80\xD1\x82\xD0\xB0", shortMonthLabel("ru_RU", 2).utf8().data()); + EXPECT_STREQ("\xD0\xBC\xD0\xB0\xD1\x80\xD1\x82", shortStandAloneMonthLabel("ru_RU", 2).utf8().data()); + EXPECT_STREQ("\xD0\xBC\xD0\xB0\xD1\x8F", shortMonthLabel("ru_RU", 4).utf8().data()); + EXPECT_STREQ("\xD0\xBC\xD0\xB0\xD0\xB9", shortStandAloneMonthLabel("ru_RU", 4).utf8().data()); +} + TEST_F(LocalizedDateICUTest, timeAMPMLabels) { EXPECT_EQ(labels("AM", "PM"), timeAMPMLabels("en_US")); diff --git a/Source/WebKit/chromium/tests/MockImageDecoder.h b/Source/WebKit/chromium/tests/MockImageDecoder.h new file mode 100644 index 000000000..5cf23744e --- /dev/null +++ b/Source/WebKit/chromium/tests/MockImageDecoder.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2012 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef MockImageDecoder_h + +#include "ImageDecoder.h" + +namespace WebCore { + +class MockImageDecoder : public ImageDecoder { +public: + MockImageDecoder() + : ImageDecoder(ImageSource::AlphaPremultiplied, ImageSource::GammaAndColorProfileApplied) + , m_frameBufferRequestCount(0) + { } + + virtual String filenameExtension() const + { + return "mock"; + } + + virtual ImageFrame* frameBufferAtIndex(size_t) + { + ++m_frameBufferRequestCount; + + m_frameBufferCache.resize(1); + m_frameBufferCache[0].setSize(size().width(), size().height()); + return &m_frameBufferCache[0]; + } + + int frameBufferRequestCount() const { return m_frameBufferRequestCount; } + +private: + int m_frameBufferRequestCount; +}; + +} // namespace WebCore + +#endif // MockImageDecoder_h -- cgit v1.2.1