| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(TOOLKIT_GTK) | 7 #if defined(TOOLKIT_GTK) |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include "base/gfx/rect.h" |
| 12 #include "base/gfx/size.h" |
| 11 #include "chrome/browser/browser.h" | 13 #include "chrome/browser/browser.h" |
| 12 #include "chrome/browser/browser_window.h" | 14 #include "chrome/browser/browser_window.h" |
| 13 #include "chrome/browser/extensions/browser_action_test_util.h" | 15 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 14 #include "chrome/browser/extensions/extension_apitest.h" | 16 #include "chrome/browser/extensions/extension_apitest.h" |
| 15 #include "chrome/browser/extensions/extension_browser_event_router.h" | 17 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 16 #include "chrome/browser/extensions/extension_tabs_module.h" | 18 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 17 #include "chrome/browser/extensions/extensions_service.h" | 19 #include "chrome/browser/extensions/extensions_service.h" |
| 18 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
| 19 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
| 20 #include "chrome/common/extensions/extension_action.h" | 22 #include "chrome/common/extensions/extension_action.h" |
| 21 #include "chrome/test/ui_test_utils.h" | 23 #include "chrome/test/ui_test_utils.h" |
| 22 | 24 |
| 23 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) | |
| 24 #include "chrome/browser/views/browser_actions_container.h" | |
| 25 #include "chrome/browser/views/extensions/extension_popup.h" | |
| 26 #include "chrome/browser/views/toolbar_view.h" | |
| 27 #endif | |
| 28 | |
| 29 class BrowserActionApiTest : public ExtensionApiTest { | 25 class BrowserActionApiTest : public ExtensionApiTest { |
| 30 public: | 26 public: |
| 31 BrowserActionApiTest() {} | 27 BrowserActionApiTest() {} |
| 32 virtual ~BrowserActionApiTest() {} | 28 virtual ~BrowserActionApiTest() {} |
| 33 | 29 |
| 30 protected: |
| 34 BrowserActionTestUtil GetBrowserActionsBar() { | 31 BrowserActionTestUtil GetBrowserActionsBar() { |
| 35 return BrowserActionTestUtil(browser()); | 32 return BrowserActionTestUtil(browser()); |
| 36 } | 33 } |
| 34 |
| 35 gfx::Rect OpenPopup(int index) { |
| 36 ResultCatcher catcher; |
| 37 GetBrowserActionsBar().Press(index); |
| 38 EXPECT_TRUE(GetBrowserActionsBar().HasPopup()); |
| 39 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 40 return GetBrowserActionsBar().GetPopupBounds(); |
| 41 } |
| 37 }; | 42 }; |
| 38 | 43 |
| 39 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { | 44 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { |
| 40 StartHTTPServer(); | 45 StartHTTPServer(); |
| 41 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; | 46 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; |
| 42 | 47 |
| 43 // Test that there is a browser action in the toolbar. | 48 // Test that there is a browser action in the toolbar. |
| 44 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 49 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); |
| 45 | 50 |
| 46 // Tell the extension to update the browser action state. | 51 // Tell the extension to update the browser action state. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 131 |
| 127 // Go back to first tab, changed title should reappear. | 132 // Go back to first tab, changed title should reappear. |
| 128 browser()->SelectTabContentsAt(0, true); | 133 browser()->SelectTabContentsAt(0, true); |
| 129 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0)); | 134 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0)); |
| 130 | 135 |
| 131 // Reload that tab, default title should come back. | 136 // Reload that tab, default title should come back. |
| 132 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 137 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 133 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0)); | 138 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0)); |
| 134 } | 139 } |
| 135 | 140 |
| 136 // TODO(estade): http://crbug.com/29710 port to Mac & Linux | 141 // TODO(estade): http://crbug.com/29710 port to Linux |
| 137 #if defined(OS_WIN) | 142 #if !defined(TOOLKIT_GTK) |
| 138 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionPopup) { | 143 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionPopup) { |
| 139 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 144 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
| 140 "browser_action/popup"))); | 145 "browser_action/popup"))); |
| 141 | 146 |
| 142 ResultCatcher catcher; | 147 ResultCatcher catcher; |
| 143 | 148 |
| 144 // This value is in api_test/popup/popup.html. | 149 // The extension's popup's size grows by |growFactor| each click. |
| 145 const int growFactor = 500; | 150 const int growFactor = 500; |
| 146 ASSERT_GT(ExtensionPopup::kMinHeight + growFactor * 2, | 151 gfx::Size minSize = BrowserActionTestUtil::GetMinPopupSize(); |
| 147 ExtensionPopup::kMaxHeight); | 152 gfx::Size maxSize = BrowserActionTestUtil::GetMaxPopupSize(); |
| 148 ASSERT_GT(ExtensionPopup::kMinWidth + growFactor * 2, | |
| 149 ExtensionPopup::kMaxWidth); | |
| 150 | 153 |
| 151 // Our initial expected size. | 154 // Ensure that two clicks will exceed the maximum allowed size. |
| 152 int width = ExtensionPopup::kMinWidth; | 155 ASSERT_GT(minSize.height() + growFactor * 2, maxSize.height()); |
| 153 int height = ExtensionPopup::kMinHeight; | 156 ASSERT_GT(minSize.width() + growFactor * 2, maxSize.width()); |
| 154 | 157 |
| 155 BrowserActionsContainer* browser_actions = | |
| 156 browser()->window()->GetBrowserWindowTesting()->GetToolbarView()-> | |
| 157 browser_actions(); | |
| 158 ASSERT_TRUE(browser_actions); | |
| 159 // Simulate a click on the browser action and verify the size of the resulting | 158 // Simulate a click on the browser action and verify the size of the resulting |
| 160 // popup. The first one tries to be 0x0, so it should be the min values. | 159 // popup. The first one tries to be 0x0, so it should be the min values. |
| 161 GetBrowserActionsBar().Press(0); | 160 gfx::Rect bounds = OpenPopup(0); |
| 162 EXPECT_TRUE(browser_actions->TestGetPopup() != NULL); | 161 EXPECT_EQ(minSize, bounds.size()); |
| 163 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 162 EXPECT_TRUE(GetBrowserActionsBar().HidePopup()); |
| 164 gfx::Rect bounds = browser_actions->TestGetPopup()->view()->bounds(); | |
| 165 EXPECT_EQ(width, bounds.width()); | |
| 166 EXPECT_EQ(height, bounds.height()); | |
| 167 browser_actions->HidePopup(); | |
| 168 EXPECT_TRUE(browser_actions->TestGetPopup() == NULL); | |
| 169 | 163 |
| 170 // Do it again, and verify the new bigger size (the popup grows each time it's | 164 bounds = OpenPopup(0); |
| 171 // opened). | 165 EXPECT_EQ(gfx::Size(growFactor, growFactor), bounds.size()); |
| 172 width = growFactor; | 166 EXPECT_TRUE(GetBrowserActionsBar().HidePopup()); |
| 173 height = growFactor; | |
| 174 browser_actions->TestExecuteBrowserAction(0); | |
| 175 EXPECT_TRUE(browser_actions->TestGetPopup() != NULL); | |
| 176 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
| 177 bounds = browser_actions->TestGetPopup()->view()->bounds(); | |
| 178 EXPECT_EQ(width, bounds.width()); | |
| 179 EXPECT_EQ(height, bounds.height()); | |
| 180 browser_actions->HidePopup(); | |
| 181 EXPECT_TRUE(browser_actions->TestGetPopup() == NULL); | |
| 182 | 167 |
| 183 // One more time, but this time it should be constrained by the max values. | 168 // One more time, but this time it should be constrained by the max values. |
| 184 width = ExtensionPopup::kMaxWidth; | 169 bounds = OpenPopup(0); |
| 185 height = ExtensionPopup::kMaxHeight; | 170 EXPECT_EQ(maxSize, bounds.size()); |
| 186 browser_actions->TestExecuteBrowserAction(0); | 171 EXPECT_TRUE(GetBrowserActionsBar().HidePopup()); |
| 187 EXPECT_TRUE(browser_actions->TestGetPopup() != NULL); | |
| 188 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
| 189 bounds = browser_actions->TestGetPopup()->view()->bounds(); | |
| 190 EXPECT_EQ(width, bounds.width()); | |
| 191 EXPECT_EQ(height, bounds.height()); | |
| 192 browser_actions->HidePopup(); | |
| 193 EXPECT_TRUE(browser_actions->TestGetPopup() == NULL); | |
| 194 } | 172 } |
| 195 #endif // defined(OS_WIN) | 173 #endif // !defined(TOOLKIT_GTK) |
| OLD | NEW |