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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "chrome/browser/extensions/browser_action_test_util.h" | 6 #include "chrome/browser/extensions/browser_action_test_util.h" |
7 #include "chrome/browser/extensions/extension_action.h" | 7 #include "chrome/browser/extensions/extension_action.h" |
8 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 8 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
9 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
11 #include "chrome/browser/extensions/extension_prefs.h" | 11 #include "chrome/browser/extensions/extension_prefs.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_system.h" |
13 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_tabstrip.h" | 17 #include "chrome/browser/ui/browser_tabstrip.h" |
17 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
18 #include "chrome/browser/ui/omnibox/location_bar.h" | 19 #include "chrome/browser/ui/omnibox/location_bar.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 30 matching lines...) Expand all Loading... |
53 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; | 54 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; |
54 const Extension* extension = GetSingleLoadedExtension(); | 55 const Extension* extension = GetSingleLoadedExtension(); |
55 ASSERT_TRUE(extension) << message_; | 56 ASSERT_TRUE(extension) << message_; |
56 | 57 |
57 // The extension declares a page action, but it should have gotten a browser | 58 // The extension declares a page action, but it should have gotten a browser |
58 // action instead. | 59 // action instead. |
59 ASSERT_TRUE(extension_action_manager()->GetBrowserAction(*extension)); | 60 ASSERT_TRUE(extension_action_manager()->GetBrowserAction(*extension)); |
60 ASSERT_FALSE(extension_action_manager()->GetPageAction(*extension)); | 61 ASSERT_FALSE(extension_action_manager()->GetPageAction(*extension)); |
61 | 62 |
62 // With the "action box" there won't be browser actions unless they're pinned. | 63 // With the "action box" there won't be browser actions unless they're pinned. |
63 ExtensionPrefs* prefs = | 64 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get( |
64 browser()->profile()->GetExtensionService()->extension_prefs(); | 65 browser()->profile())->extension_service()->extension_prefs(); |
65 prefs->SetBrowserActionVisibility(extension, true); | 66 prefs->SetBrowserActionVisibility(extension, true); |
66 | 67 |
67 // Test that there is a browser action in the toolbar. | 68 // Test that there is a browser action in the toolbar. |
68 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 69 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); |
69 | 70 |
70 { | 71 { |
71 // Tell the extension to update the page action state. | 72 // Tell the extension to update the page action state. |
72 ResultCatcher catcher; | 73 ResultCatcher catcher; |
73 ui_test_utils::NavigateToURL(browser(), | 74 ui_test_utils::NavigateToURL(browser(), |
74 GURL(extension->GetResourceURL("update.html"))); | 75 GURL(extension->GetResourceURL("update.html"))); |
75 ASSERT_TRUE(catcher.GetNextResult()); | 76 ASSERT_TRUE(catcher.GetNextResult()); |
76 } | 77 } |
77 | 78 |
78 // Test that we received the changes. | 79 // Test that we received the changes. |
79 int tab_id = ExtensionTabUtil::GetTabId( | 80 int tab_id = ExtensionTabUtil::GetTabId( |
80 chrome::GetActiveWebContents(browser())); | 81 chrome::GetActiveWebContents(browser())); |
81 ExtensionAction* action = | 82 ExtensionAction* action = |
82 extension_action_manager()->GetBrowserAction(*extension); | 83 extension_action_manager()->GetBrowserAction(*extension); |
83 ASSERT_TRUE(action); | 84 ASSERT_TRUE(action); |
84 EXPECT_EQ("Modified", action->GetTitle(tab_id)); | 85 EXPECT_EQ("Modified", action->GetTitle(tab_id)); |
85 | 86 |
86 { | 87 { |
87 // Simulate the page action being clicked. | 88 // Simulate the page action being clicked. |
88 ResultCatcher catcher; | 89 ResultCatcher catcher; |
89 ExtensionService* service = browser()->profile()->GetExtensionService(); | 90 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 91 browser()->profile())->extension_service(); |
90 service->toolbar_model()->ExecuteBrowserAction(extension, browser(), NULL); | 92 service->toolbar_model()->ExecuteBrowserAction(extension, browser(), NULL); |
91 EXPECT_TRUE(catcher.GetNextResult()); | 93 EXPECT_TRUE(catcher.GetNextResult()); |
92 } | 94 } |
93 | 95 |
94 { | 96 { |
95 // Tell the extension to update the page action state again. | 97 // Tell the extension to update the page action state again. |
96 ResultCatcher catcher; | 98 ResultCatcher catcher; |
97 ui_test_utils::NavigateToURL(browser(), | 99 ui_test_utils::NavigateToURL(browser(), |
98 GURL(extension->GetResourceURL("update2.html"))); | 100 GURL(extension->GetResourceURL("update2.html"))); |
99 ASSERT_TRUE(catcher.GetNextResult()); | 101 ASSERT_TRUE(catcher.GetNextResult()); |
(...skipping 21 matching lines...) Expand all Loading... |
121 extension_action_manager()->GetBrowserAction(*extension); | 123 extension_action_manager()->GetBrowserAction(*extension); |
122 ASSERT_TRUE(page_action) | 124 ASSERT_TRUE(page_action) |
123 << "Page action test extension should have a page action."; | 125 << "Page action test extension should have a page action."; |
124 | 126 |
125 ASSERT_FALSE(page_action->HasPopup(tab_id)); | 127 ASSERT_FALSE(page_action->HasPopup(tab_id)); |
126 | 128 |
127 // Simulate the page action being clicked. The resulting event should | 129 // Simulate the page action being clicked. The resulting event should |
128 // install a page action popup. | 130 // install a page action popup. |
129 { | 131 { |
130 ResultCatcher catcher; | 132 ResultCatcher catcher; |
131 ExtensionService* service = browser()->profile()->GetExtensionService(); | 133 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 134 browser()->profile())->extension_service(); |
132 service->toolbar_model()->ExecuteBrowserAction(extension, browser(), NULL); | 135 service->toolbar_model()->ExecuteBrowserAction(extension, browser(), NULL); |
133 ASSERT_TRUE(catcher.GetNextResult()); | 136 ASSERT_TRUE(catcher.GetNextResult()); |
134 } | 137 } |
135 | 138 |
136 ASSERT_TRUE(page_action->HasPopup(tab_id)) | 139 ASSERT_TRUE(page_action->HasPopup(tab_id)) |
137 << "Clicking on the page action should have caused a popup to be added."; | 140 << "Clicking on the page action should have caused a popup to be added."; |
138 | 141 |
139 ASSERT_STREQ("/a_popup.html", | 142 ASSERT_STREQ("/a_popup.html", |
140 page_action->GetPopupUrl(tab_id).path().c_str()); | 143 page_action->GetPopupUrl(tab_id).path().c_str()); |
141 | 144 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 ASSERT_TRUE(extension) << message_; | 194 ASSERT_TRUE(extension) << message_; |
192 | 195 |
193 ResultCatcher catcher; | 196 ResultCatcher catcher; |
194 ui_test_utils::NavigateToURL(browser(), | 197 ui_test_utils::NavigateToURL(browser(), |
195 GURL(extension->GetResourceURL("update.html"))); | 198 GURL(extension->GetResourceURL("update.html"))); |
196 ASSERT_TRUE(catcher.GetNextResult()); | 199 ASSERT_TRUE(catcher.GetNextResult()); |
197 } | 200 } |
198 | 201 |
199 } | 202 } |
200 } // namespace extensions | 203 } // namespace extensions |
OLD | NEW |