This source file includes following definitions.
- active_rules
- TEST_F
#include "chrome/browser/extensions/api/declarative_content/content_rules_registry.h"
#include <string>
#include "base/test/values_test_util.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/web_contents.h"
#include "content/public/common/frame_navigate_params.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
using base::test::ParseJson;
using testing::HasSubstr;
using content::WebContents;
class DeclarativeContentRulesRegistryTest : public testing::Test {
protected:
static const std::map<int, std::set<ContentRule*> >& active_rules(
const ContentRulesRegistry& registry) {
return registry.active_rules_;
}
};
namespace {
TEST_F(DeclarativeContentRulesRegistryTest, ActiveRulesDoesntGrow) {
TestExtensionEnvironment env;
scoped_refptr<ContentRulesRegistry> registry(
new ContentRulesRegistry(env.profile(), NULL));
EXPECT_EQ(0u, active_rules(*registry.get()).size());
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());
linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule);
RulesRegistry::Rule::Populate(
*ParseJson(
"{\n"
" \"id\": \"rule1\",\n"
" \"priority\": 100,\n"
" \"conditions\": [\n"
" {\n"
" \"instanceType\": \"declarativeContent.PageStateMatcher\",\n"
" \"css\": [\"input\"]\n"
" }],\n"
" \"actions\": [\n"
" { \"instanceType\": \"declarativeContent.ShowPageAction\" }\n"
" ]\n"
"}"),
rule.get());
std::vector<linked_ptr<RulesRegistry::Rule> > rules;
rules.push_back(rule);
const Extension* extension = env.MakeExtension(*ParseJson(
"{\"page_action\": {}}"));
registry->AddRulesImpl(extension->id(), rules);
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->Apply(tab.get(), css_selectors);
EXPECT_EQ(1u, active_rules(*registry.get()).size());
tab.reset();
EXPECT_EQ(0u, active_rules(*registry.get()).size());
tab = env.MakeTab();
registry->Apply(tab.get(), css_selectors);
EXPECT_EQ(1u, active_rules(*registry.get()).size());
registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params);
EXPECT_EQ(0u, active_rules(*registry.get()).size());
}
}
}