| 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/chrome_content_rules
_registry.h" | 5 #include "chrome/browser/extensions/api/declarative_content/chrome_content_rules
_registry.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/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting()); | 45 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting()); |
| 46 | 46 |
| 47 scoped_ptr<content::WebContents> tab = env()->MakeTab(); | 47 scoped_ptr<content::WebContents> tab = env()->MakeTab(); |
| 48 registry->MonitorWebContentsForRuleEvaluation(tab.get()); | 48 registry->MonitorWebContentsForRuleEvaluation(tab.get()); |
| 49 registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(), | 49 registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(), |
| 50 content::FrameNavigateParams()); | 50 content::FrameNavigateParams()); |
| 51 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting()); | 51 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting()); |
| 52 | 52 |
| 53 // Add a rule. | 53 // Add a rule. |
| 54 linked_ptr<core_api::events::Rule> rule(new core_api::events::Rule); | 54 linked_ptr<api::events::Rule> rule(new api::events::Rule); |
| 55 core_api::events::Rule::Populate( | 55 api::events::Rule::Populate( |
| 56 *base::test::ParseJson( | 56 *base::test::ParseJson( |
| 57 "{\n" | 57 "{\n" |
| 58 " \"id\": \"rule1\",\n" | 58 " \"id\": \"rule1\",\n" |
| 59 " \"priority\": 100,\n" | 59 " \"priority\": 100,\n" |
| 60 " \"conditions\": [\n" | 60 " \"conditions\": [\n" |
| 61 " {\n" | 61 " {\n" |
| 62 " \"instanceType\": \"declarativeContent.PageStateMatcher\",\n" | 62 " \"instanceType\": \"declarativeContent.PageStateMatcher\",\n" |
| 63 " \"css\": [\"input\"]\n" | 63 " \"css\": [\"input\"]\n" |
| 64 " }],\n" | 64 " }],\n" |
| 65 " \"actions\": [\n" | 65 " \"actions\": [\n" |
| 66 " { \"instanceType\": \"declarativeContent.ShowPageAction\" }\n" | 66 " { \"instanceType\": \"declarativeContent.ShowPageAction\" }\n" |
| 67 " ]\n" | 67 " ]\n" |
| 68 "}"), | 68 "}"), |
| 69 rule.get()); | 69 rule.get()); |
| 70 std::vector<linked_ptr<core_api::events::Rule>> rules; | 70 std::vector<linked_ptr<api::events::Rule>> rules; |
| 71 rules.push_back(rule); | 71 rules.push_back(rule); |
| 72 | 72 |
| 73 const Extension* extension = env()->MakeExtension(*base::test::ParseJson( | 73 const Extension* extension = env()->MakeExtension(*base::test::ParseJson( |
| 74 "{\"page_action\": {}}")); | 74 "{\"page_action\": {}}")); |
| 75 registry->AddRulesImpl(extension->id(), rules); | 75 registry->AddRulesImpl(extension->id(), rules); |
| 76 | 76 |
| 77 registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(), | 77 registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(), |
| 78 content::FrameNavigateParams()); | 78 content::FrameNavigateParams()); |
| 79 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting()); | 79 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting()); |
| 80 | 80 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 92 registry->UpdateMatchingCssSelectorsForTesting(tab.get(), css_selectors); | 92 registry->UpdateMatchingCssSelectorsForTesting(tab.get(), css_selectors); |
| 93 EXPECT_EQ(1u, registry->GetActiveRulesCountForTesting()); | 93 EXPECT_EQ(1u, registry->GetActiveRulesCountForTesting()); |
| 94 // Navigating the tab should erase its entry from active_rules_ if | 94 // Navigating the tab should erase its entry from active_rules_ if |
| 95 // it no longer matches. | 95 // it no longer matches. |
| 96 registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(), | 96 registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(), |
| 97 content::FrameNavigateParams()); | 97 content::FrameNavigateParams()); |
| 98 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting()); | 98 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting()); |
| 99 } | 99 } |
| 100 | 100 |
| 101 } // namespace extensions | 101 } // namespace extensions |
| OLD | NEW |