OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/extensions/browser_action_test_util.h" | 11 #include "chrome/browser/extensions/browser_action_test_util.h" |
12 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
13 #include "chrome/browser/extensions/extension_browser_event_router.h" | 13 #include "chrome/browser/extensions/extension_browser_event_router.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/extensions/extension_tab_util.h" | 15 #include "chrome/browser/extensions/extension_tab_util.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/extensions/extension_action.h" | 20 #include "chrome/common/extensions/extension_action.h" |
21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
23 #include "content/browser/tab_contents/tab_contents.h" | 23 #include "content/browser/tab_contents/tab_contents.h" |
| 24 #include "content/public/browser/notification_service.h" |
24 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
25 #include "ui/gfx/size.h" | 26 #include "ui/gfx/size.h" |
26 | 27 |
27 class BrowserActionApiTest : public ExtensionApiTest { | 28 class BrowserActionApiTest : public ExtensionApiTest { |
28 public: | 29 public: |
29 BrowserActionApiTest() {} | 30 BrowserActionApiTest() {} |
30 virtual ~BrowserActionApiTest() {} | 31 virtual ~BrowserActionApiTest() {} |
31 | 32 |
32 protected: | 33 protected: |
33 BrowserActionTestUtil GetBrowserActionsBar() { | 34 BrowserActionTestUtil GetBrowserActionsBar() { |
34 return BrowserActionTestUtil(browser()); | 35 return BrowserActionTestUtil(browser()); |
35 } | 36 } |
36 | 37 |
37 bool OpenPopup(int index) { | 38 bool OpenPopup(int index) { |
38 ResultCatcher catcher; | 39 ResultCatcher catcher; |
39 ui_test_utils::WindowedNotificationObserver popup_observer( | 40 ui_test_utils::WindowedNotificationObserver popup_observer( |
40 chrome::NOTIFICATION_EXTENSION_POPUP_VIEW_READY, | 41 chrome::NOTIFICATION_EXTENSION_POPUP_VIEW_READY, |
41 NotificationService::AllSources()); | 42 content::NotificationService::AllSources()); |
42 GetBrowserActionsBar().Press(index); | 43 GetBrowserActionsBar().Press(index); |
43 popup_observer.Wait(); | 44 popup_observer.Wait(); |
44 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 45 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
45 return GetBrowserActionsBar().HasPopup(); | 46 return GetBrowserActionsBar().HasPopup(); |
46 } | 47 } |
47 }; | 48 }; |
48 | 49 |
49 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { | 50 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) { |
50 ASSERT_TRUE(test_server()->Start()); | 51 ASSERT_TRUE(test_server()->Start()); |
51 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; | 52 ASSERT_TRUE(RunExtensionTest("browser_action/basics")) << message_; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 | 391 |
391 // There is a background page and a browser action with no badge text. | 392 // There is a background page and a browser action with no badge text. |
392 ExtensionProcessManager* manager = | 393 ExtensionProcessManager* manager = |
393 browser()->profile()->GetExtensionProcessManager(); | 394 browser()->profile()->GetExtensionProcessManager(); |
394 ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension)); | 395 ASSERT_TRUE(manager->GetBackgroundHostForExtension(extension)); |
395 ExtensionAction* action = extension->browser_action(); | 396 ExtensionAction* action = extension->browser_action(); |
396 ASSERT_EQ("", action->GetBadgeText(ExtensionAction::kDefaultTabId)); | 397 ASSERT_EQ("", action->GetBadgeText(ExtensionAction::kDefaultTabId)); |
397 | 398 |
398 ui_test_utils::WindowedNotificationObserver host_destroyed_observer( | 399 ui_test_utils::WindowedNotificationObserver host_destroyed_observer( |
399 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 400 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
400 NotificationService::AllSources()); | 401 content::NotificationService::AllSources()); |
401 | 402 |
402 // Click the browser action. | 403 // Click the browser action. |
403 browser()->profile()->GetExtensionService()->browser_event_router()-> | 404 browser()->profile()->GetExtensionService()->browser_event_router()-> |
404 BrowserActionExecuted( | 405 BrowserActionExecuted( |
405 browser()->profile(), action->extension_id(), browser()); | 406 browser()->profile(), action->extension_id(), browser()); |
406 | 407 |
407 // It can take a moment for the background page to actually get destroyed | 408 // It can take a moment for the background page to actually get destroyed |
408 // so we wait for the notification before checking that it's really gone | 409 // so we wait for the notification before checking that it's really gone |
409 // and the badge text has been set. | 410 // and the badge text has been set. |
410 host_destroyed_observer.Wait(); | 411 host_destroyed_observer.Wait(); |
411 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension)); | 412 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension)); |
412 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); | 413 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); |
413 } | 414 } |
OLD | NEW |