Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/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
| |
| 7 #include "chrome/browser/download/download_service.h" | 8 #include "chrome/browser/download/download_service.h" |
| 8 #include "chrome/browser/download/download_service_factory.h" | 9 #include "chrome/browser/download/download_service_factory.h" |
| 9 #include "chrome/browser/net/url_request_mock_util.h" | 10 #include "chrome/browser/net/url_request_mock_util.h" |
| 10 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" | |
| 14 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | |
| 12 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/find_bar/find_bar.h" | 17 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 15 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 18 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 16 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | 19 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
| 17 #include "chrome/browser/ui/panels/native_panel.h" | 20 #include "chrome/browser/ui/panels/native_panel.h" |
| 18 #include "chrome/browser/ui/panels/panel.h" | 21 #include "chrome/browser/ui/panels/panel.h" |
| 19 #include "chrome/browser/ui/panels/panel_manager.h" | 22 #include "chrome/browser/ui/panels/panel_manager.h" |
| 20 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" | 23 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" |
| 21 #include "chrome/browser/web_applications/web_app.h" | 24 #include "chrome/browser/web_applications/web_app.h" |
| (...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1384 | 1387 |
| 1385 // Wait for the panels opened by the first extension to close. | 1388 // Wait for the panels opened by the first extension to close. |
| 1386 signal.Wait(); | 1389 signal.Wait(); |
| 1387 signal1.Wait(); | 1390 signal1.Wait(); |
| 1388 | 1391 |
| 1389 // Verify that the panel that's left is the panel from the second extension. | 1392 // Verify that the panel that's left is the panel from the second extension. |
| 1390 EXPECT_EQ(panel_other, panel_manager->panels()[0]); | 1393 EXPECT_EQ(panel_other, panel_manager->panels()[0]); |
| 1391 panel_other->Close(); | 1394 panel_other->Close(); |
| 1392 } | 1395 } |
| 1393 | 1396 |
| 1397 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, OnBeforeUnloadOnClose) { | |
| 1398 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 1399 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. | |
| 1400 | |
| 1401 // HTML content with onbeforeunload handler. | |
| 1402 const char* kBeforeUnloadHTML = | |
| 1403 "<html><head><title>beforeunload</title></head><body>" | |
| 1404 "<script>window.onbeforeunload=function(e){return 'foo'}</script>" | |
| 1405 "</body></html>"; | |
| 1406 | |
| 1407 // Create a test panel with tab contents loaded. | |
| 1408 CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 100, 100), | |
| 1409 SHOW_AS_ACTIVE); | |
| 1410 params.url = GURL(std::string("data:text/html,") + kBeforeUnloadHTML); | |
| 1411 Panel* panel = CreatePanelWithParams(params); | |
| 1412 EXPECT_EQ(1, panel_manager->num_panels()); | |
| 1413 | |
| 1414 // Close panel and respond to the onbeforeunload dialog with cancel. This is | |
| 1415 // equivalent to clicking "Stay on this page" | |
| 1416 panel->Close(); | |
| 1417 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | |
| 1418 ui_test_utils::WindowedNotificationObserver signal_cancel( | |
| 1419 content::NOTIFICATION_RENDER_VIEW_HOST_RECEIVED_ON_MSG_SHOULD_CLOSE_ACK, | |
| 1420 content::Source<RenderViewHost>( | |
| 1421 panel->browser()->GetSelectedTabContents()->render_view_host())); | |
| 1422 alert->native_dialog()->CancelAppModalDialog(); | |
| 1423 signal_cancel.Wait(); | |
| 1424 EXPECT_EQ(1, panel_manager->num_panels()); | |
| 1425 | |
| 1426 // Close panel and respond to the onbeforeunload dialog with close. This is | |
| 1427 // equivalent to clicking the OS close button on the dialog. | |
| 1428 panel->Close(); | |
| 1429 alert = ui_test_utils::WaitForAppModalDialog(); | |
| 1430 ui_test_utils::WindowedNotificationObserver signal_close( | |
| 1431 content::NOTIFICATION_RENDER_VIEW_HOST_RECEIVED_ON_MSG_SHOULD_CLOSE_ACK, | |
| 1432 content::Source<RenderViewHost>( | |
| 1433 panel->browser()->GetSelectedTabContents()->render_view_host())); | |
| 1434 alert->native_dialog()->CloseAppModalDialog(); | |
| 1435 signal_close.Wait(); | |
| 1436 EXPECT_EQ(1, panel_manager->num_panels()); | |
| 1437 | |
| 1438 // Close panel and respond to the onbeforeunload dialog with accept. This is | |
| 1439 // equivalent to clicking "Leave this page". | |
| 1440 ui_test_utils::WindowedNotificationObserver panel_deleted( | |
| 1441 chrome::NOTIFICATION_PANEL_DELETED, | |
| 1442 content::Source<Panel>(panel)); | |
| 1443 | |
| 1444 panel->Close(); | |
| 1445 alert = ui_test_utils::WaitForAppModalDialog(); | |
| 1446 ui_test_utils::WindowedNotificationObserver signal_accept( | |
| 1447 content::NOTIFICATION_RENDER_VIEW_HOST_RECEIVED_ON_MSG_SHOULD_CLOSE_ACK, | |
| 1448 content::Source<RenderViewHost>( | |
| 1449 panel->browser()->GetSelectedTabContents()->render_view_host())); | |
| 1450 alert->native_dialog()->AcceptAppModalDialog(); | |
| 1451 signal_accept.Wait(); | |
| 1452 | |
| 1453 panel_deleted.Wait(); | |
| 1454 EXPECT_EQ(0, panel_manager->num_panels()); | |
| 1455 } | |
| 1456 | |
| 1394 class PanelDownloadTest : public PanelBrowserTest { | 1457 class PanelDownloadTest : public PanelBrowserTest { |
| 1395 public: | 1458 public: |
| 1396 PanelDownloadTest() : PanelBrowserTest() { } | 1459 PanelDownloadTest() : PanelBrowserTest() { } |
| 1397 | 1460 |
| 1398 // Creates a temporary directory for downloads that is auto-deleted | 1461 // Creates a temporary directory for downloads that is auto-deleted |
| 1399 // on destruction. | 1462 // on destruction. |
| 1400 bool CreateDownloadDirectory(Profile* profile) { | 1463 bool CreateDownloadDirectory(Profile* profile) { |
| 1401 bool created = downloads_directory_.CreateUniqueTempDir(); | 1464 bool created = downloads_directory_.CreateUniqueTempDir(); |
| 1402 if (!created) | 1465 if (!created) |
| 1403 return false; | 1466 return false; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1558 EXPECT_EQ(1, tabbed_browser->tab_count()); | 1621 EXPECT_EQ(1, tabbed_browser->tab_count()); |
| 1559 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); | 1622 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
| 1560 tabbed_browser->CloseWindow(); | 1623 tabbed_browser->CloseWindow(); |
| 1561 #endif | 1624 #endif |
| 1562 | 1625 |
| 1563 EXPECT_EQ(1, panel_browser->tab_count()); | 1626 EXPECT_EQ(1, panel_browser->tab_count()); |
| 1564 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); | 1627 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
| 1565 | 1628 |
| 1566 panel_browser->CloseWindow(); | 1629 panel_browser->CloseWindow(); |
| 1567 } | 1630 } |
| OLD | NEW |