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

Unified Diff: chrome/browser/ui/panels/panel_browsertest.cc

Issue 8505047: Fix panels being removed from PanelManager prematurely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change test from using notification to timeout. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_window_gtk.cc ('k') | chrome/test/data/panels/onbeforeunload.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7a74259e76f14a84cbd945614b95ae6cc33fcfe1..3d2d17cf6277ebce8beff6fc9c79fe8badec6b18 100644
--- a/chrome/browser/ui/panels/panel_browsertest.cc
+++ b/chrome/browser/ui/panels/panel_browsertest.cc
@@ -16,6 +16,8 @@
#include "chrome/browser/prefs/browser_prefs.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"
@@ -36,6 +38,7 @@
#include "content/common/desktop_notification_messages.h"
#include "content/public/browser/notification_service.h"
#include "content/public/common/url_constants.h"
+#include "net/base/net_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/screen.h"
@@ -1400,6 +1403,55 @@ 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.
+
+ const char* on_before_unload_html_file = "onbeforeunload.html";
+ const string16 title_first_close = UTF8ToUTF16("TitleFirstClose");
+ const string16 title_second_close = UTF8ToUTF16("TitleSecondClose");
+
+ // Create a test panel with tab contents loaded.
+ CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 300, 300),
+ SHOW_AS_ACTIVE);
+ params.url = GURL(net::FilePathToFileURL(
+ test_data_dir_.AppendASCII(on_before_unload_html_file)));
+ Panel* panel = CreatePanelWithParams(params);
+ EXPECT_EQ(1, panel_manager->num_panels());
+ TabContents* tab_contents = panel->browser()->GetSelectedTabContents();
+
+ // Close panel and respond to the onbeforeunload dialog with cancel. This is
+ // equivalent to clicking "Stay on this page"
+ scoped_ptr<ui_test_utils::TitleWatcher> title_watcher(
+ new ui_test_utils::TitleWatcher(tab_contents, title_first_close));
+ panel->Close();
+ AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
+ alert->native_dialog()->CancelAppModalDialog();
+ EXPECT_EQ(title_first_close, title_watcher->WaitAndGetTitle());
+ 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.
+ title_watcher.reset(
+ new ui_test_utils::TitleWatcher(tab_contents, title_second_close));
+ panel->Close();
+ alert = ui_test_utils::WaitForAppModalDialog();
+ alert->native_dialog()->CloseAppModalDialog();
+ EXPECT_EQ(title_second_close, title_watcher->WaitAndGetTitle());
+ 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 browser_closed(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::Source<Browser>(panel->browser()));
+ panel->Close();
+ alert = ui_test_utils::WaitForAppModalDialog();
+ alert->native_dialog()->AcceptAppModalDialog();
+ browser_closed.Wait();
+ EXPECT_EQ(0, panel_manager->num_panels());
+}
+
class PanelDownloadTest : public PanelBrowserTest {
public:
PanelDownloadTest() : PanelBrowserTest() { }
@@ -1725,14 +1777,12 @@ IN_PROC_BROWSER_TEST_F(PanelAndNotificationTest, NoOverlapping) {
// Closing short panel should move the notification balloon down to the same
// position when tall panel brings up its titlebar.
- panel1->Close();
- WaitForBoundsAnimationFinished(panel1);
+ 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.
- panel2->Close();
- WaitForBoundsAnimationFinished(panel2);
+ CloseWindowAndWait(panel2->browser());
EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
}
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_window_gtk.cc ('k') | chrome/test/data/panels/onbeforeunload.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698