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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // Initially, no script badges. | 131 // Initially, no script badges. |
132 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 132 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
133 testing::ElementsAre()); | 133 testing::ElementsAre()); |
134 | 134 |
135 TabHelper::ScriptExecutionObserver::ExecutingScriptsMap id_map; | 135 TabHelper::ScriptExecutionObserver::ExecutingScriptsMap id_map; |
136 id_map[extension->id()] = std::set<std::string>(); | 136 id_map[extension->id()] = std::set<std::string>(); |
137 script_badge_controller_->OnScriptsExecuted( | 137 script_badge_controller_->OnScriptsExecuted( |
138 web_contents(), | 138 web_contents(), |
139 id_map, | 139 id_map, |
140 web_contents()->GetController().GetActiveEntry()->GetPageID(), | 140 web_contents()->GetController().GetActiveEntry()->GetPageID(), |
141 GURL("")); | 141 GURL(std::string())); |
142 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 142 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
143 testing::ElementsAre(GetScriptBadge(*extension))); | 143 testing::ElementsAre(GetScriptBadge(*extension))); |
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 TabHelper::ScriptExecutionObserver::ExecutingScriptsMap id_map; | 164 TabHelper::ScriptExecutionObserver::ExecutingScriptsMap id_map; |
165 id_map[extension->id()] = std::set<std::string>(); | 165 id_map[extension->id()] = std::set<std::string>(); |
166 script_badge_controller_->OnScriptsExecuted( | 166 script_badge_controller_->OnScriptsExecuted( |
167 web_contents(), | 167 web_contents(), |
168 id_map, | 168 id_map, |
169 web_contents()->GetController().GetActiveEntry()->GetPageID(), | 169 web_contents()->GetController().GetActiveEntry()->GetPageID(), |
170 GURL("")); | 170 GURL(std::string())); |
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))); |
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; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 // Getting attention a second time should have no effect. | 251 // Getting attention a second time should have no effect. |
252 script_badge_controller_->GetAttentionFor(extension->id()); | 252 script_badge_controller_->GetAttentionFor(extension->id()); |
253 | 253 |
254 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 254 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
255 testing::ElementsAre(GetScriptBadge(*extension))); | 255 testing::ElementsAre(GetScriptBadge(*extension))); |
256 EXPECT_EQ(0, subsequent_get_attention_call.events); | 256 EXPECT_EQ(0, subsequent_get_attention_call.events); |
257 }; | 257 }; |
258 | 258 |
259 } // namespace | 259 } // namespace |
260 } // namespace extensions | 260 } // namespace extensions |
OLD | NEW |