Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2220)

Unified Diff: chrome/browser/component_updater/subresource_filter_component_installer_unittest.cc

Issue 2182493009: Framework for indexing of subresource filtering rules. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Attempt #2 to fix tests on Windows. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/component_updater/subresource_filter_component_installer_unittest.cc
diff --git a/chrome/browser/component_updater/subresource_filter_component_installer_unittest.cc b/chrome/browser/component_updater/subresource_filter_component_installer_unittest.cc
index 8a05ca813833ee267fefc4df1f717f61e1fcc2ac..7daff3cae126427192e6a2afa828e2a6d9c472dd 100644
--- a/chrome/browser/component_updater/subresource_filter_component_installer_unittest.cc
+++ b/chrome/browser/component_updater/subresource_filter_component_installer_unittest.cc
@@ -16,6 +16,8 @@
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/test/test_simple_task_runner.h"
+#include "base/version.h"
+#include "chrome/browser/after_startup_task_utils.h"
#include "chrome/test/base/testing_browser_process.h"
#include "components/component_updater/mock_component_updater_service.h"
#include "components/prefs/testing_pref_service.h"
@@ -38,18 +40,19 @@ class TestRulesetService : public subresource_filter::RulesetService {
~TestRulesetService() override {}
- void NotifyRulesetVersionAvailable(const std::string& rules,
- const base::Version& version) override {
- rules_ = rules;
- version_ = version;
+ void IndexAndStoreAndPublishRulesetVersionIfNeeded(
+ const base::FilePath& unindexed_ruleset_path,
+ const std::string& content_version) override {
+ ruleset_path_ = unindexed_ruleset_path;
+ content_version_ = content_version;
}
- const std::string& rules() { return rules_; }
- const base::Version& version() { return version_; }
+ const base::FilePath& ruleset_path() const { return ruleset_path_; }
+ const std::string& content_version() const { return content_version_; }
private:
- std::string rules_;
- base::Version version_;
+ base::FilePath ruleset_path_;
+ std::string content_version_;
DISALLOW_COPY_AND_ASSIGN(TestRulesetService);
};
@@ -81,7 +84,8 @@ class SubresourceFilterComponentInstallerTest : public PlatformTest {
ASSERT_TRUE(component_install_dir_.CreateUniqueTempDir());
ASSERT_TRUE(ruleset_service_dir_.CreateUniqueTempDir());
- subresource_filter::RulesetVersion::RegisterPrefs(pref_service_.registry());
+ subresource_filter::IndexedRulesetVersion::RegisterPrefs(
+ pref_service_.registry());
std::unique_ptr<subresource_filter::RulesetService> service(
new TestRulesetService(&pref_service_, task_runner_,
@@ -89,8 +93,11 @@ class SubresourceFilterComponentInstallerTest : public PlatformTest {
TestingBrowserProcess::GetGlobal()->SetRulesetService(std::move(service));
traits_.reset(new SubresourceFilterComponentInstallerTraits());
+ AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
}
+ void TearDown() override { AfterStartupTaskUtils::UnsafeResetForTesting(); }
+
TestRulesetService* service() {
return static_cast<TestRulesetService*>(
TestingBrowserProcess::GetGlobal()
@@ -109,24 +116,24 @@ class SubresourceFilterComponentInstallerTest : public PlatformTest {
return component_install_dir_.path();
}
- void LoadSubresourceFilterRules(const std::string& rules) {
- const base::DictionaryValue manifest;
+ void LoadSubresourceFilterRules(const std::string& ruleset_contents) {
+ std::unique_ptr<base::DictionaryValue> manifest(new base::DictionaryValue);
const base::FilePath subresource_filters_dir(component_install_dir());
const base::FilePath first_subresource_filter_file =
subresource_filters_dir.Append(
FILE_PATH_LITERAL("subresource_filter_rules.blob"));
- WriteSubresourceFilterToFile(rules, first_subresource_filter_file);
+ WriteSubresourceFilterToFile(ruleset_contents,
+ first_subresource_filter_file);
ASSERT_TRUE(
- traits_->VerifyInstallation(manifest, component_install_dir_.path()));
+ traits_->VerifyInstallation(*manifest, component_install_dir_.path()));
- const base::Version v("1.0");
- // TODO(melandory): test ComponentReady.
- traits_->LoadSubresourceFilterRulesFromDisk(component_install_dir(), v);
- // Drain the RunLoop created by the TestBrowserThreadBundle
+ const base::Version expected_version("1.2.3.4");
+ traits_->ComponentReady(expected_version, component_install_dir(),
+ std::move(manifest));
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(v, service()->version());
+ EXPECT_EQ(expected_version.GetString(), service()->content_version());
}
private:
@@ -145,7 +152,7 @@ TEST_F(SubresourceFilterComponentInstallerTest,
base::FieldTrialList field_trial_list(nullptr);
subresource_filter::testing::ScopedSubresourceFilterFeatureToggle
scoped_feature_toggle(base::FeatureList::OVERRIDE_DISABLE_FEATURE,
- subresource_filter::kActivationStateDisabled);
+ subresource_filter::kActivationStateEnabled);
std::unique_ptr<SubresourceFilterMockComponentUpdateService>
component_updater(new SubresourceFilterMockComponentUpdateService());
EXPECT_CALL(*component_updater, RegisterComponent(testing::_)).Times(0);
@@ -158,7 +165,7 @@ TEST_F(SubresourceFilterComponentInstallerTest,
base::FieldTrialList field_trial_list(nullptr);
subresource_filter::testing::ScopedSubresourceFilterFeatureToggle
scoped_feature_toggle(base::FeatureList::OVERRIDE_ENABLE_FEATURE,
- subresource_filter::kActivationStateEnabled);
+ subresource_filter::kActivationStateDisabled);
std::unique_ptr<SubresourceFilterMockComponentUpdateService>
component_updater(new SubresourceFilterMockComponentUpdateService());
EXPECT_CALL(*component_updater, RegisterComponent(testing::_)).Times(1);
@@ -167,14 +174,23 @@ TEST_F(SubresourceFilterComponentInstallerTest,
}
TEST_F(SubresourceFilterComponentInstallerTest, LoadEmptyFile) {
+ ASSERT_TRUE(service());
ASSERT_NO_FATAL_FAILURE(LoadSubresourceFilterRules(std::string()));
+ std::string actual_ruleset_contents;
+ ASSERT_TRUE(base::ReadFileToString(service()->ruleset_path(),
+ &actual_ruleset_contents));
+ EXPECT_TRUE(actual_ruleset_contents.empty()) << actual_ruleset_contents;
}
TEST_F(SubresourceFilterComponentInstallerTest, LoadFileWithData) {
ASSERT_TRUE(service());
- const std::string rules("example.com");
- ASSERT_NO_FATAL_FAILURE(LoadSubresourceFilterRules(rules));
- EXPECT_EQ(rules, service()->rules());
+ const std::string expected_ruleset_contents("foobar");
+ ASSERT_NO_FATAL_FAILURE(
+ LoadSubresourceFilterRules(expected_ruleset_contents));
+ std::string actual_ruleset_contents;
+ ASSERT_TRUE(base::ReadFileToString(service()->ruleset_path(),
+ &actual_ruleset_contents));
+ EXPECT_EQ(expected_ruleset_contents, actual_ruleset_contents);
}
} // namespace component_updater
« no previous file with comments | « chrome/browser/component_updater/subresource_filter_component_installer.cc ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698