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

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: 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 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"
29 #include "chrome/common/chrome_notification_types.h" 31 #include "chrome/common/chrome_notification_types.h"
30 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
32 #include "chrome/test/base/ui_test_utils.h" 34 #include "chrome/test/base/ui_test_utils.h"
33 #include "content/browser/download/download_manager.h" 35 #include "content/browser/download/download_manager.h"
34 #include "content/browser/net/url_request_mock_http_job.h" 36 #include "content/browser/net/url_request_mock_http_job.h"
35 #include "content/browser/tab_contents/tab_contents.h" 37 #include "content/browser/tab_contents/tab_contents.h"
36 #include "content/common/desktop_notification_messages.h" 38 #include "content/common/desktop_notification_messages.h"
37 #include "content/public/browser/notification_service.h" 39 #include "content/public/browser/notification_service.h"
38 #include "content/public/common/url_constants.h" 40 #include "content/public/common/url_constants.h"
41 #include "net/base/net_util.h"
39 #include "testing/gtest/include/gtest/gtest.h" 42 #include "testing/gtest/include/gtest/gtest.h"
40 #include "ui/gfx/screen.h" 43 #include "ui/gfx/screen.h"
41 44
42 using content::BrowserThread; 45 using content::BrowserThread;
43 46
44 class PanelBrowserTest : public BasePanelBrowserTest { 47 class PanelBrowserTest : public BasePanelBrowserTest {
45 public: 48 public:
46 PanelBrowserTest() : BasePanelBrowserTest() { 49 PanelBrowserTest() : BasePanelBrowserTest() {
47 } 50 }
48 51
(...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 1396
1394 // Wait for the panels opened by the first extension to close. 1397 // Wait for the panels opened by the first extension to close.
1395 signal.Wait(); 1398 signal.Wait();
1396 signal1.Wait(); 1399 signal1.Wait();
1397 1400
1398 // Verify that the panel that's left is the panel from the second extension. 1401 // Verify that the panel that's left is the panel from the second extension.
1399 EXPECT_EQ(panel_other, panel_manager->panels()[0]); 1402 EXPECT_EQ(panel_other, panel_manager->panels()[0]);
1400 panel_other->Close(); 1403 panel_other->Close();
1401 } 1404 }
1402 1405
1406 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, OnBeforeUnloadOnClose) {
1407 PanelManager* panel_manager = PanelManager::GetInstance();
1408 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
1409
1410 const char* on_before_unload_html_file = "onbeforeunload.html";
1411 const string16 title_first_close = UTF8ToUTF16("TitleFirstClose");
1412 const string16 title_second_close = UTF8ToUTF16("TitleSecondClose");
1413
1414 // Create a test panel with tab contents loaded.
1415 CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 300, 300),
1416 SHOW_AS_ACTIVE);
1417 params.url = GURL(net::FilePathToFileURL(
1418 test_data_dir_.AppendASCII(on_before_unload_html_file)));
1419 Panel* panel = CreatePanelWithParams(params);
1420 EXPECT_EQ(1, panel_manager->num_panels());
1421 TabContents* tab_contents = panel->browser()->GetSelectedTabContents();
1422
1423 // Close panel and respond to the onbeforeunload dialog with cancel. This is
1424 // equivalent to clicking "Stay on this page"
1425 scoped_ptr<ui_test_utils::TitleWatcher> title_watcher(
1426 new ui_test_utils::TitleWatcher(tab_contents, title_first_close));
1427 panel->Close();
1428 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
1429 alert->native_dialog()->CancelAppModalDialog();
1430 EXPECT_EQ(title_first_close, title_watcher->WaitAndGetTitle());
1431 EXPECT_EQ(1, panel_manager->num_panels());
1432
1433 // Close panel and respond to the onbeforeunload dialog with close. This is
1434 // equivalent to clicking the OS close button on the dialog.
1435 title_watcher.reset(
1436 new ui_test_utils::TitleWatcher(tab_contents, title_second_close));
1437 panel->Close();
1438 alert = ui_test_utils::WaitForAppModalDialog();
1439 alert->native_dialog()->CloseAppModalDialog();
1440 EXPECT_EQ(title_second_close, title_watcher->WaitAndGetTitle());
1441 EXPECT_EQ(1, panel_manager->num_panels());
1442
1443 // Close panel and respond to the onbeforeunload dialog with accept. This is
1444 // equivalent to clicking "Leave this page".
1445 ui_test_utils::WindowedNotificationObserver browser_closed(
1446 chrome::NOTIFICATION_BROWSER_CLOSED,
1447 content::Source<Browser>(panel->browser()));
1448 panel->Close();
1449 alert = ui_test_utils::WaitForAppModalDialog();
1450 alert->native_dialog()->AcceptAppModalDialog();
1451 browser_closed.Wait();
1452 EXPECT_EQ(0, panel_manager->num_panels());
1453 }
1454
1403 class PanelDownloadTest : public PanelBrowserTest { 1455 class PanelDownloadTest : public PanelBrowserTest {
1404 public: 1456 public:
1405 PanelDownloadTest() : PanelBrowserTest() { } 1457 PanelDownloadTest() : PanelBrowserTest() { }
1406 1458
1407 // Creates a temporary directory for downloads that is auto-deleted 1459 // Creates a temporary directory for downloads that is auto-deleted
1408 // on destruction. 1460 // on destruction.
1409 bool CreateDownloadDirectory(Profile* profile) { 1461 bool CreateDownloadDirectory(Profile* profile) {
1410 bool created = downloads_directory_.CreateUniqueTempDir(); 1462 bool created = downloads_directory_.CreateUniqueTempDir();
1411 if (!created) 1463 if (!created)
1412 return false; 1464 return false;
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 // the same position when short panel is first created. 1770 // the same position when short panel is first created.
1719 panel1->SetExpansionState(Panel::EXPANDED); 1771 panel1->SetExpansionState(Panel::EXPANDED);
1720 WaitForBoundsAnimationFinished(panel1); 1772 WaitForBoundsAnimationFinished(panel1);
1721 int balloon_bottom_after_short_panel_expanded = 1773 int balloon_bottom_after_short_panel_expanded =
1722 GetBalloonBottomPosition(balloon); 1774 GetBalloonBottomPosition(balloon);
1723 EXPECT_EQ(balloon_bottom_after_short_panel_created, 1775 EXPECT_EQ(balloon_bottom_after_short_panel_created,
1724 balloon_bottom_after_short_panel_expanded); 1776 balloon_bottom_after_short_panel_expanded);
1725 1777
1726 // Closing short panel should move the notification balloon down to the same 1778 // Closing short panel should move the notification balloon down to the same
1727 // position when tall panel brings up its titlebar. 1779 // position when tall panel brings up its titlebar.
1728 panel1->Close(); 1780 CloseWindowAndWait(panel1->browser());
1729 WaitForBoundsAnimationFinished(panel1);
1730 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, 1781 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up,
1731 GetBalloonBottomPosition(balloon)); 1782 GetBalloonBottomPosition(balloon));
1732 1783
1733 // Closing the remaining tall panel should move the notification balloon back 1784 // Closing the remaining tall panel should move the notification balloon back
1734 // to its original position. 1785 // to its original position.
1735 panel2->Close(); 1786 CloseWindowAndWait(panel2->browser());
1736 WaitForBoundsAnimationFinished(panel2);
1737 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); 1787 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon));
1738 } 1788 }
OLDNEW
« 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