diff options
Diffstat (limited to 'WebKit/chromium/tests')
24 files changed, 0 insertions, 4181 deletions
diff --git a/WebKit/chromium/tests/ArenaTestHelpers.h b/WebKit/chromium/tests/ArenaTestHelpers.h deleted file mode 100644 index 70936e5..0000000 --- a/WebKit/chromium/tests/ArenaTestHelpers.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2010 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 ArenaTestHelpers_h -#define ArenaTestHelpers_h - -#include "PODArena.h" -#include <gtest/gtest.h> -#include <wtf/NotFound.h> -#include <wtf/Vector.h> - -namespace WebCore { -namespace ArenaTestHelpers { - -// An allocator for the PODArena which tracks the regions which have -// been allocated. -class TrackedAllocator : public PODArena::FastMallocAllocator { -public: - static PassRefPtr<TrackedAllocator> create() - { - return adoptRef(new TrackedAllocator); - } - - virtual void* allocate(size_t size) - { - void* result = PODArena::FastMallocAllocator::allocate(size); - m_allocatedRegions.append(result); - return result; - } - - virtual void free(void* ptr) - { - size_t slot = m_allocatedRegions.find(ptr); - ASSERT_NE(slot, notFound); - m_allocatedRegions.remove(slot); - PODArena::FastMallocAllocator::free(ptr); - } - - bool isEmpty() const - { - return !numRegions(); - } - - int numRegions() const - { - return m_allocatedRegions.size(); - } - -private: - TrackedAllocator() { } - Vector<void*> m_allocatedRegions; -}; - -} // namespace ArenaTestHelpers -} // namespace WebCore - -#endif // ArenaTestHelpers_h diff --git a/WebKit/chromium/tests/DragImageTest.cpp b/WebKit/chromium/tests/DragImageTest.cpp deleted file mode 100644 index 8ce6fe2..0000000 --- a/WebKit/chromium/tests/DragImageTest.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (C) 2010 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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 <gtest/gtest.h> - -#include "DragImage.h" -#include "Image.h" -#include "NativeImageSkia.h" - -using namespace WebCore; - -namespace { - -class TestImage : public Image { -public: - - static PassRefPtr<TestImage> create(const IntSize& size) - { - return adoptRef(new TestImage(size)); - } - - explicit TestImage(const IntSize& size) - : Image(0) - , m_size(size) - { - m_nativeImage = new NativeImageSkia(); - m_nativeImage->setConfig(SkBitmap::kARGB_8888_Config, - size.width(), size.height(), 0); - m_nativeImage->allocPixels(); - } - - virtual ~TestImage() - { - delete m_nativeImage; - } - - virtual IntSize size() const - { - return m_size; - } - - virtual NativeImagePtr nativeImageForCurrentFrame() - { - if (m_size.isZero()) - return 0; - - return m_nativeImage; - } - - // Stub implementations of pure virtual Image functions. - virtual void destroyDecodedData(bool) - { - } - - virtual unsigned int decodedSize() const - { - return 0u; - } - - virtual void draw(WebCore::GraphicsContext*, const WebCore::FloatRect&, - const WebCore::FloatRect&, WebCore::ColorSpace, - WebCore::CompositeOperator) - { - } - -private: - - IntSize m_size; - - NativeImagePtr m_nativeImage; -}; - -TEST(DragImageTest, NullHandling) -{ - EXPECT_FALSE(createDragImageFromImage(0)); - - deleteDragImage(0); - EXPECT_TRUE(dragImageSize(0).isZero()); - EXPECT_FALSE(scaleDragImage(0, FloatSize(0.5, 0.5))); - EXPECT_FALSE(dissolveDragImageToFraction(0, 0.5)); - EXPECT_FALSE(createDragImageFromImage(0)); - EXPECT_FALSE(createDragImageIconForCachedImage(0)); -} - -TEST(DragImageTest, NonNullHandling) -{ - RefPtr<TestImage> testImage(TestImage::create(IntSize(2, 2))); - DragImageRef dragImage = createDragImageFromImage(testImage.get()); - ASSERT_TRUE(dragImage); - - dragImage = scaleDragImage(dragImage, FloatSize(0.5, 0.5)); - ASSERT_TRUE(dragImage); - IntSize size = dragImageSize(dragImage); - EXPECT_EQ(1, size.width()); - EXPECT_EQ(1, size.height()); - - dragImage = dissolveDragImageToFraction(dragImage, 0.5); - ASSERT_TRUE(dragImage); - - deleteDragImage(dragImage); -} - -TEST(DragImageTest, CreateDragImage) -{ - { - // Tests that the DrageImage implementation doesn't choke on null values - // of nativeImageForCurrentFrame(). - RefPtr<TestImage> testImage(TestImage::create(IntSize())); - EXPECT_FALSE(createDragImageFromImage(testImage.get())); - } - - { - // Tests that the drag image is a deep copy. - RefPtr<TestImage> testImage(TestImage::create(IntSize(1, 1))); - DragImageRef dragImage = createDragImageFromImage(testImage.get()); - ASSERT_TRUE(dragImage); - SkAutoLockPixels lock1(*dragImage), lock2(*(testImage->nativeImageForCurrentFrame())); - EXPECT_NE(dragImage->getPixels(), testImage->nativeImageForCurrentFrame()->getPixels()); - } -} - -} // anonymous namespace diff --git a/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp b/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp deleted file mode 100644 index 1b7f156..0000000 --- a/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (C) 2010 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 "IDBBindingUtilities.h" -#include "IDBKey.h" -#include "IDBKeyPath.h" -#include "SerializedScriptValue.h" - -#include <gtest/gtest.h> -#include <wtf/Vector.h> - -#if ENABLE(INDEXED_DATABASE) - -using namespace WebCore; - -namespace { - -class LocalContext { -public: - LocalContext() - : m_context(v8::Context::New()) - { - m_context->Enter(); - } - - virtual ~LocalContext() - { - m_context->Exit(); - m_context.Dispose(); - } - -private: - v8::Locker m_locker; - v8::HandleScope m_scope; - v8::Persistent<v8::Context> m_context; -}; - -PassRefPtr<IDBKey> checkKeyFromValueAndKeyPathInternal(SerializedScriptValue* value, const String& keyPath) -{ - Vector<IDBKeyPathElement> idbKeyPath; - IDBKeyPathParseError parseError; - IDBParseKeyPath(keyPath, idbKeyPath, parseError); - EXPECT_EQ(IDBKeyPathParseErrorNone, parseError); - return createIDBKeyFromSerializedValueAndKeyPath(value, idbKeyPath); -} - -void checkKeyPathNullValue(SerializedScriptValue* value, const String& keyPath) -{ - RefPtr<IDBKey> idbKey = checkKeyFromValueAndKeyPathInternal(value, keyPath); - ASSERT_FALSE(idbKey.get()); -} - -void checkKeyPathStringValue(SerializedScriptValue* value, const String& keyPath, const String& expected) -{ - RefPtr<IDBKey> idbKey = checkKeyFromValueAndKeyPathInternal(value, keyPath); - ASSERT_TRUE(idbKey.get()); - ASSERT_EQ(IDBKey::StringType, idbKey->type()); - ASSERT_TRUE(expected == idbKey->string()); -} - -void checkKeyPathNumberValue(SerializedScriptValue* value, const String& keyPath, int expected) -{ - RefPtr<IDBKey> idbKey = checkKeyFromValueAndKeyPathInternal(value, keyPath); - ASSERT_TRUE(idbKey.get()); - ASSERT_EQ(IDBKey::NumberType, idbKey->type()); - ASSERT_TRUE(expected == idbKey->number()); -} - -TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyStringValue) -{ - LocalContext v8context; - v8::Local<v8::Object> object = v8::Object::New(); - object->Set(v8::String::New("foo"), v8::String::New("zoo")); - - RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptValue::create(object); - - checkKeyPathStringValue(serializedScriptValue.get(), "foo", "zoo"); - checkKeyPathNullValue(serializedScriptValue.get(), "bar"); - checkKeyPathNullValue(serializedScriptValue.get(), "[3]"); -} - -TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyNumberValue) -{ - LocalContext v8context; - v8::Local<v8::Object> object = v8::Object::New(); - object->Set(v8::String::New("foo"), v8::Number::New(456)); - - RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptValue::create(object); - - checkKeyPathNumberValue(serializedScriptValue.get(), "foo", 456); - checkKeyPathNullValue(serializedScriptValue.get(), "bar"); - checkKeyPathNullValue(serializedScriptValue.get(), "[3]"); -} - -TEST(IDBKeyFromValueAndKeyPathTest, TopLevelArrayElement) -{ - LocalContext v8context; - v8::Local<v8::Array> array = v8::Array::New(); - array->Set(3, v8::String::New("zoo")); - - RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptValue::create(array); - - checkKeyPathStringValue(serializedScriptValue.get(), "[3]", "zoo"); - checkKeyPathNullValue(serializedScriptValue.get(), "foo"); - checkKeyPathNullValue(serializedScriptValue.get(), "bar"); -} - -TEST(IDBKeyFromValueAndKeyPathTest, SubProperty) -{ - LocalContext v8context; - v8::Local<v8::Object> object = v8::Object::New(); - v8::Local<v8::Object> subProperty = v8::Object::New(); - subProperty->Set(v8::String::New("bar"), v8::String::New("zee")); - object->Set(v8::String::New("foo"), subProperty); - - RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptValue::create(object); - - checkKeyPathStringValue(serializedScriptValue.get(), "foo.bar", "zee"); - checkKeyPathNullValue(serializedScriptValue.get(), "bar"); - checkKeyPathNullValue(serializedScriptValue.get(), "[3]"); -} - -TEST(IDBKeyFromValueAndKeyPathTest, Array2D) -{ - LocalContext v8context; - v8::Local<v8::Object> object = v8::Object::New(); - v8::Local<v8::Array> array = v8::Array::New(); - v8::Local<v8::Array> subArray = v8::Array::New(); - subArray->Set(7, v8::String::New("zee")); - array->Set(3, subArray); - object->Set(v8::String::New("foo"), array); - - RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptValue::create(object); - - checkKeyPathStringValue(serializedScriptValue.get(), "foo[3][7]", "zee"); - checkKeyPathNullValue(serializedScriptValue.get(), "bar"); - checkKeyPathNullValue(serializedScriptValue.get(), "[4]"); -} - -} // namespace - -#endif // ENABLE(INDEXED_DATABASE) diff --git a/WebKit/chromium/tests/IDBKeyPathTest.cpp b/WebKit/chromium/tests/IDBKeyPathTest.cpp deleted file mode 100644 index 6c378d6..0000000 --- a/WebKit/chromium/tests/IDBKeyPathTest.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (C) 2010 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 "IDBKeyPath.h" - -#include <gtest/gtest.h> -#include <wtf/Vector.h> - -#if ENABLE(INDEXED_DATABASE) - -using namespace WebCore; - -namespace { - -IDBKeyPathElement ExpectedToken(const String& identifier, bool isIndexed, int index) -{ - IDBKeyPathElement expected; - if (isIndexed) { - expected.type = IDBKeyPathElement::IsIndexed; - expected.index = index; - } else { - expected.type = IDBKeyPathElement::IsNamed; - expected.identifier = identifier; - } - return expected; -} - -void checkKeyPath(const String& keyPath, const Vector<IDBKeyPathElement>& expected, int parserError) -{ - - IDBKeyPathParseError error; - Vector<IDBKeyPathElement> idbKeyPathElements; - IDBParseKeyPath(keyPath, idbKeyPathElements, error); - ASSERT_EQ(parserError, error); - if (error != IDBKeyPathParseErrorNone) - return; - ASSERT_EQ(expected.size(), idbKeyPathElements.size()); - for (size_t i = 0; i < expected.size(); ++i) { - ASSERT_TRUE(expected[i].type == idbKeyPathElements[i].type) << i; - if (expected[i].type == IDBKeyPathElement::IsIndexed) - ASSERT_EQ(expected[i].index, idbKeyPathElements[i].index) << i; - else if (expected[i].type == IDBKeyPathElement::IsNamed) - ASSERT_TRUE(expected[i].identifier == idbKeyPathElements[i].identifier) << i; - else - ASSERT_TRUE(false) << "Invalid IDBKeyPathElement type"; - } -} - -TEST(IDBKeyPathTest, ValidKeyPath0) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("foo.bar.zoo"); - expected.append(ExpectedToken("foo", false, 0)); - expected.append(ExpectedToken("bar", false, 0)); - expected.append(ExpectedToken("zoo", false, 0)); - checkKeyPath(keyPath, expected, 0); -} - -TEST(IDBKeyPathTest, ValidKeyPath1) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("a[34][20].foo[2].bar"); - expected.append(ExpectedToken("a", false, 0)); - expected.append(ExpectedToken(String(), true, 34)); - expected.append(ExpectedToken(String(), true, 20)); - expected.append(ExpectedToken("foo", false, 0)); - expected.append(ExpectedToken(String(), true, 2)); - expected.append(ExpectedToken("bar", false, 0)); - checkKeyPath(keyPath, expected, 0); -} - -TEST(IDBKeyPathTest, ValidKeyPath2) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("foo[ 34 ].Zoo_[00023]\t._c"); - expected.append(ExpectedToken("foo", false, 0)); - expected.append(ExpectedToken(String(), true, 34)); - expected.append(ExpectedToken("Zoo_", false, 0)); - expected.append(ExpectedToken(String(), true, 23)); - expected.append(ExpectedToken("_c", false, 0)); - checkKeyPath(keyPath, expected, 0); -} - -TEST(IDBKeyPathTest, ValidKeyPath3) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("foo[ 34 ]"); - expected.append(ExpectedToken("foo", false, 0)); - expected.append(ExpectedToken(String(), true, 34)); - checkKeyPath(keyPath, expected, 0); -} - -TEST(IDBKeyPathTest, ValidKeyPath4) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("[ 34 ]"); - expected.append(ExpectedToken(String(), true, 34)); - checkKeyPath(keyPath, expected, 0); -} - -TEST(IDBKeyPathTest, InvalidKeyPath2) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("a[[34]].b[2].c"); - expected.append(ExpectedToken("a", false, 0)); - checkKeyPath(keyPath, expected, 3); -} - -TEST(IDBKeyPathTest, InvalidKeyPath3) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("a[[34].b[2].c"); - expected.append(ExpectedToken("a", false, 0)); - checkKeyPath(keyPath, expected, 3); -} - -TEST(IDBKeyPathTest, InvalidKeyPath5) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("a[[34.b[2].c"); - expected.append(ExpectedToken("a", false, 0)); - checkKeyPath(keyPath, expected, 3); -} - -TEST(IDBKeyPathTest, InvalidKeyPath6) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("+a[34].b[2].c"); - checkKeyPath(keyPath, expected, 1); -} - -TEST(IDBKeyPathTest, InvalidKeyPath7) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("%a[34].b[2].c"); - checkKeyPath(keyPath, expected, 1); -} - -TEST(IDBKeyPathTest, InvalidKeyPath8) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("a{[34]}.b[2].c"); - expected.append(ExpectedToken("a", false, 0)); - checkKeyPath(keyPath, expected, 2); -} - -TEST(IDBKeyPathTest, InvalidKeyPath9) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("a..b[2].c"); - expected.append(ExpectedToken("a", false, 0)); - checkKeyPath(keyPath, expected, 5); -} - -TEST(IDBKeyPathTest, InvalidKeyPath10) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("a[34]b.foo[2].bar"); - expected.append(ExpectedToken("a", false, 0)); - expected.append(ExpectedToken(String(), true, 34)); - checkKeyPath(keyPath, expected, 4); -} - -TEST(IDBKeyPathTest, InvalidKeyPath11) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("a[-1]"); - expected.append(ExpectedToken("a", false, 0)); - checkKeyPath(keyPath, expected, 3); -} - -TEST(IDBKeyPathTest, InvalidKeyPath12) -{ - Vector<IDBKeyPathElement> expected; - String keyPath("a[9999999999999999999999999999999999]"); - expected.append(ExpectedToken("a", false, 0)); - checkKeyPath(keyPath, expected, 3); -} - -} // namespace - -#endif // ENABLE(INDEXED_DATABASE) diff --git a/WebKit/chromium/tests/KURLTest.cpp b/WebKit/chromium/tests/KURLTest.cpp deleted file mode 100644 index 152dd31..0000000 --- a/WebKit/chromium/tests/KURLTest.cpp +++ /dev/null @@ -1,615 +0,0 @@ -/* - * Copyright (C) 2010 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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. - */ - -// Basic tests that verify our KURL's interface behaves the same as the -// original KURL's. - -#include "config.h" - -#include <gtest/gtest.h> - -#include "KURL.h" - -namespace WTF { -// Output stream operator so gTest's macros work with WebCore strings. -std::ostream& operator<<(std::ostream& out, const String& str) -{ - return str.isEmpty() ? out : out << str.utf8().data(); -} -} // namespace WTF - -namespace { - - -struct ComponentCase { - const char* url; - const char* protocol; - const char* host; - const int port; - const char* user; - const char* pass; - const char* path; - const char* lastPath; - const char* query; - const char* ref; -}; - -// Test the cases where we should be the same as WebKit's old KURL. -TEST(KURLTest, SameGetters) -{ - struct GetterCase { - const char* url; - const char* protocol; - const char* host; - int port; - const char* user; - const char* pass; - const char* lastPathComponent; - const char* query; - const char* ref; - bool hasRef; - } cases[] = { - {"http://www.google.com/foo/blah?bar=baz#ref", "http", "www.google.com", 0, "", 0, "blah", "bar=baz", "ref", true}, - {"http://foo.com:1234/foo/bar/", "http", "foo.com", 1234, "", 0, "bar", 0, 0, false}, - {"http://www.google.com?#", "http", "www.google.com", 0, "", 0, 0, "", "", true}, - {"https://me:pass@google.com:23#foo", "https", "google.com", 23, "me", "pass", 0, 0, "foo", true}, - {"javascript:hello!//world", "javascript", "", 0, "", 0, "world", 0, 0, false}, - }; - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { - // UTF-8 - WebCore::KURL kurl(WebCore::ParsedURLString, cases[i].url); - - EXPECT_EQ(cases[i].protocol, kurl.protocol()); - EXPECT_EQ(cases[i].host, kurl.host()); - EXPECT_EQ(cases[i].port, kurl.port()); - EXPECT_EQ(cases[i].user, kurl.user()); - EXPECT_EQ(cases[i].pass, kurl.pass()); - EXPECT_EQ(cases[i].lastPathComponent, kurl.lastPathComponent()); - EXPECT_EQ(cases[i].query, kurl.query()); - EXPECT_EQ(cases[i].ref, kurl.fragmentIdentifier()); - EXPECT_EQ(cases[i].hasRef, kurl.hasFragmentIdentifier()); - - // UTF-16 - WTF::String utf16(cases[i].url); - kurl = WebCore::KURL(WebCore::ParsedURLString, utf16); - - EXPECT_EQ(cases[i].protocol, kurl.protocol()); - EXPECT_EQ(cases[i].host, kurl.host()); - EXPECT_EQ(cases[i].port, kurl.port()); - EXPECT_EQ(cases[i].user, kurl.user()); - EXPECT_EQ(cases[i].pass, kurl.pass()); - EXPECT_EQ(cases[i].lastPathComponent, kurl.lastPathComponent()); - EXPECT_EQ(cases[i].query, kurl.query()); - EXPECT_EQ(cases[i].ref, kurl.fragmentIdentifier()); - EXPECT_EQ(cases[i].hasRef, kurl.hasFragmentIdentifier()); - } -} - -// Test a few cases where we're different just to make sure we give reasonable -// output. -TEST(KURLTest, DifferentGetters) -{ - ComponentCase cases[] = { - // url protocol host port user pass path lastPath query ref - - // Old WebKit allows references and queries in what we call "path" URLs - // like javascript, so the path here will only consist of "hello!". - {"javascript:hello!?#/\\world", "javascript", "", 0, "", 0, "hello!?#/\\world", "world", 0, 0}, - - // Old WebKit doesn't handle "parameters" in paths, so will - // disagree with us about where the path is for this URL. - {"http://a.com/hello;world", "http", "a.com", 0, "", 0, "/hello;world", "hello", 0, 0}, - - // WebKit doesn't like UTF-8 or UTF-16 input. - {"http://\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd/", "http", "xn--6qqa088eba", 0, "", 0, "/", 0, 0, 0}, - - // WebKit %-escapes non-ASCII characters in reference, but we don't. - {"http://www.google.com/foo/blah?bar=baz#\xce\xb1\xce\xb2", "http", "www.google.com", 0, "", 0, "/foo/blah/", "blah", "bar=baz", "\xce\xb1\xce\xb2"}, - }; - - for (size_t i = 0; i < arraysize(cases); i++) { - WebCore::KURL kurl(WebCore::ParsedURLString, cases[i].url); - - EXPECT_EQ(cases[i].protocol, kurl.protocol()); - EXPECT_EQ(cases[i].host, kurl.host()); - EXPECT_EQ(cases[i].port, kurl.port()); - EXPECT_EQ(cases[i].user, kurl.user()); - EXPECT_EQ(cases[i].pass, kurl.pass()); - EXPECT_EQ(cases[i].lastPath, kurl.lastPathComponent()); - EXPECT_EQ(cases[i].query, kurl.query()); - // Want to compare UCS-16 refs (or to null). - if (cases[i].ref) - EXPECT_EQ(WTF::String::fromUTF8(cases[i].ref), kurl.fragmentIdentifier()); - else - EXPECT_TRUE(kurl.fragmentIdentifier().isNull()); - } -} - -// Ensures that both ASCII and UTF-8 canonical URLs are handled properly and we -// get the correct string object out. -TEST(KURLTest, UTF8) -{ - const char asciiURL[] = "http://foo/bar#baz"; - WebCore::KURL asciiKURL(WebCore::ParsedURLString, asciiURL); - EXPECT_TRUE(asciiKURL.string() == WTF::String(asciiURL)); - - // When the result is ASCII, we should get an ASCII String. Some - // code depends on being able to compare the result of the .string() - // getter with another String, and the isASCIIness of the two - // strings must match for these functions (like equalIgnoringCase). - EXPECT_TRUE(WTF::equalIgnoringCase(asciiKURL, WTF::String(asciiURL))); - - // Reproduce code path in FrameLoader.cpp -- equalIgnoringCase implicitly - // expects gkurl.protocol() to have been created as ascii. - WebCore::KURL mailto(WebCore::ParsedURLString, "mailto:foo@foo.com"); - EXPECT_TRUE(WTF::equalIgnoringCase(mailto.protocol(), "mailto")); - - const char utf8URL[] = "http://foo/bar#\xe4\xbd\xa0\xe5\xa5\xbd"; - WebCore::KURL utf8KURL(WebCore::ParsedURLString, utf8URL); - - EXPECT_TRUE(utf8KURL.string() == WTF::String::fromUTF8(utf8URL)); -} - -TEST(KURLTest, Setters) -{ - // Replace the starting URL with the given components one at a time and - // verify that we're always the same as the old KURL. - // - // Note that old KURL won't canonicalize the default port away, so we - // can't set setting the http port to "80" (or even "0"). - // - // We also can't test clearing the query. - // - // The format is every other row is a test, and the row that follows it is the - // expected result. - struct ExpectedComponentCase { - const char* url; - const char* protocol; - const char* host; - const int port; - const char* user; - const char* pass; - const char* path; - const char* query; - const char* ref; - - // The full expected URL with the given "set" applied. - const char* expectedProtocol; - const char* expectedHost; - const char* expectedPort; - const char* expectedUser; - const char* expectedPass; - const char* expectedPath; - const char* expectedQuery; - const char* expectedRef; - } cases[] = { - // url protocol host port user pass path query ref - {"http://www.google.com/", "https", "news.google.com", 8888, "me", "pass", "/foo", "?q=asdf", "heehee", - "https://www.google.com/", - "https://news.google.com/", - "https://news.google.com:8888/", - "https://me@news.google.com:8888/", - "https://me:pass@news.google.com:8888/", - "https://me:pass@news.google.com:8888/foo", - "https://me:pass@news.google.com:8888/foo?q=asdf", - "https://me:pass@news.google.com:8888/foo?q=asdf#heehee"}, - - {"https://me:pass@google.com:88/a?f#b", "http", "goo.com", 92, "", "", "/", 0, "", - "http://me:pass@google.com:88/a?f#b", - "http://me:pass@goo.com:88/a?f#b", - "http://me:pass@goo.com:92/a?f#b", - "http://:pass@goo.com:92/a?f#b", - "http://goo.com:92/a?f#b", - "http://goo.com:92/?f#b", - "http://goo.com:92/#b", - "https://goo.com:92/"}, - }; - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { - WebCore::KURL kurl(WebCore::ParsedURLString, cases[i].url); - - kurl.setProtocol(cases[i].protocol); - EXPECT_STREQ(cases[i].expectedProtocol, kurl.string().utf8().data()); - - kurl.setHost(cases[i].host); - EXPECT_STREQ(cases[i].expectedHost, kurl.string().utf8().data()); - - kurl.setPort(cases[i].port); - EXPECT_STREQ(cases[i].expectedPort, kurl.string().utf8().data()); - - kurl.setUser(cases[i].user); - EXPECT_STREQ(cases[i].expectedUser, kurl.string().utf8().data()); - - kurl.setPass(cases[i].pass); - EXPECT_STREQ(cases[i].expectedPass, kurl.string().utf8().data()); - - kurl.setPath(cases[i].path); - EXPECT_STREQ(cases[i].expectedPath, kurl.string().utf8().data()); - - kurl.setQuery(cases[i].query); - EXPECT_STREQ(cases[i].expectedQuery, kurl.string().utf8().data()); - - // Refs are tested below. On the Safari 3.1 branch, we don't match their - // KURL since we integrated a fix from their trunk. - } -} - -// Tests that KURL::decodeURLEscapeSequences works as expected -#if USE(GOOGLEURL) -TEST(KURLTest, Decode) -{ - struct DecodeCase { - const char* input; - const char* output; - } decodeCases[] = { - {"hello, world", "hello, world"}, - {"%01%02%03%04%05%06%07%08%09%0a%0B%0C%0D%0e%0f/", "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0B\x0C\x0D\x0e\x0f/"}, - {"%10%11%12%13%14%15%16%17%18%19%1a%1B%1C%1D%1e%1f/", "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1B\x1C\x1D\x1e\x1f/"}, - {"%20%21%22%23%24%25%26%27%28%29%2a%2B%2C%2D%2e%2f/", " !\"#$%&'()*+,-.//"}, - {"%30%31%32%33%34%35%36%37%38%39%3a%3B%3C%3D%3e%3f/", "0123456789:;<=>?/"}, - {"%40%41%42%43%44%45%46%47%48%49%4a%4B%4C%4D%4e%4f/", "@ABCDEFGHIJKLMNO/"}, - {"%50%51%52%53%54%55%56%57%58%59%5a%5B%5C%5D%5e%5f/", "PQRSTUVWXYZ[\\]^_/"}, - {"%60%61%62%63%64%65%66%67%68%69%6a%6B%6C%6D%6e%6f/", "`abcdefghijklmno/"}, - {"%70%71%72%73%74%75%76%77%78%79%7a%7B%7C%7D%7e%7f/", "pqrstuvwxyz{|}~\x7f/"}, - // Test un-UTF-8-ization. - {"%e4%bd%a0%e5%a5%bd", "\xe4\xbd\xa0\xe5\xa5\xbd"}, - }; - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(decodeCases); i++) { - WTF::String input(decodeCases[i].input); - WTF::String str = WebCore::decodeURLEscapeSequences(input); - EXPECT_STREQ(decodeCases[i].output, str.utf8().data()); - } - - // Our decode should decode %00 - WTF::String zero = WebCore::decodeURLEscapeSequences("%00"); - EXPECT_STRNE("%00", zero.utf8().data()); - - // Test the error behavior for invalid UTF-8 (we differ from WebKit here). - WTF::String invalid = WebCore::decodeURLEscapeSequences( - "%e4%a0%e5%a5%bd"); - char16 invalidExpectedHelper[4] = { 0x00e4, 0x00a0, 0x597d, 0 }; - WTF::String invalidExpected( - reinterpret_cast<const ::UChar*>(invalidExpectedHelper), - 3); - EXPECT_EQ(invalidExpected, invalid); -} -#endif - -TEST(KURLTest, Encode) -{ - // Also test that it gets converted to UTF-8 properly. - char16 wideInputHelper[3] = { 0x4f60, 0x597d, 0 }; - WTF::String wideInput( - reinterpret_cast<const ::UChar*>(wideInputHelper), 2); - WTF::String wideReference("\xe4\xbd\xa0\xe5\xa5\xbd", 6); - WTF::String wideOutput = - WebCore::encodeWithURLEscapeSequences(wideInput); - EXPECT_EQ(wideReference, wideOutput); - - // Our encode only escapes NULLs for safety (see the implementation for - // more), so we only bother to test a few cases. - WTF::String input( - "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 16); - WTF::String reference( - "%00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 18); - WTF::String output = WebCore::encodeWithURLEscapeSequences(input); - EXPECT_EQ(reference, output); -} - -TEST(KURLTest, ResolveEmpty) -{ - WebCore::KURL emptyBase; - - // WebKit likes to be able to resolve absolute input agains empty base URLs, - // which would normally be invalid since the base URL is invalid. - const char abs[] = "http://www.google.com/"; - WebCore::KURL resolveAbs(emptyBase, abs); - EXPECT_TRUE(resolveAbs.isValid()); - EXPECT_STREQ(abs, resolveAbs.string().utf8().data()); - - // Resolving a non-relative URL agains the empty one should still error. - const char rel[] = "foo.html"; - WebCore::KURL resolveErr(emptyBase, rel); - EXPECT_FALSE(resolveErr.isValid()); -} - -// WebKit will make empty URLs and set components on them. kurl doesn't allow -// replacements on invalid URLs, but here we do. -TEST(KURLTest, ReplaceInvalid) -{ - WebCore::KURL kurl; - - EXPECT_FALSE(kurl.isValid()); - EXPECT_TRUE(kurl.isEmpty()); - EXPECT_STREQ("", kurl.string().utf8().data()); - - kurl.setProtocol("http"); - // GKURL will say that a URL with just a scheme is invalid, KURL will not. -#if USE(GOOGLEURL) - EXPECT_FALSE(kurl.isValid()); -#else - EXPECT_TRUE(kurl.isValid()); -#endif - EXPECT_FALSE(kurl.isEmpty()); - // At this point, we do things slightly differently if there is only a scheme. - // We check the results here to make it more obvious what is going on, but it - // shouldn't be a big deal if these change. -#if USE(GOOGLEURL) - EXPECT_STREQ("http:", kurl.string().utf8().data()); -#else - EXPECT_STREQ("http:/", kurl.string().utf8().data()); -#endif - - kurl.setHost("www.google.com"); - EXPECT_TRUE(kurl.isValid()); - EXPECT_FALSE(kurl.isEmpty()); - EXPECT_STREQ("http://www.google.com/", kurl.string().utf8().data()); - - kurl.setPort(8000); - EXPECT_TRUE(kurl.isValid()); - EXPECT_FALSE(kurl.isEmpty()); - EXPECT_STREQ("http://www.google.com:8000/", kurl.string().utf8().data()); - - kurl.setPath("/favicon.ico"); - EXPECT_TRUE(kurl.isValid()); - EXPECT_FALSE(kurl.isEmpty()); - EXPECT_STREQ("http://www.google.com:8000/favicon.ico", kurl.string().utf8().data()); - - // Now let's test that giving an invalid replacement fails. Invalid - // protocols fail without modifying the URL, which should remain valid. -#if USE(GOOGLEURL) - EXPECT_FALSE(kurl.setProtocol("f/sj#@")); - EXPECT_TRUE(kurl.isValid()); -#endif -} - -TEST(KURLTest, Path) -{ - const char initial[] = "http://www.google.com/path/foo"; - WebCore::KURL kurl(WebCore::ParsedURLString, initial); - - // Clear by setting a null string. - WTF::String nullString; - EXPECT_TRUE(nullString.isNull()); - kurl.setPath(nullString); - EXPECT_STREQ("http://www.google.com/", kurl.string().utf8().data()); -} - -// Test that setting the query to different things works. Thq query is handled -// a littler differently than some of the other components. -TEST(KURLTest, Query) -{ - const char initial[] = "http://www.google.com/search?q=awesome"; - WebCore::KURL kurl(WebCore::ParsedURLString, initial); - - // Clear by setting a null string. - WTF::String nullString; - EXPECT_TRUE(nullString.isNull()); - kurl.setQuery(nullString); - EXPECT_STREQ("http://www.google.com/search", kurl.string().utf8().data()); - - // Clear by setting an empty string. - kurl = WebCore::KURL(WebCore::ParsedURLString, initial); - WTF::String emptyString(""); - EXPECT_FALSE(emptyString.isNull()); - kurl.setQuery(emptyString); - EXPECT_STREQ("http://www.google.com/search?", kurl.string().utf8().data()); - - // Set with something that begins in a question mark. - const char question[] = "?foo=bar"; - kurl.setQuery(question); - EXPECT_STREQ("http://www.google.com/search?foo=bar", - kurl.string().utf8().data()); - - // Set with something that doesn't begin in a question mark. - const char query[] = "foo=bar"; - kurl.setQuery(query); - EXPECT_STREQ("http://www.google.com/search?foo=bar", - kurl.string().utf8().data()); -} - -TEST(KURLTest, Ref) -{ - WebCore::KURL kurl(WebCore::ParsedURLString, "http://foo/bar#baz"); - - // Basic ref setting. - WebCore::KURL cur(WebCore::ParsedURLString, "http://foo/bar"); - cur.setFragmentIdentifier("asdf"); - EXPECT_STREQ("http://foo/bar#asdf", cur.string().utf8().data()); - cur = kurl; - cur.setFragmentIdentifier("asdf"); - EXPECT_STREQ("http://foo/bar#asdf", cur.string().utf8().data()); - - // Setting a ref to the empty string will set it to "#". - cur = WebCore::KURL(WebCore::ParsedURLString, "http://foo/bar"); - cur.setFragmentIdentifier(""); - EXPECT_STREQ("http://foo/bar#", cur.string().utf8().data()); - cur = kurl; - cur.setFragmentIdentifier(""); - EXPECT_STREQ("http://foo/bar#", cur.string().utf8().data()); - - // Setting the ref to the null string will clear it altogether. - cur = WebCore::KURL(WebCore::ParsedURLString, "http://foo/bar"); - cur.setFragmentIdentifier(WTF::String()); - EXPECT_STREQ("http://foo/bar", cur.string().utf8().data()); - cur = kurl; - cur.setFragmentIdentifier(WTF::String()); - EXPECT_STREQ("http://foo/bar", cur.string().utf8().data()); -} - -TEST(KURLTest, Empty) -{ - WebCore::KURL kurl; - - // First test that regular empty URLs are the same. - EXPECT_TRUE(kurl.isEmpty()); - EXPECT_FALSE(kurl.isValid()); - EXPECT_TRUE(kurl.isNull()); - EXPECT_TRUE(kurl.string().isNull()); - EXPECT_TRUE(kurl.string().isEmpty()); - - // Test resolving a null URL on an empty string. - WebCore::KURL kurl2(kurl, ""); - EXPECT_FALSE(kurl2.isNull()); - EXPECT_TRUE(kurl2.isEmpty()); - EXPECT_FALSE(kurl2.isValid()); - EXPECT_FALSE(kurl2.string().isNull()); - EXPECT_TRUE(kurl2.string().isEmpty()); - EXPECT_FALSE(kurl2.string().isNull()); - EXPECT_TRUE(kurl2.string().isEmpty()); - - // Resolve the null URL on a null string. - WebCore::KURL kurl22(kurl, WTF::String()); - EXPECT_FALSE(kurl22.isNull()); - EXPECT_TRUE(kurl22.isEmpty()); - EXPECT_FALSE(kurl22.isValid()); - EXPECT_FALSE(kurl22.string().isNull()); - EXPECT_TRUE(kurl22.string().isEmpty()); - EXPECT_FALSE(kurl22.string().isNull()); - EXPECT_TRUE(kurl22.string().isEmpty()); - - // Test non-hierarchical schemes resolving. The actual URLs will be different. - // WebKit's one will set the string to "something.gif" and we'll set it to an - // empty string. I think either is OK, so we just check our behavior. -#if USE(GOOGLEURL) - WebCore::KURL kurl3(WebCore::KURL(WebCore::ParsedURLString, "data:foo"), - "something.gif"); - EXPECT_TRUE(kurl3.isEmpty()); - EXPECT_FALSE(kurl3.isValid()); -#endif - - // Test for weird isNull string input, - // see: http://bugs.webkit.org/show_bug.cgi?id=16487 - WebCore::KURL kurl4(WebCore::ParsedURLString, kurl.string()); - EXPECT_TRUE(kurl4.isEmpty()); - EXPECT_FALSE(kurl4.isValid()); - EXPECT_TRUE(kurl4.string().isNull()); - EXPECT_TRUE(kurl4.string().isEmpty()); - - // Resolving an empty URL on an invalid string. - WebCore::KURL kurl5(WebCore::KURL(), "foo.js"); - // We'll be empty in this case, but KURL won't be. Should be OK. - // EXPECT_EQ(kurl5.isEmpty(), kurl5.isEmpty()); - // EXPECT_EQ(kurl5.string().isEmpty(), kurl5.string().isEmpty()); - EXPECT_FALSE(kurl5.isValid()); - EXPECT_FALSE(kurl5.string().isNull()); - - // Empty string as input - WebCore::KURL kurl6(WebCore::ParsedURLString, ""); - EXPECT_TRUE(kurl6.isEmpty()); - EXPECT_FALSE(kurl6.isValid()); - EXPECT_FALSE(kurl6.string().isNull()); - EXPECT_TRUE(kurl6.string().isEmpty()); - - // Non-empty but invalid C string as input. - WebCore::KURL kurl7(WebCore::ParsedURLString, "foo.js"); - // WebKit will actually say this URL has the string "foo.js" but is invalid. - // We don't do that. - // EXPECT_EQ(kurl7.isEmpty(), kurl7.isEmpty()); - EXPECT_FALSE(kurl7.isValid()); - EXPECT_FALSE(kurl7.string().isNull()); -} - -TEST(KURLTest, UserPass) -{ - const char* src = "http://user:pass@google.com/"; - WebCore::KURL kurl(WebCore::ParsedURLString, src); - - // Clear just the username. - kurl.setUser(""); - EXPECT_EQ("http://:pass@google.com/", kurl.string()); - - // Clear just the password. - kurl = WebCore::KURL(WebCore::ParsedURLString, src); - kurl.setPass(""); - EXPECT_EQ("http://user@google.com/", kurl.string()); - - // Now clear both. - kurl.setUser(""); - EXPECT_EQ("http://google.com/", kurl.string()); -} - -TEST(KURLTest, Offsets) -{ - const char* src1 = "http://user:pass@google.com/foo/bar.html?baz=query#ref"; - WebCore::KURL kurl1(WebCore::ParsedURLString, src1); - - EXPECT_EQ(17u, kurl1.hostStart()); - EXPECT_EQ(27u, kurl1.hostEnd()); - EXPECT_EQ(27u, kurl1.pathStart()); - EXPECT_EQ(40u, kurl1.pathEnd()); - EXPECT_EQ(32u, kurl1.pathAfterLastSlash()); - - const char* src2 = "http://google.com/foo/"; - WebCore::KURL kurl2(WebCore::ParsedURLString, src2); - - EXPECT_EQ(7u, kurl2.hostStart()); - EXPECT_EQ(17u, kurl2.hostEnd()); - EXPECT_EQ(17u, kurl2.pathStart()); - EXPECT_EQ(22u, kurl2.pathEnd()); - EXPECT_EQ(22u, kurl2.pathAfterLastSlash()); - - const char* src3 = "javascript:foobar"; - WebCore::KURL kurl3(WebCore::ParsedURLString, src3); - - EXPECT_EQ(11u, kurl3.hostStart()); - EXPECT_EQ(11u, kurl3.hostEnd()); - EXPECT_EQ(11u, kurl3.pathStart()); - EXPECT_EQ(17u, kurl3.pathEnd()); - EXPECT_EQ(11u, kurl3.pathAfterLastSlash()); -} - -TEST(KURLTest, DeepCopy) -{ - const char url[] = "http://www.google.com/"; - WebCore::KURL src(WebCore::ParsedURLString, url); - EXPECT_TRUE(src.string() == url); // This really just initializes the cache. - WebCore::KURL dest = src.copy(); - EXPECT_TRUE(dest.string() == url); // This really just initializes the cache. - - // The pointers should be different for both UTF-8 and UTF-16. - EXPECT_NE(dest.string().characters(), src.string().characters()); - EXPECT_NE(dest.utf8String().data(), src.utf8String().data()); -} - -TEST(KURLTest, ProtocolIs) -{ - WebCore::KURL url1(WebCore::ParsedURLString, "foo://bar"); - EXPECT_TRUE(url1.protocolIs("foo")); - EXPECT_FALSE(url1.protocolIs("foo-bar")); - - WebCore::KURL url2(WebCore::ParsedURLString, "foo-bar:"); - EXPECT_TRUE(url2.protocolIs("foo-bar")); - EXPECT_FALSE(url2.protocolIs("foo")); -} - -} // namespace diff --git a/WebKit/chromium/tests/KeyboardTest.cpp b/WebKit/chromium/tests/KeyboardTest.cpp deleted file mode 100644 index 07bed3c..0000000 --- a/WebKit/chromium/tests/KeyboardTest.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (C) 2010 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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 <gtest/gtest.h> - -#include "EditorClientImpl.h" -#include "EventTarget.h" -#include "KeyboardCodes.h" -#include "KeyboardEvent.h" -#include "WebInputEvent.h" -#include "WebInputEventConversion.h" - -using namespace WebCore; -using namespace WebKit; - -namespace { - -class KeyboardTest : public testing::Test { -public: - - // Pass a WebKeyboardEvent into the EditorClient and get back the string - // name of which editing event that key causes. - // E.g., sending in the enter key gives back "InsertNewline". - const char* interpretKeyEvent( - const WebKeyboardEvent& webKeyboardEvent, - PlatformKeyboardEvent::Type keyType) - { - EditorClientImpl editorImpl(0); - PlatformKeyboardEventBuilder evt(webKeyboardEvent); - evt.setKeyType(keyType); - RefPtr<KeyboardEvent> keyboardEvent = KeyboardEvent::create(evt, 0); - return editorImpl.interpretKeyEvent(keyboardEvent.get()); - } - - // Set up a WebKeyboardEvent KEY_DOWN event with key code and modifiers. - void setupKeyDownEvent(WebKeyboardEvent* keyboardEvent, - char keyCode, - int modifiers) - { - keyboardEvent->windowsKeyCode = keyCode; - keyboardEvent->modifiers = modifiers; - keyboardEvent->type = WebInputEvent::KeyDown; - keyboardEvent->text[0] = keyCode; - keyboardEvent->setKeyIdentifierFromWindowsKeyCode(); - } - - // Like interpretKeyEvent, but with pressing down OSModifier+|keyCode|. - // OSModifier is the platform's standard modifier key: control on most - // platforms, but meta (command) on Mac. - const char* interpretOSModifierKeyPress(char keyCode) - { - WebKeyboardEvent keyboardEvent; -#if OS(DARWIN) - WebInputEvent::Modifiers osModifier = WebInputEvent::MetaKey; -#else - WebInputEvent::Modifiers osModifier = WebInputEvent::ControlKey; -#endif - setupKeyDownEvent(&keyboardEvent, keyCode, osModifier); - return interpretKeyEvent(keyboardEvent, PlatformKeyboardEvent::RawKeyDown); - } - - // Like interpretKeyEvent, but with pressing down ctrl+|keyCode|. - const char* interpretCtrlKeyPress(char keyCode) - { - WebKeyboardEvent keyboardEvent; - setupKeyDownEvent(&keyboardEvent, keyCode, WebInputEvent::ControlKey); - return interpretKeyEvent(keyboardEvent, PlatformKeyboardEvent::RawKeyDown); - } - - // Like interpretKeyEvent, but with typing a tab. - const char* interpretTab(int modifiers) - { - WebKeyboardEvent keyboardEvent; - setupKeyDownEvent(&keyboardEvent, '\t', modifiers); - return interpretKeyEvent(keyboardEvent, PlatformKeyboardEvent::Char); - } - - // Like interpretKeyEvent, but with typing a newline. - const char* interpretNewLine(int modifiers) - { - WebKeyboardEvent keyboardEvent; - setupKeyDownEvent(&keyboardEvent, '\r', modifiers); - return interpretKeyEvent(keyboardEvent, PlatformKeyboardEvent::Char); - } - - // A name for "no modifiers set". - static const int noModifiers = 0; -}; - -TEST_F(KeyboardTest, TestCtrlReturn) -{ - EXPECT_STREQ("InsertNewline", interpretCtrlKeyPress(0xD)); -} - -TEST_F(KeyboardTest, TestOSModifierZ) -{ -#if !OS(DARWIN) - EXPECT_STREQ("Undo", interpretOSModifierKeyPress('Z')); -#endif -} - -TEST_F(KeyboardTest, TestOSModifierY) -{ -#if !OS(DARWIN) - EXPECT_STREQ("Redo", interpretOSModifierKeyPress('Y')); -#endif -} - -TEST_F(KeyboardTest, TestOSModifierA) -{ -#if !OS(DARWIN) - EXPECT_STREQ("SelectAll", interpretOSModifierKeyPress('A')); -#endif -} - -TEST_F(KeyboardTest, TestOSModifierX) -{ -#if !OS(DARWIN) - EXPECT_STREQ("Cut", interpretOSModifierKeyPress('X')); -#endif -} - -TEST_F(KeyboardTest, TestOSModifierC) -{ -#if !OS(DARWIN) - EXPECT_STREQ("Copy", interpretOSModifierKeyPress('C')); -#endif -} - -TEST_F(KeyboardTest, TestOSModifierV) -{ -#if !OS(DARWIN) - EXPECT_STREQ("Paste", interpretOSModifierKeyPress('V')); -#endif -} - -TEST_F(KeyboardTest, TestEscape) -{ - WebKeyboardEvent keyboardEvent; - setupKeyDownEvent(&keyboardEvent, WebCore::VKEY_ESCAPE, noModifiers); - - const char* result = interpretKeyEvent(keyboardEvent, - PlatformKeyboardEvent::RawKeyDown); - EXPECT_STREQ("Cancel", result); -} - -TEST_F(KeyboardTest, TestInsertTab) -{ - EXPECT_STREQ("InsertTab", interpretTab(noModifiers)); -} - -TEST_F(KeyboardTest, TestInsertBackTab) -{ - EXPECT_STREQ("InsertBacktab", interpretTab(WebInputEvent::ShiftKey)); -} - -TEST_F(KeyboardTest, TestInsertNewline) -{ - EXPECT_STREQ("InsertNewline", interpretNewLine(noModifiers)); -} - -TEST_F(KeyboardTest, TestInsertNewline2) -{ - EXPECT_STREQ("InsertNewline", interpretNewLine(WebInputEvent::ControlKey)); -} - -TEST_F(KeyboardTest, TestInsertLineBreak) -{ - EXPECT_STREQ("InsertLineBreak", interpretNewLine(WebInputEvent::ShiftKey)); -} - -TEST_F(KeyboardTest, TestInsertNewline3) -{ - EXPECT_STREQ("InsertNewline", interpretNewLine(WebInputEvent::AltKey)); -} - -TEST_F(KeyboardTest, TestInsertNewline4) -{ - int modifiers = WebInputEvent::AltKey | WebInputEvent::ShiftKey; - const char* result = interpretNewLine(modifiers); - EXPECT_STREQ("InsertNewline", result); -} - -} // empty namespace diff --git a/WebKit/chromium/tests/PODArenaTest.cpp b/WebKit/chromium/tests/PODArenaTest.cpp deleted file mode 100644 index c5b1ede..0000000 --- a/WebKit/chromium/tests/PODArenaTest.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2010 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 "PODArena.h" - -#include "ArenaTestHelpers.h" -#include <algorithm> -#include <gtest/gtest.h> -#include <wtf/FastMalloc.h> -#include <wtf/RefPtr.h> -#include <wtf/Vector.h> - -namespace WebCore { - -using ArenaTestHelpers::TrackedAllocator; - -namespace { - -// A couple of simple structs to allocate. -struct TestClass1 { - TestClass1() - : x(0), y(0), z(0), w(1) { } - - float x, y, z, w; -}; - -struct TestClass2 { - TestClass2() - : a(1), b(2), c(3), d(4) { } - - float a, b, c, d; -}; - -} // anonymous namespace - -class PODArenaTest : public testing::Test { -}; - -// Make sure the arena can successfully allocate from more than one -// region. -TEST_F(PODArenaTest, CanAllocateFromMoreThanOneRegion) -{ - RefPtr<TrackedAllocator> allocator = TrackedAllocator::create(); - RefPtr<PODArena> arena = PODArena::create(allocator); - int numIterations = 10 * PODArena::DefaultChunkSize / sizeof(TestClass1); - for (int i = 0; i < numIterations; ++i) - arena->allocateObject<TestClass1>(); - EXPECT_GT(allocator->numRegions(), 1); -} - -// Make sure the arena frees all allocated regions during destruction. -TEST_F(PODArenaTest, FreesAllAllocatedRegions) -{ - RefPtr<TrackedAllocator> allocator = TrackedAllocator::create(); - { - RefPtr<PODArena> arena = PODArena::create(allocator); - for (int i = 0; i < 3; i++) - arena->allocateObject<TestClass1>(); - EXPECT_GT(allocator->numRegions(), 0); - } - EXPECT_TRUE(allocator->isEmpty()); -} - -// Make sure the arena runs constructors of the objects allocated within. -TEST_F(PODArenaTest, RunsConstructors) -{ - RefPtr<PODArena> arena = PODArena::create(); - for (int i = 0; i < 10000; i++) { - TestClass1* tc1 = arena->allocateObject<TestClass1>(); - EXPECT_EQ(0, tc1->x); - EXPECT_EQ(0, tc1->y); - EXPECT_EQ(0, tc1->z); - EXPECT_EQ(1, tc1->w); - TestClass2* tc2 = arena->allocateObject<TestClass2>(); - EXPECT_EQ(1, tc2->a); - EXPECT_EQ(2, tc2->b); - EXPECT_EQ(3, tc2->c); - EXPECT_EQ(4, tc2->d); - } -} - -} // namespace WebCore diff --git a/WebKit/chromium/tests/PODIntervalTreeTest.cpp b/WebKit/chromium/tests/PODIntervalTreeTest.cpp deleted file mode 100644 index 8241a89..0000000 --- a/WebKit/chromium/tests/PODIntervalTreeTest.cpp +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Copyright (C) 2010 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. - */ - -// Tests for the interval tree class. - -#include "config.h" - -#include "PODIntervalTree.h" - -#include "Logging.h" -#include "TreeTestHelpers.h" -#include <gtest/gtest.h> -#include <wtf/Vector.h> -#include <wtf/text/WTFString.h> - -namespace WebCore { - -using TreeTestHelpers::generateSeed; -using TreeTestHelpers::initRandom; -using TreeTestHelpers::nextRandom; - -#ifndef NDEBUG -template<> -struct ValueToString<float> { - static String string(const float& value) { return String::number(value); } -}; - -template<> -struct ValueToString<void*> { - static String string(void* const& value) - { - return String::format("0x%p", value); - } -}; -#endif - -TEST(PODIntervalTreeTest, TestInsertion) -{ - PODIntervalTree<float> tree; - tree.add(PODInterval<float>(2, 4)); - ASSERT_TRUE(tree.checkInvariants()); -} - -TEST(PODIntervalTreeTest, TestInsertionAndQuery) -{ - PODIntervalTree<float> tree; - tree.add(PODInterval<float>(2, 4)); - ASSERT_TRUE(tree.checkInvariants()); - Vector<PODInterval<float> > result = tree.allOverlaps(PODInterval<float>(1, 3)); - EXPECT_EQ(1U, result.size()); - EXPECT_EQ(2, result[0].low()); - EXPECT_EQ(4, result[0].high()); -} - -TEST(PODIntervalTreeTest, TestQueryAgainstZeroSizeInterval) -{ - PODIntervalTree<float> tree; - tree.add(PODInterval<float>(1, 2.5)); - tree.add(PODInterval<float>(3.5, 5)); - tree.add(PODInterval<float>(2, 4)); - ASSERT_TRUE(tree.checkInvariants()); - Vector<PODInterval<float> > result = tree.allOverlaps(PODInterval<float>(3, 3)); - EXPECT_EQ(1U, result.size()); - EXPECT_EQ(2, result[0].low()); - EXPECT_EQ(4, result[0].high()); -} - -#ifndef NDEBUG -template<> -struct ValueToString<int*> { - static String string(int* const& value) - { - return String::format("0x%p", value); - } -}; -#endif - -TEST(PODIntervalTreeTest, TestDuplicateElementInsertion) -{ - PODIntervalTree<float, int*> tree; - int tmp1 = 1; - int tmp2 = 2; - typedef PODIntervalTree<float, int*>::IntervalType IntervalType; - IntervalType interval1(1, 3, &tmp1); - IntervalType interval2(1, 3, &tmp2); - tree.add(interval1); - tree.add(interval2); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_TRUE(tree.contains(interval1)); - EXPECT_TRUE(tree.contains(interval2)); - EXPECT_TRUE(tree.remove(interval1)); - EXPECT_TRUE(tree.contains(interval2)); - EXPECT_FALSE(tree.contains(interval1)); - EXPECT_TRUE(tree.remove(interval2)); - EXPECT_EQ(0, tree.size()); -} - -namespace { - -struct UserData1 { -public: - UserData1() - : a(0), b(1) { } - - float a; - int b; -}; - -} // anonymous namespace - -#ifndef NDEBUG -template<> -struct ValueToString<UserData1> { - static String string(const UserData1& value) - { - return String("[UserData1 a=") + String::number(value.a) + " b=" + String::number(value.b) + "]"; - } -}; -#endif - -TEST(PODIntervalTreeTest, TestInsertionOfComplexUserData) -{ - PODIntervalTree<float, UserData1> tree; - UserData1 data1; - data1.a = 5; - data1.b = 6; - tree.add(tree.createInterval(2, 4, data1)); - ASSERT_TRUE(tree.checkInvariants()); -} - -TEST(PODIntervalTreeTest, TestQueryingOfComplexUserData) -{ - PODIntervalTree<float, UserData1> tree; - UserData1 data1; - data1.a = 5; - data1.b = 6; - tree.add(tree.createInterval(2, 4, data1)); - ASSERT_TRUE(tree.checkInvariants()); - Vector<PODInterval<float, UserData1> > overlaps = tree.allOverlaps(tree.createInterval(3, 5, data1)); - EXPECT_EQ(1U, overlaps.size()); - EXPECT_EQ(5, overlaps[0].data().a); - EXPECT_EQ(6, overlaps[0].data().b); -} - -namespace { - -class EndpointType1 { -public: - explicit EndpointType1(int value) - : m_value(value) { } - - int value() const { return m_value; } - - bool operator<(const EndpointType1& other) const { return m_value < other.m_value; } - bool operator==(const EndpointType1& other) const { return m_value == other.m_value; } - -private: - int m_value; - // These operators should not be called by the interval tree. - bool operator>(const EndpointType1& other); - bool operator<=(const EndpointType1& other); - bool operator>=(const EndpointType1& other); - bool operator!=(const EndpointType1& other); -}; - -} // anonymous namespace - -#ifndef NDEBUG -template<> -struct ValueToString<EndpointType1> { - static String string(const EndpointType1& value) - { - return String("[EndpointType1 value=") + String::number(value.value()) + "]"; - } -}; -#endif - -TEST(PODIntervalTreeTest, TestTreeDoesNotRequireMostOperators) -{ - PODIntervalTree<EndpointType1> tree; - tree.add(tree.createInterval(EndpointType1(1), EndpointType1(2))); - ASSERT_TRUE(tree.checkInvariants()); -} - -// Uncomment to debug a failure of the insertion and deletion test. Won't work -// in release builds. -// #define DEBUG_INSERTION_AND_DELETION_TEST - -#ifndef NDEBUG -template<> -struct ValueToString<int> { - static String string(const int& value) { return String::number(value); } -}; -#endif - -namespace { - -void InsertionAndDeletionTest(int32_t seed, int treeSize) -{ - initRandom(seed); - int maximumValue = treeSize; - // Build the tree - PODIntervalTree<int> tree; - Vector<PODInterval<int> > addedElements; - Vector<PODInterval<int> > removedElements; - for (int i = 0; i < treeSize; i++) { - int left = nextRandom(maximumValue); - int length = nextRandom(maximumValue); - PODInterval<int> interval(left, left + length); - tree.add(interval); -#ifdef DEBUG_INSERTION_AND_DELETION_TEST - LOG_ERROR("*** Adding element %s", ValueToString<PODInterval<int> >::string(interval).ascii().data()); -#endif - addedElements.append(interval); - } - // Churn the tree's contents. - // First remove half of the elements in random order. - for (int i = 0; i < treeSize / 2; i++) { - int index = nextRandom(addedElements.size()); -#ifdef DEBUG_INSERTION_AND_DELETION_TEST - LOG_ERROR("*** Removing element %s", ValueToString<PODInterval<int> >::string(addedElements[index]).ascii().data()); -#endif - ASSERT_TRUE(tree.contains(addedElements[index])) << "Test failed for seed " << seed; - tree.remove(addedElements[index]); - removedElements.append(addedElements[index]); - addedElements.remove(index); - ASSERT_TRUE(tree.checkInvariants()) << "Test failed for seed " << seed; - } - // Now randomly add or remove elements. - for (int i = 0; i < 2 * treeSize; i++) { - bool add = false; - if (!addedElements.size()) - add = true; - else if (!removedElements.size()) - add = false; - else - add = (nextRandom(2) == 1); - if (add) { - int index = nextRandom(removedElements.size()); -#ifdef DEBUG_INSERTION_AND_DELETION_TEST - LOG_ERROR("*** Adding element %s", ValueToString<PODInterval<int> >::string(removedElements[index]).ascii().data()); -#endif - tree.add(removedElements[index]); - addedElements.append(removedElements[index]); - removedElements.remove(index); - } else { - int index = nextRandom(addedElements.size()); -#ifdef DEBUG_INSERTION_AND_DELETION_TEST - LOG_ERROR("*** Removing element %s", ValueToString<PODInterval<int> >::string(addedElements[index]).ascii().data()); -#endif - ASSERT_TRUE(tree.contains(addedElements[index])) << "Test failed for seed " << seed; - ASSERT_TRUE(tree.remove(addedElements[index])) << "Test failed for seed " << seed; - removedElements.append(addedElements[index]); - addedElements.remove(index); - } - ASSERT_TRUE(tree.checkInvariants()) << "Test failed for seed " << seed; - } -} - -} // anonymous namespace - -TEST(PODIntervalTreeTest, RandomDeletionAndInsertionRegressionTest1) -{ - InsertionAndDeletionTest(13972, 100); -} - -TEST(PODIntervalTreeTest, RandomDeletionAndInsertionRegressionTest2) -{ - InsertionAndDeletionTest(1283382113, 10); -} - -TEST(PODIntervalTreeTest, RandomDeletionAndInsertionRegressionTest3) -{ - // This is the sequence of insertions and deletions that triggered - // the failure in RandomDeletionAndInsertionRegressionTest2. - PODIntervalTree<int> tree; - tree.add(tree.createInterval(0, 5)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(4, 5)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(8, 9)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(1, 4)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(3, 5)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(4, 12)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(0, 2)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(0, 2)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(9, 13)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(0, 1)); - ASSERT_TRUE(tree.checkInvariants()); - tree.remove(tree.createInterval(0, 2)); - ASSERT_TRUE(tree.checkInvariants()); - tree.remove(tree.createInterval(9, 13)); - ASSERT_TRUE(tree.checkInvariants()); - tree.remove(tree.createInterval(0, 2)); - ASSERT_TRUE(tree.checkInvariants()); - tree.remove(tree.createInterval(0, 1)); - ASSERT_TRUE(tree.checkInvariants()); - tree.remove(tree.createInterval(4, 5)); - ASSERT_TRUE(tree.checkInvariants()); - tree.remove(tree.createInterval(4, 12)); - ASSERT_TRUE(tree.checkInvariants()); -} - -TEST(PODIntervalTreeTest, RandomDeletionAndInsertionRegressionTest4) -{ - // Even further reduced test case for RandomDeletionAndInsertionRegressionTest3. - PODIntervalTree<int> tree; - tree.add(tree.createInterval(0, 5)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(8, 9)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(1, 4)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(3, 5)); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(tree.createInterval(4, 12)); - ASSERT_TRUE(tree.checkInvariants()); - tree.remove(tree.createInterval(4, 12)); - ASSERT_TRUE(tree.checkInvariants()); -} - -TEST(PODIntervalTreeTest, TestRandomDeletionAndInsertion) -{ - InsertionAndDeletionTest(generateSeed(), 1000); -} - -} // namespace WebCore diff --git a/WebKit/chromium/tests/PODRedBlackTreeTest.cpp b/WebKit/chromium/tests/PODRedBlackTreeTest.cpp deleted file mode 100644 index 0cc10e7..0000000 --- a/WebKit/chromium/tests/PODRedBlackTreeTest.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (C) 2010 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. - */ - -// Tests for the red-black tree class. - -#include "config.h" - -#include "PODRedBlackTree.h" - -#include "ArenaTestHelpers.h" -#include "TreeTestHelpers.h" -#include <gtest/gtest.h> -#include <wtf/Vector.h> - -namespace WebCore { - -using ArenaTestHelpers::TrackedAllocator; -using TreeTestHelpers::generateSeed; -using TreeTestHelpers::initRandom; -using TreeTestHelpers::nextRandom; - -TEST(PODRedBlackTreeTest, TestTreeAllocatesFromArena) -{ - RefPtr<TrackedAllocator> allocator = TrackedAllocator::create(); - { - RefPtr<PODArena> arena = PODArena::create(allocator); - PODRedBlackTree<int> tree(arena); - int numAdditions = 2 * PODArena::DefaultChunkSize / sizeof(int); - for (int i = 0; i < numAdditions; ++i) - tree.add(i); - EXPECT_GT(allocator->numRegions(), 1); - } - EXPECT_EQ(allocator->numRegions(), 0); -} - -TEST(PODRedBlackTreeTest, TestSingleElementInsertion) -{ - PODRedBlackTree<int> tree; - tree.add(5); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_TRUE(tree.contains(5)); -} - -TEST(PODRedBlackTreeTest, TestMultipleElementInsertion) -{ - PODRedBlackTree<int> tree; - tree.add(4); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_TRUE(tree.contains(4)); - tree.add(3); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_TRUE(tree.contains(3)); - tree.add(5); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_TRUE(tree.contains(5)); - EXPECT_TRUE(tree.contains(4)); - EXPECT_TRUE(tree.contains(3)); -} - -TEST(PODRedBlackTreeTest, TestDuplicateElementInsertion) -{ - PODRedBlackTree<int> tree; - tree.add(3); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(3); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(3); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_EQ(3, tree.size()); - EXPECT_TRUE(tree.contains(3)); -} - -TEST(PODRedBlackTreeTest, TestSingleElementInsertionAndDeletion) -{ - PODRedBlackTree<int> tree; - tree.add(5); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_TRUE(tree.contains(5)); - tree.remove(5); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_FALSE(tree.contains(5)); -} - -TEST(PODRedBlackTreeTest, TestMultipleElementInsertionAndDeletion) -{ - PODRedBlackTree<int> tree; - tree.add(4); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_TRUE(tree.contains(4)); - tree.add(3); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_TRUE(tree.contains(3)); - tree.add(5); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_TRUE(tree.contains(5)); - EXPECT_TRUE(tree.contains(4)); - EXPECT_TRUE(tree.contains(3)); - tree.remove(4); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_TRUE(tree.contains(3)); - EXPECT_FALSE(tree.contains(4)); - EXPECT_TRUE(tree.contains(5)); - tree.remove(5); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_TRUE(tree.contains(3)); - EXPECT_FALSE(tree.contains(4)); - EXPECT_FALSE(tree.contains(5)); - EXPECT_EQ(1, tree.size()); -} - -TEST(PODRedBlackTreeTest, TestDuplicateElementInsertionAndDeletion) -{ - PODRedBlackTree<int> tree; - tree.add(3); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(3); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(3); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_EQ(3, tree.size()); - EXPECT_TRUE(tree.contains(3)); - tree.remove(3); - ASSERT_TRUE(tree.checkInvariants()); - tree.remove(3); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_EQ(1, tree.size()); - EXPECT_TRUE(tree.contains(3)); - tree.remove(3); - ASSERT_TRUE(tree.checkInvariants()); - EXPECT_EQ(0, tree.size()); - EXPECT_FALSE(tree.contains(3)); -} - -TEST(PODRedBlackTreeTest, FailingInsertionRegressionTest1) -{ - // These numbers came from a previously-failing randomized test run. - PODRedBlackTree<int> tree; - tree.add(5113); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(4517); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(3373); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(9307); - ASSERT_TRUE(tree.checkInvariants()); - tree.add(7077); - ASSERT_TRUE(tree.checkInvariants()); -} - -namespace { -void InsertionAndDeletionTest(const int32_t seed, const int treeSize) -{ - initRandom(seed); - const int maximumValue = treeSize; - // Build the tree. - PODRedBlackTree<int> tree; - Vector<int> values; - for (int i = 0; i < treeSize; i++) { - int value = nextRandom(maximumValue); - tree.add(value); - ASSERT_TRUE(tree.checkInvariants()) << "Test failed for seed " << seed; - values.append(value); - } - // Churn the tree's contents. - for (int i = 0; i < treeSize; i++) { - // Pick a random value to remove. - int index = nextRandom(treeSize); - int value = values[index]; - // Remove this value. - tree.remove(value); - ASSERT_TRUE(tree.checkInvariants()) << "Test failed for seed " << seed; - // Replace it with a new one. - value = nextRandom(maximumValue); - values[index] = value; - tree.add(value); - ASSERT_TRUE(tree.checkInvariants()) << "Test failed for seed " << seed; - } -} -} // anonymous namespace - -TEST(PODRedBlackTreeTest, RandomDeletionAndInsertionRegressionTest1) -{ - InsertionAndDeletionTest(12311, 100); -} - -TEST(PODRedBlackTreeTest, TestRandomDeletionAndInsertion) -{ - InsertionAndDeletionTest(generateSeed(), 100); -} - -} // namespace WebCore diff --git a/WebKit/chromium/tests/PopupMenuTest.cpp b/WebKit/chromium/tests/PopupMenuTest.cpp deleted file mode 100644 index 4b6b123..0000000 --- a/WebKit/chromium/tests/PopupMenuTest.cpp +++ /dev/null @@ -1,378 +0,0 @@ -/* - * Copyright (C) 2010 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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 <gtest/gtest.h> - -#include "Color.h" -#include "KeyboardCodes.h" -#include "PopupMenu.h" -#include "PopupMenuClient.h" -#include "PopupMenuChromium.h" -#include "WebFrameClient.h" -#include "WebFrameImpl.h" -#include "WebInputEvent.h" -#include "WebPopupMenuImpl.h" -#include "WebScreenInfo.h" -#include "WebViewClient.h" -#include "WebViewImpl.h" - -using namespace WebCore; -using namespace WebKit; - -namespace { - -class TestPopupMenuClient : public PopupMenuClient { -public: - // Item at index 0 is selected by default. - TestPopupMenuClient() : m_selectIndex(0) { } - virtual ~TestPopupMenuClient() {} - virtual void valueChanged(unsigned listIndex, bool fireEvents = true) - { - m_selectIndex = listIndex; - } - virtual void selectionChanged(unsigned, bool) {} - virtual void selectionCleared() {} - - virtual String itemText(unsigned listIndex) const - { - String str("Item "); - str.append(String::number(listIndex)); - return str; - } - virtual String itemLabel(unsigned) const { return String(); } - virtual String itemIcon(unsigned) const { return String(); } - virtual String itemToolTip(unsigned listIndex) const { return itemText(listIndex); } - virtual String itemAccessibilityText(unsigned listIndex) const { return itemText(listIndex); } - virtual bool itemIsEnabled(unsigned listIndex) const { return true; } - virtual PopupMenuStyle itemStyle(unsigned listIndex) const - { - Font font(FontPlatformData(12.0, false, false), false); - return PopupMenuStyle(Color::black, Color::white, font, true, false, Length(), TextDirection()); - } - virtual PopupMenuStyle menuStyle() const { return itemStyle(0); } - virtual int clientInsetLeft() const { return 0; } - virtual int clientInsetRight() const { return 0; } - virtual int clientPaddingLeft() const { return 0; } - virtual int clientPaddingRight() const { return 0; } - virtual int listSize() const { return 10; } - virtual int selectedIndex() const { return m_selectIndex; } - virtual void popupDidHide() { } - virtual bool itemIsSeparator(unsigned listIndex) const { return false; } - virtual bool itemIsLabel(unsigned listIndex) const { return false; } - virtual bool itemIsSelected(unsigned listIndex) const { return listIndex == m_selectIndex; } - virtual bool shouldPopOver() const { return false; } - virtual bool valueShouldChangeOnHotTrack() const { return false; } - virtual void setTextFromItem(unsigned listIndex) { } - - virtual FontSelector* fontSelector() const { return 0; } - virtual HostWindow* hostWindow() const { return 0; } - - virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize) { return 0; } - -private: - unsigned m_selectIndex; -}; - -class TestWebWidgetClient : public WebWidgetClient { -public: - ~TestWebWidgetClient() { } -}; - -class TestWebPopupMenuImpl : public WebPopupMenuImpl { -public: - static PassRefPtr<TestWebPopupMenuImpl> create(WebWidgetClient* client) - { - return adoptRef(new TestWebPopupMenuImpl(client)); - } - - ~TestWebPopupMenuImpl() { } - -private: - TestWebPopupMenuImpl(WebWidgetClient* client) : WebPopupMenuImpl(client) { } -}; - -class TestWebWidget : public WebWidget { -public: - virtual ~TestWebWidget() { } - virtual void close() { } - virtual WebSize size() { return WebSize(100, 100); } - virtual void resize(const WebSize&) { } - virtual void layout() { } - virtual void paint(WebCanvas*, const WebRect&) { } - virtual void themeChanged() { } - virtual void composite(bool finish) { } - virtual bool handleInputEvent(const WebInputEvent&) { return true; } - virtual void mouseCaptureLost() { } - virtual void setFocus(bool) { } - virtual bool setComposition( - const WebString& text, - const WebVector<WebCompositionUnderline>& underlines, - int selectionStart, - int selectionEnd) { return true; } - virtual bool confirmComposition() { return true; } - virtual bool confirmComposition(const WebString& text) { return true; } - virtual WebTextInputType textInputType() { return WebKit::WebTextInputTypeNone; } - virtual WebRect caretOrSelectionBounds() { return WebRect(); } - virtual void setTextDirection(WebTextDirection) { } -}; - -class TestWebViewClient : public WebViewClient { -public: - TestWebViewClient() : m_webPopupMenu(TestWebPopupMenuImpl::create(&m_webWidgetClient)) { } - ~TestWebViewClient() { } - - virtual WebWidget* createPopupMenu(WebPopupType) { return m_webPopupMenu.get(); } - - // We need to override this so that the popup menu size is not 0 - // (the layout code checks to see if the popup fits on the screen). - virtual WebScreenInfo screenInfo() - { - WebScreenInfo screenInfo; - screenInfo.availableRect.height = 2000; - screenInfo.availableRect.width = 2000; - return screenInfo; - } - -private: - TestWebWidgetClient m_webWidgetClient; - RefPtr<TestWebPopupMenuImpl> m_webPopupMenu; -}; - -class TestWebFrameClient : public WebFrameClient { -public: - ~TestWebFrameClient() { } -}; - -class SelectPopupMenuTest : public testing::Test { -public: - SelectPopupMenuTest() - { - } - -protected: - virtual void SetUp() - { - m_webView = static_cast<WebViewImpl*>(WebView::create(&m_webviewClient, 0)); - m_webView->initializeMainFrame(&m_webFrameClient); - m_popupMenu = adoptRef(new PopupMenuChromium(&m_popupMenuClient)); - } - - virtual void TearDown() - { - m_popupMenu = 0; - m_webView->close(); - } - - // Returns true if there currently is a select popup in the WebView. - bool popupOpen() const { return m_webView->selectPopup(); } - - int selectedIndex() const { return m_popupMenuClient.selectedIndex(); } - - void showPopup() - { - m_popupMenu->show(IntRect(0, 0, 100, 100), - static_cast<WebFrameImpl*>(m_webView->mainFrame())->frameView(), 0); - ASSERT_TRUE(popupOpen()); - EXPECT_TRUE(m_webView->selectPopup()->popupType() == PopupContainer::Select); - } - - void hidePopup() - { - m_popupMenu->hide(); - EXPECT_FALSE(popupOpen()); - } - - void simulateKeyDownEvent(int keyCode) - { - simulateKeyEvent(WebInputEvent::RawKeyDown, keyCode); - } - - void simulateKeyUpEvent(int keyCode) - { - simulateKeyEvent(WebInputEvent::KeyUp, keyCode); - } - - // Simulates a key event on the WebView. - // The WebView forwards the event to the select popup if one is open. - void simulateKeyEvent(WebInputEvent::Type eventType, int keyCode) - { - WebKeyboardEvent keyEvent; - keyEvent.windowsKeyCode = keyCode; - keyEvent.type = eventType; - m_webView->handleInputEvent(keyEvent); - } - - // Simulates a mouse event on the select popup. - void simulateLeftMouseDownEvent(const IntPoint& point) - { - PlatformMouseEvent mouseEvent(point, point, LeftButton, MouseEventPressed, - 1, false, false, false, false, 0); - m_webView->selectPopup()->handleMouseDownEvent(mouseEvent); - } - void simulateLeftMouseUpEvent(const IntPoint& point) - { - PlatformMouseEvent mouseEvent(point, point, LeftButton, MouseEventReleased, - 1, false, false, false, false, 0); - m_webView->selectPopup()->handleMouseReleaseEvent(mouseEvent); - } - -protected: - TestWebViewClient m_webviewClient; - WebViewImpl* m_webView; - TestWebFrameClient m_webFrameClient; - TestPopupMenuClient m_popupMenuClient; - RefPtr<PopupMenu> m_popupMenu; -}; - -// Tests that show/hide and repeats. Select popups are reused in web pages when -// they are reopened, that what this is testing. -TEST_F(SelectPopupMenuTest, ShowThenHide) -{ - for (int i = 0; i < 3; i++) { - showPopup(); - hidePopup(); - } -} - -// Tests that showing a select popup and deleting it does not cause problem. -// This happens in real-life if a page navigates while a select popup is showing. -TEST_F(SelectPopupMenuTest, ShowThenDelete) -{ - showPopup(); - // Nothing else to do, TearDown() deletes the popup. -} - -// Tests that losing focus closes the select popup. -TEST_F(SelectPopupMenuTest, ShowThenLoseFocus) -{ - showPopup(); - // Simulate losing focus. - m_webView->setFocus(false); - - // Popup should have closed. - EXPECT_FALSE(popupOpen()); -} - -// Tests that pressing ESC closes the popup. -TEST_F(SelectPopupMenuTest, ShowThenPressESC) -{ - showPopup(); - simulateKeyDownEvent(VKEY_ESCAPE); - // Popup should have closed. - EXPECT_FALSE(popupOpen()); -} - -// Tests selecting an item with the arrows and enter/esc/tab. -TEST_F(SelectPopupMenuTest, SelectWithKeys) -{ - showPopup(); - // Simulate selecting the 2nd item by pressing Down, Down, enter. - simulateKeyDownEvent(VKEY_DOWN); - simulateKeyDownEvent(VKEY_DOWN); - simulateKeyDownEvent(VKEY_RETURN); - - // Popup should have closed. - EXPECT_TRUE(!popupOpen()); - EXPECT_EQ(2, selectedIndex()); - - // It should work as well with ESC. - showPopup(); - simulateKeyDownEvent(VKEY_DOWN); - simulateKeyDownEvent(VKEY_ESCAPE); - EXPECT_FALSE(popupOpen()); - EXPECT_EQ(3, selectedIndex()); - - // It should work as well with TAB. - showPopup(); - simulateKeyDownEvent(VKEY_DOWN); - simulateKeyDownEvent(VKEY_TAB); - EXPECT_FALSE(popupOpen()); - EXPECT_EQ(4, selectedIndex()); -} - -// Tests that selecting an item with the mouse does select the item and close -// the popup. -TEST_F(SelectPopupMenuTest, ClickItem) -{ - showPopup(); - - // Y of 18 to be on the item at index 1 (12 font plus border and more to be safe). - IntPoint row1Point(2, 18); - // Simulate a click down/up on the first item. - simulateLeftMouseDownEvent(row1Point); - simulateLeftMouseUpEvent(row1Point); - - // Popup should have closed and the item at index 1 selected. - EXPECT_FALSE(popupOpen()); - EXPECT_EQ(1, selectedIndex()); -} - -// Tests that moving the mouse over an item and then clicking outside the select popup -// leaves the seleted item unchanged. -TEST_F(SelectPopupMenuTest, MouseOverItemClickOutside) -{ - showPopup(); - - // Y of 18 to be on the item at index 1 (12 font plus border and more to be safe). - IntPoint row1Point(2, 18); - // Simulate the mouse moving over the first item. - PlatformMouseEvent mouseEvent(row1Point, row1Point, NoButton, MouseEventMoved, - 1, false, false, false, false, 0); - m_webView->selectPopup()->handleMouseMoveEvent(mouseEvent); - - // Click outside the popup. - simulateLeftMouseDownEvent(IntPoint(1000, 1000)); - - // Popup should have closed and item 0 should still be selected. - EXPECT_FALSE(popupOpen()); - EXPECT_EQ(0, selectedIndex()); -} - -// Tests that selecting an item with the keyboard and then clicking outside the select -// popup does select that item. -TEST_F(SelectPopupMenuTest, SelectItemWithKeyboardItemClickOutside) -{ - showPopup(); - - // Simulate selecting the 2nd item by pressing Down, Down. - simulateKeyDownEvent(VKEY_DOWN); - simulateKeyDownEvent(VKEY_DOWN); - - // Click outside the popup. - simulateLeftMouseDownEvent(IntPoint(1000, 1000)); - - // Popup should have closed and the item should have been selected. - EXPECT_FALSE(popupOpen()); - EXPECT_EQ(2, selectedIndex()); -} - -} // namespace diff --git a/WebKit/chromium/tests/RunAllTests.cpp b/WebKit/chromium/tests/RunAllTests.cpp deleted file mode 100644 index b213de7..0000000 --- a/WebKit/chromium/tests/RunAllTests.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2010 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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. - */ - -// FIXME: Avoid this source dependency on Chromium's base module. -#include <base/test/test_suite.h> - -#include "WebKit.h" -#include "WebKitClient.h" -#include <webkit/support/webkit_support.h> - -#if defined(WIN32) && defined(WEBKIT_DLL_UNITTEST) -#include "WebUnitTests.h" -#endif - -int main(int argc, char** argv) -{ - TestSuite testSuite(argc, argv); - // TestSuite must be created before SetUpTestEnvironment so it performs - // initializations needed by WebKit support. - webkit_support::SetUpTestEnvironmentForUnitTests(); - -#if defined(WIN32) && defined(WEBKIT_DLL_UNITTEST) - // For chromium multi-dll build, need to call webkit api to create a - // TestSuite instance in webkit.dll and run all tests from there. - int result = WebKit::RunAllUnitTests(argc, argv); -#else - int result = testSuite.Run(); -#endif - - webkit_support::TearDownTestEnvironment(); - return result; -} diff --git a/WebKit/chromium/tests/TilingDataTest.cpp b/WebKit/chromium/tests/TilingDataTest.cpp deleted file mode 100755 index ec18f01..0000000 --- a/WebKit/chromium/tests/TilingDataTest.cpp +++ /dev/null @@ -1,334 +0,0 @@ -/* - * Copyright (C) 2010 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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 "TilingData.h" - -#include <gtest/gtest.h> - -using namespace WebCore; - -namespace { - -TEST(TilingDataTest, numTiles_NoTiling) -{ - EXPECT_EQ(1, TilingData(16, 16, 16, false).numTiles()); - EXPECT_EQ(1, TilingData(16, 15, 15, true).numTiles()); - EXPECT_EQ(1, TilingData(16, 16, 16, true).numTiles()); - EXPECT_EQ(1, TilingData(16, 1, 16, false).numTiles()); - EXPECT_EQ(1, TilingData(15, 15, 15, true).numTiles()); -} - -TEST(TilingDataTest, numTiles_TilingNoBorders) -{ - EXPECT_EQ(1, TilingData(4, 1, 4, false).numTiles()); - EXPECT_EQ(1, TilingData(4, 2, 4, false).numTiles()); - EXPECT_EQ(1, TilingData(4, 3, 4, false).numTiles()); - EXPECT_EQ(1, TilingData(4, 4, 4, false).numTiles()); - EXPECT_EQ(2, TilingData(4, 5, 4, false).numTiles()); - EXPECT_EQ(2, TilingData(4, 6, 4, false).numTiles()); - EXPECT_EQ(2, TilingData(4, 7, 4, false).numTiles()); - EXPECT_EQ(2, TilingData(4, 8, 4, false).numTiles()); - EXPECT_EQ(3, TilingData(4, 9, 4, false).numTiles()); - EXPECT_EQ(3, TilingData(4, 10, 4, false).numTiles()); - EXPECT_EQ(3, TilingData(4, 11, 4, false).numTiles()); - - EXPECT_EQ(1, TilingData(5, 1, 5, false).numTiles()); - EXPECT_EQ(1, TilingData(5, 2, 5, false).numTiles()); - EXPECT_EQ(1, TilingData(5, 3, 5, false).numTiles()); - EXPECT_EQ(1, TilingData(5, 4, 5, false).numTiles()); - EXPECT_EQ(1, TilingData(5, 5, 5, false).numTiles()); - EXPECT_EQ(2, TilingData(5, 6, 5, false).numTiles()); - EXPECT_EQ(2, TilingData(5, 7, 5, false).numTiles()); - EXPECT_EQ(2, TilingData(5, 8, 5, false).numTiles()); - EXPECT_EQ(2, TilingData(5, 9, 5, false).numTiles()); - EXPECT_EQ(2, TilingData(5, 10, 5, false).numTiles()); - EXPECT_EQ(3, TilingData(5, 11, 5, false).numTiles()); - - EXPECT_EQ(1, TilingData(16, 16, 16, false).numTiles()); - EXPECT_EQ(1, TilingData(17, 16, 16, false).numTiles()); - EXPECT_EQ(4, TilingData(15, 16, 16, false).numTiles()); - EXPECT_EQ(4, TilingData(8, 16, 16, false).numTiles()); - EXPECT_EQ(6, TilingData(8, 17, 16, false).numTiles()); -} - -TEST(TilingDataTest, numTiles_TilingWithBorders) -{ - EXPECT_EQ(1, TilingData(3, 1, 3, true).numTiles()); - EXPECT_EQ(1, TilingData(3, 2, 3, true).numTiles()); - EXPECT_EQ(1, TilingData(3, 3, 3, true).numTiles()); - EXPECT_EQ(2, TilingData(3, 4, 3, true).numTiles()); - EXPECT_EQ(3, TilingData(3, 5, 3, true).numTiles()); - EXPECT_EQ(4, TilingData(3, 6, 3, true).numTiles()); - EXPECT_EQ(5, TilingData(3, 7, 3, true).numTiles()); - - EXPECT_EQ(1, TilingData(4, 1, 4, true).numTiles()); - EXPECT_EQ(1, TilingData(4, 2, 4, true).numTiles()); - EXPECT_EQ(1, TilingData(4, 3, 4, true).numTiles()); - EXPECT_EQ(1, TilingData(4, 4, 4, true).numTiles()); - EXPECT_EQ(2, TilingData(4, 5, 4, true).numTiles()); - EXPECT_EQ(2, TilingData(4, 6, 4, true).numTiles()); - EXPECT_EQ(3, TilingData(4, 7, 4, true).numTiles()); - EXPECT_EQ(3, TilingData(4, 8, 4, true).numTiles()); - EXPECT_EQ(4, TilingData(4, 9, 4, true).numTiles()); - EXPECT_EQ(4, TilingData(4, 10, 4, true).numTiles()); - EXPECT_EQ(5, TilingData(4, 11, 4, true).numTiles()); - - EXPECT_EQ(1, TilingData(5, 1, 5, true).numTiles()); - EXPECT_EQ(1, TilingData(5, 2, 5, true).numTiles()); - EXPECT_EQ(1, TilingData(5, 3, 5, true).numTiles()); - EXPECT_EQ(1, TilingData(5, 4, 5, true).numTiles()); - EXPECT_EQ(1, TilingData(5, 5, 5, true).numTiles()); - EXPECT_EQ(2, TilingData(5, 6, 5, true).numTiles()); - EXPECT_EQ(2, TilingData(5, 7, 5, true).numTiles()); - EXPECT_EQ(2, TilingData(5, 8, 5, true).numTiles()); - EXPECT_EQ(3, TilingData(5, 9, 5, true).numTiles()); - EXPECT_EQ(3, TilingData(5, 10, 5, true).numTiles()); - EXPECT_EQ(3, TilingData(5, 11, 5, true).numTiles()); -} - -TEST(TilingDataTest, tileXIndexFromSrcCoord) -{ - EXPECT_EQ(0, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(0)); - EXPECT_EQ(0, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(1)); - EXPECT_EQ(0, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(2)); - EXPECT_EQ(1, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(3)); - EXPECT_EQ(1, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(4)); - EXPECT_EQ(1, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(5)); - EXPECT_EQ(2, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(6)); - EXPECT_EQ(2, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(7)); - EXPECT_EQ(2, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(8)); - EXPECT_EQ(3, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(9)); - EXPECT_EQ(3, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(10)); - EXPECT_EQ(3, TilingData(3, 10, 10, false).tileXIndexFromSrcCoord(11)); - - EXPECT_EQ(0, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(0)); - EXPECT_EQ(0, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(1)); - EXPECT_EQ(1, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(2)); - EXPECT_EQ(2, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(3)); - EXPECT_EQ(3, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(4)); - EXPECT_EQ(4, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(5)); - EXPECT_EQ(5, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(6)); - EXPECT_EQ(6, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(7)); - EXPECT_EQ(7, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(8)); - EXPECT_EQ(7, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(9)); - EXPECT_EQ(7, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(10)); - EXPECT_EQ(7, TilingData(3, 10, 10, true).tileXIndexFromSrcCoord(11)); -} -TEST(TilingDataTest, tileYIndexFromSrcCoord) -{ - EXPECT_EQ(0, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(0)); - EXPECT_EQ(0, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(1)); - EXPECT_EQ(0, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(2)); - EXPECT_EQ(1, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(3)); - EXPECT_EQ(1, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(4)); - EXPECT_EQ(1, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(5)); - EXPECT_EQ(2, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(6)); - EXPECT_EQ(2, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(7)); - EXPECT_EQ(2, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(8)); - EXPECT_EQ(3, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(9)); - EXPECT_EQ(3, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(10)); - EXPECT_EQ(3, TilingData(3, 10, 10, false).tileYIndexFromSrcCoord(11)); - - EXPECT_EQ(0, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(0)); - EXPECT_EQ(0, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(1)); - EXPECT_EQ(1, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(2)); - EXPECT_EQ(2, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(3)); - EXPECT_EQ(3, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(4)); - EXPECT_EQ(4, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(5)); - EXPECT_EQ(5, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(6)); - EXPECT_EQ(6, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(7)); - EXPECT_EQ(7, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(8)); - EXPECT_EQ(7, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(9)); - EXPECT_EQ(7, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(10)); - EXPECT_EQ(7, TilingData(3, 10, 10, true).tileYIndexFromSrcCoord(11)); -} - -TEST(TilingDataTest, tileSizeX) -{ - EXPECT_EQ(5, TilingData(5, 5, 5, false).tileSizeX(0)); - EXPECT_EQ(5, TilingData(5, 5, 5, true).tileSizeX(0)); - - EXPECT_EQ(5, TilingData(5, 6, 6, false).tileSizeX(0)); - EXPECT_EQ(1, TilingData(5, 6, 6, false).tileSizeX(1)); - EXPECT_EQ(4, TilingData(5, 6, 6, true).tileSizeX(0)); - EXPECT_EQ(2, TilingData(5, 6, 6, true).tileSizeX(1)); - - EXPECT_EQ(5, TilingData(5, 8, 8, false).tileSizeX(0)); - EXPECT_EQ(3, TilingData(5, 8, 8, false).tileSizeX(1)); - EXPECT_EQ(4, TilingData(5, 8, 8, true).tileSizeX(0)); - EXPECT_EQ(4, TilingData(5, 8, 8, true).tileSizeX(1)); - - EXPECT_EQ(5, TilingData(5, 10, 10, false).tileSizeX(0)); - EXPECT_EQ(5, TilingData(5, 10, 10, false).tileSizeX(1)); - EXPECT_EQ(4, TilingData(5, 10, 10, true).tileSizeX(0)); - EXPECT_EQ(3, TilingData(5, 10, 10, true).tileSizeX(1)); - EXPECT_EQ(3, TilingData(5, 10, 10, true).tileSizeX(2)); - - EXPECT_EQ(4, TilingData(5, 11, 11, true).tileSizeX(2)); - EXPECT_EQ(3, TilingData(5, 12, 12, true).tileSizeX(2)); -} -TEST(TilingDataTest, tileSizeY) -{ - EXPECT_EQ(5, TilingData(5, 5, 5, false).tileSizeY(0)); - EXPECT_EQ(5, TilingData(5, 5, 5, true).tileSizeY(0)); - - EXPECT_EQ(5, TilingData(5, 6, 6, false).tileSizeY(0)); - EXPECT_EQ(1, TilingData(5, 6, 6, false).tileSizeY(1)); - EXPECT_EQ(4, TilingData(5, 6, 6, true).tileSizeY(0)); - EXPECT_EQ(2, TilingData(5, 6, 6, true).tileSizeY(1)); - - EXPECT_EQ(5, TilingData(5, 8, 8, false).tileSizeY(0)); - EXPECT_EQ(3, TilingData(5, 8, 8, false).tileSizeY(1)); - EXPECT_EQ(4, TilingData(5, 8, 8, true).tileSizeY(0)); - EXPECT_EQ(4, TilingData(5, 8, 8, true).tileSizeY(1)); - - EXPECT_EQ(5, TilingData(5, 10, 10, false).tileSizeY(0)); - EXPECT_EQ(5, TilingData(5, 10, 10, false).tileSizeY(1)); - EXPECT_EQ(4, TilingData(5, 10, 10, true).tileSizeY(0)); - EXPECT_EQ(3, TilingData(5, 10, 10, true).tileSizeY(1)); - EXPECT_EQ(3, TilingData(5, 10, 10, true).tileSizeY(2)); - - EXPECT_EQ(4, TilingData(5, 11, 11, true).tileSizeY(2)); - EXPECT_EQ(3, TilingData(5, 12, 12, true).tileSizeY(2)); -} - -TEST(TilingDataTest, tileSizeX_and_tilePositionX) -{ - // Single tile cases: - EXPECT_EQ(1, TilingData(3, 1, 1, false).tileSizeX(0)); - EXPECT_EQ(0, TilingData(3, 1, 1, false).tilePositionX(0)); - EXPECT_EQ(1, TilingData(3, 1, 100, false).tileSizeX(0)); - EXPECT_EQ(0, TilingData(3, 1, 100, false).tilePositionX(0)); - EXPECT_EQ(3, TilingData(3, 3, 1, false).tileSizeX(0)); - EXPECT_EQ(0, TilingData(3, 3, 1, false).tilePositionX(0)); - EXPECT_EQ(3, TilingData(3, 3, 100, false).tileSizeX(0)); - EXPECT_EQ(0, TilingData(3, 3, 100, false).tilePositionX(0)); - EXPECT_EQ(1, TilingData(3, 1, 1, true).tileSizeX(0)); - EXPECT_EQ(0, TilingData(3, 1, 1, true).tilePositionX(0)); - EXPECT_EQ(1, TilingData(3, 1, 100, true).tileSizeX(0)); - EXPECT_EQ(0, TilingData(3, 1, 100, true).tilePositionX(0)); - EXPECT_EQ(3, TilingData(3, 3, 1, true).tileSizeX(0)); - EXPECT_EQ(0, TilingData(3, 3, 1, true).tilePositionX(0)); - EXPECT_EQ(3, TilingData(3, 3, 100, true).tileSizeX(0)); - EXPECT_EQ(0, TilingData(3, 3, 100, true).tilePositionX(0)); - - // Multiple tiles: - // no border - // positions 0, 3 - EXPECT_EQ(2, TilingData(3, 6, 1, false).numTiles()); - EXPECT_EQ(3, TilingData(3, 6, 1, false).tileSizeX(0)); - EXPECT_EQ(3, TilingData(3, 6, 1, false).tileSizeX(1)); - EXPECT_EQ(0, TilingData(3, 6, 1, false).tilePositionX(0)); - EXPECT_EQ(3, TilingData(3, 6, 1, false).tilePositionX(1)); - EXPECT_EQ(3, TilingData(3, 6, 100, false).tileSizeX(0)); - EXPECT_EQ(3, TilingData(3, 6, 100, false).tileSizeX(1)); - EXPECT_EQ(0, TilingData(3, 6, 100, false).tilePositionX(0)); - EXPECT_EQ(3, TilingData(3, 6, 100, false).tilePositionX(1)); - - // Multiple tiles: - // with border - // positions 0, 2, 3, 4 - EXPECT_EQ(4, TilingData(3, 6, 1, true).numTiles()); - EXPECT_EQ(2, TilingData(3, 6, 1, true).tileSizeX(0)); - EXPECT_EQ(1, TilingData(3, 6, 1, true).tileSizeX(1)); - EXPECT_EQ(1, TilingData(3, 6, 1, true).tileSizeX(2)); - EXPECT_EQ(2, TilingData(3, 6, 1, true).tileSizeX(3)); - EXPECT_EQ(0, TilingData(3, 6, 1, true).tilePositionX(0)); - EXPECT_EQ(2, TilingData(3, 6, 1, true).tilePositionX(1)); - EXPECT_EQ(3, TilingData(3, 6, 1, true).tilePositionX(2)); - EXPECT_EQ(4, TilingData(3, 6, 1, true).tilePositionX(3)); - EXPECT_EQ(2, TilingData(3, 6, 100, true).tileSizeX(0)); - EXPECT_EQ(1, TilingData(3, 6, 100, true).tileSizeX(1)); - EXPECT_EQ(1, TilingData(3, 6, 100, true).tileSizeX(2)); - EXPECT_EQ(2, TilingData(3, 6, 100, true).tileSizeX(3)); - EXPECT_EQ(0, TilingData(3, 6, 100, true).tilePositionX(0)); - EXPECT_EQ(2, TilingData(3, 6, 100, true).tilePositionX(1)); - EXPECT_EQ(3, TilingData(3, 6, 100, true).tilePositionX(2)); - EXPECT_EQ(4, TilingData(3, 6, 100, true).tilePositionX(3)); -} - -TEST(TilingDataTest, tileSizeY_and_tilePositionY) -{ - // Single tile cases: - EXPECT_EQ(1, TilingData(3, 1, 1, false).tileSizeY(0)); - EXPECT_EQ(0, TilingData(3, 1, 1, false).tilePositionY(0)); - EXPECT_EQ(1, TilingData(3, 100, 1, false).tileSizeY(0)); - EXPECT_EQ(0, TilingData(3, 100, 1, false).tilePositionY(0)); - EXPECT_EQ(3, TilingData(3, 1, 3, false).tileSizeY(0)); - EXPECT_EQ(0, TilingData(3, 1, 3, false).tilePositionY(0)); - EXPECT_EQ(3, TilingData(3, 100, 3, false).tileSizeY(0)); - EXPECT_EQ(0, TilingData(3, 100, 3, false).tilePositionY(0)); - EXPECT_EQ(1, TilingData(3, 1, 1, true).tileSizeY(0)); - EXPECT_EQ(0, TilingData(3, 1, 1, true).tilePositionY(0)); - EXPECT_EQ(1, TilingData(3, 100, 1, true).tileSizeY(0)); - EXPECT_EQ(0, TilingData(3, 100, 1, true).tilePositionY(0)); - EXPECT_EQ(3, TilingData(3, 1, 3, true).tileSizeY(0)); - EXPECT_EQ(0, TilingData(3, 1, 3, true).tilePositionY(0)); - EXPECT_EQ(3, TilingData(3, 100, 3, true).tileSizeY(0)); - EXPECT_EQ(0, TilingData(3, 100, 3, true).tilePositionY(0)); - - // Multiple tiles: - // no border - // positions 0, 3 - EXPECT_EQ(2, TilingData(3, 1, 6, false).numTiles()); - EXPECT_EQ(3, TilingData(3, 1, 6, false).tileSizeY(0)); - EXPECT_EQ(3, TilingData(3, 1, 6, false).tileSizeY(1)); - EXPECT_EQ(0, TilingData(3, 1, 6, false).tilePositionY(0)); - EXPECT_EQ(3, TilingData(3, 1, 6, false).tilePositionY(1)); - EXPECT_EQ(3, TilingData(3, 100, 6, false).tileSizeY(0)); - EXPECT_EQ(3, TilingData(3, 100, 6, false).tileSizeY(1)); - EXPECT_EQ(0, TilingData(3, 100, 6, false).tilePositionY(0)); - EXPECT_EQ(3, TilingData(3, 100, 6, false).tilePositionY(1)); - - // Multiple tiles: - // with border - // positions 0, 2, 3, 4 - EXPECT_EQ(4, TilingData(3, 1, 6, true).numTiles()); - EXPECT_EQ(2, TilingData(3, 1, 6, true).tileSizeY(0)); - EXPECT_EQ(1, TilingData(3, 1, 6, true).tileSizeY(1)); - EXPECT_EQ(1, TilingData(3, 1, 6, true).tileSizeY(2)); - EXPECT_EQ(2, TilingData(3, 1, 6, true).tileSizeY(3)); - EXPECT_EQ(0, TilingData(3, 1, 6, true).tilePositionY(0)); - EXPECT_EQ(2, TilingData(3, 1, 6, true).tilePositionY(1)); - EXPECT_EQ(3, TilingData(3, 1, 6, true).tilePositionY(2)); - EXPECT_EQ(4, TilingData(3, 1, 6, true).tilePositionY(3)); - EXPECT_EQ(2, TilingData(3, 100, 6, true).tileSizeY(0)); - EXPECT_EQ(1, TilingData(3, 100, 6, true).tileSizeY(1)); - EXPECT_EQ(1, TilingData(3, 100, 6, true).tileSizeY(2)); - EXPECT_EQ(2, TilingData(3, 100, 6, true).tileSizeY(3)); - EXPECT_EQ(0, TilingData(3, 100, 6, true).tilePositionY(0)); - EXPECT_EQ(2, TilingData(3, 100, 6, true).tilePositionY(1)); - EXPECT_EQ(3, TilingData(3, 100, 6, true).tilePositionY(2)); - EXPECT_EQ(4, TilingData(3, 100, 6, true).tilePositionY(3)); -} - -} // namespace diff --git a/WebKit/chromium/tests/TransparencyWinTest.cpp b/WebKit/chromium/tests/TransparencyWinTest.cpp deleted file mode 100644 index ed7f12f..0000000 --- a/WebKit/chromium/tests/TransparencyWinTest.cpp +++ /dev/null @@ -1,693 +0,0 @@ -/* - * Copyright (C) 2010 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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 "TransparencyWin.h" - -#include "AffineTransform.h" -#include "ImageBuffer.h" - -#include <gtest/gtest.h> -#include <windows.h> - -namespace WebCore { - -static FloatRect RECTToFloatRect(const RECT* rect) -{ - return FloatRect(static_cast<float>(rect->left), - static_cast<float>(rect->top), - static_cast<float>(rect->right - rect->left), - static_cast<float>(rect->bottom - rect->top)); -} - -static void drawNativeRect(GraphicsContext* context, - int x, int y, int w, int h) -{ - skia::PlatformCanvas* canvas = context->platformContext()->canvas(); - HDC dc = canvas->beginPlatformPaint(); - - RECT innerRc; - innerRc.left = x; - innerRc.top = y; - innerRc.right = x + w; - innerRc.bottom = y + h; - FillRect(dc, &innerRc, - reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH))); - - canvas->endPlatformPaint(); -} - -static Color getPixelAt(GraphicsContext* context, int x, int y) -{ - const SkBitmap& bitmap = context->platformContext()->canvas()-> - getTopPlatformDevice().accessBitmap(false); - return Color(*reinterpret_cast<const RGBA32*>(bitmap.getAddr32(x, y))); -} - -// Resets the top layer's alpha channel to 0 for each pixel. This simulates -// Windows messing it up. -static void clearTopLayerAlphaChannel(GraphicsContext* context) -{ - SkBitmap& bitmap = const_cast<SkBitmap&>(context->platformContext()-> - canvas()->getTopPlatformDevice().accessBitmap(false)); - for (int y = 0; y < bitmap.height(); y++) { - uint32_t* row = bitmap.getAddr32(0, y); - for (int x = 0; x < bitmap.width(); x++) - row[x] &= 0x00FFFFFF; - } -} - -// Clears the alpha channel on the specified pixel. -static void clearTopLayerAlphaPixel(GraphicsContext* context, int x, int y) -{ - SkBitmap& bitmap = const_cast<SkBitmap&>(context->platformContext()-> - canvas()->getTopPlatformDevice().accessBitmap(false)); - *bitmap.getAddr32(x, y) &= 0x00FFFFFF; -} - -static std::ostream& operator<<(std::ostream& out, const Color& c) -{ - std::ios_base::fmtflags oldFlags = out.flags(std::ios_base::hex | - std::ios_base::showbase); - out << c.rgb(); - out.flags(oldFlags); - return out; -} - -TEST(TransparencyWin, NoLayer) -{ - OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(17, 16), ColorSpaceDeviceRGB)); - - // KeepTransform - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::NoLayer, - TransparencyWin::KeepTransform, - IntRect(1, 1, 14, 12)); - - EXPECT_TRUE(src->context() == helper.context()); - EXPECT_TRUE(IntSize(14, 12) == helper.m_layerSize); - EXPECT_TRUE(IntRect(1, 1, 14, 12) == helper.drawRect()); - } - - // Untransform is not allowed for NoLayer. - - // ScaleTransform - src->context()->save(); - src->context()->scale(FloatSize(2.0, 0.5)); - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::NoLayer, - TransparencyWin::ScaleTransform, - IntRect(2, 2, 6, 6)); - helper.composite(); - - // The coordinate system should be based in the upper left of our box. - // It should be post-transformed. - EXPECT_TRUE(src->context() == helper.context()); - EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize); - EXPECT_TRUE(IntRect(4, 1, 12, 3) == helper.drawRect()); - } - src->context()->restore(); -} - -TEST(TransparencyWin, WhiteLayer) -{ - OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), ColorSpaceDeviceRGB)); - - // KeepTransform - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::WhiteLayer, - TransparencyWin::KeepTransform, - IntRect(1, 1, 14, 12)); - helper.composite(); - - EXPECT_TRUE(src->context() != helper.context()); - EXPECT_TRUE(IntSize(14, 12) == helper.m_layerSize); - EXPECT_TRUE(IntRect(1, 1, 14, 12) == helper.drawRect()); - } - - // Untransform - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::WhiteLayer, - TransparencyWin::Untransform, - IntRect(1, 1, 14, 12)); - helper.composite(); - - EXPECT_TRUE(src->context() != helper.context()); - EXPECT_TRUE(IntSize(14, 12) == helper.m_layerSize); - EXPECT_TRUE(IntRect(0, 0, 14, 12) == helper.drawRect()); - } - - // ScaleTransform - src->context()->save(); - src->context()->scale(FloatSize(2.0, 0.5)); - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::WhiteLayer, - TransparencyWin::ScaleTransform, - IntRect(2, 2, 6, 6)); - helper.composite(); - - // The coordinate system should be based in the upper left of our box. - // It should be post-transformed. - EXPECT_TRUE(src->context() != helper.context()); - EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize); - EXPECT_TRUE(IntRect(0, 0, 12, 3) == helper.drawRect()); - } - src->context()->restore(); -} - -TEST(TransparencyWin, TextComposite) -{ - OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), ColorSpaceDeviceRGB)); - - // KeepTransform is the only valid transform mode for TextComposite. - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::TextComposite, - TransparencyWin::KeepTransform, - IntRect(1, 1, 14, 12)); - helper.composite(); - - EXPECT_TRUE(src->context() != helper.context()); - EXPECT_TRUE(IntSize(14, 12) == helper.m_layerSize); - EXPECT_TRUE(IntRect(1, 1, 14, 12) == helper.drawRect()); - } -} - -TEST(TransparencyWin, OpaqueCompositeLayer) -{ - OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), ColorSpaceDeviceRGB)); - - // KeepTransform - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::OpaqueCompositeLayer, - TransparencyWin::KeepTransform, - IntRect(1, 1, 14, 12)); - helper.composite(); - - EXPECT_TRUE(src->context() != helper.context()); - EXPECT_TRUE(IntSize(14, 12) == helper.m_layerSize); - EXPECT_TRUE(IntRect(1, 1, 14, 12) == helper.drawRect()); - } - - // KeepTransform with scroll applied. - src->context()->save(); - src->context()->translate(0, -1); - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::OpaqueCompositeLayer, - TransparencyWin::KeepTransform, - IntRect(1, 1, 14, 14)); - helper.composite(); - - EXPECT_TRUE(src->context() != helper.context()); - EXPECT_TRUE(IntSize(14, 14) == helper.m_layerSize); - EXPECT_TRUE(IntRect(1, 1, 14, 14) == helper.drawRect()); - } - src->context()->restore(); - - // Untransform - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::OpaqueCompositeLayer, - TransparencyWin::Untransform, - IntRect(1, 1, 14, 12)); - helper.composite(); - - EXPECT_TRUE(src->context() != helper.context()); - EXPECT_TRUE(IntSize(14, 12) == helper.m_layerSize); - EXPECT_TRUE(IntRect(0, 0, 14, 12) == helper.drawRect()); - } - - // ScaleTransform - src->context()->save(); - src->context()->scale(FloatSize(2.0, 0.5)); - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::OpaqueCompositeLayer, - TransparencyWin::ScaleTransform, - IntRect(2, 2, 6, 6)); - helper.composite(); - - // The coordinate system should be based in the upper left of our box. - // It should be post-transformed. - EXPECT_TRUE(src->context() != helper.context()); - EXPECT_TRUE(IntSize(12, 3) == helper.m_layerSize); - EXPECT_TRUE(IntRect(0, 0, 12, 3) == helper.drawRect()); - } - src->context()->restore(); -} - -TEST(TransparencyWin, WhiteLayerPixelTest) -{ - // Make a total transparent buffer, and draw the white layer inset by 1 px. - OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), ColorSpaceDeviceRGB)); - - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::WhiteLayer, - TransparencyWin::KeepTransform, - IntRect(1, 1, 14, 14)); - - // Coordinates should be in the original space, not the layer. - drawNativeRect(helper.context(), 3, 3, 1, 1); - clearTopLayerAlphaChannel(helper.context()); - helper.composite(); - } - - // The final image should be transparent around the edges for 1 px, white - // in the middle, with (3,3) (what we drew above) being opaque black. - EXPECT_EQ(Color(Color::transparent), getPixelAt(src->context(), 0, 0)); - EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 2, 2)); - EXPECT_EQ(Color(Color::black), getPixelAt(src->context(), 3, 3)); - EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 4, 4)); -} - -TEST(TransparencyWin, OpaqueCompositeLayerPixel) -{ - Color red(0xFFFF0000), darkRed(0xFFBF0000); - Color green(0xFF00FF00); - - // Make a red bottom layer, followed by a half green next layer @ 50%. - OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), ColorSpaceDeviceRGB)); - - FloatRect fullRect(0, 0, 16, 16); - src->context()->fillRect(fullRect, red, ColorSpaceDeviceRGB); - src->context()->beginTransparencyLayer(0.5); - FloatRect rightHalf(8, 0, 8, 16); - src->context()->fillRect(rightHalf, green, ColorSpaceDeviceRGB); - - // Make a transparency layer inset by one pixel, and fill it inset by - // another pixel with 50% black. - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::OpaqueCompositeLayer, - TransparencyWin::KeepTransform, - IntRect(1, 1, 14, 14)); - - FloatRect inner(2, 2, 12, 12); - helper.context()->fillRect(inner, Color(0x7f000000), ColorSpaceDeviceRGB); - // These coordinates are relative to the layer, whish is inset by 1x1 - // pixels from the top left. So we're actually clearing (2, 2) and - // (13,13), which are the extreme corners of the black area (and which - // we check below). - clearTopLayerAlphaPixel(helper.context(), 1, 1); - clearTopLayerAlphaPixel(helper.context(), 12, 12); - helper.composite(); - } - - // Finish the compositing. - src->context()->endTransparencyLayer(); - - // Check that we got the right values, it should be like the rectangle was - // drawn with half opacity even though the alpha channel got messed up. - EXPECT_EQ(red, getPixelAt(src->context(), 0, 0)); - EXPECT_EQ(red, getPixelAt(src->context(), 1, 1)); - EXPECT_EQ(darkRed, getPixelAt(src->context(), 2, 2)); - - // The dark result is: - // (black @ 50% atop green) @ 50% atop red = 0xFF804000 - // which is 0xFFA02000 (Skia computes 0xFFA11F00 due to rounding). - Color darkGreenRed(0xFF803f00); - EXPECT_EQ(darkGreenRed, getPixelAt(src->context(), 13, 13)); - - // 50% green on top of red = FF808000 (rounded to what Skia will produce). - Color greenRed(0xFF807F00); - EXPECT_EQ(greenRed, getPixelAt(src->context(), 14, 14)); - EXPECT_EQ(greenRed, getPixelAt(src->context(), 15, 15)); -} - -// Tests that translations are properly handled when using KeepTransform. -TEST(TransparencyWin, TranslateOpaqueCompositeLayer) -{ - // Fill with white. - OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), ColorSpaceDeviceRGB)); - Color white(0xFFFFFFFF); - FloatRect fullRect(0, 0, 16, 16); - src->context()->fillRect(fullRect, white, ColorSpaceDeviceRGB); - - // Scroll down by 8 (coordinate system goes up). - src->context()->save(); - src->context()->translate(0, -8); - - Color red(0xFFFF0000); - Color green(0xFF00FF00); - { - // Make the transparency layer after translation will be @ (0, -8) with - // size 16x16. - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::OpaqueCompositeLayer, - TransparencyWin::KeepTransform, - IntRect(0, 0, 16, 16)); - - // Draw a red pixel at (15, 15). This should be the at (15, 7) after - // the transform. - FloatRect bottomRight(15, 15, 1, 1); - helper.context()->fillRect(bottomRight, green, ColorSpaceDeviceRGB); - helper.composite(); - } - - src->context()->restore(); - - // Check the pixel we wrote. - EXPECT_EQ(green, getPixelAt(src->context(), 15, 7)); -} - -// Same as OpaqueCompositeLayer, but the canvas has a rotation applied. This -// tests that the propert transform is applied to the copied layer. -TEST(TransparencyWin, RotateOpaqueCompositeLayer) -{ - OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), ColorSpaceDeviceRGB)); - - // The background is white. - Color white(0xFFFFFFFF); - FloatRect fullRect(0, 0, 16, 16); - src->context()->fillRect(fullRect, white, ColorSpaceDeviceRGB); - - // Rotate the image by 90 degrees. This matrix is the same as - // cw90.rotate(90); but avoids rounding errors. Rounding errors can cause - // Skia to think that !rectStaysRect() and it will fall through to path - // drawing mode, which in turn gives us antialiasing. We want no - // antialiasing or other rounding problems since we're testing exact pixel - // values. - src->context()->save(); - AffineTransform cw90(0, 1, -1, 0, 0, 0); - src->context()->concatCTM(cw90); - - // Make a transparency layer consisting of a horizontal line of 50% black. - // Since the rotation is applied, this will actually be a vertical line - // down the middle of the image. - src->context()->beginTransparencyLayer(0.5); - FloatRect blackRect(0, -9, 16, 2); - Color black(0xFF000000); - src->context()->fillRect(blackRect, black, ColorSpaceDeviceRGB); - - // Now draw 50% red square. - { - // Create a transparency helper inset one pixel in the buffer. The - // coordinates are before transforming into this space, and maps to - // IntRect(1, 1, 14, 14). - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::OpaqueCompositeLayer, - TransparencyWin::Untransform, - IntRect(1, -15, 14, 14)); - - // Fill with red. - helper.context()->fillRect(helper.drawRect(), Color(0x7f7f0000), ColorSpaceDeviceRGB); - clearTopLayerAlphaChannel(helper.context()); - helper.composite(); - } - - // Finish the compositing. - src->context()->endTransparencyLayer(); - - // Top corner should be the original background. - EXPECT_EQ(white, getPixelAt(src->context(), 0, 0)); - - // Check the stripe down the middle, first at the top... - Color gray(0xFF808080); - EXPECT_EQ(white, getPixelAt(src->context(), 6, 0)); - EXPECT_EQ(gray, getPixelAt(src->context(), 7, 0)); - EXPECT_EQ(gray, getPixelAt(src->context(), 8, 0)); - EXPECT_EQ(white, getPixelAt(src->context(), 9, 0)); - - // ...now at the bottom. - EXPECT_EQ(white, getPixelAt(src->context(), 6, 15)); - EXPECT_EQ(gray, getPixelAt(src->context(), 7, 15)); - EXPECT_EQ(gray, getPixelAt(src->context(), 8, 15)); - EXPECT_EQ(white, getPixelAt(src->context(), 9, 15)); - - // Our red square should be 25% red over the top of those two. - Color redwhite(0xFFdfbfbf); - Color redgray(0xFF9f8080); - EXPECT_EQ(white, getPixelAt(src->context(), 0, 1)); - EXPECT_EQ(redwhite, getPixelAt(src->context(), 1, 1)); - EXPECT_EQ(redwhite, getPixelAt(src->context(), 6, 1)); - EXPECT_EQ(redgray, getPixelAt(src->context(), 7, 1)); - EXPECT_EQ(redgray, getPixelAt(src->context(), 8, 1)); - EXPECT_EQ(redwhite, getPixelAt(src->context(), 9, 1)); - EXPECT_EQ(redwhite, getPixelAt(src->context(), 14, 1)); - EXPECT_EQ(white, getPixelAt(src->context(), 15, 1)); - - // Complete the 50% transparent layer. - src->context()->restore(); -} - -TEST(TransparencyWin, TranslateScaleOpaqueCompositeLayer) -{ - OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), ColorSpaceDeviceRGB)); - - // The background is white on top with red on bottom. - Color white(0xFFFFFFFF); - FloatRect topRect(0, 0, 16, 8); - src->context()->fillRect(topRect, white, ColorSpaceDeviceRGB); - Color red(0xFFFF0000); - FloatRect bottomRect(0, 8, 16, 8); - src->context()->fillRect(bottomRect, red, ColorSpaceDeviceRGB); - - src->context()->save(); - - // Translate left by one pixel. - AffineTransform left; - left.translate(-1, 0); - - // Scale by 2x. - AffineTransform scale; - scale.scale(2.0); - src->context()->concatCTM(scale); - - // Then translate up by one pixel (which will actually be 2 due to scaling). - AffineTransform up; - up.translate(0, -1); - src->context()->concatCTM(up); - - // Now draw 50% red square. - { - // Create a transparency helper inset one pixel in the buffer. The - // coordinates are before transforming into this space, and maps to - // IntRect(1, 1, 14, 14). - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::OpaqueCompositeLayer, - TransparencyWin::KeepTransform, - IntRect(1, -15, 14, 14)); - - // Fill with red. - helper.context()->fillRect(helper.drawRect(), Color(0x7f7f0000), ColorSpaceDeviceRGB); - clearTopLayerAlphaChannel(helper.context()); - helper.composite(); - } -} - -// Tests scale mode with no additional copy. -TEST(TransparencyWin, Scale) -{ - // Create an opaque white buffer. - OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), ColorSpaceDeviceRGB)); - FloatRect fullBuffer(0, 0, 16, 16); - src->context()->fillRect(fullBuffer, Color::white, ColorSpaceDeviceRGB); - - // Scale by 2x. - src->context()->save(); - AffineTransform scale; - scale.scale(2.0); - src->context()->concatCTM(scale); - - // Start drawing a rectangle from 1->4. This should get scaled to 2->8. - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::NoLayer, - TransparencyWin::ScaleTransform, - IntRect(1, 1, 3, 3)); - - // The context should now have the identity transform and the returned - // rect should be scaled. - EXPECT_TRUE(helper.context()->getCTM().isIdentity()); - EXPECT_EQ(2, helper.drawRect().x()); - EXPECT_EQ(2, helper.drawRect().y()); - EXPECT_EQ(8, helper.drawRect().right()); - EXPECT_EQ(8, helper.drawRect().bottom()); - - // Set the pixel at (2, 2) to be transparent. This should be fixed when - // the helper goes out of scope. We don't want to call - // clearTopLayerAlphaChannel because that will actually clear the whole - // canvas (since we have no extra layer!). - SkBitmap& bitmap = const_cast<SkBitmap&>(helper.context()-> - platformContext()->canvas()->getTopPlatformDevice(). - accessBitmap(false)); - *bitmap.getAddr32(2, 2) &= 0x00FFFFFF; - helper.composite(); - } - - src->context()->restore(); - - // Check the pixel we previously made transparent, it should have gotten - // fixed back up to white. - - // The current version doesn't fixup transparency when there is no layer. - // This seems not to be necessary, so we don't bother, but if it becomes - // necessary, this line should be uncommented. - // EXPECT_EQ(Color(Color::white), getPixelAt(src->context(), 2, 2)); -} - -// Tests scale mode with an additional copy for transparency. This will happen -// if we have a scaled textbox, for example. WebKit will create a new -// transparency layer, draw the text field, then draw the text into it, then -// composite this down with an opacity. -TEST(TransparencyWin, ScaleTransparency) -{ - // Create an opaque white buffer. - OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), ColorSpaceDeviceRGB)); - FloatRect fullBuffer(0, 0, 16, 16); - src->context()->fillRect(fullBuffer, Color::white, ColorSpaceDeviceRGB); - - // Make another layer (which duplicates how WebKit will make this). We fill - // the top half with red, and have the layer be 50% opaque. - src->context()->beginTransparencyLayer(0.5); - FloatRect topHalf(0, 0, 16, 8); - src->context()->fillRect(topHalf, Color(0xFFFF0000), ColorSpaceDeviceRGB); - - // Scale by 2x. - src->context()->save(); - AffineTransform scale; - scale.scale(2.0); - src->context()->concatCTM(scale); - - // Make a layer inset two pixels (because of scaling, this is 2->14). And - // will it with 50% black. - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::OpaqueCompositeLayer, - TransparencyWin::ScaleTransform, - IntRect(1, 1, 6, 6)); - - helper.context()->fillRect(helper.drawRect(), Color(0x7f000000), ColorSpaceDeviceRGB); - clearTopLayerAlphaChannel(helper.context()); - helper.composite(); - } - - // Finish the layer. - src->context()->restore(); - src->context()->endTransparencyLayer(); - - Color redBackground(0xFFFF8080); // 50% red composited on white. - EXPECT_EQ(redBackground, getPixelAt(src->context(), 0, 0)); - EXPECT_EQ(redBackground, getPixelAt(src->context(), 1, 1)); - - // Top half (minus two pixel border) should be 50% gray atop opaque - // red = 0xFF804141. Then that's composited with 50% transparency on solid - // white = 0xFFC0A1A1. - Color darkRed(0xFFBF8080); - EXPECT_EQ(darkRed, getPixelAt(src->context(), 2, 2)); - EXPECT_EQ(darkRed, getPixelAt(src->context(), 7, 7)); - - // Bottom half (minus a two pixel border) should be a layer with 5% gray - // with another 50% opacity composited atop white. - Color darkWhite(0xFFBFBFBF); - EXPECT_EQ(darkWhite, getPixelAt(src->context(), 8, 8)); - EXPECT_EQ(darkWhite, getPixelAt(src->context(), 13, 13)); - - Color white(0xFFFFFFFF); // Background in the lower-right. - EXPECT_EQ(white, getPixelAt(src->context(), 14, 14)); - EXPECT_EQ(white, getPixelAt(src->context(), 15, 15)); -} - -TEST(TransparencyWin, Text) -{ - OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), ColorSpaceDeviceRGB)); - - // Our text should end up 50% transparent blue-green. - Color fullResult(0x80008080); - - { - TransparencyWin helper; - helper.init(src->context(), - TransparencyWin::TextComposite, - TransparencyWin::KeepTransform, - IntRect(0, 0, 16, 16)); - helper.setTextCompositeColor(fullResult); - - // Write several different squares to simulate ClearType. These should - // all reduce to 2/3 coverage. - FloatRect pixel(0, 0, 1, 1); - helper.context()->fillRect(pixel, 0xFFFF0000, ColorSpaceDeviceRGB); - pixel.move(1.0f, 0.0f); - helper.context()->fillRect(pixel, 0xFF00FF00, ColorSpaceDeviceRGB); - pixel.move(1.0f, 0.0f); - helper.context()->fillRect(pixel, 0xFF0000FF, ColorSpaceDeviceRGB); - pixel.move(1.0f, 0.0f); - helper.context()->fillRect(pixel, 0xFF008080, ColorSpaceDeviceRGB); - pixel.move(1.0f, 0.0f); - helper.context()->fillRect(pixel, 0xFF800080, ColorSpaceDeviceRGB); - pixel.move(1.0f, 0.0f); - helper.context()->fillRect(pixel, 0xFF808000, ColorSpaceDeviceRGB); - - // Try one with 100% coverage (opaque black). - pixel.move(1.0f, 0.0f); - helper.context()->fillRect(pixel, 0xFF000000, ColorSpaceDeviceRGB); - - // Now mess with the alpha channel. - clearTopLayerAlphaChannel(helper.context()); - helper.composite(); - } - - Color oneThirdResult(0x55005555); // = fullResult * 2 / 3 - EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 0, 0)); - EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 1, 0)); - EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 2, 0)); - EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 3, 0)); - EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 4, 0)); - EXPECT_EQ(oneThirdResult, getPixelAt(src->context(), 5, 0)); - EXPECT_EQ(fullResult, getPixelAt(src->context(), 6, 0)); - EXPECT_EQ(Color::transparent, getPixelAt(src->context(), 7, 0)); -} - -} // namespace WebCore diff --git a/WebKit/chromium/tests/TreeTestHelpers.cpp b/WebKit/chromium/tests/TreeTestHelpers.cpp deleted file mode 100644 index 103b871..0000000 --- a/WebKit/chromium/tests/TreeTestHelpers.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2010 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 "TreeTestHelpers.h" - -#include <cstdlib> -#include <wtf/CurrentTime.h> - -namespace WebCore { -namespace TreeTestHelpers { - -int32_t generateSeed() -{ - // A seed of 1 has the special behavior of resetting the random - // number generator. Assume that if we call this routine that we - // don't want this behavior. - int32_t seed; - do { - seed = static_cast<int32_t>(currentTime()); - } while (seed <= 1); - return seed; -} - -void initRandom(const int32_t seed) -{ - srand(seed); -} - -int32_t nextRandom(const int32_t maximumValue) -{ - // rand_r is not available on Windows - return rand() % maximumValue; -} - -} // namespace TreeTestHelpers -} // namespace WebCore diff --git a/WebKit/chromium/tests/TreeTestHelpers.h b/WebKit/chromium/tests/TreeTestHelpers.h deleted file mode 100644 index af07b2a..0000000 --- a/WebKit/chromium/tests/TreeTestHelpers.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2010 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. - */ - -// Simple pseudorandom number generator helper functions, used by the -// red-black and interval tree tests. -// -// These are **not** thread safe! - -#ifndef TreeTestHelpers_h -#define TreeTestHelpers_h - -#include <stdint.h> - -namespace WebCore { -namespace TreeTestHelpers { - -// Generates a seed value to be passed to initRandom(). -int32_t generateSeed(); - -// Initializes the pseudo-random number generator with a specific seed. -void initRandom(const int32_t seed); - -// Produces the next pseudo-random number in the sequence, in the -// range from [0..maximumValue). Negative numbers are not allowed and will -// produce undefined results. -int32_t nextRandom(const int32_t maximumValue); - -} // namespace TreeTestHelpers -} // namespace WebCore - -#endif // TreeTestHelpers_h diff --git a/WebKit/chromium/tests/UniscribeHelperTest.cpp b/WebKit/chromium/tests/UniscribeHelperTest.cpp deleted file mode 100644 index 8aaed11..0000000 --- a/WebKit/chromium/tests/UniscribeHelperTest.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (C) 2010 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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 <gtest/gtest.h> - -#include "PlatformString.h" -#include "UniscribeHelper.h" - -using namespace WebCore; - -namespace { - -class UniscribeTest : public testing::Test { -public: - UniscribeTest() - { - } - - // Returns an HFONT with the given name. The caller does not have to free - // this, it will be automatically freed at the end of the test. Returns 0 - // on failure. On success, the - HFONT MakeFont(const wchar_t* fontName, SCRIPT_CACHE** cache) - { - LOGFONT lf; - memset(&lf, 0, sizeof(LOGFONT)); - lf.lfHeight = 20; - wcscpy_s(lf.lfFaceName, fontName); - - HFONT hfont = CreateFontIndirect(&lf); - if (!hfont) - return 0; - - *cache = new SCRIPT_CACHE; - **cache = 0; - createdFonts.append(std::make_pair(hfont, *cache)); - return hfont; - } - -protected: - // Default font properties structure for tests to use. - SCRIPT_FONTPROPERTIES properties; - -private: - virtual void SetUp() - { - memset(&properties, 0, sizeof(SCRIPT_FONTPROPERTIES)); - properties.cBytes = sizeof(SCRIPT_FONTPROPERTIES); - properties.wgBlank = ' '; - properties.wgDefault = '?'; // Used when the char is not in the font. - properties.wgInvalid = '#'; // Used for invalid characters. - } - - virtual void TearDown() - { - // Free any allocated fonts. - for (size_t i = 0; i < createdFonts.size(); i++) { - DeleteObject(createdFonts[i].first); - ScriptFreeCache(createdFonts[i].second); - delete createdFonts[i].second; - } - createdFonts.clear(); - } - - // Tracks allocated fonts so we can delete them at the end of the test. - // The script cache pointer is heap allocated and must be freed. - Vector< std::pair<HFONT, SCRIPT_CACHE*> > createdFonts; -}; - -} // namespace - -// This test tests giving Uniscribe a very large buffer, which will cause a -// failure. -TEST_F(UniscribeTest, TooBig) -{ - // Make a large string with an e with a zillion combining accents. - String input(L"e"); - for (int i = 0; i < 100000; i++) - input.append(static_cast<UChar>(0x301)); // Combining acute accent. - - SCRIPT_CACHE* scriptCache; - HFONT hfont = MakeFont(L"Times New Roman", &scriptCache); - ASSERT_TRUE(hfont); - - // Test a long string without the normal length protection we have. This - // will cause shaping to fail. - { - UniscribeHelper uniscribe( - input.characters(), static_cast<int>(input.length()), - false, hfont, scriptCache, &properties); - uniscribe.initWithOptionalLengthProtection(false); - - // There should be one shaping entry, with nothing in it. - ASSERT_EQ(1, uniscribe.m_shapes.size()); - EXPECT_EQ(0, uniscribe.m_shapes[0].m_glyphs.size()); - EXPECT_EQ(0, uniscribe.m_shapes[0].m_logs.size()); - EXPECT_EQ(0, uniscribe.m_shapes[0].m_visualAttributes.size()); - EXPECT_EQ(0, uniscribe.m_shapes[0].m_advance.size()); - EXPECT_EQ(0, uniscribe.m_shapes[0].m_offsets.size()); - EXPECT_EQ(0, uniscribe.m_shapes[0].m_justify.size()); - EXPECT_EQ(0, uniscribe.m_shapes[0].m_abc.abcA); - EXPECT_EQ(0, uniscribe.m_shapes[0].m_abc.abcB); - EXPECT_EQ(0, uniscribe.m_shapes[0].m_abc.abcC); - - // The sizes of the other stuff should match the shaping entry. - EXPECT_EQ(1, uniscribe.m_runs.size()); - EXPECT_EQ(1, uniscribe.m_screenOrder.size()); - - // Check that the various querying functions handle the empty case - // properly. - EXPECT_EQ(0, uniscribe.width()); - EXPECT_EQ(0, uniscribe.firstGlyphForCharacter(0)); - EXPECT_EQ(0, uniscribe.firstGlyphForCharacter(1000)); - EXPECT_EQ(0, uniscribe.xToCharacter(0)); - EXPECT_EQ(0, uniscribe.xToCharacter(1000)); - } - - // Now test the very large string and make sure it is handled properly by - // the length protection. - { - UniscribeHelper uniscribe( - input.characters(), static_cast<int>(input.length()), - false, hfont, scriptCache, &properties); - uniscribe.initWithOptionalLengthProtection(true); - - // There should be 0 runs and shapes. - EXPECT_EQ(0, uniscribe.m_runs.size()); - EXPECT_EQ(0, uniscribe.m_shapes.size()); - EXPECT_EQ(0, uniscribe.m_screenOrder.size()); - - EXPECT_EQ(0, uniscribe.width()); - EXPECT_EQ(0, uniscribe.firstGlyphForCharacter(0)); - EXPECT_EQ(0, uniscribe.firstGlyphForCharacter(1000)); - EXPECT_EQ(0, uniscribe.xToCharacter(0)); - EXPECT_EQ(0, uniscribe.xToCharacter(1000)); - } -} diff --git a/WebKit/chromium/tests/WebFrameTest.cpp b/WebKit/chromium/tests/WebFrameTest.cpp deleted file mode 100644 index cf91cb4..0000000 --- a/WebKit/chromium/tests/WebFrameTest.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (C) 2010 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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 <googleurl/src/gurl.h> -#include <gtest/gtest.h> -#include <webkit/support/webkit_support.h> -#include "WebFrame.h" -#include "WebFrameClient.h" -#include "WebString.h" -#include "WebURL.h" -#include "WebURLRequest.h" -#include "WebURLResponse.h" -#include "WebView.h" - -using namespace WebKit; - -namespace { - -class WebFrameTest : public testing::Test { -public: - WebFrameTest() {} - - virtual void TearDown() - { - webkit_support::UnregisterAllMockedURLs(); - } - - void registerMockedURLLoad(const WebURL& url, const WebURLResponse& response, const WebString& fileName) - { - std::string filePath = webkit_support::GetWebKitRootDir().utf8(); - filePath.append("/WebKit/chromium/tests/data/"); - filePath.append(fileName.utf8()); - webkit_support::RegisterMockedURL(url, response, WebString::fromUTF8(filePath)); - } - - void serveRequests() - { - webkit_support::ServeAsynchronousMockedRequests(); - } -}; - -class TestWebFrameClient : public WebFrameClient { -}; - -TEST_F(WebFrameTest, ContentText) -{ - // Register our resources. - WebURLResponse response; - response.initialize(); - response.setMIMEType("text/html"); - std::string rootURL = "http://www.test.com/"; - const char* files[] = { "iframes_test.html", "visible_iframe.html", - "invisible_iframe.html", "zero_sized_iframe.html" }; - for (int i = 0; i < (sizeof(files) / sizeof(char*)); ++i) { - WebURL webURL = GURL(rootURL + files[i]); - registerMockedURLLoad(webURL, response, WebString::fromUTF8(files[i])); - } - - // Create and initialize the WebView. - TestWebFrameClient webFrameClient; - WebView* webView = WebView::create(0, 0); - webView->initializeMainFrame(&webFrameClient); - - // Load the main frame URL. - WebURL testURL(GURL(rootURL + files[0])); - WebURLRequest urlRequest; - urlRequest.initialize(); - urlRequest.setURL(testURL); - webView->mainFrame()->loadRequest(urlRequest); - - // Load all pending asynchronous requests. - serveRequests(); - - // Now retrieve the frames text and test it only includes visible elements. - std::string content = webView->mainFrame()->contentAsText(1024).utf8(); - EXPECT_NE(std::string::npos, content.find(" visible paragraph")); - EXPECT_NE(std::string::npos, content.find(" visible iframe")); - EXPECT_EQ(std::string::npos, content.find(" invisible pararaph")); - EXPECT_EQ(std::string::npos, content.find(" invisible iframe")); - EXPECT_EQ(std::string::npos, content.find("iframe with zero size")); - - webView->close(); -} - -} diff --git a/WebKit/chromium/tests/WebInputEventFactoryTestGtk.cpp b/WebKit/chromium/tests/WebInputEventFactoryTestGtk.cpp deleted file mode 100644 index 7cd4837..0000000 --- a/WebKit/chromium/tests/WebInputEventFactoryTestGtk.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (C) 2010 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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 <gdk/gdk.h> -#include <gtest/gtest.h> - -#include "WebInputEvent.h" -#include "WebInputEventFactory.h" - -using WebKit::WebMouseEvent; -using WebKit::WebInputEventFactory; - -namespace { - -TEST(WebInputEventFactoryTest, DoubleClick) -{ - GdkEventButton firstClick; - firstClick.type = GDK_BUTTON_PRESS; - firstClick.window = static_cast<GdkWindow*>(GINT_TO_POINTER(1)); - firstClick.x = firstClick.y = firstClick.x_root = firstClick.y_root = 100; - firstClick.state = 0; - firstClick.time = 0; - firstClick.button = 1; - - // Single click works. - WebMouseEvent firstClickEvent = WebInputEventFactory::mouseEvent(&firstClick); - EXPECT_EQ(1, firstClickEvent.clickCount); - - // Make sure double click works. - GdkEventButton secondClick = firstClick; - secondClick.time = firstClick.time + 100; - WebMouseEvent secondClickEvent = WebInputEventFactory::mouseEvent(&secondClick); - EXPECT_EQ(2, secondClickEvent.clickCount); - - // Reset the click count. - firstClick.time += 10000; - firstClickEvent = WebInputEventFactory::mouseEvent(&firstClick); - EXPECT_EQ(1, firstClickEvent.clickCount); - - // Two clicks with a long gap in between aren't counted as a double click. - secondClick = firstClick; - secondClick.time = firstClick.time + 1000; - secondClickEvent = WebInputEventFactory::mouseEvent(&secondClick); - EXPECT_EQ(1, secondClickEvent.clickCount); - - // Reset the click count. - firstClick.time += 10000; - firstClickEvent = WebInputEventFactory::mouseEvent(&firstClick); - EXPECT_EQ(1, firstClickEvent.clickCount); - - // Two clicks far apart (horizontally) aren't counted as a double click. - secondClick = firstClick; - secondClick.time = firstClick.time + 1; - secondClick.x = firstClick.x + 100; - secondClickEvent = WebInputEventFactory::mouseEvent(&secondClick); - EXPECT_EQ(1, secondClickEvent.clickCount); - - // Reset the click count. - firstClick.time += 10000; - firstClickEvent = WebInputEventFactory::mouseEvent(&firstClick); - EXPECT_EQ(1, firstClickEvent.clickCount); - - // Two clicks far apart (vertically) aren't counted as a double click. - secondClick = firstClick; - secondClick.time = firstClick.time + 1; - secondClick.x = firstClick.y + 100; - secondClickEvent = WebInputEventFactory::mouseEvent(&secondClick); - EXPECT_EQ(1, secondClickEvent.clickCount); - - // Reset the click count. - firstClick.time += 10000; - firstClickEvent = WebInputEventFactory::mouseEvent(&firstClick); - EXPECT_EQ(1, firstClickEvent.clickCount); - - // Two clicks on different windows aren't a double click. - secondClick = firstClick; - secondClick.time = firstClick.time + 1; - secondClick.window = static_cast<GdkWindow*>(GINT_TO_POINTER(2)); - secondClickEvent = WebInputEventFactory::mouseEvent(&secondClick); - EXPECT_EQ(1, secondClickEvent.clickCount); -} - -} // anonymous namespace diff --git a/WebKit/chromium/tests/WebUnitTests.cpp b/WebKit/chromium/tests/WebUnitTests.cpp deleted file mode 100644 index 5e207f3..0000000 --- a/WebKit/chromium/tests/WebUnitTests.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2010 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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 "WebUnitTests.h" - -#include <base/test/test_suite.h> - -namespace WebKit { - -int RunAllUnitTests(int argc, char** argv) -{ - TestSuite testSuite(argc, argv); - return testSuite.Run(); -} - -} // namespace WebKit diff --git a/WebKit/chromium/tests/WebUnitTests.h b/WebKit/chromium/tests/WebUnitTests.h deleted file mode 100644 index 3add1c2..0000000 --- a/WebKit/chromium/tests/WebUnitTests.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2010 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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 WebUnitTests_h -#define WebUnitTests_h - -#include "WebCommon.h" - -namespace WebKit { - -// In chromium multi-dll build, webkit unittest code are compiled in webkit.dll. -// This is the API to run all unittests inside webkit.dll. -WEBKIT_API int RunAllUnitTests(int argc, char** argv); - -} // namespace WebKit - -#endif diff --git a/WebKit/chromium/tests/data/iframes_test.html b/WebKit/chromium/tests/data/iframes_test.html deleted file mode 100644 index 425709b..0000000 --- a/WebKit/chromium/tests/data/iframes_test.html +++ /dev/null @@ -1,9 +0,0 @@ -<html> - <body> - <iframe src="visible_iframe.html"></iframe> - <iframe width=0 height=0 src="zero_sized_iframe.html"></iframe> - <iframe style="visibility:hidden;" src="invisible_iframe.html"></iframe> - <p>This is a visible paragraph.</p> - <p style="visibility:hidden;">This is an invisible paragraph.</p> - </body> -</html> diff --git a/WebKit/chromium/tests/data/invisible_iframe.html b/WebKit/chromium/tests/data/invisible_iframe.html deleted file mode 100644 index e5686c7..0000000 --- a/WebKit/chromium/tests/data/invisible_iframe.html +++ /dev/null @@ -1,5 +0,0 @@ -<html> - <body> - This is an invisible frame. - </body> -</html> diff --git a/WebKit/chromium/tests/data/visible_iframe.html b/WebKit/chromium/tests/data/visible_iframe.html deleted file mode 100644 index 291af3d..0000000 --- a/WebKit/chromium/tests/data/visible_iframe.html +++ /dev/null @@ -1,5 +0,0 @@ -<html> - <body> - This is a visible iframe. - </body> -</html> diff --git a/WebKit/chromium/tests/data/zero_sized_iframe.html b/WebKit/chromium/tests/data/zero_sized_iframe.html deleted file mode 100644 index 6728cab..0000000 --- a/WebKit/chromium/tests/data/zero_sized_iframe.html +++ /dev/null @@ -1,5 +0,0 @@ -<html> - <body> - This is an iframe with zero size. - </body> -</html> |