| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist
ry.h" | 5 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist
ry.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/test/values_test_util.h" | 9 #include "base/test/values_test_util.h" |
| 10 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" |
| 10 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
| 11 #include "chrome/browser/extensions/test_extension_environment.h" | 12 #include "chrome/browser/extensions/test_extension_environment.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 13 #include "content/public/browser/navigation_details.h" | 14 #include "content/public/browser/navigation_details.h" |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/common/frame_navigate_params.h" | 16 #include "content/public/common/frame_navigate_params.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace extensions { | 20 namespace extensions { |
| 20 | 21 |
| 21 using base::test::ParseJson; | 22 using base::test::ParseJson; |
| 22 using testing::HasSubstr; | 23 using testing::HasSubstr; |
| 23 using content::WebContents; | 24 using content::WebContents; |
| 24 | 25 |
| 25 // Must be outside the anonymous namespace to be a friend of | 26 // Must be outside the anonymous namespace to be a friend of |
| 26 // ContentRulesRegistry. | 27 // ContentRulesRegistry. |
| 27 class DeclarativeContentRulesRegistryTest : public testing::Test { | 28 class DeclarativeContentRulesRegistryTest : public testing::Test { |
| 28 protected: | 29 protected: |
| 29 static const std::map<int, std::set<ContentRule*> >& active_rules( | 30 static const std::map<int, std::set<ContentRule*> >& active_rules( |
| 30 const ContentRulesRegistry& registry) { | 31 const ContentRulesRegistry& registry) { |
| 31 return registry.active_rules_; | 32 return registry.active_rules_; |
| 32 } | 33 } |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 38 namespace constants = extensions::declarative_content_constants; |
| 39 |
| 37 TEST_F(DeclarativeContentRulesRegistryTest, ActiveRulesDoesntGrow) { | 40 TEST_F(DeclarativeContentRulesRegistryTest, ActiveRulesDoesntGrow) { |
| 38 TestExtensionEnvironment env; | 41 TestExtensionEnvironment env; |
| 39 | 42 |
| 40 scoped_refptr<ContentRulesRegistry> registry( | 43 scoped_refptr<ContentRulesRegistry> registry( |
| 41 new ContentRulesRegistry(env.profile(), NULL)); | 44 new ContentRulesRegistry(env.profile(), |
| 45 constants::kOnPageChanged, |
| 46 CONTENT_RULES_REGISTRY, |
| 47 NULL)); |
| 42 | 48 |
| 43 EXPECT_EQ(0u, active_rules(*registry.get()).size()); | 49 EXPECT_EQ(0u, active_rules(*registry.get()).size()); |
| 44 | 50 |
| 45 content::LoadCommittedDetails load_details; | 51 content::LoadCommittedDetails load_details; |
| 46 content::FrameNavigateParams navigate_params; | 52 content::FrameNavigateParams navigate_params; |
| 47 scoped_ptr<WebContents> tab = env.MakeTab(); | 53 scoped_ptr<WebContents> tab = env.MakeTab(); |
| 48 registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params); | 54 registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params); |
| 49 EXPECT_EQ(0u, active_rules(*registry.get()).size()); | 55 EXPECT_EQ(0u, active_rules(*registry.get()).size()); |
| 50 | 56 |
| 51 // Add a rule. | 57 // Add a rule. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 registry->Apply(tab.get(), css_selectors); | 94 registry->Apply(tab.get(), css_selectors); |
| 89 EXPECT_EQ(1u, active_rules(*registry.get()).size()); | 95 EXPECT_EQ(1u, active_rules(*registry.get()).size()); |
| 90 // Navigating the tab should erase its entry from active_rules_ if | 96 // Navigating the tab should erase its entry from active_rules_ if |
| 91 // it no longer matches. | 97 // it no longer matches. |
| 92 registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params); | 98 registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params); |
| 93 EXPECT_EQ(0u, active_rules(*registry.get()).size()); | 99 EXPECT_EQ(0u, active_rules(*registry.get()).size()); |
| 94 } | 100 } |
| 95 | 101 |
| 96 } // namespace | 102 } // namespace |
| 97 } // namespace extensions | 103 } // namespace extensions |
| OLD | NEW |