| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 scoped_refptr<const Extension> extension = ExtensionBuilder() | 78 scoped_refptr<const Extension> extension = ExtensionBuilder() |
| 79 .SetManifest(DictionaryBuilder() | 79 .SetManifest(DictionaryBuilder() |
| 80 .Set("name", "Extension with page action") | 80 .Set("name", "Extension with page action") |
| 81 .Set("version", "1.0.0") | 81 .Set("version", "1.0.0") |
| 82 .Set("manifest_version", 2) | 82 .Set("manifest_version", 2) |
| 83 .Set("permissions", ListBuilder() | 83 .Set("permissions", ListBuilder() |
| 84 .Append("tabs")) | 84 .Append("tabs")) |
| 85 .Set("page_action", DictionaryBuilder() | 85 .Set("page_action", DictionaryBuilder() |
| 86 .Set("default_title", "Hello"))) | 86 .Set("default_title", "Hello"))) |
| 87 .Build(); | 87 .Build(); |
| 88 extension_service_->AddExtension(extension); | 88 extension_service_->AddExtension(extension.get()); |
| 89 return extension; | 89 return extension; |
| 90 } | 90 } |
| 91 | 91 |
| 92 ExtensionAction* GetScriptBadge(const Extension& extension) { | 92 ExtensionAction* GetScriptBadge(const Extension& extension) { |
| 93 return ExtensionActionManager::Get(profile())->GetScriptBadge(extension); | 93 return ExtensionActionManager::Get(profile())->GetScriptBadge(extension); |
| 94 } | 94 } |
| 95 | 95 |
| 96 ExtensionService* extension_service_; | 96 ExtensionService* extension_service_; |
| 97 ScriptBadgeController* script_badge_controller_; | 97 ScriptBadgeController* script_badge_controller_; |
| 98 | 98 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 testing::ElementsAre()); | 145 testing::ElementsAre()); |
| 146 | 146 |
| 147 TabHelper::ScriptExecutionObserver::ExecutingScriptsMap id_map; | 147 TabHelper::ScriptExecutionObserver::ExecutingScriptsMap id_map; |
| 148 id_map[extension->id()] = std::set<std::string>(); | 148 id_map[extension->id()] = std::set<std::string>(); |
| 149 script_badge_controller_->OnScriptsExecuted( | 149 script_badge_controller_->OnScriptsExecuted( |
| 150 web_contents(), | 150 web_contents(), |
| 151 id_map, | 151 id_map, |
| 152 web_contents()->GetController().GetActiveEntry()->GetPageID(), | 152 web_contents()->GetController().GetActiveEntry()->GetPageID(), |
| 153 GURL(std::string())); | 153 GURL(std::string())); |
| 154 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 154 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
| 155 testing::ElementsAre(GetScriptBadge(*extension))); | 155 testing::ElementsAre(GetScriptBadge(*extension.get()))); |
| 156 EXPECT_THAT(location_bar_updated.events, testing::Gt(0)); | 156 EXPECT_THAT(location_bar_updated.events, testing::Gt(0)); |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 TEST_F(ScriptBadgeControllerTest, FragmentNavigation) { | 159 TEST_F(ScriptBadgeControllerTest, FragmentNavigation) { |
| 160 scoped_refptr<const Extension> extension = AddTestExtension(); | 160 scoped_refptr<const Extension> extension = AddTestExtension(); |
| 161 Profile* profile = | 161 Profile* profile = |
| 162 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 162 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 163 | 163 |
| 164 // Establish a page id. | 164 // Establish a page id. |
| 165 NavigateAndCommit(GURL("http://www.google.com")); | 165 NavigateAndCommit(GURL("http://www.google.com")); |
| 166 | 166 |
| 167 // Run script. Should be a notification and a script badge. | 167 // Run script. Should be a notification and a script badge. |
| 168 { | 168 { |
| 169 content::NotificationRegistrar notification_registrar; | 169 content::NotificationRegistrar notification_registrar; |
| 170 CountingNotificationObserver location_bar_updated; | 170 CountingNotificationObserver location_bar_updated; |
| 171 notification_registrar.Add( | 171 notification_registrar.Add( |
| 172 &location_bar_updated, | 172 &location_bar_updated, |
| 173 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 173 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
| 174 content::Source<Profile>(profile)); | 174 content::Source<Profile>(profile)); |
| 175 | 175 |
| 176 TabHelper::ScriptExecutionObserver::ExecutingScriptsMap id_map; | 176 TabHelper::ScriptExecutionObserver::ExecutingScriptsMap id_map; |
| 177 id_map[extension->id()] = std::set<std::string>(); | 177 id_map[extension->id()] = std::set<std::string>(); |
| 178 script_badge_controller_->OnScriptsExecuted( | 178 script_badge_controller_->OnScriptsExecuted( |
| 179 web_contents(), | 179 web_contents(), |
| 180 id_map, | 180 id_map, |
| 181 web_contents()->GetController().GetActiveEntry()->GetPageID(), | 181 web_contents()->GetController().GetActiveEntry()->GetPageID(), |
| 182 GURL(std::string())); | 182 GURL(std::string())); |
| 183 | 183 |
| 184 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 184 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
| 185 testing::ElementsAre(GetScriptBadge(*extension))); | 185 testing::ElementsAre(GetScriptBadge(*extension.get()))); |
| 186 EXPECT_EQ(1, location_bar_updated.events); | 186 EXPECT_EQ(1, location_bar_updated.events); |
| 187 } | 187 } |
| 188 | 188 |
| 189 // Navigate to a hash fragment. Shouldn't change. | 189 // Navigate to a hash fragment. Shouldn't change. |
| 190 { | 190 { |
| 191 content::NotificationRegistrar notification_registrar; | 191 content::NotificationRegistrar notification_registrar; |
| 192 CountingNotificationObserver location_bar_updated; | 192 CountingNotificationObserver location_bar_updated; |
| 193 notification_registrar.Add( | 193 notification_registrar.Add( |
| 194 &location_bar_updated, | 194 &location_bar_updated, |
| 195 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 195 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
| 196 content::Source<Profile>(profile)); | 196 content::Source<Profile>(profile)); |
| 197 | 197 |
| 198 NavigateAndCommit(GURL("http://www.google.com#hash")); | 198 NavigateAndCommit(GURL("http://www.google.com#hash")); |
| 199 | 199 |
| 200 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 200 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
| 201 testing::ElementsAre(GetScriptBadge(*extension))); | 201 testing::ElementsAre(GetScriptBadge(*extension.get()))); |
| 202 EXPECT_EQ(0, location_bar_updated.events); | 202 EXPECT_EQ(0, location_bar_updated.events); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // Refreshing the page should reset the badges. | 205 // Refreshing the page should reset the badges. |
| 206 { | 206 { |
| 207 content::NotificationRegistrar notification_registrar; | 207 content::NotificationRegistrar notification_registrar; |
| 208 CountingNotificationObserver location_bar_updated; | 208 CountingNotificationObserver location_bar_updated; |
| 209 notification_registrar.Add( | 209 notification_registrar.Add( |
| 210 &location_bar_updated, | 210 &location_bar_updated, |
| 211 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 211 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 223 | 223 |
| 224 scoped_refptr<const Extension> extension = | 224 scoped_refptr<const Extension> extension = |
| 225 ExtensionBuilder() | 225 ExtensionBuilder() |
| 226 .SetManifest(DictionaryBuilder() | 226 .SetManifest(DictionaryBuilder() |
| 227 .Set("name", "Extension") | 227 .Set("name", "Extension") |
| 228 .Set("version", "1.0.0") | 228 .Set("version", "1.0.0") |
| 229 .Set("manifest_version", 2) | 229 .Set("manifest_version", 2) |
| 230 .Set("permissions", ListBuilder() | 230 .Set("permissions", ListBuilder() |
| 231 .Append("tabs"))) | 231 .Append("tabs"))) |
| 232 .Build(); | 232 .Build(); |
| 233 extension_service_->AddExtension(extension); | 233 extension_service_->AddExtension(extension.get()); |
| 234 | 234 |
| 235 // Establish a page id. | 235 // Establish a page id. |
| 236 NavigateAndCommit(GURL("http://www.google.com")); | 236 NavigateAndCommit(GURL("http://www.google.com")); |
| 237 | 237 |
| 238 CountingNotificationObserver initial_badge_display; | 238 CountingNotificationObserver initial_badge_display; |
| 239 Profile* profile = | 239 Profile* profile = |
| 240 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 240 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 241 notification_registrar.Add( | 241 notification_registrar.Add( |
| 242 &initial_badge_display, | 242 &initial_badge_display, |
| 243 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 243 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
| 244 content::Source<Profile>(profile)); | 244 content::Source<Profile>(profile)); |
| 245 | 245 |
| 246 // Initially, no script badges. | 246 // Initially, no script badges. |
| 247 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 247 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
| 248 testing::ElementsAre()); | 248 testing::ElementsAre()); |
| 249 | 249 |
| 250 // Getting attention the first time should display the badge. | 250 // Getting attention the first time should display the badge. |
| 251 script_badge_controller_->GetAttentionFor(extension->id()); | 251 script_badge_controller_->GetAttentionFor(extension->id()); |
| 252 | 252 |
| 253 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 253 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
| 254 testing::ElementsAre(GetScriptBadge(*extension))); | 254 testing::ElementsAre(GetScriptBadge(*extension.get()))); |
| 255 EXPECT_THAT(initial_badge_display.events, testing::Gt(0)); | 255 EXPECT_THAT(initial_badge_display.events, testing::Gt(0)); |
| 256 | 256 |
| 257 CountingNotificationObserver subsequent_get_attention_call; | 257 CountingNotificationObserver subsequent_get_attention_call; |
| 258 notification_registrar.Add( | 258 notification_registrar.Add( |
| 259 &subsequent_get_attention_call, | 259 &subsequent_get_attention_call, |
| 260 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 260 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
| 261 content::Source<Profile>(profile)); | 261 content::Source<Profile>(profile)); |
| 262 | 262 |
| 263 // Getting attention a second time should have no effect. | 263 // Getting attention a second time should have no effect. |
| 264 script_badge_controller_->GetAttentionFor(extension->id()); | 264 script_badge_controller_->GetAttentionFor(extension->id()); |
| 265 | 265 |
| 266 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 266 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
| 267 testing::ElementsAre(GetScriptBadge(*extension))); | 267 testing::ElementsAre(GetScriptBadge(*extension.get()))); |
| 268 EXPECT_EQ(0, subsequent_get_attention_call.events); | 268 EXPECT_EQ(0, subsequent_get_attention_call.events); |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 } // namespace | 271 } // namespace |
| 272 } // namespace extensions | 272 } // namespace extensions |
| OLD | NEW |