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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/content_rules_registry_unittest.cc

Issue 16295003: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/extension_tab_util.h" 10 #include "chrome/browser/extensions/extension_tab_util.h"
(...skipping 22 matching lines...) Expand all
33 }; 33 };
34 34
35 namespace { 35 namespace {
36 36
37 TEST_F(DeclarativeContentRulesRegistryTest, ActiveRulesDoesntGrow) { 37 TEST_F(DeclarativeContentRulesRegistryTest, ActiveRulesDoesntGrow) {
38 TestExtensionEnvironment env; 38 TestExtensionEnvironment env;
39 39
40 scoped_refptr<ContentRulesRegistry> registry( 40 scoped_refptr<ContentRulesRegistry> registry(
41 new ContentRulesRegistry(env.profile(), NULL /*ui_part*/)); 41 new ContentRulesRegistry(env.profile(), NULL /*ui_part*/));
42 42
43 EXPECT_EQ(0u, active_rules(*registry).size()); 43 EXPECT_EQ(0u, active_rules(*registry.get()).size());
44 44
45 content::LoadCommittedDetails load_details; 45 content::LoadCommittedDetails load_details;
46 content::FrameNavigateParams navigate_params; 46 content::FrameNavigateParams navigate_params;
47 scoped_ptr<WebContents> tab = env.MakeTab(); 47 scoped_ptr<WebContents> tab = env.MakeTab();
48 registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params); 48 registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params);
49 EXPECT_EQ(0u, active_rules(*registry).size()); 49 EXPECT_EQ(0u, active_rules(*registry.get()).size());
50 50
51 // Add a rule. 51 // Add a rule.
52 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule); 52 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule);
53 RulesRegistry::Rule::Populate( 53 RulesRegistry::Rule::Populate(
54 *ParseJson( 54 *ParseJson(
55 "{\n" 55 "{\n"
56 " \"id\": \"rule1\",\n" 56 " \"id\": \"rule1\",\n"
57 " \"priority\": 100,\n" 57 " \"priority\": 100,\n"
58 " \"conditions\": [\n" 58 " \"conditions\": [\n"
59 " {\n" 59 " {\n"
60 " \"instanceType\": \"declarativeContent.PageStateMatcher\",\n" 60 " \"instanceType\": \"declarativeContent.PageStateMatcher\",\n"
61 " \"css\": [\"input\"]\n" 61 " \"css\": [\"input\"]\n"
62 " }],\n" 62 " }],\n"
63 " \"actions\": [\n" 63 " \"actions\": [\n"
64 " { \"instanceType\": \"declarativeContent.ShowPageAction\" }\n" 64 " { \"instanceType\": \"declarativeContent.ShowPageAction\" }\n"
65 " ]\n" 65 " ]\n"
66 "}"), 66 "}"),
67 rule.get()); 67 rule.get());
68 std::vector<linked_ptr<RulesRegistry::Rule> > rules; 68 std::vector<linked_ptr<RulesRegistry::Rule> > rules;
69 rules.push_back(rule); 69 rules.push_back(rule);
70 70
71 const Extension* extension = env.MakeExtension(*ParseJson( 71 const Extension* extension = env.MakeExtension(*ParseJson(
72 "{\"page_action\": {}}")); 72 "{\"page_action\": {}}"));
73 registry->AddRulesImpl(extension->id(), rules); 73 registry->AddRulesImpl(extension->id(), rules);
74 74
75 registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params); 75 registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params);
76 EXPECT_EQ(0u, active_rules(*registry).size()); 76 EXPECT_EQ(0u, active_rules(*registry.get()).size());
77 77
78 std::vector<std::string> css_selectors; 78 std::vector<std::string> css_selectors;
79 css_selectors.push_back("input"); 79 css_selectors.push_back("input");
80 registry->Apply(tab.get(), css_selectors); 80 registry->Apply(tab.get(), css_selectors);
81 EXPECT_EQ(1u, active_rules(*registry).size()); 81 EXPECT_EQ(1u, active_rules(*registry.get()).size());
82 82
83 // Closing the tab should erase its entry from active_rules_. 83 // Closing the tab should erase its entry from active_rules_.
84 tab.reset(); 84 tab.reset();
85 EXPECT_EQ(0u, active_rules(*registry).size()); 85 EXPECT_EQ(0u, active_rules(*registry.get()).size());
86 86
87 tab = env.MakeTab(); 87 tab = env.MakeTab();
88 registry->Apply(tab.get(), css_selectors); 88 registry->Apply(tab.get(), css_selectors);
89 EXPECT_EQ(1u, active_rules(*registry).size()); 89 EXPECT_EQ(1u, active_rules(*registry.get()).size());
90 // Navigating the tab should erase its entry from active_rules_ if 90 // Navigating the tab should erase its entry from active_rules_ if
91 // it no longer matches. 91 // it no longer matches.
92 registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params); 92 registry->DidNavigateMainFrame(tab.get(), load_details, navigate_params);
93 EXPECT_EQ(0u, active_rules(*registry).size()); 93 EXPECT_EQ(0u, active_rules(*registry.get()).size());
94 } 94 }
95 95
96 } // namespace 96 } // namespace
97 } // namespace extensions 97 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698