summaryrefslogtreecommitdiffstats
path: root/WebKit/chromium/tests
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/chromium/tests')
-rw-r--r--WebKit/chromium/tests/DragImageTest.cpp151
-rw-r--r--WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp165
-rw-r--r--WebKit/chromium/tests/IDBKeyPathTest.cpp205
-rw-r--r--WebKit/chromium/tests/KURLTest.cpp55
-rw-r--r--WebKit/chromium/tests/PopupMenuTest.cpp375
-rw-r--r--WebKit/chromium/tests/RunAllTests.cpp17
-rwxr-xr-xWebKit/chromium/tests/TilingDataTest.cpp334
-rw-r--r--WebKit/chromium/tests/WebFrameTest.cpp112
-rw-r--r--WebKit/chromium/tests/WebInputEventFactoryTestGtk.cpp112
-rw-r--r--WebKit/chromium/tests/data/iframes_test.html9
-rw-r--r--WebKit/chromium/tests/data/invisible_iframe.html5
-rw-r--r--WebKit/chromium/tests/data/visible_iframe.html5
-rw-r--r--WebKit/chromium/tests/data/zero_sized_iframe.html5
13 files changed, 1513 insertions, 37 deletions
diff --git a/WebKit/chromium/tests/DragImageTest.cpp b/WebKit/chromium/tests/DragImageTest.cpp
new file mode 100644
index 0000000..8ce6fe2
--- /dev/null
+++ b/WebKit/chromium/tests/DragImageTest.cpp
@@ -0,0 +1,151 @@
+/*
+ * 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
new file mode 100644
index 0000000..1b7f156
--- /dev/null
+++ b/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp
@@ -0,0 +1,165 @@
+/*
+ * 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
new file mode 100644
index 0000000..ac10f4f
--- /dev/null
+++ b/WebKit/chromium/tests/IDBKeyPathTest.cpp
@@ -0,0 +1,205 @@
+/*
+ * 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 (int 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
index b316683..c46da2a 100644
--- a/WebKit/chromium/tests/KURLTest.cpp
+++ b/WebKit/chromium/tests/KURLTest.cpp
@@ -40,7 +40,7 @@
namespace {
// Output stream operator so gTest's macros work with WebCore strings.
-std::ostream& operator<<(std::ostream& out, const WebCore::String& str)
+std::ostream& operator<<(std::ostream& out, const WTF::String& str)
{
return str.isEmpty() ? out : out << str.utf8().data();
}
@@ -95,7 +95,7 @@ TEST(KURLTest, SameGetters)
EXPECT_EQ(cases[i].hasRef, kurl.hasFragmentIdentifier());
// UTF-16
- WebCore::String utf16(cases[i].url);
+ WTF::String utf16(cases[i].url);
kurl = WebCore::KURL(WebCore::ParsedURLString, utf16);
EXPECT_EQ(cases[i].protocol, kurl.protocol());
@@ -144,7 +144,7 @@ TEST(KURLTest, DifferentGetters)
EXPECT_EQ(cases[i].query, kurl.query());
// Want to compare UCS-16 refs (or to null).
if (cases[i].ref)
- EXPECT_EQ(WebCore::String::fromUTF8(cases[i].ref), kurl.fragmentIdentifier());
+ EXPECT_EQ(WTF::String::fromUTF8(cases[i].ref), kurl.fragmentIdentifier());
else
EXPECT_TRUE(kurl.fragmentIdentifier().isNull());
}
@@ -156,23 +156,23 @@ TEST(KURLTest, UTF8)
{
const char asciiURL[] = "http://foo/bar#baz";
WebCore::KURL asciiKURL(WebCore::ParsedURLString, asciiURL);
- EXPECT_TRUE(asciiKURL.string() == WebCore::String(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(WebCore::equalIgnoringCase(asciiKURL, WebCore::String(asciiURL)));
+ 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(WebCore::equalIgnoringCase(mailto.protocol(), "mailto"));
+ 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() == WebCore::String::fromUTF8(utf8URL));
+ EXPECT_TRUE(utf8KURL.string() == WTF::String::fromUTF8(utf8URL));
}
TEST(KURLTest, Setters)
@@ -281,20 +281,20 @@ TEST(KURLTest, Decode)
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(decodeCases); i++) {
- WebCore::String input(decodeCases[i].input);
- WebCore::String str = WebCore::decodeURLEscapeSequences(input);
+ 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
- WebCore::String zero = WebCore::decodeURLEscapeSequences("%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).
- WebCore::String invalid = WebCore::decodeURLEscapeSequences(
+ WTF::String invalid = WebCore::decodeURLEscapeSequences(
"%e4%a0%e5%a5%bd");
char16 invalidExpectedHelper[4] = { 0x00e4, 0x00a0, 0x597d, 0 };
- WebCore::String invalidExpected(
+ WTF::String invalidExpected(
reinterpret_cast<const ::UChar*>(invalidExpectedHelper),
3);
EXPECT_EQ(invalidExpected, invalid);
@@ -305,20 +305,20 @@ TEST(KURLTest, Encode)
{
// Also test that it gets converted to UTF-8 properly.
char16 wideInputHelper[3] = { 0x4f60, 0x597d, 0 };
- WebCore::String wideInput(
+ WTF::String wideInput(
reinterpret_cast<const ::UChar*>(wideInputHelper), 2);
- WebCore::String wideReference("\xe4\xbd\xa0\xe5\xa5\xbd", 6);
- WebCore::String wideOutput =
+ 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.
- WebCore::String input(
+ WTF::String input(
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 16);
- WebCore::String reference(
+ WTF::String reference(
"%00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 18);
- WebCore::String output = WebCore::encodeWithURLEscapeSequences(input);
+ WTF::String output = WebCore::encodeWithURLEscapeSequences(input);
EXPECT_EQ(reference, output);
}
@@ -381,10 +381,11 @@ TEST(KURLTest, ReplaceInvalid)
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 still fails.
+ // Now let's test that giving an invalid replacement fails. Invalid
+ // protocols fail without modifying the URL, which should remain valid.
#if USE(GOOGLEURL)
- kurl.setProtocol("f/sj#@");
- EXPECT_FALSE(kurl.isValid());
+ EXPECT_FALSE(kurl.setProtocol("f/sj#@"));
+ EXPECT_TRUE(kurl.isValid());
#endif
}
@@ -394,7 +395,7 @@ TEST(KURLTest, Path)
WebCore::KURL kurl(WebCore::ParsedURLString, initial);
// Clear by setting a null string.
- WebCore::String nullString;
+ WTF::String nullString;
EXPECT_TRUE(nullString.isNull());
kurl.setPath(nullString);
EXPECT_STREQ("http://www.google.com/", kurl.string().utf8().data());
@@ -408,14 +409,14 @@ TEST(KURLTest, Query)
WebCore::KURL kurl(WebCore::ParsedURLString, initial);
// Clear by setting a null string.
- WebCore::String nullString;
+ 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);
- WebCore::String emptyString("");
+ WTF::String emptyString("");
EXPECT_FALSE(emptyString.isNull());
kurl.setQuery(emptyString);
EXPECT_STREQ("http://www.google.com/search?", kurl.string().utf8().data());
@@ -455,10 +456,10 @@ TEST(KURLTest, Ref)
// Setting the ref to the null string will clear it altogether.
cur = WebCore::KURL(WebCore::ParsedURLString, "http://foo/bar");
- cur.setFragmentIdentifier(WebCore::String());
+ cur.setFragmentIdentifier(WTF::String());
EXPECT_STREQ("http://foo/bar", cur.string().utf8().data());
cur = kurl;
- cur.setFragmentIdentifier(WebCore::String());
+ cur.setFragmentIdentifier(WTF::String());
EXPECT_STREQ("http://foo/bar", cur.string().utf8().data());
}
@@ -484,7 +485,7 @@ TEST(KURLTest, Empty)
EXPECT_TRUE(kurl2.string().isEmpty());
// Resolve the null URL on a null string.
- WebCore::KURL kurl22(kurl, WebCore::String());
+ WebCore::KURL kurl22(kurl, WTF::String());
EXPECT_FALSE(kurl22.isNull());
EXPECT_TRUE(kurl22.isEmpty());
EXPECT_FALSE(kurl22.isValid());
diff --git a/WebKit/chromium/tests/PopupMenuTest.cpp b/WebKit/chromium/tests/PopupMenuTest.cpp
new file mode 100644
index 0000000..50319af
--- /dev/null
+++ b/WebKit/chromium/tests/PopupMenuTest.cpp
@@ -0,0 +1,375 @@
+/*
+ * 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, 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 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 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
index 0f3f82f..cfcfbee 100644
--- a/WebKit/chromium/tests/RunAllTests.cpp
+++ b/WebKit/chromium/tests/RunAllTests.cpp
@@ -33,18 +33,15 @@
#include "WebKit.h"
#include "WebKitClient.h"
-
-// WebKitClient has a protected destructor, so we need to subclass.
-class DummyWebKitClient : public WebKit::WebKitClient {
-};
+#include <webkit/support/webkit_support.h>
int main(int argc, char** argv)
{
- DummyWebKitClient dummyClient;
- WebKit::initialize(&dummyClient);
-
- int result = TestSuite(argc, argv).Run();
-
- WebKit::shutdown();
+ TestSuite testSuite(argc, argv);
+ // TestSuite must be created before SetUpTestEnvironment so it performs
+ // initializations needed by WebKit support.
+ webkit_support::SetUpTestEnvironmentForUnitTests();
+ int result = testSuite.Run();
+ webkit_support::TearDownTestEnvironment();
return result;
}
diff --git a/WebKit/chromium/tests/TilingDataTest.cpp b/WebKit/chromium/tests/TilingDataTest.cpp
new file mode 100755
index 0000000..ec18f01
--- /dev/null
+++ b/WebKit/chromium/tests/TilingDataTest.cpp
@@ -0,0 +1,334 @@
+/*
+ * 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/WebFrameTest.cpp b/WebKit/chromium/tests/WebFrameTest.cpp
new file mode 100644
index 0000000..cf91cb4
--- /dev/null
+++ b/WebKit/chromium/tests/WebFrameTest.cpp
@@ -0,0 +1,112 @@
+/*
+ * 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
new file mode 100644
index 0000000..7cd4837
--- /dev/null
+++ b/WebKit/chromium/tests/WebInputEventFactoryTestGtk.cpp
@@ -0,0 +1,112 @@
+/*
+ * 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/data/iframes_test.html b/WebKit/chromium/tests/data/iframes_test.html
new file mode 100644
index 0000000..425709b
--- /dev/null
+++ b/WebKit/chromium/tests/data/iframes_test.html
@@ -0,0 +1,9 @@
+<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
new file mode 100644
index 0000000..e5686c7
--- /dev/null
+++ b/WebKit/chromium/tests/data/invisible_iframe.html
@@ -0,0 +1,5 @@
+<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
new file mode 100644
index 0000000..291af3d
--- /dev/null
+++ b/WebKit/chromium/tests/data/visible_iframe.html
@@ -0,0 +1,5 @@
+<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
new file mode 100644
index 0000000..6728cab
--- /dev/null
+++ b/WebKit/chromium/tests/data/zero_sized_iframe.html
@@ -0,0 +1,5 @@
+<html>
+ <body>
+ This is an iframe with zero size.
+ </body>
+</html>