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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 scoped_refptr<const Extension> extension = ExtensionBuilder() | 72 scoped_refptr<const Extension> extension = ExtensionBuilder() |
73 .SetManifest(DictionaryBuilder() | 73 .SetManifest(DictionaryBuilder() |
74 .Set("name", "Extension with page action") | 74 .Set("name", "Extension with page action") |
75 .Set("version", "1.0.0") | 75 .Set("version", "1.0.0") |
76 .Set("manifest_version", 2) | 76 .Set("manifest_version", 2) |
77 .Set("permissions", ListBuilder() | 77 .Set("permissions", ListBuilder() |
78 .Append("tabs")) | 78 .Append("tabs")) |
79 .Set("page_action", DictionaryBuilder() | 79 .Set("page_action", DictionaryBuilder() |
80 .Set("default_title", "Hello"))) | 80 .Set("default_title", "Hello"))) |
81 .Build(); | 81 .Build(); |
82 extension_service_->AddExtension(extension); | 82 extension_service_->AddExtension(extension.get()); |
83 return extension; | 83 return extension; |
84 } | 84 } |
85 | 85 |
86 ExtensionAction* GetScriptBadge(const Extension& extension) { | 86 ExtensionAction* GetScriptBadge(const Extension& extension) { |
87 return ExtensionActionManager::Get(profile())->GetScriptBadge(extension); | 87 return ExtensionActionManager::Get(profile())->GetScriptBadge(extension); |
88 } | 88 } |
89 | 89 |
90 ExtensionService* extension_service_; | 90 ExtensionService* extension_service_; |
91 ScriptBadgeController* script_badge_controller_; | 91 ScriptBadgeController* script_badge_controller_; |
92 | 92 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 testing::ElementsAre()); | 133 testing::ElementsAre()); |
134 | 134 |
135 ListValue val; | 135 ListValue val; |
136 script_badge_controller_->OnExecuteScriptFinished( | 136 script_badge_controller_->OnExecuteScriptFinished( |
137 extension->id(), | 137 extension->id(), |
138 "", // no error | 138 "", // no error |
139 web_contents()->GetController().GetActiveEntry()->GetPageID(), | 139 web_contents()->GetController().GetActiveEntry()->GetPageID(), |
140 GURL(""), | 140 GURL(""), |
141 val); | 141 val); |
142 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 142 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
143 testing::ElementsAre(GetScriptBadge(*extension))); | 143 testing::ElementsAre(GetScriptBadge(*extension.get()))); |
144 EXPECT_THAT(location_bar_updated.events, testing::Gt(0)); | 144 EXPECT_THAT(location_bar_updated.events, testing::Gt(0)); |
145 }; | 145 }; |
146 | 146 |
147 TEST_F(ScriptBadgeControllerTest, FragmentNavigation) { | 147 TEST_F(ScriptBadgeControllerTest, FragmentNavigation) { |
148 scoped_refptr<const Extension> extension = AddTestExtension(); | 148 scoped_refptr<const Extension> extension = AddTestExtension(); |
149 Profile* profile = | 149 Profile* profile = |
150 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 150 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
151 | 151 |
152 // Establish a page id. | 152 // Establish a page id. |
153 NavigateAndCommit(GURL("http://www.google.com")); | 153 NavigateAndCommit(GURL("http://www.google.com")); |
154 | 154 |
155 // Run script. Should be a notification and a script badge. | 155 // Run script. Should be a notification and a script badge. |
156 { | 156 { |
157 content::NotificationRegistrar notification_registrar; | 157 content::NotificationRegistrar notification_registrar; |
158 CountingNotificationObserver location_bar_updated; | 158 CountingNotificationObserver location_bar_updated; |
159 notification_registrar.Add( | 159 notification_registrar.Add( |
160 &location_bar_updated, | 160 &location_bar_updated, |
161 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 161 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
162 content::Source<Profile>(profile)); | 162 content::Source<Profile>(profile)); |
163 | 163 |
164 ListValue val; | 164 ListValue val; |
165 script_badge_controller_->OnExecuteScriptFinished( | 165 script_badge_controller_->OnExecuteScriptFinished( |
166 extension->id(), | 166 extension->id(), |
167 "", // no error | 167 "", // no error |
168 web_contents()->GetController().GetActiveEntry()->GetPageID(), | 168 web_contents()->GetController().GetActiveEntry()->GetPageID(), |
169 GURL(""), | 169 GURL(""), |
170 val); | 170 val); |
171 | 171 |
172 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 172 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
173 testing::ElementsAre(GetScriptBadge(*extension))); | 173 testing::ElementsAre(GetScriptBadge(*extension.get()))); |
174 EXPECT_EQ(1, location_bar_updated.events); | 174 EXPECT_EQ(1, location_bar_updated.events); |
175 } | 175 } |
176 | 176 |
177 // Navigate to a hash fragment. Shouldn't change. | 177 // Navigate to a hash fragment. Shouldn't change. |
178 { | 178 { |
179 content::NotificationRegistrar notification_registrar; | 179 content::NotificationRegistrar notification_registrar; |
180 CountingNotificationObserver location_bar_updated; | 180 CountingNotificationObserver location_bar_updated; |
181 notification_registrar.Add( | 181 notification_registrar.Add( |
182 &location_bar_updated, | 182 &location_bar_updated, |
183 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 183 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
184 content::Source<Profile>(profile)); | 184 content::Source<Profile>(profile)); |
185 | 185 |
186 NavigateAndCommit(GURL("http://www.google.com#hash")); | 186 NavigateAndCommit(GURL("http://www.google.com#hash")); |
187 | 187 |
188 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 188 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
189 testing::ElementsAre(GetScriptBadge(*extension))); | 189 testing::ElementsAre(GetScriptBadge(*extension.get()))); |
190 EXPECT_EQ(0, location_bar_updated.events); | 190 EXPECT_EQ(0, location_bar_updated.events); |
191 } | 191 } |
192 | 192 |
193 // Refreshing the page should reset the badges. | 193 // Refreshing the page should reset the badges. |
194 { | 194 { |
195 content::NotificationRegistrar notification_registrar; | 195 content::NotificationRegistrar notification_registrar; |
196 CountingNotificationObserver location_bar_updated; | 196 CountingNotificationObserver location_bar_updated; |
197 notification_registrar.Add( | 197 notification_registrar.Add( |
198 &location_bar_updated, | 198 &location_bar_updated, |
199 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 199 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
(...skipping 12 matching lines...) Expand all Loading... |
212 | 212 |
213 scoped_refptr<const Extension> extension = | 213 scoped_refptr<const Extension> extension = |
214 ExtensionBuilder() | 214 ExtensionBuilder() |
215 .SetManifest(DictionaryBuilder() | 215 .SetManifest(DictionaryBuilder() |
216 .Set("name", "Extension") | 216 .Set("name", "Extension") |
217 .Set("version", "1.0.0") | 217 .Set("version", "1.0.0") |
218 .Set("manifest_version", 2) | 218 .Set("manifest_version", 2) |
219 .Set("permissions", ListBuilder() | 219 .Set("permissions", ListBuilder() |
220 .Append("tabs"))) | 220 .Append("tabs"))) |
221 .Build(); | 221 .Build(); |
222 extension_service_->AddExtension(extension); | 222 extension_service_->AddExtension(extension.get()); |
223 | 223 |
224 // Establish a page id. | 224 // Establish a page id. |
225 NavigateAndCommit(GURL("http://www.google.com")); | 225 NavigateAndCommit(GURL("http://www.google.com")); |
226 | 226 |
227 CountingNotificationObserver initial_badge_display; | 227 CountingNotificationObserver initial_badge_display; |
228 Profile* profile = | 228 Profile* profile = |
229 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 229 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
230 notification_registrar.Add( | 230 notification_registrar.Add( |
231 &initial_badge_display, | 231 &initial_badge_display, |
232 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 232 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
233 content::Source<Profile>(profile)); | 233 content::Source<Profile>(profile)); |
234 | 234 |
235 // Initially, no script badges. | 235 // Initially, no script badges. |
236 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 236 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
237 testing::ElementsAre()); | 237 testing::ElementsAre()); |
238 | 238 |
239 // Getting attention the first time should display the badge. | 239 // Getting attention the first time should display the badge. |
240 script_badge_controller_->GetAttentionFor(extension->id()); | 240 script_badge_controller_->GetAttentionFor(extension->id()); |
241 | 241 |
242 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 242 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
243 testing::ElementsAre(GetScriptBadge(*extension))); | 243 testing::ElementsAre(GetScriptBadge(*extension.get()))); |
244 EXPECT_THAT(initial_badge_display.events, testing::Gt(0)); | 244 EXPECT_THAT(initial_badge_display.events, testing::Gt(0)); |
245 | 245 |
246 CountingNotificationObserver subsequent_get_attention_call; | 246 CountingNotificationObserver subsequent_get_attention_call; |
247 notification_registrar.Add( | 247 notification_registrar.Add( |
248 &subsequent_get_attention_call, | 248 &subsequent_get_attention_call, |
249 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 249 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
250 content::Source<Profile>(profile)); | 250 content::Source<Profile>(profile)); |
251 | 251 |
252 // Getting attention a second time should have no effect. | 252 // Getting attention a second time should have no effect. |
253 script_badge_controller_->GetAttentionFor(extension->id()); | 253 script_badge_controller_->GetAttentionFor(extension->id()); |
254 | 254 |
255 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 255 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
256 testing::ElementsAre(GetScriptBadge(*extension))); | 256 testing::ElementsAre(GetScriptBadge(*extension.get()))); |
257 EXPECT_EQ(0, subsequent_get_attention_call.events); | 257 EXPECT_EQ(0, subsequent_get_attention_call.events); |
258 }; | 258 }; |
259 | 259 |
260 } // namespace | 260 } // namespace |
261 } // namespace extensions | 261 } // namespace extensions |
OLD | NEW |