diff options
Diffstat (limited to 'Tools/TestWebKitAPI')
| -rw-r--r-- | Tools/TestWebKitAPI/TestWebKitAPI.gyp/TestWebKitAPI.gyp | 87 | ||||
| -rw-r--r-- | Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj | 12 | ||||
| -rw-r--r-- | Tools/TestWebKitAPI/Tests/WTF/MetaAllocator.cpp | 24 | ||||
| -rw-r--r-- | Tools/TestWebKitAPI/Tests/WTF/RedBlackTree.cpp | 37 | ||||
| -rw-r--r-- | Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp | 89 | ||||
| -rw-r--r-- | Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp | 2 | ||||
| -rw-r--r-- | Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp | 68 | ||||
| -rw-r--r-- | Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp | 79 | ||||
| -rw-r--r-- | Tools/TestWebKitAPI/Tests/mac/InspectorBar.mm | 87 |
9 files changed, 463 insertions, 22 deletions
diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.gyp/TestWebKitAPI.gyp b/Tools/TestWebKitAPI/TestWebKitAPI.gyp/TestWebKitAPI.gyp new file mode 100644 index 000000000..4babcb23d --- /dev/null +++ b/Tools/TestWebKitAPI/TestWebKitAPI.gyp/TestWebKitAPI.gyp @@ -0,0 +1,87 @@ +# +# Copyright (C) 2012 Google Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * 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. +# + +{ + 'variables': { + 'tools_dir': '../..', + 'source_dir': '../../../Source', + 'conditions': [ + # Location of the chromium src directory and target type is different + # if webkit is built inside chromium or as standalone project. + ['inside_chromium_build==0', { + # Webkit is being built outside of the full chromium project. + # e.g. via build-webkit --chromium + 'chromium_src_dir': '<(source_dir)/WebKit/chromium', + },{ + # WebKit is checked out in src/chromium/third_party/WebKit + 'chromium_src_dir': '<(tools_dir)/../../..', + }], + ], + }, + 'includes': [ + '../TestWebKitAPI.gypi', + '../../../Source/WebKit/chromium/features.gypi', + ], + 'targets': [ + { + 'target_name': 'TestWebKitAPI', + 'type': 'executable', + 'dependencies': [ + '<(source_dir)/WebKit/chromium/WebKit.gyp:webkit', + '<(source_dir)/WebCore/WebCore.gyp/WebCore.gyp:webcore', + '<(chromium_src_dir)/base/base.gyp:test_support_base', + '<(chromium_src_dir)/testing/gtest.gyp:gtest', + '<(chromium_src_dir)/testing/gmock.gyp:gmock', + '<(chromium_src_dir)/webkit/support/webkit_support.gyp:webkit_support', + ], + 'include_dirs': [ + '<(tools_dir)/TestWebKitAPI', + # Needed by tests/RunAllTests.cpp, as well as ChromiumCurrentTime.cpp and + # ChromiumThreading.cpp in chromium shared library configuration. + '<(source_dir)/WebKit/chromium/public', + ], + 'sources': [ + # Reuse the same testing driver of Chromium's webkit_unit_tests. + '<(source_dir)/WebKit/chromium/tests/RunAllTests.cpp', + '<@(TestWebKitAPI_files)', + ], + 'conditions': [ + ['inside_chromium_build==1 and component=="shared_library"', { + 'sources': [ + # To satisfy linking of WTF::currentTime() etc. in shared library configuration, + # as the symbols are not exported from the DLLs. + '<(source_dir)/WebKit/chromium/src/ChromiumCurrentTime.cpp', + '<(source_dir)/WebKit/chromium/src/ChromiumThreading.cpp', + ], + }], + ], + }, + ], # targets +} diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj index 3483bec21..6c403a844 100644 --- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj +++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj @@ -38,6 +38,8 @@ 520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */; }; 520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4B141EB09E00937EA8 /* WebArchive.cpp */; }; 52CB47411448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */; }; + 52E5CE4614D21E9D003B2BD8 /* ParentFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52E5CE4514D21E9D003B2BD8 /* ParentFrame.cpp */; }; + 52E5CE4914D21EAB003B2BD8 /* ParentFrame_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52E5CE4814D21EAB003B2BD8 /* ParentFrame_Bundle.cpp */; }; 81B50193140F232300D9EB58 /* StringBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81B50192140F232300D9EB58 /* StringBuilder.cpp */; }; 939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */ = {isa = PBXBuildFile; fileRef = 939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */; }; A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */; }; @@ -105,6 +107,7 @@ C0BD669F131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0BD669E131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp */; }; C0C5D3BE14598B6F00A802A6 /* GetBackingScaleFactor.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */; }; C0C5D3C61459912900A802A6 /* GetBackingScaleFactor_Bundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */; }; + C507E8A714C6545B005D6B3B /* InspectorBar.mm in Sources */ = {isa = PBXBuildFile; fileRef = C507E8A614C6545B005D6B3B /* InspectorBar.mm */; }; F3FC3EE313678B7300126A65 /* libgtest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F3FC3EE213678B7300126A65 /* libgtest.a */; }; F6F3F29113342FEB00A6BF19 /* CookieManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6F3F29013342FEB00A6BF19 /* CookieManager.cpp */; }; F6FDDDD314241AD4004F1729 /* PrivateBrowsingPushStateNoHistoryCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6FDDDD214241AD4004F1729 /* PrivateBrowsingPushStateNoHistoryCallback.cpp */; }; @@ -189,6 +192,8 @@ 520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebArchive_Bundle.cpp; sourceTree = "<group>"; }; 520BCF4B141EB09E00937EA8 /* WebArchive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebArchive.cpp; sourceTree = "<group>"; }; 52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadAlternateHTMLStringWithNonDirectoryURL.cpp; sourceTree = "<group>"; }; + 52E5CE4514D21E9D003B2BD8 /* ParentFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParentFrame.cpp; sourceTree = "<group>"; }; + 52E5CE4814D21EAB003B2BD8 /* ParentFrame_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParentFrame_Bundle.cpp; sourceTree = "<group>"; }; 81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringBuilder.cpp; path = WTF/StringBuilder.cpp; sourceTree = "<group>"; }; 8DD76FA10486AA7600D96B5E /* TestWebKitAPI */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TestWebKitAPI; sourceTree = BUILT_PRODUCTS_DIR; }; 939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceScaleFactorOnBack.mm; sourceTree = "<group>"; }; @@ -271,6 +276,7 @@ C0BD669E131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResponsivenessTimerDoesntFireEarly_Bundle.cpp; sourceTree = "<group>"; }; C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GetBackingScaleFactor.mm; sourceTree = "<group>"; }; C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GetBackingScaleFactor_Bundle.mm; sourceTree = "<group>"; }; + C507E8A614C6545B005D6B3B /* InspectorBar.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InspectorBar.mm; sourceTree = "<group>"; }; F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; }; F6F3F29013342FEB00A6BF19 /* CookieManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CookieManager.cpp; sourceTree = "<group>"; }; F6FDDDD214241AD4004F1729 /* PrivateBrowsingPushStateNoHistoryCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrivateBrowsingPushStateNoHistoryCallback.cpp; sourceTree = "<group>"; }; @@ -435,6 +441,8 @@ 33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */, BC909779125571AB00083756 /* PageLoadBasic.cpp */, BC2D004812A9FDFA00E732A3 /* PageLoadDidChangeLocationWithinPageForFrame.cpp */, + 52E5CE4514D21E9D003B2BD8 /* ParentFrame.cpp */, + 52E5CE4814D21EAB003B2BD8 /* ParentFrame_Bundle.cpp */, 333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */, F6FDDDD214241AD4004F1729 /* PrivateBrowsingPushStateNoHistoryCallback.cpp */, C0BD669C131D3CF700E18F2A /* ResponsivenessTimerDoesntFireEarly.cpp */, @@ -529,6 +537,7 @@ 37DC678B140D7C5000ABCCDB /* DOMRangeOfString.mm */, C07E6CAE13FD67650038B22B /* DynamicDeviceScaleFactor.mm */, 939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */, + C507E8A614C6545B005D6B3B /* InspectorBar.mm */, 3722C8681461E03E00C45D00 /* RenderedImageFromDOMRange.mm */, 3799AD3914120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm */, 37A6895D148A9B50005100FA /* SubresourceErrorCrash.mm */, @@ -725,6 +734,8 @@ BCAA485814A044D40088FAC4 /* EditorCommands.mm in Sources */, BC55F5F914AD78EE00484BE1 /* Vector.cpp in Sources */, 440A1D3914A0103A008A66F2 /* KURL.cpp in Sources */, + C507E8A714C6545B005D6B3B /* InspectorBar.mm in Sources */, + 52E5CE4614D21E9D003B2BD8 /* ParentFrame.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -747,6 +758,7 @@ 520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */, C0C5D3C61459912900A802A6 /* GetBackingScaleFactor_Bundle.mm in Sources */, BC901E331492AF390074A667 /* WKConnection_Bundle.cpp in Sources */, + 52E5CE4914D21EAB003B2BD8 /* ParentFrame_Bundle.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tools/TestWebKitAPI/Tests/WTF/MetaAllocator.cpp b/Tools/TestWebKitAPI/Tests/WTF/MetaAllocator.cpp index 4de523a3b..61c16d1ab 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/MetaAllocator.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/MetaAllocator.cpp @@ -182,7 +182,7 @@ public: MetaAllocatorHandle* allocate(size_t sizeInBytes, SanityCheckMode sanityCheckMode = RunSanityCheck) { - MetaAllocatorHandle* handle = allocator->allocate(sizeInBytes).leakRef(); + MetaAllocatorHandle* handle = allocator->allocate(sizeInBytes, 0).leakRef(); EXPECT_TRUE(handle); EXPECT_EQ(handle->sizeInBytes(), sizeInBytes); @@ -464,7 +464,7 @@ public: sanityCheck(); - EXPECT_TRUE(!allocator->allocate(sizeInBytes)); + EXPECT_TRUE(!allocator->allocate(sizeInBytes, 0)); for (size_t index = 0; index < numAllocations; ++index) free(handles.at(index), DontRunSanityCheck); @@ -571,7 +571,7 @@ public: sanityCheck(); // Assert that the heap is not empty. - EXPECT_TRUE(!allocator->allocate(defaultPagesInHeap * pageSize())); + EXPECT_TRUE(!allocator->allocate(defaultPagesInHeap * pageSize(), 0)); // Allocate the remainder of the heap. MetaAllocatorHandle* remainder = allocate(defaultPagesInHeap * pageSize() - secondSize); @@ -589,12 +589,12 @@ public: void testDemandAllocCoalesce(size_t firstSize, size_t numPages, size_t secondSize) { - EXPECT_TRUE(!allocator->allocate((defaultPagesInHeap + numPages) * pageSize())); + EXPECT_TRUE(!allocator->allocate((defaultPagesInHeap + numPages) * pageSize(), 0)); MetaAllocatorHandle* firstHandle = allocate(firstSize); - EXPECT_TRUE(!allocator->allocate(secondSize)); - EXPECT_TRUE(!allocator->allocate((defaultPagesInHeap + numPages) * pageSize())); + EXPECT_TRUE(!allocator->allocate(secondSize, 0)); + EXPECT_TRUE(!allocator->allocate((defaultPagesInHeap + numPages) * pageSize(), 0)); currentHeapGrowthMode = ForTestDemandAllocCoalesce; allowAllocatePages = numPages; @@ -618,12 +618,12 @@ public: { free(allocate(firstSize)); free(allocate(defaultPagesInHeap * pageSize())); - EXPECT_TRUE(!allocator->allocate((defaultPagesInHeap + numPages) * pageSize())); + EXPECT_TRUE(!allocator->allocate((defaultPagesInHeap + numPages) * pageSize(), 0)); MetaAllocatorHandle* firstHandle = allocate(firstSize); - EXPECT_TRUE(!allocator->allocate(secondSize)); - EXPECT_TRUE(!allocator->allocate((defaultPagesInHeap + numPages) * pageSize())); + EXPECT_TRUE(!allocator->allocate(secondSize, 0)); + EXPECT_TRUE(!allocator->allocate((defaultPagesInHeap + numPages) * pageSize(), 0)); currentHeapGrowthMode = ForTestDemandAllocDontCoalesce; allowAllocatePages = numPages; @@ -637,12 +637,12 @@ public: requestedNumPages = 0; - EXPECT_TRUE(!allocator->allocate((defaultPagesInHeap + numPages) * pageSize())); + EXPECT_TRUE(!allocator->allocate((defaultPagesInHeap + numPages) * pageSize(), 0)); free(firstHandle); free(secondHandle); - EXPECT_TRUE(!allocator->allocate((defaultPagesInHeap + numPages) * pageSize())); + EXPECT_TRUE(!allocator->allocate((defaultPagesInHeap + numPages) * pageSize(), 0)); firstHandle = allocate(firstSize); secondHandle = allocate(secondSize); @@ -663,7 +663,7 @@ TEST_F(MetaAllocatorTest, AllocZero) // Tests that allocating a zero-length block returns 0 and // does not change anything in memory. - ASSERT(!allocator->allocate(0)); + ASSERT(!allocator->allocate(0, 0)); MetaAllocatorHandle* final = allocate(defaultPagesInHeap * pageSize()); EXPECT_EQ(final->start(), reinterpret_cast<void*>(basePage * pageSize())); diff --git a/Tools/TestWebKitAPI/Tests/WTF/RedBlackTree.cpp b/Tools/TestWebKitAPI/Tests/WTF/RedBlackTree.cpp index efac240ab..1a1c9fdfc 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/RedBlackTree.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/RedBlackTree.cpp @@ -34,7 +34,24 @@ using namespace WTF; namespace TestWebKitAPI { -class RedBlackTreeTest: public testing::Test { +class TestNode : public RedBlackTree<TestNode, char>::Node { +public: + TestNode(char key, unsigned value) + : m_key(key) + , m_value(value) + { + } + + char key() + { + return m_key; + } + + char m_key; + unsigned m_value; +}; + +class RedBlackTreeTest : public testing::Test { public: unsigned m_counter; @@ -135,18 +152,18 @@ public: } // This deliberately passes a copy of the vector. - void assertEqual(RedBlackTree<char, unsigned>& asTree, PairVector asVector) + void assertEqual(RedBlackTree<TestNode, char>& asTree, PairVector asVector) { - for (RedBlackTree<char, unsigned>::Node* current = asTree.first(); current; current = current->successor()) + for (TestNode* current = asTree.first(); current; current = current->successor()) assertFoundAndRemove(asVector, current->m_key, current->m_value); } - void assertSameValuesForKey(RedBlackTree<char, unsigned>& asTree, RedBlackTree<char, unsigned>::Node* node, PairVector foundValues, char key) + void assertSameValuesForKey(RedBlackTree<TestNode, char>& asTree, TestNode* node, PairVector foundValues, char key) { if (node) { EXPECT_EQ(node->m_key, key); - RedBlackTree<char, unsigned>::Node* prevNode = node; + TestNode* prevNode = node; do { node = prevNode; prevNode = prevNode->predecessor(); @@ -176,7 +193,7 @@ public: void testDriver(const char* controlString) { PairVector asVector; - RedBlackTree<char, unsigned> asTree; + RedBlackTree<TestNode, char> asTree; for (const char* current = controlString; *current; current += 2) { char command = current[0]; @@ -188,14 +205,14 @@ public: switch (command) { case '+': { - RedBlackTree<char, unsigned>::Node* node = new RedBlackTree<char, unsigned>::Node(key, value); + TestNode* node = new TestNode(key, value); asTree.insert(node); asVector.append(Pair(key, value)); break; } case '*': { - RedBlackTree<char, unsigned>::Node* node = asTree.findExact(key); + TestNode* node = asTree.findExact(key); if (node) EXPECT_EQ(node->m_key, key); assertSameValuesForKey(asTree, node, findExact(asVector, key), key); @@ -203,7 +220,7 @@ public: } case '@': { - RedBlackTree<char, unsigned>::Node* node = asTree.findLeastGreaterThanOrEqual(key); + TestNode* node = asTree.findLeastGreaterThanOrEqual(key); if (node) { EXPECT_TRUE(node->m_key >= key); assertSameValuesForKey(asTree, node, findLeastGreaterThanOrEqual(asVector, key), node->m_key); @@ -214,7 +231,7 @@ public: case '!': { while (true) { - RedBlackTree<char, unsigned>::Node* node = asTree.remove(key); + TestNode* node = asTree.remove(key); if (node) { EXPECT_EQ(node->m_key, key); assertFoundAndRemove(asVector, node->m_key, node->m_value); diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp index 35b124441..8ee5c6e04 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp @@ -75,6 +75,16 @@ TEST(StringBuilderTest, Append) builder1.append("XYZ"); builder.append(builder1.characters(), builder1.length()); expectBuilderContent("0123456789abcdefg#0123456789abcdefg#XYZ", builder); + + StringBuilder builder2; + builder2.reserveCapacity(100); + builder2.append("xyz"); + const UChar* characters = builder2.characters(); + builder2.append("0123456789"); + ASSERT_EQ(characters, builder2.characters()); + builder2.toStringPreserveCapacity(); // Test after reifyString with buffer preserved. + builder2.append("abcd"); + ASSERT_EQ(characters, builder2.characters()); } TEST(StringBuilderTest, ToString) @@ -114,7 +124,9 @@ TEST(StringBuilderTest, ToStringPreserveCapacity) { StringBuilder builder; builder.append("0123456789"); + unsigned capacity = builder.capacity(); String string = builder.toStringPreserveCapacity(); + ASSERT_EQ(capacity, builder.capacity()); ASSERT_EQ(String("0123456789"), string); ASSERT_EQ(string.impl(), builder.toStringPreserveCapacity().impl()); ASSERT_EQ(string.characters(), builder.characters()); @@ -125,14 +137,18 @@ TEST(StringBuilderTest, ToStringPreserveCapacity) // Changing the StringBuilder should not affect the original result of toStringPreserveCapacity() in case the capacity is not changed. builder.reserveCapacity(200); + capacity = builder.capacity(); string = builder.toStringPreserveCapacity(); + ASSERT_EQ(capacity, builder.capacity()); ASSERT_EQ(string.characters(), builder.characters()); ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string); builder.append("ABC"); ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string); // Changing the original result of toStringPreserveCapacity() should not affect the content of the StringBuilder. + capacity = builder.capacity(); String string1 = builder.toStringPreserveCapacity(); + ASSERT_EQ(capacity, builder.capacity()); ASSERT_EQ(string1.characters(), builder.characters()); ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1); string1.append("DEF"); @@ -140,7 +156,9 @@ TEST(StringBuilderTest, ToStringPreserveCapacity) ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABCDEF"), string1); // Resizing the StringBuilder should not affect the original result of toStringPreserveCapacity(). + capacity = builder.capacity(); string1 = builder.toStringPreserveCapacity(); + ASSERT_EQ(capacity, builder.capacity()); ASSERT_EQ(string.characters(), builder.characters()); builder.resize(10); builder.append("###"); @@ -185,4 +203,75 @@ TEST(StringBuilderTest, Resize) expectEmpty(builder); } +TEST(StringBuilderTest, Equal) +{ + StringBuilder builder1; + StringBuilder builder2; + ASSERT_TRUE(builder1 == builder2); + ASSERT_TRUE(equal(builder1, static_cast<LChar*>(0), 0)); + ASSERT_TRUE(builder1 == String()); + ASSERT_TRUE(String() == builder1); + ASSERT_TRUE(builder1 != String("abc")); + + builder1.append("123"); + builder1.reserveCapacity(32); + builder2.append("123"); + builder1.reserveCapacity(64); + ASSERT_TRUE(builder1 == builder2); + ASSERT_TRUE(builder1 == String("123")); + ASSERT_TRUE(String("123") == builder1); + + builder2.append("456"); + ASSERT_TRUE(builder1 != builder2); + ASSERT_TRUE(builder2 != builder1); + ASSERT_TRUE(String("123") != builder2); + ASSERT_TRUE(builder2 != String("123")); + builder2.toString(); // Test after reifyString(). + ASSERT_TRUE(builder1 != builder2); + + builder2.resize(3); + ASSERT_TRUE(builder1 == builder2); + + builder1.toString(); // Test after reifyString(). + ASSERT_TRUE(builder1 == builder2); +} + +TEST(StringBuilderTest, CanShrink) +{ + StringBuilder builder; + builder.reserveCapacity(256); + ASSERT_TRUE(builder.canShrink()); + for (int i = 0; i < 256; i++) + builder.append('x'); + ASSERT_EQ(builder.length(), builder.capacity()); + ASSERT_FALSE(builder.canShrink()); +} + +TEST(StringBuilderTest, ToAtomicString) +{ + StringBuilder builder; + builder.append("123"); + AtomicString atomicString = builder.toAtomicString(); + ASSERT_EQ(String("123"), atomicString); + + builder.reserveCapacity(256); + ASSERT_TRUE(builder.canShrink()); + for (int i = builder.length(); i < 128; i++) + builder.append('x'); + AtomicString atomicString1 = builder.toAtomicString(); + ASSERT_EQ(128u, atomicString1.length()); + ASSERT_EQ('x', atomicString1[127]); + + // Later change of builder should not affect the atomic string. + for (int i = builder.length(); i < 256; i++) + builder.append('x'); + ASSERT_EQ(128u, atomicString1.length()); + + ASSERT_FALSE(builder.canShrink()); + String string = builder.toString(); + AtomicString atomicString2 = builder.toAtomicString(); + // They should share the same StringImpl. + ASSERT_EQ(atomicString2.impl(), string.impl()); +} + } // namespace diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp index 0191b6593..f7bbf732f 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2/PageLoadBasic.cpp @@ -90,6 +90,7 @@ static void decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WK State* state = reinterpret_cast<State*>(const_cast<void*>(clientInfo)); EXPECT_FALSE(state->didStartProvisionalLoadForFrame); EXPECT_FALSE(state->didCommitLoadForFrame); + EXPECT_TRUE(mouseButton = kWKEventMouseButtonNoButton); state->didDecidePolicyForNavigationAction = true; @@ -98,6 +99,7 @@ static void decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WK static void decidePolicyForNewWindowAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKStringRef frameName, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo) { + EXPECT_TRUE(mouseButton = kWKEventMouseButtonNoButton); WKFramePolicyListenerUse(listener); } diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp new file mode 100644 index 000000000..7645c66ee --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2012 Apple 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 INC. 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 INC. 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 "PlatformUtilities.h" +#include "PlatformWebView.h" +#include <WebKit2/WKContextPrivate.h> + +namespace TestWebKitAPI { + +static bool didReceiveMessage; +static bool isParentFrameCheckSuccessful; + +static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef body, const void*) +{ + didReceiveMessage = true; + + EXPECT_WK_STREQ("DidCheckParentFrame", messageName); + EXPECT_EQ(WKBooleanGetTypeID(), WKGetTypeID(body)); + + isParentFrameCheckSuccessful = WKBooleanGetValue(static_cast<WKBooleanRef>(body)); +} + +static void setInjectedBundleClient(WKContextRef context) +{ + WKContextInjectedBundleClient injectedBundleClient; + memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); + injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; + + WKContextSetInjectedBundleClient(context, &injectedBundleClient); +} + +TEST(WebKit2, ParentFrame) +{ + WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("ParentFrameTest")); + setInjectedBundleClient(context.get()); + + PlatformWebView webView(context.get()); + + WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple-iframe", "html")).get()); + + Util::run(&didReceiveMessage); + EXPECT_TRUE(isParentFrameCheckSuccessful); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp new file mode 100644 index 000000000..40035e90c --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKit2/ParentFrame_Bundle.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2012 Apple 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 INC. 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 INC. 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 "InjectedBundleTest.h" + +#include "PlatformUtilities.h" +#include <WebKit2/WKBundlePage.h> +#include <WebKit2/WKBundleFrame.h> +#include <WebKit2/WKRetainPtr.h> + +namespace TestWebKitAPI { + +static WKRetainPtr<WKBundleRef> testBundle; +static WKRetainPtr<WKBundleFrameRef> childFrame; + +class ParentFrameTest : public InjectedBundleTest { +public: + ParentFrameTest(const std::string& identifier); + +private: + virtual void didCreatePage(WKBundleRef, WKBundlePageRef); + +}; + +static InjectedBundleTest::Register<ParentFrameTest> registrar("ParentFrameTest"); + +ParentFrameTest::ParentFrameTest(const std::string& identifier) + : InjectedBundleTest(identifier) +{ +} + +static void didFinishLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo) +{ + if (!WKBundleFrameIsMainFrame(frame)) { + childFrame = frame; + return; + } + + bool isParentFrameCheckSuccessful = childFrame ? WKBundleFrameGetParentFrame(childFrame.get()) == frame : false; + WKBundlePostMessage(testBundle.get(), Util::toWK("DidCheckParentFrame").get(), adoptWK(WKBooleanCreate(isParentFrameCheckSuccessful)).get()); +} + +void ParentFrameTest::didCreatePage(WKBundleRef bundle, WKBundlePageRef page) +{ + testBundle = bundle; + + WKBundlePageLoaderClient pageLoaderClient; + memset(&pageLoaderClient, 0, sizeof(pageLoaderClient)); + + pageLoaderClient.version = 1; + pageLoaderClient.didFinishLoadForFrame = didFinishLoadForFrame; + + WKBundlePageSetPageLoaderClient(page, &pageLoaderClient); +} + +} // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/mac/InspectorBar.mm b/Tools/TestWebKitAPI/Tests/mac/InspectorBar.mm new file mode 100644 index 000000000..0a51e2fb4 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/mac/InspectorBar.mm @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2011, 2012 Apple 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 INC. 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 INC. 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. + */ + +#import "config.h" +#import "PlatformUtilities.h" +#import <wtf/RetainPtr.h> + +@interface InspectorBarController : NSObject { +} +@end + +static bool didFinishLoad; + +@implementation InspectorBarController + +- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame +{ + didFinishLoad = true; +} + +- (NSDictionary *)convertAttributes:(NSDictionary *)dictionary +{ + NSMutableDictionary *newDictionary = [dictionary mutableCopy]; + [newDictionary removeObjectForKey:NSForegroundColorAttributeName]; + return [newDictionary autorelease]; +} +@end + +namespace TestWebKitAPI { + +TEST(WebKit1, InspectorBarTest) +{ + RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]); + RetainPtr<InspectorBarController> inspectorBarController(AdoptNS, [InspectorBarController new]); + + webView.get().frameLoadDelegate = inspectorBarController.get(); + [webView.get().mainFrame loadHTMLString:@"<body contenteditable style=\"color: green\"><u>Lorem ipsum sit amet</u></body>" baseURL:[NSURL URLWithString:@"about:blank"]]; + + Util::run(&didFinishLoad); + + DOMDocument *document = webView.get().mainFrameDocument; + [[document body] focus]; + + EXPECT_TRUE([webView.get() respondsToSelector:@selector(typingAttributes)]); + NSDictionary *attributes = [(id)webView.get() typingAttributes]; + [(id)[[[webView.get() mainFrame] frameView] documentView] doCommandBySelector:@selector(bold:)]; + EXPECT_FALSE([attributes isEqual:[(id)webView.get() typingAttributes]]); + + [webView.get() selectAll:nil]; + NSAttributedString *attrString = [(NSView <NSTextInput> *)[[[webView.get() mainFrame] frameView] documentView] attributedSubstringFromRange:NSMakeRange(0, 5)]; + attributes = [attrString attributesAtIndex:0 effectiveRange:0]; + + EXPECT_TRUE([[attributes objectForKey:NSUnderlineStyleAttributeName] intValue] != 0); + + [webView.get() changeAttributes:inspectorBarController.get()]; + + DOMNode *currentNode = [document body]; + while ([[currentNode firstChild] nodeType] != DOM_TEXT_NODE) + currentNode = [currentNode firstChild]; + + DOMCSSStyleDeclaration *style = [document getComputedStyle:(DOMElement *)currentNode pseudoElement:nil]; + EXPECT_WK_STREQ(@"rgb(0, 0, 0)", [style color]); +} + +} // namespace TestWebKitAPI |
