Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: chrome/browser/ui/panels/panel_browsertest.cc

Issue 8503037: Fix the problem that notifications and panels overlap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
32 #include "chrome/test/base/testing_pref_service.h"
25 #include "chrome/test/base/ui_test_utils.h" 33 #include "chrome/test/base/ui_test_utils.h"
26 #include "content/browser/download/download_manager.h" 34 #include "content/browser/download/download_manager.h"
27 #include "content/browser/net/url_request_mock_http_job.h" 35 #include "content/browser/net/url_request_mock_http_job.h"
28 #include "content/browser/tab_contents/tab_contents.h" 36 #include "content/browser/tab_contents/tab_contents.h"
37 #include "content/common/desktop_notification_messages.h"
29 #include "content/public/browser/notification_service.h" 38 #include "content/public/browser/notification_service.h"
30 #include "content/public/common/url_constants.h" 39 #include "content/public/common/url_constants.h"
31 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.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 }
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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;
jennb 2011/11/09 21:44:34 This is done in StandardTestNotification() already
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));
jennb 2011/11/09 21:44:34 Does this assume notification balloons are wider t
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698