<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[182239] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/182239">182239</a></dd>
<dt>Author</dt> <dd>achristensen@apple.com</dd>
<dt>Date</dt> <dd>2015-04-01 10:48:57 -0700 (Wed, 01 Apr 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>[Content Extensions] Properly handle regexes that match everything.
https://bugs.webkit.org/show_bug.cgi?id=143281
Reviewed by Benjamin Poulain.
Source/WebCore:
* contentextensions/ContentExtensionCompiler.cpp:
(WebCore::ContentExtensions::compileRuleList):
Make sure we always have at least one NFA for rule lists with triggers that all match everything.
* contentextensions/DFABytecodeInterpreter.cpp:
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction):
Add helper functions to reduce duplicate code.
(WebCore::ContentExtensions::DFABytecodeInterpreter::actionsFromDFARoot):
Get all actions without flags from the DFA root.
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):
Remove branches when interpreting.
* contentextensions/DFABytecodeInterpreter.h:
Add helper functions to reduce duplicate code.
Tools:
* TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::testRequest):
(TestWebKitAPI::makeBackend):
(TestWebKitAPI::TEST_F):
Removed duplicate code and added test.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsContentExtensionCompilercpp">trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsDFABytecodeInterpretercpp">trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsDFABytecodeInterpreterh">trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebCoreContentExtensionscpp">trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (182238 => 182239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-04-01 17:43:21 UTC (rev 182238)
+++ trunk/Source/WebCore/ChangeLog        2015-04-01 17:48:57 UTC (rev 182239)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2015-04-01 Alex Christensen <achristensen@webkit.org>
+
+ [Content Extensions] Properly handle regexes that match everything.
+ https://bugs.webkit.org/show_bug.cgi?id=143281
+
+ Reviewed by Benjamin Poulain.
+
+ * contentextensions/ContentExtensionCompiler.cpp:
+ (WebCore::ContentExtensions::compileRuleList):
+ Make sure we always have at least one NFA for rule lists with triggers that all match everything.
+ * contentextensions/DFABytecodeInterpreter.cpp:
+ (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction):
+ (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction):
+ Add helper functions to reduce duplicate code.
+ (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsFromDFARoot):
+ Get all actions without flags from the DFA root.
+ (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):
+ Remove branches when interpreting.
+ * contentextensions/DFABytecodeInterpreter.h:
+ Add helper functions to reduce duplicate code.
+
</ins><span class="cx"> 2015-04-01 Myles C. Maxfield <mmaxfield@apple.com>
</span><span class="cx">
</span><span class="cx"> Addressing post-review comments.
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsContentExtensionCompilercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp (182238 => 182239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp        2015-04-01 17:43:21 UTC (rev 182238)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp        2015-04-01 17:48:57 UTC (rev 182239)
</span><span class="lines">@@ -173,6 +173,8 @@
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> Vector<NFA> nfas = combinedURLFilters.createNFAs();
</span><ins>+ if (!nfas.size() && universalActionLocations.size())
+ nfas.append(NFA());
</ins><span class="cx">
</span><span class="cx"> #if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
</span><span class="cx"> double nfaBuildTimeEnd = monotonicallyIncreasingTime();
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsDFABytecodeInterpretercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp (182238 => 182239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp        2015-04-01 17:43:21 UTC (rev 182238)
+++ trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp        2015-04-01 17:48:57 UTC (rev 182239)
</span><span class="lines">@@ -41,18 +41,39 @@
</span><span class="cx"> return *reinterpret_cast<const IntType*>(&bytecode[index]);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void DFABytecodeInterpreter::interpretAppendAction(unsigned& programCounter, Actions& actions)
+{
+ ASSERT(getBits<DFABytecodeInstruction>(m_bytecode, m_bytecodeLength, programCounter) == DFABytecodeInstruction::AppendAction);
+ actions.add(static_cast<uint64_t>(getBits<unsigned>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode))));
+ programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
+}
+
+void DFABytecodeInterpreter::interpretTestFlagsAndAppendAction(unsigned& programCounter, uint16_t flags, Actions& actions)
+{
+ ASSERT(getBits<DFABytecodeInstruction>(m_bytecode, m_bytecodeLength, programCounter) == DFABytecodeInstruction::TestFlagsAndAppendAction);
+ if (flags & getBits<uint16_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode)))
+ actions.add(static_cast<uint64_t>(getBits<unsigned>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode) + sizeof(uint16_t))));
+ programCounter += instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendAction);
+}
+
</ins><span class="cx"> DFABytecodeInterpreter::Actions DFABytecodeInterpreter::actionsFromDFARoot()
</span><span class="cx"> {
</span><del>- DFABytecodeInterpreter::Actions universalActionLocations;
</del><ins>+ Actions actions;
</ins><span class="cx">
</span><del>- // Skip first DFA header. All universal actions are in the first DFA root.
</del><ins>+ // DFA header.
+ unsigned dfaBytecodeLength = getBits<unsigned>(m_bytecode, m_bytecodeLength, 0);
</ins><span class="cx"> unsigned programCounter = sizeof(unsigned);
</span><span class="cx">
</span><del>- while (static_cast<DFABytecodeInstruction>(m_bytecode[programCounter]) == DFABytecodeInstruction::AppendAction) {
- universalActionLocations.add(static_cast<uint64_t>(getBits<unsigned>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode))));
- programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
</del><ins>+ while (programCounter < dfaBytecodeLength) {
+ DFABytecodeInstruction instruction = static_cast<DFABytecodeInstruction>(m_bytecode[programCounter]);
+ if (instruction == DFABytecodeInstruction::AppendAction)
+ interpretAppendAction(programCounter, actions);
+ else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendAction)
+ programCounter += instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendAction);
+ else
+ break;
</ins><span class="cx"> }
</span><del>- return universalActionLocations;
</del><ins>+ return actions;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> DFABytecodeInterpreter::Actions DFABytecodeInterpreter::interpret(const CString& urlCString, uint16_t flags)
</span><span class="lines">@@ -71,9 +92,22 @@
</span><span class="cx"> programCounter += sizeof(unsigned);
</span><span class="cx">
</span><span class="cx"> // Skip the actions on the DFA root. These are accessed via actionsFromDFARoot.
</span><del>- while (static_cast<DFABytecodeInstruction>(m_bytecode[programCounter]) == DFABytecodeInstruction::AppendAction) {
- ASSERT_WITH_MESSAGE(!dfaStart, "Triggers that match everything should only be in the first DFA.");
- programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
</del><ins>+ if (!dfaStart) {
+ while (programCounter < dfaBytecodeLength) {
+ DFABytecodeInstruction instruction = static_cast<DFABytecodeInstruction>(m_bytecode[programCounter]);
+ if (instruction == DFABytecodeInstruction::AppendAction)
+ programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
+ else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendAction)
+ interpretTestFlagsAndAppendAction(programCounter, flags, actions);
+ else
+ break;
+ }
+ if (programCounter >= m_bytecodeLength)
+ return actions;
+ } else {
+ ASSERT_WITH_MESSAGE(static_cast<DFABytecodeInstruction>(m_bytecode[programCounter]) != DFABytecodeInstruction::AppendAction
+ && static_cast<DFABytecodeInstruction>(m_bytecode[programCounter]) != DFABytecodeInstruction::TestFlagsAndAppendAction,
+ "Triggers that match everything should only be in the first DFA.");
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Interpret the bytecode from this DFA.
</span><span class="lines">@@ -87,49 +121,70 @@
</span><span class="cx"> case DFABytecodeInstruction::Terminate:
</span><span class="cx"> goto nextDFA;
</span><span class="cx">
</span><del>- case DFABytecodeInstruction::CheckValueCaseSensitive:
- case DFABytecodeInstruction::CheckValueCaseInsensitive: {
</del><ins>+ case DFABytecodeInstruction::CheckValueCaseSensitive: {
</ins><span class="cx"> if (urlIndexIsAfterEndOfString)
</span><span class="cx"> goto nextDFA;
</span><span class="cx">
</span><ins>+ // Check to see if the next character in the url is the value stored with the bytecode.
</ins><span class="cx"> char character = url[urlIndex];
</span><del>- if (static_cast<DFABytecodeInstruction>(m_bytecode[programCounter]) == DFABytecodeInstruction::CheckValueCaseInsensitive)
- character = toASCIILower(character);
</del><ins>+ if (character == getBits<uint8_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode))) {
+ programCounter = getBits<unsigned>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode) + sizeof(uint8_t));
+ if (!character)
+ urlIndexIsAfterEndOfString = true;
+ urlIndex++; // This represents an edge in the DFA.
+ } else
+ programCounter += instructionSizeWithArguments(DFABytecodeInstruction::CheckValueCaseSensitive);
+ break;
+ }
</ins><span class="cx">
</span><ins>+ case DFABytecodeInstruction::CheckValueCaseInsensitive: {
+ if (urlIndexIsAfterEndOfString)
+ goto nextDFA;
+
</ins><span class="cx"> // Check to see if the next character in the url is the value stored with the bytecode.
</span><ins>+ char character = toASCIILower(url[urlIndex]);
</ins><span class="cx"> if (character == getBits<uint8_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode))) {
</span><span class="cx"> programCounter = getBits<unsigned>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode) + sizeof(uint8_t));
</span><span class="cx"> if (!character)
</span><span class="cx"> urlIndexIsAfterEndOfString = true;
</span><span class="cx"> urlIndex++; // This represents an edge in the DFA.
</span><del>- } else {
- programCounter += instructionSizeWithArguments(DFABytecodeInstruction::CheckValueCaseSensitive);
- ASSERT(instructionSizeWithArguments(DFABytecodeInstruction::CheckValueCaseSensitive) == instructionSizeWithArguments(DFABytecodeInstruction::CheckValueCaseInsensitive));
- }
</del><ins>+ } else
+ programCounter += instructionSizeWithArguments(DFABytecodeInstruction::CheckValueCaseInsensitive);
</ins><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- case DFABytecodeInstruction::CheckValueRangeCaseSensitive:
- case DFABytecodeInstruction::CheckValueRangeCaseInsensitive: {
</del><ins>+ case DFABytecodeInstruction::CheckValueRangeCaseSensitive: {
</ins><span class="cx"> if (urlIndexIsAfterEndOfString)
</span><span class="cx"> goto nextDFA;
</span><span class="cx">
</span><span class="cx"> char character = url[urlIndex];
</span><del>- if (static_cast<DFABytecodeInstruction>(m_bytecode[programCounter]) == DFABytecodeInstruction::CheckValueRangeCaseInsensitive)
- character = toASCIILower(character);
</del><span class="cx"> if (character >= getBits<uint8_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode))
</span><span class="cx"> && character <= getBits<uint8_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode) + sizeof(uint8_t))) {
</span><span class="cx"> programCounter = getBits<unsigned>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode) + sizeof(uint8_t) + sizeof(uint8_t));
</span><span class="cx"> if (!character)
</span><span class="cx"> urlIndexIsAfterEndOfString = true;
</span><span class="cx"> urlIndex++; // This represents an edge in the DFA.
</span><del>- } else {
</del><ins>+ } else
</ins><span class="cx"> programCounter += instructionSizeWithArguments(DFABytecodeInstruction::CheckValueRangeCaseSensitive);
</span><del>- ASSERT(instructionSizeWithArguments(DFABytecodeInstruction::CheckValueRangeCaseSensitive) == instructionSizeWithArguments(DFABytecodeInstruction::CheckValueRangeCaseInsensitive));
- }
</del><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ case DFABytecodeInstruction::CheckValueRangeCaseInsensitive: {
+ if (urlIndexIsAfterEndOfString)
+ goto nextDFA;
+
+ char character = toASCIILower(url[urlIndex]);
+ if (character >= getBits<uint8_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode))
+ && character <= getBits<uint8_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode) + sizeof(uint8_t))) {
+ programCounter = getBits<unsigned>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode) + sizeof(uint8_t) + sizeof(uint8_t));
+ if (!character)
+ urlIndexIsAfterEndOfString = true;
+ urlIndex++; // This represents an edge in the DFA.
+ } else
+ programCounter += instructionSizeWithArguments(DFABytecodeInstruction::CheckValueRangeCaseInsensitive);
+ break;
+ }
+
</ins><span class="cx"> case DFABytecodeInstruction::Jump:
</span><span class="cx"> if (!url[urlIndex] || urlIndexIsAfterEndOfString)
</span><span class="cx"> goto nextDFA;
</span><span class="lines">@@ -139,14 +194,11 @@
</span><span class="cx"> break;
</span><span class="cx">
</span><span class="cx"> case DFABytecodeInstruction::AppendAction:
</span><del>- actions.add(static_cast<uint64_t>(getBits<unsigned>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode))));
- programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
</del><ins>+ interpretAppendAction(programCounter, actions);
</ins><span class="cx"> break;
</span><span class="cx">
</span><span class="cx"> case DFABytecodeInstruction::TestFlagsAndAppendAction:
</span><del>- if (flags & getBits<uint16_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode)))
- actions.add(static_cast<uint64_t>(getBits<unsigned>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode) + sizeof(uint16_t))));
- programCounter += instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendAction);
</del><ins>+ interpretTestFlagsAndAppendAction(programCounter, flags, actions);
</ins><span class="cx"> break;
</span><span class="cx">
</span><span class="cx"> default:
</span><span class="lines">@@ -155,6 +207,7 @@
</span><span class="cx"> // We should always terminate before or at a null character at the end of a String.
</span><span class="cx"> ASSERT(urlIndex <= urlCString.length() || (urlIndexIsAfterEndOfString && urlIndex <= urlCString.length() + 1));
</span><span class="cx"> }
</span><ins>+ RELEASE_ASSERT_NOT_REACHED(); // The while loop can only be exited using goto nextDFA.
</ins><span class="cx"> nextDFA:
</span><span class="cx"> ASSERT(dfaBytecodeLength);
</span><span class="cx"> programCounter = dfaStart + dfaBytecodeLength;
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsDFABytecodeInterpreterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h (182238 => 182239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h        2015-04-01 17:43:21 UTC (rev 182238)
+++ trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h        2015-04-01 17:48:57 UTC (rev 182239)
</span><span class="lines">@@ -51,6 +51,8 @@
</span><span class="cx"> Actions actionsFromDFARoot();
</span><span class="cx">
</span><span class="cx"> private:
</span><ins>+ void interpretAppendAction(unsigned& programCounter, Actions&);
+ void interpretTestFlagsAndAppendAction(unsigned& programCounter, uint16_t flags, Actions&);
</ins><span class="cx"> const DFABytecode* m_bytecode;
</span><span class="cx"> const unsigned m_bytecodeLength;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (182238 => 182239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-04-01 17:43:21 UTC (rev 182238)
+++ trunk/Tools/ChangeLog        2015-04-01 17:48:57 UTC (rev 182239)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2015-04-01 Alex Christensen <achristensen@webkit.org>
+
+ [Content Extensions] Properly handle regexes that match everything.
+ https://bugs.webkit.org/show_bug.cgi?id=143281
+
+ Reviewed by Benjamin Poulain.
+
+ * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
+ (TestWebKitAPI::testRequest):
+ (TestWebKitAPI::makeBackend):
+ (TestWebKitAPI::TEST_F):
+ Removed duplicate code and added test.
+
</ins><span class="cx"> 2015-03-31 Benjamin Poulain <bpoulain@apple.com>
</span><span class="cx">
</span><span class="cx"> Content Extensions: split the state machines to minimize prefix states
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebCoreContentExtensionscpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp (182238 => 182239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp        2015-04-01 17:43:21 UTC (rev 182238)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp        2015-04-01 17:48:57 UTC (rev 182239)
</span><span class="lines">@@ -136,9 +136,8 @@
</span><span class="cx"> void static testRequest(ContentExtensions::ContentExtensionsBackend contentExtensionsBackend, const ResourceLoadInfo& resourceLoadInfo, Vector<ContentExtensions::ActionType> expectedActions, bool ignorePreviousRules = false)
</span><span class="cx"> {
</span><span class="cx"> auto actions = contentExtensionsBackend.actionsForResourceLoad(resourceLoadInfo);
</span><del>-
</del><span class="cx"> unsigned expectedSize = actions.size();
</span><del>- if (actions.size() && !ignorePreviousRules)
</del><ins>+ if (!ignorePreviousRules)
</ins><span class="cx"> expectedSize--; // The last action is applying the compiled stylesheet.
</span><span class="cx">
</span><span class="cx"> EXPECT_EQ(expectedActions.size(), expectedSize);
</span><span class="lines">@@ -156,27 +155,26 @@
</span><span class="cx"> return { URL(URL(), url), URL(URL(), url), resourceType };
</span><span class="cx"> }
</span><span class="cx">
</span><del>-const char* basicFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\"}}]";
-
-TEST_F(ContentExtensionTest, Basic)
</del><ins>+ContentExtensions::ContentExtensionsBackend makeBackend(const char* json)
</ins><span class="cx"> {
</span><del>- auto extension = InMemoryCompiledContentExtension::createFromFilter(basicFilter);
-
</del><ins>+ auto extension = InMemoryCompiledContentExtension::createFromFilter(json);
</ins><span class="cx"> ContentExtensions::ContentExtensionsBackend backend;
</span><span class="cx"> backend.addContentExtension("testFilter", extension);
</span><ins>+ return backend;
+}
</ins><span class="cx">
</span><ins>+TEST_F(ContentExtensionTest, Basic)
+{
+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\"}}]");
+
</ins><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, RangeBasic)
</span><span class="cx"> {
</span><del>- const char* rangeBasicFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"w[0-9]c\", \"url-filter-is-case-sensitive\":true}},"
- "{\"action\":{\"type\":\"block-cookies\"},\"trigger\":{\"url-filter\":\"[A-H][a-z]cko\", \"url-filter-is-case-sensitive\":true}}]";
- auto extension = InMemoryCompiledContentExtension::createFromFilter(rangeBasicFilter);
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"w[0-9]c\", \"url-filter-is-case-sensitive\":true}},"
+ "{\"action\":{\"type\":\"block-cookies\"},\"trigger\":{\"url-filter\":\"[A-H][a-z]cko\", \"url-filter-is-case-sensitive\":true}}]");
</ins><span class="cx">
</span><del>- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("PatternNestedGroupsFilter", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("http://w3c.org"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("w2c://whatwg.org/"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/w0c"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -197,12 +195,8 @@
</span><span class="cx"> TEST_F(ContentExtensionTest, RangeExclusionGeneratingUniversalTransition)
</span><span class="cx"> {
</span><span class="cx"> // Transition of the type ([^X]X) effictively transition on every input.
</span><del>- const char* rangeExclusionGeneratingUniversalTransitionFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"[^a]+afoobar\"}}]";
- auto extension = InMemoryCompiledContentExtension::createFromFilter(rangeExclusionGeneratingUniversalTransitionFilter);
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"[^a]+afoobar\"}}]");
</ins><span class="cx">
</span><del>- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("PatternNestedGroupsFilter", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("http://w3c.org"), { });
</span><span class="cx">
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://w3c.org/foobafoobar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -219,12 +213,8 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, PatternStartingWithGroup)
</span><span class="cx"> {
</span><del>- const char* patternsStartingWithGroupFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^(http://whatwg\\\\.org/)?webkit\134\134.org\"}}]";
- auto extension = InMemoryCompiledContentExtension::createFromFilter(patternsStartingWithGroupFilter);
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^(http://whatwg\\\\.org/)?webkit\134\134.org\"}}]");
</ins><span class="cx">
</span><del>- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("PatternNestedGroupsFilter", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("http://whatwg.org/webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://whatwg.org/webkit.org"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/"), { });
</span><span class="lines">@@ -234,13 +224,8 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, PatternNestedGroups)
</span><span class="cx"> {
</span><del>- const char* patternNestedGroupsFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^http://webkit\\\\.org/(foo(bar)*)+\"}}]";
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^http://webkit\\\\.org/(foo(bar)*)+\"}}]");
</ins><span class="cx">
</span><del>- auto extension = InMemoryCompiledContentExtension::createFromFilter(patternNestedGroupsFilter);
-
- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("PatternNestedGroupsFilter", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/foo"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/foobarbar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -256,13 +241,8 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, MatchPastEndOfString)
</span><span class="cx"> {
</span><del>- const char* matchPastEndOfStringFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".+\"}}]";
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".+\"}}]");
</ins><span class="cx">
</span><del>- auto extension = InMemoryCompiledContentExtension::createFromFilter(matchPastEndOfStringFilter);
-
- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("MatchPastEndOfString", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/foo"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -273,15 +253,10 @@
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/foor"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> }
</span><span class="cx">
</span><del>-const char* startOfLineAssertionFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^foobar\"}}]";
-
</del><span class="cx"> TEST_F(ContentExtensionTest, StartOfLineAssertion)
</span><span class="cx"> {
</span><del>- auto extension = InMemoryCompiledContentExtension::createFromFilter(startOfLineAssertionFilter);
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^foobar\"}}]");
</ins><span class="cx">
</span><del>- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("StartOfLineAssertion", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("foobar://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("foobars:///foobar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("foobarfoobar:///foobarfoobarfoobar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -294,12 +269,8 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, EndOfLineAssertion)
</span><span class="cx"> {
</span><del>- const char* endOfLineAssertionFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"foobar$\"}}]";
- auto extension = InMemoryCompiledContentExtension::createFromFilter(endOfLineAssertionFilter);
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"foobar$\"}}]");
</ins><span class="cx">
</span><del>- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("EndOfLineAssertion", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("file:///foobar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("file:///foobarfoobarfoobar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -310,12 +281,8 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, EndOfLineAssertionWithInvertedCharacterSet)
</span><span class="cx"> {
</span><del>- const char* endOfLineAssertionWithInvertedCharacterSetFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"[^y]$\"}}]";
- auto extension = InMemoryCompiledContentExtension::createFromFilter(endOfLineAssertionWithInvertedCharacterSetFilter);
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"[^y]$\"}}]");
</ins><span class="cx">
</span><del>- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("EndOfLineAssertion", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/a"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -329,15 +296,11 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, PrefixInfixSuffixExactMatch)
</span><span class="cx"> {
</span><del>- const char* prefixInfixSuffixExactMatchFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"infix\"}},"
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"infix\"}},"
</ins><span class="cx"> "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^prefix\"}},"
</span><span class="cx"> "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"suffix$\"}},"
</span><del>- "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^http://exact\\\\.org/$\"}}]";
- auto extension = InMemoryCompiledContentExtension::createFromFilter(prefixInfixSuffixExactMatchFilter);
</del><ins>+ "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^http://exact\\\\.org/$\"}}]");
</ins><span class="cx">
</span><del>- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("PrefixInfixSuffixExactMatch", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("infix://webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://infix.org/"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("https://webkit.org/infix"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -356,13 +319,9 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, DuplicatedMatchAllTermsInVariousFormat)
</span><span class="cx"> {
</span><del>- const char* duplicatedMatchAllTermsInVariousFormatFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*.*(.)*(.*)(.+)*(.?)*infix\"}},"
- "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"pre(.?)+(.+)?post\"}}]";
- auto extension = InMemoryCompiledContentExtension::createFromFilter(duplicatedMatchAllTermsInVariousFormatFilter);
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*.*(.)*(.*)(.+)*(.?)*infix\"}},"
+ "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"pre(.?)+(.+)?post\"}}]");
</ins><span class="cx">
</span><del>- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("DuplicatedMatchAllTermsInVariousFormat", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("infix://webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://infix.org/"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("https://webkit.org/infix"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -380,7 +339,7 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, TermsKnownToMatchAnything)
</span><span class="cx"> {
</span><del>- const char* termsKnownToMatchAnythingFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^pre1.*post1$\"}},"
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^pre1.*post1$\"}},"
</ins><span class="cx"> "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^pre2(.*)post2$\"}},"
</span><span class="cx"> "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^pre3(.*)?post3$\"}},"
</span><span class="cx"> "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^pre4(.*)+post4$\"}},"
</span><span class="lines">@@ -389,12 +348,8 @@
</span><span class="cx"> "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^pre7(.+)*post7$\"}},"
</span><span class="cx"> "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^pre8(.?)*post8$\"}},"
</span><span class="cx"> "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^pre9(.+)?post9$\"}},"
</span><del>- "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^pre0(.?)+post0$\"}}]";
- auto extension = InMemoryCompiledContentExtension::createFromFilter(termsKnownToMatchAnythingFilter);
</del><ins>+ "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^pre0(.?)+post0$\"}}]");
</ins><span class="cx">
</span><del>- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("TermsKnownToMatchAnything", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("pre1://webkit.org/post1"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("pre2://webkit.org/post2"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("pre3://webkit.org/post3"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -431,13 +386,9 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, TrailingDotStar)
</span><span class="cx"> {
</span><del>- const char* trailingDotStarFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"foo.*$\"}},"
- "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"bar(.*)$\"}}]";
- auto extension = InMemoryCompiledContentExtension::createFromFilter(trailingDotStarFilter);
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"foo.*$\"}},"
+ "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"bar(.*)$\"}}]");
</ins><span class="cx">
</span><del>- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("TrailingDotStar", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("https://webkit.org/"), { });
</span><span class="cx">
</span><span class="cx"> testRequest(backend, mainDocumentRequest("foo://webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -453,14 +404,10 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, TrailingTermsCarryingNoData)
</span><span class="cx"> {
</span><del>- const char* trailingTermsCarryingNoDataFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"foob?a?r?\"}},"
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"foob?a?r?\"}},"
</ins><span class="cx"> "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"bazo(ok)?a?$\"}},"
</span><del>- "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"cats*$\"}}]";
- auto extension = InMemoryCompiledContentExtension::createFromFilter(trailingTermsCarryingNoDataFilter);
</del><ins>+ "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"cats*$\"}}]");
</ins><span class="cx">
</span><del>- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("TrailingTermsCarryingNoData", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("https://webkit.org/"), { });
</span><span class="cx">
</span><span class="cx"> // Anything is fine after foo.
</span><span class="lines">@@ -494,15 +441,10 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, LoadType)
</span><span class="cx"> {
</span><del>- const char* loadTypeFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"load-type\":[\"third-party\"]}},"
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"load-type\":[\"third-party\"]}},"
</ins><span class="cx"> "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"whatwg.org\",\"load-type\":[\"first-party\"]}},"
</span><del>- "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"alwaysblock.pdf\"}}]";
-
- auto extension = InMemoryCompiledContentExtension::createFromFilter(loadTypeFilter);
-
- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("LoadTypeFilter", extension);
-
</del><ins>+ "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"alwaysblock.pdf\"}}]");
+
</ins><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org"), { });
</span><span class="cx"> testRequest(backend, {URL(URL(), "http://webkit.org"), URL(URL(), "http://not_webkit.org"), ResourceType::Document}, { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx">
</span><span class="lines">@@ -515,14 +457,9 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, ResourceType)
</span><span class="cx"> {
</span><del>- const char* resourceTypeFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"block_all_types.org\",\"resource-type\":[\"document\",\"image\",\"style-sheet\",\"script\",\"font\",\"raw\",\"svg-document\",\"media\"]}},"
- "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"block_only_images\",\"resource-type\":[\"image\"]}}]";
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"block_all_types.org\",\"resource-type\":[\"document\",\"image\",\"style-sheet\",\"script\",\"font\",\"raw\",\"svg-document\",\"media\"]}},"
+ "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"block_only_images\",\"resource-type\":[\"image\"]}}]");
</ins><span class="cx">
</span><del>- auto extension = InMemoryCompiledContentExtension::createFromFilter(resourceTypeFilter);
-
- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("ResourceTypeFilter", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::Document), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::Image), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::StyleSheet), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -535,6 +472,17 @@
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://block_only_images.org", ResourceType::Document), { });
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+TEST_F(ContentExtensionTest, ResourceOrLoadTypeMatchingEverything)
+{
+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*\",\"resource-type\":[\"image\"]}},"
+ "{\"action\":{\"type\":\"block-cookies\"},\"trigger\":{\"url-filter\":\".*\",\"load-type\":[\"third-party\"]}},"
+ "{\"action\":{\"type\":\"ignore-previous-rules\"},\"trigger\":{\"url-filter\":\".*\",\"load-type\":[\"first-party\"]}}]");
+
+ testRequest(backend, mainDocumentRequest("http://webkit.org"), { }, true);
+ testRequest(backend, {URL(URL(), "http://webkit.org"), URL(URL(), "http://not_webkit.org"), ResourceType::Document}, { ContentExtensions::ActionType::BlockCookies });
+ testRequest(backend, {URL(URL(), "http://webkit.org"), URL(URL(), "http://not_webkit.org"), ResourceType::Image}, { ContentExtensions::ActionType::BlockCookies, ContentExtensions::ActionType::BlockLoad });
+}
+
</ins><span class="cx"> TEST_F(ContentExtensionTest, MultiDFA)
</span><span class="cx"> {
</span><span class="cx"> // Make an NFA with about 1400 nodes.
</span><span class="lines">@@ -563,10 +511,7 @@
</span><span class="cx"> }
</span><span class="cx"> ruleList.append(']');
</span><span class="cx">
</span><del>- auto extension = InMemoryCompiledContentExtension::createFromFilter(ruleList.toString());
-
- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("ResourceTypeFilter", extension);
</del><ins>+ auto backend = makeBackend(ruleList.toString().utf8().data());
</ins><span class="cx">
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/AAA"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/ZAA"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -624,15 +569,10 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, StrictPrefixSeparatedMachines1)
</span><span class="cx"> {
</span><del>- const char* strictPrefixSeparatedMachinesFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^.*foo\"}},"
- "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"bar$\"}},"
- "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^[ab]+bang\"}}]";
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^.*foo\"}},"
+ "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"bar$\"}},"
+ "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^[ab]+bang\"}}]");
</ins><span class="cx">
</span><del>- auto extension = InMemoryCompiledContentExtension::createFromFilter(strictPrefixSeparatedMachinesFilter);
-
- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("StrictPrefixSeparatedMachines1", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/foo"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("foo://webkit.org/bar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/bar"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="lines">@@ -662,16 +602,11 @@
</span><span class="cx">
</span><span class="cx"> TEST_F(ContentExtensionTest, StrictPrefixSeparatedMachines2)
</span><span class="cx"> {
</span><del>- const char* strictPrefixSeparatedMachinesFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^foo\"}},"
</del><ins>+ auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^foo\"}},"
</ins><span class="cx"> "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^.*[a-c]+bar\"}},"
</span><span class="cx"> "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^webkit:\"}},"
</span><del>- "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"[a-c]+b+oom\"}}]";
</del><ins>+ "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"[a-c]+b+oom\"}}]");
</ins><span class="cx">
</span><del>- auto extension = InMemoryCompiledContentExtension::createFromFilter(strictPrefixSeparatedMachinesFilter);
-
- ContentExtensions::ContentExtensionsBackend backend;
- backend.addContentExtension("StrictPrefixSeparatedMachines2", extension);
-
</del><span class="cx"> testRequest(backend, mainDocumentRequest("http://webkit.org/"), { });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("foo://webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
</span><span class="cx"> testRequest(backend, mainDocumentRequest("webkit://webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
</span></span></pre>
</div>
</div>
</body>
</html>