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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/string_number_conversions.h" | 6 #include "base/string_number_conversions.h" |
| 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/download/download_service.h" | 9 #include "chrome/browser/download/download_service.h" |
8 #include "chrome/browser/download/download_service_factory.h" | 10 #include "chrome/browser/download/download_service_factory.h" |
9 #include "chrome/browser/net/url_request_mock_util.h" | 11 #include "chrome/browser/net/url_request_mock_util.h" |
| 12 #include "chrome/browser/notifications/balloon_collection_impl.h" |
| 13 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 14 #include "chrome/browser/notifications/notification.h" |
| 15 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 16 #include "chrome/browser/prefs/browser_prefs.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
13 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/find_bar/find_bar.h" | 21 #include "chrome/browser/ui/find_bar/find_bar.h" |
15 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 22 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
16 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | 23 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
17 #include "chrome/browser/ui/panels/native_panel.h" | 24 #include "chrome/browser/ui/panels/native_panel.h" |
18 #include "chrome/browser/ui/panels/panel.h" | 25 #include "chrome/browser/ui/panels/panel.h" |
19 #include "chrome/browser/ui/panels/panel_manager.h" | 26 #include "chrome/browser/ui/panels/panel_manager.h" |
20 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" | 27 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" |
21 #include "chrome/browser/web_applications/web_app.h" | 28 #include "chrome/browser/web_applications/web_app.h" |
22 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
24 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
25 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
26 #include "content/browser/download/download_manager.h" | 33 #include "content/browser/download/download_manager.h" |
27 #include "content/browser/net/url_request_mock_http_job.h" | 34 #include "content/browser/net/url_request_mock_http_job.h" |
28 #include "content/browser/tab_contents/tab_contents.h" | 35 #include "content/browser/tab_contents/tab_contents.h" |
| 36 #include "content/common/desktop_notification_messages.h" |
29 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
30 #include "content/public/common/url_constants.h" | 38 #include "content/public/common/url_constants.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 40 #include "ui/gfx/screen.h" |
32 | 41 |
33 using content::BrowserThread; | 42 using content::BrowserThread; |
34 | 43 |
35 class PanelBrowserTest : public BasePanelBrowserTest { | 44 class PanelBrowserTest : public BasePanelBrowserTest { |
36 public: | 45 public: |
37 PanelBrowserTest() : BasePanelBrowserTest() { | 46 PanelBrowserTest() : BasePanelBrowserTest() { |
38 } | 47 } |
39 | 48 |
40 protected: | 49 protected: |
41 void CloseWindowAndWait(Browser* browser) { | 50 void CloseWindowAndWait(Browser* browser) { |
(...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 EXPECT_EQ(1, tabbed_browser->tab_count()); | 1565 EXPECT_EQ(1, tabbed_browser->tab_count()); |
1557 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); | 1566 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
1558 tabbed_browser->CloseWindow(); | 1567 tabbed_browser->CloseWindow(); |
1559 #endif | 1568 #endif |
1560 | 1569 |
1561 EXPECT_EQ(1, panel_browser->tab_count()); | 1570 EXPECT_EQ(1, panel_browser->tab_count()); |
1562 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); | 1571 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
1563 | 1572 |
1564 panel_browser->CloseWindow(); | 1573 panel_browser->CloseWindow(); |
1565 } | 1574 } |
| 1575 |
| 1576 class PanelAndNotificationTest : public PanelBrowserTest { |
| 1577 public: |
| 1578 PanelAndNotificationTest() : PanelBrowserTest() { |
| 1579 // Do not use our own testing work area since desktop notification code |
| 1580 // does not have the hook up for testing work area. |
| 1581 set_testing_work_area(gfx::Rect()); |
| 1582 } |
| 1583 |
| 1584 virtual ~PanelAndNotificationTest() { |
| 1585 } |
| 1586 |
| 1587 virtual void SetUpOnMainThread() OVERRIDE { |
| 1588 g_browser_process->local_state()->SetInteger( |
| 1589 prefs::kDesktopNotificationPosition, BalloonCollection::LOWER_RIGHT); |
| 1590 balloons_ = new BalloonCollectionImpl(); |
| 1591 ui_manager_.reset(NotificationUIManager::Create( |
| 1592 g_browser_process->local_state(), balloons_)); |
| 1593 service_.reset(new DesktopNotificationService(browser()->profile(), |
| 1594 ui_manager_.get())); |
| 1595 |
| 1596 PanelBrowserTest::SetUpOnMainThread(); |
| 1597 } |
| 1598 |
| 1599 virtual void CleanUpOnMainThread() OVERRIDE { |
| 1600 balloons_->RemoveAll(); |
| 1601 MessageLoopForUI::current()->RunAllPending(); |
| 1602 |
| 1603 service_.reset(); |
| 1604 ui_manager_.reset(); |
| 1605 |
| 1606 PanelBrowserTest::CleanUpOnMainThread(); |
| 1607 } |
| 1608 |
| 1609 DesktopNotificationHostMsg_Show_Params StandardTestNotification() { |
| 1610 DesktopNotificationHostMsg_Show_Params params; |
| 1611 params.notification_id = 0; |
| 1612 params.origin = GURL("http://www.google.com"); |
| 1613 params.is_html = false; |
| 1614 params.icon_url = GURL("/icon.png"); |
| 1615 params.title = ASCIIToUTF16("Title"); |
| 1616 params.body = ASCIIToUTF16("Text"); |
| 1617 params.direction = WebKit::WebTextDirectionDefault; |
| 1618 return params; |
| 1619 } |
| 1620 |
| 1621 int GetBalloonBottomPosition(Balloon* balloon) const { |
| 1622 #if defined(OS_MACOSX) |
| 1623 // The position returned by the notification balloon is based on Mac's |
| 1624 // vertically inverted orientation. We need to flip it so that it can |
| 1625 // be compared against the position returned by the panel. |
| 1626 gfx::Size screen_size = gfx::Screen::GetPrimaryMonitorSize(); |
| 1627 return screen_size.height() - balloon->GetPosition().y(); |
| 1628 #else |
| 1629 return balloon->GetPosition().y() + balloon->GetViewSize().height(); |
| 1630 #endif |
| 1631 } |
| 1632 |
| 1633 DesktopNotificationService* service() const { return service_.get(); } |
| 1634 const BalloonCollection::Balloons& balloons() const { |
| 1635 return balloons_->GetActiveBalloons(); |
| 1636 } |
| 1637 |
| 1638 private: |
| 1639 BalloonCollectionImpl* balloons_; // Owned by NotificationUIManager. |
| 1640 scoped_ptr<NotificationUIManager> ui_manager_; |
| 1641 scoped_ptr<DesktopNotificationService> service_; |
| 1642 }; |
| 1643 |
| 1644 IN_PROC_BROWSER_TEST_F(PanelAndNotificationTest, NoOverlapping) { |
| 1645 const int kPanelWidth = 200; |
| 1646 const int kShortPanelHeight = 150; |
| 1647 const int kTallPanelHeight = 200; |
| 1648 |
| 1649 DesktopNotificationHostMsg_Show_Params params = StandardTestNotification(); |
| 1650 EXPECT_TRUE(service()->ShowDesktopNotification( |
| 1651 params, 0, 0, DesktopNotificationService::PageNotification)); |
| 1652 MessageLoopForUI::current()->RunAllPending(); |
| 1653 Balloon* balloon = balloons().front(); |
| 1654 int original_balloon_bottom = GetBalloonBottomPosition(balloon); |
| 1655 // Ensure that balloon width is greater than the panel width. |
| 1656 EXPECT_GT(balloon->GetViewSize().width(), kPanelWidth); |
| 1657 |
| 1658 // Creating a short panel should move the notification balloon up. |
| 1659 Panel* panel1 = CreatePanelWithBounds( |
| 1660 "Panel1", gfx::Rect(0, 0, kPanelWidth, kShortPanelHeight)); |
| 1661 WaitForPanelAdded(panel1); |
| 1662 int balloon_bottom_after_short_panel_created = |
| 1663 GetBalloonBottomPosition(balloon); |
| 1664 EXPECT_LT(balloon_bottom_after_short_panel_created, panel1->GetBounds().y()); |
| 1665 EXPECT_LT(balloon_bottom_after_short_panel_created, original_balloon_bottom); |
| 1666 |
| 1667 // Creating another tall panel should move the notification balloon further |
| 1668 // up. |
| 1669 Panel* panel2 = CreatePanelWithBounds( |
| 1670 "Panel2", gfx::Rect(0, 0, kPanelWidth, kTallPanelHeight)); |
| 1671 WaitForPanelAdded(panel2); |
| 1672 int balloon_bottom_after_tall_panel_created = |
| 1673 GetBalloonBottomPosition(balloon); |
| 1674 EXPECT_LT(balloon_bottom_after_tall_panel_created, panel2->GetBounds().y()); |
| 1675 EXPECT_LT(balloon_bottom_after_tall_panel_created, |
| 1676 balloon_bottom_after_short_panel_created); |
| 1677 |
| 1678 // Minimizing tall panel should move the notification balloon down to the same |
| 1679 // position when short panel is first created. |
| 1680 panel2->SetExpansionState(Panel::MINIMIZED); |
| 1681 WaitForBoundsAnimationFinished(panel2); |
| 1682 int balloon_bottom_after_tall_panel_minimized = |
| 1683 GetBalloonBottomPosition(balloon); |
| 1684 EXPECT_EQ(balloon_bottom_after_short_panel_created, |
| 1685 balloon_bottom_after_tall_panel_minimized); |
| 1686 |
| 1687 // Minimizing short panel should move the notification balloon further down. |
| 1688 panel1->SetExpansionState(Panel::MINIMIZED); |
| 1689 WaitForBoundsAnimationFinished(panel1); |
| 1690 int balloon_bottom_after_both_panels_minimized = |
| 1691 GetBalloonBottomPosition(balloon); |
| 1692 EXPECT_LT(balloon_bottom_after_both_panels_minimized, |
| 1693 panel1->GetBounds().y()); |
| 1694 EXPECT_LT(balloon_bottom_after_both_panels_minimized, |
| 1695 panel2->GetBounds().y()); |
| 1696 EXPECT_LT(balloon_bottom_after_short_panel_created, |
| 1697 balloon_bottom_after_both_panels_minimized); |
| 1698 EXPECT_LT(balloon_bottom_after_both_panels_minimized, |
| 1699 original_balloon_bottom); |
| 1700 |
| 1701 // Bringing up the titlebar for tall panel should move the notification |
| 1702 // balloon up a little bit. |
| 1703 panel2->SetExpansionState(Panel::TITLE_ONLY); |
| 1704 WaitForBoundsAnimationFinished(panel2); |
| 1705 int balloon_bottom_after_tall_panel_titlebar_up = |
| 1706 GetBalloonBottomPosition(balloon); |
| 1707 EXPECT_LT(balloon_bottom_after_tall_panel_titlebar_up, |
| 1708 panel2->GetBounds().y()); |
| 1709 EXPECT_LT(balloon_bottom_after_tall_panel_titlebar_up, |
| 1710 balloon_bottom_after_both_panels_minimized); |
| 1711 EXPECT_LT(balloon_bottom_after_short_panel_created, |
| 1712 balloon_bottom_after_tall_panel_titlebar_up); |
| 1713 |
| 1714 // Expanding short panel should move the notification balloon further up to |
| 1715 // the same position when short panel is first created. |
| 1716 panel1->SetExpansionState(Panel::EXPANDED); |
| 1717 WaitForBoundsAnimationFinished(panel1); |
| 1718 int balloon_bottom_after_short_panel_expanded = |
| 1719 GetBalloonBottomPosition(balloon); |
| 1720 EXPECT_EQ(balloon_bottom_after_short_panel_created, |
| 1721 balloon_bottom_after_short_panel_expanded); |
| 1722 |
| 1723 // Closing short panel should move the notification balloon down to the same |
| 1724 // position when tall panel brings up its titlebar. |
| 1725 panel1->Close(); |
| 1726 WaitForBoundsAnimationFinished(panel1); |
| 1727 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, |
| 1728 GetBalloonBottomPosition(balloon)); |
| 1729 |
| 1730 // Closing the remaining tall panel should move the notification balloon back |
| 1731 // to its original position. |
| 1732 panel2->Close(); |
| 1733 WaitForBoundsAnimationFinished(panel2); |
| 1734 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); |
| 1735 } |
OLD | NEW |