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 "chrome/browser/browser_process.h" | |
7 #include "chrome/browser/download/download_service.h" | 8 #include "chrome/browser/download/download_service.h" |
8 #include "chrome/browser/download/download_service_factory.h" | 9 #include "chrome/browser/download/download_service_factory.h" |
9 #include "chrome/browser/net/url_request_mock_util.h" | 10 #include "chrome/browser/net/url_request_mock_util.h" |
11 #include "chrome/browser/notifications/balloon_collection_impl.h" | |
12 #include "chrome/browser/notifications/desktop_notification_service.h" | |
13 #include "chrome/browser/notifications/notification.h" | |
14 #include "chrome/browser/notifications/notification_ui_manager.h" | |
15 #include "chrome/browser/prefs/browser_prefs.h" | |
10 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
13 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/find_bar/find_bar.h" | 20 #include "chrome/browser/ui/find_bar/find_bar.h" |
15 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 21 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
16 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | 22 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
17 #include "chrome/browser/ui/panels/native_panel.h" | 23 #include "chrome/browser/ui/panels/native_panel.h" |
18 #include "chrome/browser/ui/panels/panel.h" | 24 #include "chrome/browser/ui/panels/panel.h" |
19 #include "chrome/browser/ui/panels/panel_manager.h" | 25 #include "chrome/browser/ui/panels/panel_manager.h" |
20 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" | 26 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" |
21 #include "chrome/browser/web_applications/web_app.h" | 27 #include "chrome/browser/web_applications/web_app.h" |
22 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
24 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
31 #include "chrome/test/base/testing_pref_service.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" |
32 | 40 |
33 using content::BrowserThread; | 41 using content::BrowserThread; |
34 | 42 |
35 class PanelBrowserTest : public BasePanelBrowserTest { | 43 class PanelBrowserTest : public BasePanelBrowserTest { |
36 public: | 44 public: |
37 PanelBrowserTest() : BasePanelBrowserTest() { | 45 PanelBrowserTest() : BasePanelBrowserTest() { |
38 } | 46 } |
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1411 | 1419 |
1412 BrowserThread::PostTask( | 1420 BrowserThread::PostTask( |
1413 BrowserThread::IO, FROM_HERE, | 1421 BrowserThread::IO, FROM_HERE, |
1414 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 1422 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
1415 } | 1423 } |
1416 | 1424 |
1417 private: | 1425 private: |
1418 // Location of the downloads directory for download tests. | 1426 // Location of the downloads directory for download tests. |
1419 ScopedTempDir downloads_directory_; | 1427 ScopedTempDir downloads_directory_; |
1420 }; | 1428 }; |
1421 | 1429 |
Dmitry Titov
2011/11/09 03:09:57
extra line
jianli
2011/11/09 19:04:40
Done.
| |
1430 | |
1422 class DownloadObserver : public DownloadManager::Observer { | 1431 class DownloadObserver : public DownloadManager::Observer { |
1423 public: | 1432 public: |
1424 explicit DownloadObserver(Profile* profile) | 1433 explicit DownloadObserver(Profile* profile) |
1425 : download_manager_( | 1434 : download_manager_( |
1426 DownloadServiceFactory::GetForProfile(profile)->GetDownloadManager()), | 1435 DownloadServiceFactory::GetForProfile(profile)->GetDownloadManager()), |
1427 saw_download_(false), | 1436 saw_download_(false), |
1428 waiting_(false) { | 1437 waiting_(false) { |
1429 download_manager_->AddObserver(this); | 1438 download_manager_->AddObserver(this); |
1430 } | 1439 } |
1431 | 1440 |
(...skipping 124 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::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 PanelAndNotificationTest::~PanelAndNotificationTest() { | |
1585 } | |
1586 | |
1587 virtual void PanelAndNotificationTest::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 PanelAndNotificationTest::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 = L"Title"; | |
1616 params.body = L"Text"; | |
1617 params.direction = WebKit::WebTextDirectionDefault; | |
1618 return params; | |
1619 } | |
1620 | |
1621 int GetBalloonBottomPosition(Balloon* balloon) const { | |
1622 return balloon->GetPosition().y() + balloon->GetViewSize().height(); | |
1623 } | |
1624 | |
1625 DesktopNotificationService* service() const { return service_.get(); } | |
1626 const BalloonCollection::Balloons& balloons() const { | |
1627 return balloons_->GetActiveBalloons(); | |
1628 } | |
1629 | |
1630 private: | |
1631 BalloonCollectionImpl* balloons_; // Owned by NotificationUIManager. | |
1632 scoped_ptr<NotificationUIManager> ui_manager_; | |
1633 scoped_ptr<DesktopNotificationService> service_; | |
1634 }; | |
1635 | |
1636 IN_PROC_BROWSER_TEST_F(PanelAndNotificationTest, NoOverlapping) { | |
1637 DesktopNotificationHostMsg_Show_Params params = StandardTestNotification(); | |
1638 params.notification_id = 0; | |
1639 EXPECT_TRUE(service()->ShowDesktopNotification( | |
1640 params, 0, 0, DesktopNotificationService::PageNotification)); | |
1641 MessageLoopForUI::current()->RunAllPending(); | |
1642 Balloon* balloon = balloons().front(); | |
1643 int original_balloon_bottom = GetBalloonBottomPosition(balloon); | |
1644 | |
1645 // Creating a short panel should move the notification balloon up. | |
1646 Panel* panel1 = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 200, 200)); | |
1647 int balloon_bottom_after_short_panel_created = | |
1648 GetBalloonBottomPosition(balloon); | |
1649 EXPECT_LT(balloon_bottom_after_short_panel_created, panel1->GetBounds().y()); | |
1650 EXPECT_LT(balloon_bottom_after_short_panel_created, original_balloon_bottom); | |
1651 | |
1652 // Creating another tall panel should move the notification balloon further | |
1653 // up. | |
1654 Panel* panel2 = CreatePanelWithBounds("Panel2", gfx::Rect(0, 0, 200, 400)); | |
1655 int balloon_bottom_after_tall_panel_created = | |
1656 GetBalloonBottomPosition(balloon); | |
1657 EXPECT_LT(balloon_bottom_after_tall_panel_created, panel2->GetBounds().y()); | |
1658 EXPECT_LT(balloon_bottom_after_tall_panel_created, | |
1659 balloon_bottom_after_short_panel_created); | |
1660 | |
1661 // Minimizing tall panel should move the notification balloon down to the same | |
1662 // position when short panel is first created. | |
1663 panel2->SetExpansionState(Panel::MINIMIZED); | |
1664 WaitForBoundsAnimationFinished(panel2); | |
1665 int balloon_bottom_after_tall_panel_minimized = | |
1666 GetBalloonBottomPosition(balloon); | |
1667 EXPECT_EQ(balloon_bottom_after_short_panel_created, | |
1668 balloon_bottom_after_tall_panel_minimized); | |
1669 | |
1670 // Minimizing short panel should move the notification balloon further down. | |
1671 panel1->SetExpansionState(Panel::MINIMIZED); | |
1672 WaitForBoundsAnimationFinished(panel1); | |
1673 int balloon_bottom_after_both_panels_minimized = | |
1674 GetBalloonBottomPosition(balloon); | |
1675 EXPECT_LT(balloon_bottom_after_both_panels_minimized, | |
1676 panel1->GetBounds().y()); | |
1677 EXPECT_LT(balloon_bottom_after_both_panels_minimized, | |
1678 panel2->GetBounds().y()); | |
1679 EXPECT_LT(balloon_bottom_after_short_panel_created, | |
1680 balloon_bottom_after_both_panels_minimized); | |
1681 EXPECT_LT(balloon_bottom_after_both_panels_minimized, | |
1682 original_balloon_bottom); | |
1683 | |
1684 // Bringing up the titlebar for tall panel should move the notification | |
1685 // balloon up a little bit. | |
1686 panel2->SetExpansionState(Panel::TITLE_ONLY); | |
1687 WaitForBoundsAnimationFinished(panel2); | |
1688 int balloon_bottom_after_tall_panel_titlebar_up = | |
1689 GetBalloonBottomPosition(balloon); | |
1690 EXPECT_LT(balloon_bottom_after_tall_panel_titlebar_up, | |
1691 panel2->GetBounds().y()); | |
1692 EXPECT_LT(balloon_bottom_after_tall_panel_titlebar_up, | |
1693 balloon_bottom_after_both_panels_minimized); | |
1694 EXPECT_LT(balloon_bottom_after_short_panel_created, | |
1695 balloon_bottom_after_tall_panel_titlebar_up); | |
1696 | |
1697 // Expanding short panel should move the notification balloon further up to | |
1698 // the same position when short panel is first created. | |
1699 panel1->SetExpansionState(Panel::EXPANDED); | |
1700 WaitForBoundsAnimationFinished(panel1); | |
1701 int balloon_bottom_after_short_panel_expanded = | |
1702 GetBalloonBottomPosition(balloon); | |
1703 EXPECT_EQ(balloon_bottom_after_short_panel_created, | |
1704 balloon_bottom_after_short_panel_expanded); | |
1705 | |
1706 // Closing short panel should move the notification balloon down to the same | |
1707 // position when tall panel brings up its titlebar. | |
1708 CloseWindowAndWait(panel1->browser()); | |
1709 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, | |
1710 GetBalloonBottomPosition(balloon)); | |
1711 | |
1712 // Closing the remaining tall panel should move the notification balloon back | |
1713 // to its original position. | |
1714 CloseWindowAndWait(panel2->browser()); | |
1715 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); | |
1716 } | |
OLD | NEW |