[Content Filtering] Add tests
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Mar 2015 23:39:05 +0000 (23:39 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Mar 2015 23:39:05 +0000 (23:39 +0000)
commit895f6925b29c4d11aa7f86d0d1a7863770b22c65
tree95634cbecd83b7a63a2e31e0edd16f9399e85217
parentb6bb93806c5a2896efd8332e3c7bb370cc3bd38b
[Content Filtering] Add tests
https://bugs.webkit.org/show_bug.cgi?id=142475

Reviewed by Andreas Kling.

Source/WebCore:

Added a mock content filter that can be configured by window.internals. A test can control whether the filter
is enabled, what to display when a page is blocked, at what point the allow/block decision is made, and what
decision to make.

Added tests to cover allowing and blocking content at each decision point.

Tests: contentfiltering/allow-after-add-data.html
       contentfiltering/allow-after-finished-adding-data.html
       contentfiltering/allow-after-response.html
       contentfiltering/block-after-add-data.html
       contentfiltering/block-after-finished-adding-data.html
       contentfiltering/block-after-response.html

* DerivedSources.make: Added MockContentFilterSettings.idl.
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSMockContentFilterSettingsCustom.cpp: Added.
(WebCore::JSMockContentFilterSettings::decisionPoint): Returned the decision point's JSValue.
(WebCore::JSMockContentFilterSettings::setDecisionPoint): Set the decision point; threw an exception for invalid values.
(WebCore::JSMockContentFilterSettings::decision): Returned the decision's JSValue.
(WebCore::JSMockContentFilterSettings::setDecision): Set the decision; threw an exception for invalid values.
* platform/ContentFilter.cpp:
(WebCore::ContentFilter::types): Renamed from contentFilterTypes.
(WebCore::ContentFilter::createIfNeeded):
(WebCore::contentFilterType): Deleted.
(WebCore::contentFilterTypes): Deleted.
* platform/ContentFilter.h:
(WebCore::ContentFilter::addType): Used to register a new content filter type.
(WebCore::ContentFilter::type): Renamed from contentFilterType.
* platform/cocoa/NetworkExtensionContentFilter.h: Moved definition of HAVE_NE_FILTER_SOURCE to here.
* testing/Internals.cpp:
(WebCore::Internals::resetToConsistentState): Called MockContentFilterSettings::reset().
(WebCore::Internals::Internals): Called MockContentFilter::ensureInstalled().
(WebCore::Internals::mockContentFilterSettings): Returned a reference to MockContentFilterSettings::singleton().
* testing/Internals.h:
* testing/Internals.idl: Added attribute mockContentFilterSettings.
* testing/MockContentFilter.cpp: Added.
(WebCore::MockContentFilter::ensureInstalled): Called MockContentFilter::addType().
(WebCore::MockContentFilter::canHandleResponse): Returned whether MockContentFilterSettings is enabled.
(WebCore::MockContentFilter::create): Returned a new MockContentFilter.
(WebCore::MockContentFilter::MockContentFilter): Called maybeDetermineStatus().
(WebCore::MockContentFilter::addData): Copied data into m_replacementData and called maybeDetermineStatus().
(WebCore::MockContentFilter::finishedAddingData): Called maybeDetermineStatus().
(WebCore::MockContentFilter::needsMoreData): Returned whether m_status equals NeedsMoreData.
(WebCore::MockContentFilter::didBlockData): Returned whether m_status equals Blocked.
(WebCore::MockContentFilter::getReplacementData): Returned a pointer to the start of m_replacementData.
(WebCore::MockContentFilter::unblockHandler): Returned an empty ContentFilterUnblockHandler.
(WebCore::MockContentFilter::maybeDetermineStatus): If m_status is NeedsMoreData and the current decision point
equals MockContentFilterSettings's decision point, set m_status according to MockContentFilterSettings's
decision. If m_status becomes Blocked, clear the original page data from m_replacementData and copy
MockContentFilterSettings's blocked string instead.
* testing/MockContentFilter.h: Copied from Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h.
* testing/MockContentFilterSettings.cpp: Copied from Source/WebCore/platform/ContentFilter.h.
(WebCore::MockContentFilterSettings::singleton):
(WebCore::MockContentFilterSettings::reset): Reset settings to their initial values.
(WebCore::MockContentFilterSettings::MockContentFilterSettings):
* testing/MockContentFilterSettings.h: Copied from Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h.
(WebCore::MockContentFilterSettings::ref): Added an empty implementation to make the bindings think this is RefCounted.
(WebCore::MockContentFilterSettings::deref): Ditto.
(WebCore::MockContentFilterSettings::enabled):
(WebCore::MockContentFilterSettings::setEnabled):
(WebCore::MockContentFilterSettings::blockedString):
(WebCore::MockContentFilterSettings::setBlockedString):
(WebCore::MockContentFilterSettings::decisionPoint):
(WebCore::MockContentFilterSettings::setDecisionPoint):
(WebCore::MockContentFilterSettings::decision):
(WebCore::MockContentFilterSettings::setDecision):
* testing/MockContentFilterSettings.idl: Copied from Source/WebCore/platform/ContentFilter.h.

LayoutTests:

* contentfiltering/allow-after-add-data-expected.html: Added.
* contentfiltering/allow-after-add-data.html: Added.
* contentfiltering/allow-after-finished-adding-data-expected.html: Added.
* contentfiltering/allow-after-finished-adding-data.html: Added.
* contentfiltering/allow-after-response-expected.html: Added.
* contentfiltering/allow-after-response.html: Added.
* contentfiltering/block-after-add-data-expected.html: Added.
* contentfiltering/block-after-add-data.html: Added.
* contentfiltering/block-after-finished-adding-data-expected.html: Added.
* contentfiltering/block-after-finished-adding-data.html: Added.
* contentfiltering/block-after-response-expected.html: Added.
* contentfiltering/block-after-response.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181291 268f45cc-cd09-0410-ab3c-d52691b4dbfc
31 files changed:
LayoutTests/ChangeLog
LayoutTests/contentfiltering/allow-after-add-data-expected.html [new file with mode: 0644]
LayoutTests/contentfiltering/allow-after-add-data.html [new file with mode: 0644]
LayoutTests/contentfiltering/allow-after-finished-adding-data-expected.html [new file with mode: 0644]
LayoutTests/contentfiltering/allow-after-finished-adding-data.html [new file with mode: 0644]
LayoutTests/contentfiltering/allow-after-response-expected.html [new file with mode: 0644]
LayoutTests/contentfiltering/allow-after-response.html [new file with mode: 0644]
LayoutTests/contentfiltering/block-after-add-data-expected.html [new file with mode: 0644]
LayoutTests/contentfiltering/block-after-add-data.html [new file with mode: 0644]
LayoutTests/contentfiltering/block-after-finished-adding-data-expected.html [new file with mode: 0644]
LayoutTests/contentfiltering/block-after-finished-adding-data.html [new file with mode: 0644]
LayoutTests/contentfiltering/block-after-response-expected.html [new file with mode: 0644]
LayoutTests/contentfiltering/block-after-response.html [new file with mode: 0644]
LayoutTests/platform/efl/TestExpectations
LayoutTests/platform/gtk/TestExpectations
LayoutTests/platform/win/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSMockContentFilterSettingsCustom.cpp [new file with mode: 0644]
Source/WebCore/platform/ContentFilter.cpp
Source/WebCore/platform/ContentFilter.h
Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebCore/testing/MockContentFilter.cpp [new file with mode: 0644]
Source/WebCore/testing/MockContentFilter.h [new file with mode: 0644]
Source/WebCore/testing/MockContentFilterSettings.cpp [new file with mode: 0644]
Source/WebCore/testing/MockContentFilterSettings.h [new file with mode: 0644]
Source/WebCore/testing/MockContentFilterSettings.idl [new file with mode: 0644]