Index: chrome/browser/ui/panels/panel_browsertest.cc |
diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc |
index f561ace83d05412ef67e146b76b2503ad2e8f490..21dbc9ae74b9e47e6810514aa21a3adb09718591 100644 |
--- a/chrome/browser/ui/panels/panel_browsertest.cc |
+++ b/chrome/browser/ui/panels/panel_browsertest.cc |
@@ -4,9 +4,15 @@ |
#include "base/bind.h" |
#include "base/string_number_conversions.h" |
+#include "chrome/browser/browser_process.h" |
#include "chrome/browser/download/download_service.h" |
#include "chrome/browser/download/download_service_factory.h" |
#include "chrome/browser/net/url_request_mock_util.h" |
+#include "chrome/browser/notifications/balloon_collection_impl.h" |
+#include "chrome/browser/notifications/desktop_notification_service.h" |
+#include "chrome/browser/notifications/notification.h" |
+#include "chrome/browser/notifications/notification_ui_manager.h" |
+#include "chrome/browser/prefs/browser_prefs.h" |
#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/browser_list.h" |
@@ -22,10 +28,12 @@ |
#include "chrome/common/chrome_notification_types.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/common/url_constants.h" |
+#include "chrome/test/base/testing_pref_service.h" |
#include "chrome/test/base/ui_test_utils.h" |
#include "content/browser/download/download_manager.h" |
#include "content/browser/net/url_request_mock_http_job.h" |
#include "content/browser/tab_contents/tab_contents.h" |
+#include "content/common/desktop_notification_messages.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/common/url_constants.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -1419,6 +1427,7 @@ class PanelDownloadTest : public PanelBrowserTest { |
ScopedTempDir downloads_directory_; |
}; |
Dmitry Titov
2011/11/09 03:09:57
extra line
jianli
2011/11/09 19:04:40
Done.
|
+ |
class DownloadObserver : public DownloadManager::Observer { |
public: |
explicit DownloadObserver(Profile* profile) |
@@ -1563,3 +1572,145 @@ IN_PROC_BROWSER_TEST_F(PanelDownloadTest, DownloadNoTabbedBrowser) { |
panel_browser->CloseWindow(); |
} |
+ |
+class PanelAndNotificationTest : public PanelBrowserTest { |
+ public: |
+ PanelAndNotificationTest::PanelAndNotificationTest() : PanelBrowserTest() { |
+ // Do not use our own testing work area since desktop notification code |
+ // does not have the hook up for testing work area. |
+ set_testing_work_area(gfx::Rect()); |
+ } |
+ |
+ PanelAndNotificationTest::~PanelAndNotificationTest() { |
+ } |
+ |
+ virtual void PanelAndNotificationTest::SetUpOnMainThread() OVERRIDE { |
+ g_browser_process->local_state()->SetInteger( |
+ prefs::kDesktopNotificationPosition, BalloonCollection::LOWER_RIGHT); |
+ balloons_ = new BalloonCollectionImpl(); |
+ ui_manager_.reset(NotificationUIManager::Create( |
+ g_browser_process->local_state(), balloons_)); |
+ service_.reset(new DesktopNotificationService(browser()->profile(), |
+ ui_manager_.get())); |
+ |
+ PanelBrowserTest::SetUpOnMainThread(); |
+ } |
+ |
+ virtual void PanelAndNotificationTest::CleanUpOnMainThread() OVERRIDE { |
+ balloons_->RemoveAll(); |
+ MessageLoopForUI::current()->RunAllPending(); |
+ |
+ service_.reset(); |
+ ui_manager_.reset(); |
+ |
+ PanelBrowserTest::CleanUpOnMainThread(); |
+ } |
+ |
+ DesktopNotificationHostMsg_Show_Params StandardTestNotification() { |
+ DesktopNotificationHostMsg_Show_Params params; |
+ params.notification_id = 0; |
+ params.origin = GURL("http://www.google.com"); |
+ params.is_html = false; |
+ params.icon_url = GURL("/icon.png"); |
+ params.title = L"Title"; |
+ params.body = L"Text"; |
+ params.direction = WebKit::WebTextDirectionDefault; |
+ return params; |
+ } |
+ |
+ int GetBalloonBottomPosition(Balloon* balloon) const { |
+ return balloon->GetPosition().y() + balloon->GetViewSize().height(); |
+ } |
+ |
+ DesktopNotificationService* service() const { return service_.get(); } |
+ const BalloonCollection::Balloons& balloons() const { |
+ return balloons_->GetActiveBalloons(); |
+ } |
+ |
+ private: |
+ BalloonCollectionImpl* balloons_; // Owned by NotificationUIManager. |
+ scoped_ptr<NotificationUIManager> ui_manager_; |
+ scoped_ptr<DesktopNotificationService> service_; |
+}; |
+ |
+IN_PROC_BROWSER_TEST_F(PanelAndNotificationTest, NoOverlapping) { |
+ DesktopNotificationHostMsg_Show_Params params = StandardTestNotification(); |
+ params.notification_id = 0; |
+ EXPECT_TRUE(service()->ShowDesktopNotification( |
+ params, 0, 0, DesktopNotificationService::PageNotification)); |
+ MessageLoopForUI::current()->RunAllPending(); |
+ Balloon* balloon = balloons().front(); |
+ int original_balloon_bottom = GetBalloonBottomPosition(balloon); |
+ |
+ // Creating a short panel should move the notification balloon up. |
+ Panel* panel1 = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 200, 200)); |
+ int balloon_bottom_after_short_panel_created = |
+ GetBalloonBottomPosition(balloon); |
+ EXPECT_LT(balloon_bottom_after_short_panel_created, panel1->GetBounds().y()); |
+ EXPECT_LT(balloon_bottom_after_short_panel_created, original_balloon_bottom); |
+ |
+ // Creating another tall panel should move the notification balloon further |
+ // up. |
+ Panel* panel2 = CreatePanelWithBounds("Panel2", gfx::Rect(0, 0, 200, 400)); |
+ int balloon_bottom_after_tall_panel_created = |
+ GetBalloonBottomPosition(balloon); |
+ EXPECT_LT(balloon_bottom_after_tall_panel_created, panel2->GetBounds().y()); |
+ EXPECT_LT(balloon_bottom_after_tall_panel_created, |
+ balloon_bottom_after_short_panel_created); |
+ |
+ // Minimizing tall panel should move the notification balloon down to the same |
+ // position when short panel is first created. |
+ panel2->SetExpansionState(Panel::MINIMIZED); |
+ WaitForBoundsAnimationFinished(panel2); |
+ int balloon_bottom_after_tall_panel_minimized = |
+ GetBalloonBottomPosition(balloon); |
+ EXPECT_EQ(balloon_bottom_after_short_panel_created, |
+ balloon_bottom_after_tall_panel_minimized); |
+ |
+ // Minimizing short panel should move the notification balloon further down. |
+ panel1->SetExpansionState(Panel::MINIMIZED); |
+ WaitForBoundsAnimationFinished(panel1); |
+ int balloon_bottom_after_both_panels_minimized = |
+ GetBalloonBottomPosition(balloon); |
+ EXPECT_LT(balloon_bottom_after_both_panels_minimized, |
+ panel1->GetBounds().y()); |
+ EXPECT_LT(balloon_bottom_after_both_panels_minimized, |
+ panel2->GetBounds().y()); |
+ EXPECT_LT(balloon_bottom_after_short_panel_created, |
+ balloon_bottom_after_both_panels_minimized); |
+ EXPECT_LT(balloon_bottom_after_both_panels_minimized, |
+ original_balloon_bottom); |
+ |
+ // Bringing up the titlebar for tall panel should move the notification |
+ // balloon up a little bit. |
+ panel2->SetExpansionState(Panel::TITLE_ONLY); |
+ WaitForBoundsAnimationFinished(panel2); |
+ int balloon_bottom_after_tall_panel_titlebar_up = |
+ GetBalloonBottomPosition(balloon); |
+ EXPECT_LT(balloon_bottom_after_tall_panel_titlebar_up, |
+ panel2->GetBounds().y()); |
+ EXPECT_LT(balloon_bottom_after_tall_panel_titlebar_up, |
+ balloon_bottom_after_both_panels_minimized); |
+ EXPECT_LT(balloon_bottom_after_short_panel_created, |
+ balloon_bottom_after_tall_panel_titlebar_up); |
+ |
+ // Expanding short panel should move the notification balloon further up to |
+ // the same position when short panel is first created. |
+ panel1->SetExpansionState(Panel::EXPANDED); |
+ WaitForBoundsAnimationFinished(panel1); |
+ int balloon_bottom_after_short_panel_expanded = |
+ GetBalloonBottomPosition(balloon); |
+ EXPECT_EQ(balloon_bottom_after_short_panel_created, |
+ balloon_bottom_after_short_panel_expanded); |
+ |
+ // Closing short panel should move the notification balloon down to the same |
+ // position when tall panel brings up its titlebar. |
+ CloseWindowAndWait(panel1->browser()); |
+ EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, |
+ GetBalloonBottomPosition(balloon)); |
+ |
+ // Closing the remaining tall panel should move the notification balloon back |
+ // to its original position. |
+ CloseWindowAndWait(panel2->browser()); |
+ EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); |
+} |