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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "chrome/browser/extensions/active_script_controller.h" | 10 #include "chrome/browser/extensions/active_script_controller.h" |
| 11 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
11 #include "chrome/browser/extensions/extension_action.h" | 12 #include "chrome/browser/extensions/extension_action.h" |
12 #include "chrome/browser/extensions/extension_action_manager.h" | 13 #include "chrome/browser/extensions/extension_action_manager.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/location_bar_controller.h" | 15 #include "chrome/browser/extensions/location_bar_controller.h" |
15 #include "chrome/browser/extensions/tab_helper.h" | 16 #include "chrome/browser/extensions/tab_helper.h" |
16 #include "chrome/browser/extensions/test_extension_system.h" | 17 #include "chrome/browser/extensions/test_extension_system.h" |
17 #include "chrome/browser/sessions/session_tab_helper.h" | 18 #include "chrome/browser/sessions/session_tab_helper.h" |
18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
19 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
20 #include "components/crx_file/id_util.h" | 21 #include "components/crx_file/id_util.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 TEST_F(LocationBarControllerUnitTest, NavigationClearsState) { | 153 TEST_F(LocationBarControllerUnitTest, NavigationClearsState) { |
153 const Extension* extension = AddExtension(true, "page_actions"); | 154 const Extension* extension = AddExtension(true, "page_actions"); |
154 | 155 |
155 NavigateAndCommit(GURL("http://www.google.com")); | 156 NavigateAndCommit(GURL("http://www.google.com")); |
156 | 157 |
157 ExtensionAction& page_action = | 158 ExtensionAction& page_action = |
158 *ExtensionActionManager::Get(profile())->GetPageAction(*extension); | 159 *ExtensionActionManager::Get(profile())->GetPageAction(*extension); |
159 page_action.SetTitle(tab_id(), "Goodbye"); | 160 page_action.SetTitle(tab_id(), "Goodbye"); |
160 page_action.SetPopupUrl(tab_id(), extension->GetResourceURL("popup.html")); | 161 page_action.SetPopupUrl(tab_id(), extension->GetResourceURL("popup.html")); |
161 | 162 |
| 163 ExtensionActionAPI* extension_action_api = |
| 164 ExtensionActionAPI::Get(profile()); |
| 165 // By default, extensions shouldn't want to act on a page. |
| 166 EXPECT_FALSE(extension_action_api->ExtensionWantsToRun(extension, |
| 167 web_contents())); |
| 168 // Showing the page action should indicate that an extension *does* want to |
| 169 // run on the page. |
| 170 page_action.SetIsVisible(tab_id(), true); |
| 171 EXPECT_TRUE(extension_action_api->ExtensionWantsToRun(extension, |
| 172 web_contents())); |
| 173 |
162 EXPECT_EQ("Goodbye", page_action.GetTitle(tab_id())); | 174 EXPECT_EQ("Goodbye", page_action.GetTitle(tab_id())); |
163 EXPECT_EQ(extension->GetResourceURL("popup.html"), | 175 EXPECT_EQ(extension->GetResourceURL("popup.html"), |
164 page_action.GetPopupUrl(tab_id())); | 176 page_action.GetPopupUrl(tab_id())); |
165 | 177 |
166 // Within-page navigation should keep the settings. | 178 // Within-page navigation should keep the settings. |
167 NavigateAndCommit(GURL("http://www.google.com/#hash")); | 179 NavigateAndCommit(GURL("http://www.google.com/#hash")); |
168 | 180 |
169 EXPECT_EQ("Goodbye", page_action.GetTitle(tab_id())); | 181 EXPECT_EQ("Goodbye", page_action.GetTitle(tab_id())); |
170 EXPECT_EQ(extension->GetResourceURL("popup.html"), | 182 EXPECT_EQ(extension->GetResourceURL("popup.html"), |
171 page_action.GetPopupUrl(tab_id())); | 183 page_action.GetPopupUrl(tab_id())); |
| 184 EXPECT_TRUE(extension_action_api->ExtensionWantsToRun(extension, |
| 185 web_contents())); |
172 | 186 |
173 // Should discard the settings, and go back to the defaults. | 187 // Should discard the settings, and go back to the defaults. |
174 NavigateAndCommit(GURL("http://www.yahoo.com")); | 188 NavigateAndCommit(GURL("http://www.yahoo.com")); |
175 | 189 |
176 EXPECT_EQ("Hello", page_action.GetTitle(tab_id())); | 190 EXPECT_EQ("Hello", page_action.GetTitle(tab_id())); |
177 EXPECT_EQ(GURL(), page_action.GetPopupUrl(tab_id())); | 191 EXPECT_EQ(GURL(), page_action.GetPopupUrl(tab_id())); |
| 192 EXPECT_FALSE(extension_action_api->ExtensionWantsToRun(extension, |
| 193 web_contents())); |
178 } | 194 } |
179 | 195 |
180 } // namespace | 196 } // namespace |
181 } // namespace extensions | 197 } // namespace extensions |
OLD | NEW |