| 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_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/extensions/extension_browser_event_router.h" | 8 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 9 #include "chrome/browser/extensions/extension_prefs.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/sessions/restore_tab_helper.h" | 13 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/omnibox/location_bar.h" | 16 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 19 #include "chrome/common/extensions/extension_action.h" | 20 #include "chrome/common/extensions/extension_action.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 22 | 23 |
| 23 // These are a mash-up of the tests from from page_actions_apitest.cc and | 24 // These are a mash-up of the tests from from page_actions_apitest.cc and |
| 24 // browser_actions_apitest.cc. | 25 // browser_actions_apitest.cc. |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 class PageAsBrowserActionApiTest : public ExtensionApiTest { | 29 class PageAsBrowserActionApiTest : public ExtensionApiTest { |
| 29 public: | 30 public: |
| 30 PageAsBrowserActionApiTest() {} | 31 PageAsBrowserActionApiTest() {} |
| 31 virtual ~PageAsBrowserActionApiTest() {} | 32 virtual ~PageAsBrowserActionApiTest() {} |
| 32 | 33 |
| 33 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 34 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 34 ExtensionApiTest::SetUpCommandLine(command_line); | 35 ExtensionApiTest::SetUpCommandLine(command_line); |
| 35 command_line->AppendSwitch(switches::kEnableBrowserActionsForAll); | 36 command_line->AppendSwitch(switches::kEnableActionBox); |
| 36 } | 37 } |
| 37 | 38 |
| 38 protected: | 39 protected: |
| 39 BrowserActionTestUtil GetBrowserActionsBar() { | 40 BrowserActionTestUtil GetBrowserActionsBar() { |
| 40 return BrowserActionTestUtil(browser()); | 41 return BrowserActionTestUtil(browser()); |
| 41 } | 42 } |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 IN_PROC_BROWSER_TEST_F(PageAsBrowserActionApiTest, Basic) { | 45 IN_PROC_BROWSER_TEST_F(PageAsBrowserActionApiTest, Basic) { |
| 45 ASSERT_TRUE(test_server()->Start()); | 46 ASSERT_TRUE(test_server()->Start()); |
| 46 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; | 47 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; |
| 47 const Extension* extension = GetSingleLoadedExtension(); | 48 const Extension* extension = GetSingleLoadedExtension(); |
| 48 ASSERT_TRUE(extension) << message_; | 49 ASSERT_TRUE(extension) << message_; |
| 49 | 50 |
| 51 // The extension declares a page action, but it should have gotten a browser |
| 52 // action instead. |
| 53 ASSERT_TRUE(extension->browser_action()); |
| 54 ASSERT_FALSE(extension->page_action()); |
| 55 |
| 56 // With the "action box" there won't be browser actions unless they're pinned. |
| 57 ExtensionPrefs* prefs = |
| 58 browser()->profile()->GetExtensionService()->extension_prefs(); |
| 59 prefs->SetBrowserActionVisibility(extension, true); |
| 60 |
| 50 // Test that there is a browser action in the toolbar. | 61 // Test that there is a browser action in the toolbar. |
| 51 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 62 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); |
| 52 | 63 |
| 53 { | 64 { |
| 54 // Tell the extension to update the page action state. | 65 // Tell the extension to update the page action state. |
| 55 ResultCatcher catcher; | 66 ResultCatcher catcher; |
| 56 ui_test_utils::NavigateToURL(browser(), | 67 ui_test_utils::NavigateToURL(browser(), |
| 57 GURL(extension->GetResourceURL("update.html"))); | 68 GURL(extension->GetResourceURL("update.html"))); |
| 58 ASSERT_TRUE(catcher.GetNextResult()); | 69 ASSERT_TRUE(catcher.GetNextResult()); |
| 59 } | 70 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 const Extension* extension = GetSingleLoadedExtension(); | 176 const Extension* extension = GetSingleLoadedExtension(); |
| 166 ASSERT_TRUE(extension) << message_; | 177 ASSERT_TRUE(extension) << message_; |
| 167 | 178 |
| 168 ResultCatcher catcher; | 179 ResultCatcher catcher; |
| 169 ui_test_utils::NavigateToURL(browser(), | 180 ui_test_utils::NavigateToURL(browser(), |
| 170 GURL(extension->GetResourceURL("update.html"))); | 181 GURL(extension->GetResourceURL("update.html"))); |
| 171 ASSERT_TRUE(catcher.GetNextResult()); | 182 ASSERT_TRUE(catcher.GetNextResult()); |
| 172 } | 183 } |
| 173 | 184 |
| 174 } | 185 } |
| OLD | NEW |