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 382642ccdf36a36fb05c7138447480a3873d1047..137ab81bfa30d6bce3908c15762a9b6f305cb3f2 100644 |
--- a/chrome/browser/ui/panels/panel_browsertest.cc |
+++ b/chrome/browser/ui/panels/panel_browsertest.cc |
@@ -4,11 +4,14 @@ |
#include "base/bind.h" |
#include "base/string_number_conversions.h" |
+#include "base/test/test_timeouts.h" |
Dmitry Titov
2011/11/11 05:18:10
is this include file needed?
prasadt
2011/11/11 18:29:58
I had it when I was doing timeout instead of waiti
prasadt
2011/11/11 19:22:30
After I sent this, I realized that I could return
|
#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/prefs/pref_service.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" |
+#include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
#include "chrome/browser/ui/browser_list.h" |
#include "chrome/browser/ui/browser_window.h" |
#include "chrome/browser/ui/find_bar/find_bar.h" |
@@ -1391,6 +1394,66 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, |
panel_other->Close(); |
} |
+IN_PROC_BROWSER_TEST_F(PanelBrowserTest, OnBeforeUnloadOnClose) { |
+ PanelManager* panel_manager = PanelManager::GetInstance(); |
+ EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. |
+ |
+ // HTML content with onbeforeunload handler. |
+ const char* kBeforeUnloadHTML = |
+ "<html><head><title>beforeunload</title></head><body>" |
+ "<script>window.onbeforeunload=function(e){return 'foo'}</script>" |
+ "</body></html>"; |
+ |
+ // Create a test panel with tab contents loaded. |
+ CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 100, 100), |
+ SHOW_AS_ACTIVE); |
+ params.url = GURL(std::string("data:text/html,") + kBeforeUnloadHTML); |
+ Panel* panel = CreatePanelWithParams(params); |
+ EXPECT_EQ(1, panel_manager->num_panels()); |
+ |
+ // Close panel and respond to the onbeforeunload dialog with cancel. This is |
+ // equivalent to clicking "Stay on this page" |
+ panel->Close(); |
+ AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
+ ui_test_utils::WindowedNotificationObserver signal_cancel( |
+ content::NOTIFICATION_RENDER_VIEW_HOST_RECEIVED_ON_MSG_SHOULD_CLOSE_ACK, |
+ content::Source<RenderViewHost>( |
+ panel->browser()->GetSelectedTabContents()->render_view_host())); |
+ alert->native_dialog()->CancelAppModalDialog(); |
+ signal_cancel.Wait(); |
+ EXPECT_EQ(1, panel_manager->num_panels()); |
+ |
+ // Close panel and respond to the onbeforeunload dialog with close. This is |
+ // equivalent to clicking the OS close button on the dialog. |
+ panel->Close(); |
+ alert = ui_test_utils::WaitForAppModalDialog(); |
+ ui_test_utils::WindowedNotificationObserver signal_close( |
+ content::NOTIFICATION_RENDER_VIEW_HOST_RECEIVED_ON_MSG_SHOULD_CLOSE_ACK, |
+ content::Source<RenderViewHost>( |
+ panel->browser()->GetSelectedTabContents()->render_view_host())); |
+ alert->native_dialog()->CloseAppModalDialog(); |
+ signal_close.Wait(); |
+ EXPECT_EQ(1, panel_manager->num_panels()); |
+ |
+ // Close panel and respond to the onbeforeunload dialog with accept. This is |
+ // equivalent to clicking "Leave this page". |
+ ui_test_utils::WindowedNotificationObserver panel_deleted( |
+ chrome::NOTIFICATION_PANEL_DELETED, |
+ content::Source<Panel>(panel)); |
+ |
+ panel->Close(); |
+ alert = ui_test_utils::WaitForAppModalDialog(); |
+ ui_test_utils::WindowedNotificationObserver signal_accept( |
+ content::NOTIFICATION_RENDER_VIEW_HOST_RECEIVED_ON_MSG_SHOULD_CLOSE_ACK, |
+ content::Source<RenderViewHost>( |
+ panel->browser()->GetSelectedTabContents()->render_view_host())); |
+ alert->native_dialog()->AcceptAppModalDialog(); |
+ signal_accept.Wait(); |
+ |
+ panel_deleted.Wait(); |
+ EXPECT_EQ(0, panel_manager->num_panels()); |
+} |
+ |
class PanelDownloadTest : public PanelBrowserTest { |
public: |
PanelDownloadTest() : PanelBrowserTest() { } |