| Index: chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry_unittest.cc
|
| diff --git a/chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry_unittest.cc b/chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry_unittest.cc
|
| index df17ed3652ebd9fc174e0a3a4e9dde2ef3141b6b..4c6c04ce7b7e6c28bcd1dc0cbd611324d5cb0a4c 100644
|
| --- a/chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry_unittest.cc
|
| +++ b/chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry_unittest.cc
|
| @@ -7,12 +7,10 @@
|
| #include <string>
|
|
|
| #include "base/test/values_test_util.h"
|
| -#include "chrome/browser/chrome_notification_types.h"
|
| +#include "chrome/browser/extensions/extension_tab_util.h"
|
| #include "chrome/browser/extensions/test_extension_environment.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| #include "content/public/browser/navigation_details.h"
|
| -#include "content/public/browser/notification_details.h"
|
| -#include "content/public/browser/notification_source.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/common/frame_navigate_params.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| @@ -20,27 +18,42 @@
|
|
|
| namespace extensions {
|
|
|
| -TEST(DeclarativeChromeContentRulesRegistryTest, ActiveRulesDoesntGrow) {
|
| +using base::test::ParseJson;
|
| +using testing::HasSubstr;
|
| +using content::WebContents;
|
| +
|
| +// Must be outside the anonymous namespace to be a friend of
|
| +// ContentRulesRegistry.
|
| +class DeclarativeChromeContentRulesRegistryTest : public testing::Test {
|
| + protected:
|
| + using RulesMap =
|
| + std::map<content::WebContents*, std::set<const ContentRule*>>;
|
| + static const RulesMap& active_rules(
|
| + const ChromeContentRulesRegistry& registry) {
|
| + return registry.active_rules_;
|
| + }
|
| +};
|
| +
|
| +namespace {
|
| +
|
| +TEST_F(DeclarativeChromeContentRulesRegistryTest, ActiveRulesDoesntGrow) {
|
| TestExtensionEnvironment env;
|
|
|
| scoped_refptr<ChromeContentRulesRegistry> registry(
|
| new ChromeContentRulesRegistry(env.profile(), NULL));
|
|
|
| - EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting());
|
| + EXPECT_EQ(0u, active_rules(*registry.get()).size());
|
|
|
| - scoped_ptr<content::WebContents> tab = env.MakeTab();
|
| - // Let the registry know about the tab.
|
| - registry->Observe(chrome::NOTIFICATION_TAB_ADDED,
|
| - content::Source<content::WebContentsDelegate>(nullptr),
|
| - content::Details<content::WebContents>(tab.get()));
|
| - registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(),
|
| - content::FrameNavigateParams());
|
| - EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting());
|
| + content::LoadCommittedDetails load_details;
|
| + content::FrameNavigateParams navigate_params;
|
| + scoped_ptr<WebContents> tab = env.MakeTab();
|
| + registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params);
|
| + EXPECT_EQ(0u, active_rules(*registry.get()).size());
|
|
|
| // Add a rule.
|
| linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule);
|
| RulesRegistry::Rule::Populate(
|
| - *base::test::ParseJson(
|
| + *ParseJson(
|
| "{\n"
|
| " \"id\": \"rule1\",\n"
|
| " \"priority\": 100,\n"
|
| @@ -57,35 +70,30 @@
|
| std::vector<linked_ptr<RulesRegistry::Rule> > rules;
|
| rules.push_back(rule);
|
|
|
| - const Extension* extension = env.MakeExtension(*base::test::ParseJson(
|
| + const Extension* extension = env.MakeExtension(*ParseJson(
|
| "{\"page_action\": {}}"));
|
| registry->AddRulesImpl(extension->id(), rules);
|
|
|
| - registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(),
|
| - content::FrameNavigateParams());
|
| - EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting());
|
| + registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params);
|
| + EXPECT_EQ(0u, active_rules(*registry.get()).size());
|
|
|
| std::vector<std::string> css_selectors;
|
| css_selectors.push_back("input");
|
| - registry->UpdateMatchingCssSelectorsForTesting(tab.get(), css_selectors);
|
| - EXPECT_EQ(1u, registry->GetActiveRulesCountForTesting());
|
| + registry->Apply(tab.get(), css_selectors);
|
| + EXPECT_EQ(1u, active_rules(*registry.get()).size());
|
|
|
| // Closing the tab should erase its entry from active_rules_.
|
| tab.reset();
|
| - EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting());
|
| + EXPECT_EQ(0u, active_rules(*registry.get()).size());
|
|
|
| tab = env.MakeTab();
|
| - // Let the registry know about the tab.
|
| - registry->Observe(chrome::NOTIFICATION_TAB_ADDED,
|
| - content::Source<content::WebContentsDelegate>(nullptr),
|
| - content::Details<content::WebContents>(tab.get()));
|
| - registry->UpdateMatchingCssSelectorsForTesting(tab.get(), css_selectors);
|
| - EXPECT_EQ(1u, registry->GetActiveRulesCountForTesting());
|
| + registry->Apply(tab.get(), css_selectors);
|
| + EXPECT_EQ(1u, active_rules(*registry.get()).size());
|
| // Navigating the tab should erase its entry from active_rules_ if
|
| // it no longer matches.
|
| - registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(),
|
| - content::FrameNavigateParams());
|
| - EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting());
|
| + registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params);
|
| + EXPECT_EQ(0u, active_rules(*registry.get()).size());
|
| }
|
|
|
| +} // namespace
|
| } // namespace extensions
|
|
|