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

Side by Side 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: Got rid of timeout by adding Details to notification from RenderViewHost. 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" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/download/download_service.h" 9 #include "chrome/browser/download/download_service.h"
10 #include "chrome/browser/download/download_service_factory.h" 10 #include "chrome/browser/download/download_service_factory.h"
11 #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" 12 #include "chrome/browser/notifications/balloon_collection_impl.h"
13 #include "chrome/browser/notifications/desktop_notification_service.h" 13 #include "chrome/browser/notifications/desktop_notification_service.h"
14 #include "chrome/browser/notifications/notification.h" 14 #include "chrome/browser/notifications/notification.h"
15 #include "chrome/browser/notifications/notification_ui_manager.h" 15 #include "chrome/browser/notifications/notification_ui_manager.h"
16 #include "chrome/browser/prefs/browser_prefs.h" 16 #include "chrome/browser/prefs/browser_prefs.h"
17 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
20 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
19 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
20 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/find_bar/find_bar.h" 23 #include "chrome/browser/ui/find_bar/find_bar.h"
22 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 24 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
23 #include "chrome/browser/ui/panels/base_panel_browser_test.h" 25 #include "chrome/browser/ui/panels/base_panel_browser_test.h"
24 #include "chrome/browser/ui/panels/native_panel.h" 26 #include "chrome/browser/ui/panels/native_panel.h"
25 #include "chrome/browser/ui/panels/panel.h" 27 #include "chrome/browser/ui/panels/panel.h"
26 #include "chrome/browser/ui/panels/panel_manager.h" 28 #include "chrome/browser/ui/panels/panel_manager.h"
27 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" 29 #include "chrome/browser/ui/panels/panel_settings_menu_model.h"
28 #include "chrome/browser/web_applications/web_app.h" 30 #include "chrome/browser/web_applications/web_app.h"
(...skipping 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 1395
1394 // Wait for the panels opened by the first extension to close. 1396 // Wait for the panels opened by the first extension to close.
1395 signal.Wait(); 1397 signal.Wait();
1396 signal1.Wait(); 1398 signal1.Wait();
1397 1399
1398 // Verify that the panel that's left is the panel from the second extension. 1400 // Verify that the panel that's left is the panel from the second extension.
1399 EXPECT_EQ(panel_other, panel_manager->panels()[0]); 1401 EXPECT_EQ(panel_other, panel_manager->panels()[0]);
1400 panel_other->Close(); 1402 panel_other->Close();
1401 } 1403 }
1402 1404
1405 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, OnBeforeUnloadOnClose) {
1406 PanelManager* panel_manager = PanelManager::GetInstance();
1407 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
1408
1409 // HTML content with onbeforeunload handler.
1410 const char* kBeforeUnloadHTML =
1411 "<html><head><title>beforeunload</title></head><body>"
1412 "<script>window.onbeforeunload=function(e){return 'foo'}</script>"
1413 "</body></html>";
1414
1415 // Create a test panel with tab contents loaded.
1416 CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 100, 100),
1417 SHOW_AS_ACTIVE);
1418 params.url = GURL(std::string("data:text/html,") + kBeforeUnloadHTML);
1419 Panel* panel = CreatePanelWithParams(params);
1420 EXPECT_EQ(1, panel_manager->num_panels());
1421
1422 // Close panel and respond to the onbeforeunload dialog with cancel. This is
1423 // equivalent to clicking "Stay on this page"
1424 panel->Close();
1425 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
1426 content::Source<RenderViewHost> source_render_view_host(
1427 panel->browser()->GetSelectedTabContents()->render_view_host());
1428 ui_test_utils::WindowedNotificationObserverWithDetails<bool> signal_cancel(
1429 content::NOTIFICATION_RENDER_VIEW_HOST_RECEIVED_ON_MSG_SHOULD_CLOSE_ACK,
1430 source_render_view_host);
1431 alert->native_dialog()->CancelAppModalDialog();
1432 signal_cancel.Wait();
1433
1434 bool proceed;
1435 EXPECT_TRUE(signal_cancel.GetDetailsFor(source_render_view_host.map_key(),
1436 &proceed));
1437 EXPECT_FALSE(proceed);
1438 EXPECT_EQ(1, panel_manager->num_panels());
1439
1440 // Close panel and respond to the onbeforeunload dialog with close. This is
1441 // equivalent to clicking the OS close button on the dialog.
1442 panel->Close();
1443 alert = ui_test_utils::WaitForAppModalDialog();
1444 ui_test_utils::WindowedNotificationObserverWithDetails<bool> signal_close(
1445 content::NOTIFICATION_RENDER_VIEW_HOST_RECEIVED_ON_MSG_SHOULD_CLOSE_ACK,
1446 source_render_view_host);
1447 alert->native_dialog()->CloseAppModalDialog();
1448 signal_close.Wait();
1449
1450 EXPECT_TRUE(signal_close.GetDetailsFor(source_render_view_host.map_key(),
1451 &proceed));
1452 EXPECT_FALSE(proceed);
1453 EXPECT_EQ(1, panel_manager->num_panels());
1454
1455 // Close panel and respond to the onbeforeunload dialog with accept. This is
1456 // equivalent to clicking "Leave this page".
1457 ui_test_utils::WindowedNotificationObserver panel_deleted(
1458 chrome::NOTIFICATION_PANEL_DELETED, content::Source<Panel>(panel));
1459
1460 panel->Close();
1461 alert = ui_test_utils::WaitForAppModalDialog();
1462 ui_test_utils::WindowedNotificationObserverWithDetails<bool> signal_accept(
1463 content::NOTIFICATION_RENDER_VIEW_HOST_RECEIVED_ON_MSG_SHOULD_CLOSE_ACK,
1464 source_render_view_host);
1465 alert->native_dialog()->AcceptAppModalDialog();
1466 signal_accept.Wait();
1467
1468 EXPECT_TRUE(signal_accept.GetDetailsFor(source_render_view_host.map_key(),
1469 &proceed));
1470 EXPECT_TRUE(proceed);
1471 panel_deleted.Wait();
1472 EXPECT_EQ(0, panel_manager->num_panels());
1473 }
1474
1403 class PanelDownloadTest : public PanelBrowserTest { 1475 class PanelDownloadTest : public PanelBrowserTest {
1404 public: 1476 public:
1405 PanelDownloadTest() : PanelBrowserTest() { } 1477 PanelDownloadTest() : PanelBrowserTest() { }
1406 1478
1407 // Creates a temporary directory for downloads that is auto-deleted 1479 // Creates a temporary directory for downloads that is auto-deleted
1408 // on destruction. 1480 // on destruction.
1409 bool CreateDownloadDirectory(Profile* profile) { 1481 bool CreateDownloadDirectory(Profile* profile) {
1410 bool created = downloads_directory_.CreateUniqueTempDir(); 1482 bool created = downloads_directory_.CreateUniqueTempDir();
1411 if (!created) 1483 if (!created)
1412 return false; 1484 return false;
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 WaitForBoundsAnimationFinished(panel1); 1800 WaitForBoundsAnimationFinished(panel1);
1729 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, 1801 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up,
1730 GetBalloonBottomPosition(balloon)); 1802 GetBalloonBottomPosition(balloon));
1731 1803
1732 // Closing the remaining tall panel should move the notification balloon back 1804 // Closing the remaining tall panel should move the notification balloon back
1733 // to its original position. 1805 // to its original position.
1734 panel2->Close(); 1806 panel2->Close();
1735 WaitForBoundsAnimationFinished(panel2); 1807 WaitForBoundsAnimationFinished(panel2);
1736 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); 1808 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
1737 } 1809 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698