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" | 11 #include "base/gfx/rect.h" |
12 #include "base/gfx/size.h" | 12 #include "base/gfx/size.h" |
13 #include "chrome/browser/browser.h" | 13 #include "chrome/browser/browser.h" |
14 #include "chrome/browser/browser_window.h" | 14 #include "chrome/browser/browser_window.h" |
15 #include "chrome/browser/extensions/browser_action_test_util.h" | 15 #include "chrome/browser/extensions/browser_action_test_util.h" |
16 #include "chrome/browser/extensions/extension_apitest.h" | 16 #include "chrome/browser/extensions/extension_apitest.h" |
17 #include "chrome/browser/extensions/extension_browser_event_router.h" | 17 #include "chrome/browser/extensions/extension_browser_event_router.h" |
18 #include "chrome/browser/extensions/extension_tabs_module.h" | 18 #include "chrome/browser/extensions/extension_tabs_module.h" |
19 #include "chrome/browser/extensions/extensions_service.h" | 19 #include "chrome/browser/extensions/extensions_service.h" |
20 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
21 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
| 22 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/extensions/extension_action.h" | 23 #include "chrome/common/extensions/extension_action.h" |
| 24 #include "chrome/common/url_constants.h" |
23 #include "chrome/test/ui_test_utils.h" | 25 #include "chrome/test/ui_test_utils.h" |
24 | 26 |
25 static const int kTimeoutMs = 60 * 1000; // 1 minute | 27 static const int kTimeoutMs = 60 * 1000; // 1 minute |
26 | 28 |
27 class BrowserActionApiTest : public ExtensionApiTest { | 29 class BrowserActionApiTest : public ExtensionApiTest { |
28 public: | 30 public: |
29 BrowserActionApiTest() {} | 31 BrowserActionApiTest() {} |
30 virtual ~BrowserActionApiTest() {} | 32 virtual ~BrowserActionApiTest() {} |
31 | 33 |
32 protected: | 34 protected: |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 GURL(extension->GetResourceURL("remove_popup.html"))); | 256 GURL(extension->GetResourceURL("remove_popup.html"))); |
255 ASSERT_TRUE(catcher.GetNextResult()); | 257 ASSERT_TRUE(catcher.GetNextResult()); |
256 } | 258 } |
257 | 259 |
258 ASSERT_FALSE(browser_action->HasPopup(tab_id)) | 260 ASSERT_FALSE(browser_action->HasPopup(tab_id)) |
259 << "Browser action popup should have been removed."; | 261 << "Browser action popup should have been removed."; |
260 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)) | 262 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)) |
261 << "Browser action popup default should not be changed by setting " | 263 << "Browser action popup default should not be changed by setting " |
262 << "a specific tab id."; | 264 << "a specific tab id."; |
263 } | 265 } |
| 266 |
| 267 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoBasic) { |
| 268 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 269 switches::kEnableExperimentalExtensionApis); |
| 270 |
| 271 StartHTTPServer(); |
| 272 |
| 273 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; |
| 274 Extension* extension = GetSingleLoadedExtension(); |
| 275 ASSERT_TRUE(extension) << message_; |
| 276 |
| 277 // Test that there is a browser action in the toolbar. |
| 278 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); |
| 279 |
| 280 // Open an incognito window and test that the browser action isn't there by |
| 281 // default. |
| 282 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); |
| 283 Browser* incognito_browser = Browser::Create(incognito_profile); |
| 284 |
| 285 ASSERT_EQ(0, |
| 286 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions()); |
| 287 |
| 288 // Now enable the extension in incognito mode, and test that the browser |
| 289 // action shows up. Note that we don't update the existing window at the |
| 290 // moment, so we just create a new one. |
| 291 browser()->profile()->GetExtensionsService()->extension_prefs()-> |
| 292 SetIsIncognitoEnabled(extension->id(), true); |
| 293 |
| 294 incognito_browser->CloseWindow(); |
| 295 incognito_browser = Browser::Create(incognito_profile); |
| 296 ASSERT_EQ(1, |
| 297 BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions()); |
| 298 |
| 299 // TODO(mpcomplete): simulate a click and have it do the right thing in |
| 300 // incognito. |
| 301 } |
| 302 |
| 303 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoDragging) { |
| 304 ExtensionsService* service = browser()->profile()->GetExtensionsService(); |
| 305 |
| 306 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 307 switches::kEnableExperimentalExtensionApis); |
| 308 |
| 309 // The tooltips for each respective browser action. |
| 310 const char kTooltipA[] = "Make this page red"; |
| 311 const char kTooltipB[] = "grow"; |
| 312 const char kTooltipC[] = "Test setPopup()"; |
| 313 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
| 314 "browser_action/basics"))); |
| 315 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
| 316 "browser_action/popup"))); |
| 317 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
| 318 "browser_action/add_popup"))); |
| 319 |
| 320 // Test that there are 3 browser actions in the toolbar. |
| 321 ASSERT_EQ(3u, service->extensions()->size()); |
| 322 ASSERT_EQ(3, GetBrowserActionsBar().NumberOfBrowserActions()); |
| 323 |
| 324 // Now enable 2 of the extensions in incognito mode, and test that the browser |
| 325 // actions show up. |
| 326 service->extension_prefs()->SetIsIncognitoEnabled( |
| 327 service->extensions()->at(0)->id(), true); |
| 328 service->extension_prefs()->SetIsIncognitoEnabled( |
| 329 service->extensions()->at(2)->id(), true); |
| 330 |
| 331 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); |
| 332 Browser* incognito_browser = Browser::Create(incognito_profile); |
| 333 BrowserActionTestUtil incognito_bar(incognito_browser); |
| 334 |
| 335 // Navigate just to have a tab in this window, otherwise wonky things happen. |
| 336 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), |
| 337 GURL(chrome::kChromeUIExtensionsURL)); |
| 338 |
| 339 ASSERT_EQ(2, incognito_bar.NumberOfBrowserActions()); |
| 340 |
| 341 // Ensure that the browser actions are in the right order (ABC). |
| 342 EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(0)); |
| 343 EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(1)); |
| 344 EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(2)); |
| 345 |
| 346 EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(0)); |
| 347 EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(1)); |
| 348 |
| 349 // Now rearrange them and ensure that they are rearranged correctly in both |
| 350 // regular and incognito mode. |
| 351 |
| 352 // ABC -> CAB |
| 353 service->toolbar_model()->MoveBrowserAction(service->extensions()->at(2), 0); |
| 354 |
| 355 EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(0)); |
| 356 EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(1)); |
| 357 EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(2)); |
| 358 |
| 359 EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(0)); |
| 360 EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1)); |
| 361 |
| 362 // CAB -> CBA |
| 363 service->toolbar_model()->MoveBrowserAction(service->extensions()->at(1), 1); |
| 364 |
| 365 EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(0)); |
| 366 EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(1)); |
| 367 EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(2)); |
| 368 |
| 369 EXPECT_EQ(kTooltipC, incognito_bar.GetTooltip(0)); |
| 370 EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1)); |
| 371 } |
OLD | NEW |