diff options
author | aboxhall@chromium.org <aboxhall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-15 21:01:12 +0000 |
---|---|---|
committer | aboxhall@chromium.org <aboxhall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-15 21:01:12 +0000 |
commit | f0f2241e15c48116e4e096aada603bd320aeef41 (patch) | |
tree | 0118bd5c976446a37e0000f46133ac247bd0bf9b /content/browser | |
parent | 08392131bdf655152ca1c5445c52422a99214416 (diff) | |
download | chromium_src-f0f2241e15c48116e4e096aada603bd320aeef41.zip chromium_src-f0f2241e15c48116e4e096aada603bd320aeef41.tar.gz chromium_src-f0f2241e15c48116e4e096aada603bd320aeef41.tar.bz2 |
Switch filters to being a struct and processed on a last one wins basis
BUG=
Review URL: https://chromiumcodereview.appspot.com/11877021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176969 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
3 files changed, 42 insertions, 33 deletions
diff --git a/content/browser/accessibility/dump_accessibility_tree_browsertest.cc b/content/browser/accessibility/dump_accessibility_tree_browsertest.cc index 0422146..abf0672 100644 --- a/content/browser/accessibility/dump_accessibility_tree_browsertest.cc +++ b/content/browser/accessibility/dump_accessibility_tree_browsertest.cc @@ -37,6 +37,8 @@ namespace { namespace content { +typedef DumpAccessibilityTreeHelper::Filter Filter; + // This test takes a snapshot of the platform BrowserAccessibility tree and // tests it against an expected baseline. // @@ -75,15 +77,13 @@ class DumpAccessibilityTreeTest : public ContentBrowserTest { return diff_lines; } - void AddDefaultFilters(std::set<string16>* allow_filters, - std::set<string16>* deny_filters) { - allow_filters->insert(ASCIIToUTF16("FOCUSABLE")); - allow_filters->insert(ASCIIToUTF16("READONLY")); + void AddDefaultFilters(std::vector<Filter>* filters) { + filters->push_back(Filter(ASCIIToUTF16("FOCUSABLE"), Filter::ALLOW)); + filters->push_back(Filter(ASCIIToUTF16("READONLY"), Filter::ALLOW)); } void ParseFilters(const std::string& test_html, - std::set<string16>* allow_filters, - std::set<string16>* deny_filters) { + std::vector<Filter>* filters) { std::vector<std::string> lines; base::SplitString(test_html, '\n', &lines); for (std::vector<std::string>::const_iterator iter = lines.begin(); @@ -92,10 +92,13 @@ class DumpAccessibilityTreeTest : public ContentBrowserTest { const std::string& line = *iter; const std::string& allow_str = helper_.GetAllowString(); const std::string& deny_str = helper_.GetDenyString(); - if (StartsWithASCII(line, allow_str, true)) - allow_filters->insert(UTF8ToUTF16(line.substr(allow_str.size()))); - else if (StartsWithASCII(line, deny_str, true)) - deny_filters->insert(UTF8ToUTF16(line.substr(deny_str.size()))); + if (StartsWithASCII(line, allow_str, true)) { + filters->push_back(Filter(UTF8ToUTF16(line.substr(allow_str.size())), + Filter::ALLOW)); + } else if (StartsWithASCII(line, deny_str, true)) { + filters->push_back(Filter(UTF8ToUTF16(line.substr(deny_str.size())), + Filter::DENY)); + } } } @@ -130,11 +133,10 @@ void DumpAccessibilityTreeTest::RunTest(const FilePath::CharType* file_path) { file_util::ReadFileToString(html_file, &html_contents); // Parse filters in the test file. - std::set<string16> allow_filters; - std::set<string16> deny_filters; - AddDefaultFilters(&allow_filters, &deny_filters); - ParseFilters(html_contents, &allow_filters, &deny_filters); - helper_.SetFilters(allow_filters, deny_filters); + std::vector<Filter> filters; + AddDefaultFilters(&filters); + ParseFilters(html_contents, &filters); + helper_.SetFilters(filters); // Read the expected file. std::string expected_contents_raw; diff --git a/content/browser/accessibility/dump_accessibility_tree_helper.cc b/content/browser/accessibility/dump_accessibility_tree_helper.cc index e8a28f9..1e52bca 100644 --- a/content/browser/accessibility/dump_accessibility_tree_helper.cc +++ b/content/browser/accessibility/dump_accessibility_tree_helper.cc @@ -45,24 +45,19 @@ void DumpAccessibilityTreeHelper::RecursiveDumpAccessibilityTree( } void DumpAccessibilityTreeHelper::SetFilters( - const std::set<string16>& allow_filters, - const std::set<string16>& deny_filters) { - allow_filters_ = allow_filters; - deny_filters_ = deny_filters; + const std::vector<Filter>& filters) { + filters_ = filters; } bool DumpAccessibilityTreeHelper::MatchesFilters( const string16& text, bool default_result) { - std::set<string16>::const_iterator iter = allow_filters_.begin(); - for (iter = allow_filters_.begin(); iter != allow_filters_.end(); ++iter) { - if (MatchPattern(text, *iter)) - return true; + std::vector<Filter>::const_iterator iter = filters_.begin(); + bool allow = default_result; + for (iter = filters_.begin(); iter != filters_.end(); ++iter) { + if (MatchPattern(text, iter->match_str)) + allow = (iter->type == Filter::ALLOW); } - for (iter = deny_filters_.begin(); iter != deny_filters_.end(); ++iter) { - if (MatchPattern(text, *iter)) - return false; - } - return default_result; + return allow; } void DumpAccessibilityTreeHelper::StartLine() { diff --git a/content/browser/accessibility/dump_accessibility_tree_helper.h b/content/browser/accessibility/dump_accessibility_tree_helper.h index 42e04fa..015a6a2 100644 --- a/content/browser/accessibility/dump_accessibility_tree_helper.h +++ b/content/browser/accessibility/dump_accessibility_tree_helper.h @@ -5,7 +5,7 @@ #ifndef CONTENT_BROWSER_ACCESSIBILITY_DUMP_ACCESSIBILITY_TREE_HELPER_H_ #define CONTENT_BROWSER_ACCESSIBILITY_DUMP_ACCESSIBILITY_TREE_HELPER_H_ -#include <set> +#include <vector> #include "base/file_path.h" #include "base/string16.h" @@ -26,10 +26,23 @@ class DumpAccessibilityTreeHelper { void DumpAccessibilityTree(BrowserAccessibility* node, string16* contents); + // A single filter specification. See GetAllowString() and GetDenyString() + // for more information. + struct Filter { + enum Type { + ALLOW, + DENY + }; + string16 match_str; + Type type; + + Filter(string16 match_str, Type type) + : match_str(match_str), type(type) {} + }; + // Set regular expression filters that apply to each component of every // line before it's output. - void SetFilters(const std::set<string16>& allow_filters, - const std::set<string16>& deny_filters); + void SetFilters(const std::vector<Filter>& filters); // Suffix of the expectation file corresponding to html file. // Example: @@ -70,8 +83,7 @@ class DumpAccessibilityTreeHelper { void Add(bool include_by_default, const string16& attr); string16 FinishLine(); - std::set<string16> allow_filters_; - std::set<string16> deny_filters_; + std::vector<Filter> filters_; string16 line_; DISALLOW_COPY_AND_ASSIGN(DumpAccessibilityTreeHelper); |