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/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/tabs/tab_strip_model.h" |
19 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
20 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/find_bar/find_bar.h" | 22 #include "chrome/browser/ui/find_bar/find_bar.h" |
22 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 23 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
23 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | 24 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
24 #include "chrome/browser/ui/panels/native_panel.h" | 25 #include "chrome/browser/ui/panels/native_panel.h" |
25 #include "chrome/browser/ui/panels/panel.h" | 26 #include "chrome/browser/ui/panels/panel.h" |
26 #include "chrome/browser/ui/panels/panel_manager.h" | 27 #include "chrome/browser/ui/panels/panel_manager.h" |
27 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" | 28 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" |
28 #include "chrome/browser/web_applications/web_app.h" | 29 #include "chrome/browser/web_applications/web_app.h" |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 const FilePath::CharType* kUpdateSizeTestFile = | 844 const FilePath::CharType* kUpdateSizeTestFile = |
844 FILE_PATH_LITERAL("update-preferred-size.html"); | 845 FILE_PATH_LITERAL("update-preferred-size.html"); |
845 ui_test_utils::NavigateToURL(panel->browser(), | 846 ui_test_utils::NavigateToURL(panel->browser(), |
846 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 847 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
847 FilePath(kUpdateSizeTestFile))); | 848 FilePath(kUpdateSizeTestFile))); |
848 gfx::Rect initial_bounds = panel->GetBounds(); | 849 gfx::Rect initial_bounds = panel->GetBounds(); |
849 EXPECT_LE(100, initial_bounds.width()); | 850 EXPECT_LE(100, initial_bounds.width()); |
850 EXPECT_LE(100, initial_bounds.height()); | 851 EXPECT_LE(100, initial_bounds.height()); |
851 | 852 |
852 // Expand the test page. | 853 // Expand the test page. |
| 854 ui_test_utils::WindowedNotificationObserver enlarge( |
| 855 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 856 content::Source<Panel>(panel)); |
853 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( | 857 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
854 panel->browser()->GetSelectedTabContents()->render_view_host(), | 858 panel->browser()->GetSelectedTabContents()->render_view_host(), |
855 std::wstring(), | 859 std::wstring(), |
856 L"changeSize(50);")); | 860 L"changeSize(50);")); |
857 | 861 enlarge.Wait(); |
858 // Wait until the bounds get changed. | 862 gfx::Rect bounds_on_grow = panel->GetBounds(); |
859 gfx::Rect bounds_on_grow; | |
860 while ((bounds_on_grow = panel->GetBounds()) == initial_bounds) { | |
861 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | |
862 MessageLoop::current()->RunAllPending(); | |
863 } | |
864 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); | 863 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); |
865 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); | 864 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); |
866 | 865 |
867 // Shrink the test page. | 866 // Shrink the test page. |
| 867 ui_test_utils::WindowedNotificationObserver shrink( |
| 868 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 869 content::Source<Panel>(panel)); |
868 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( | 870 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
869 panel->browser()->GetSelectedTabContents()->render_view_host(), | 871 panel->browser()->GetSelectedTabContents()->render_view_host(), |
870 std::wstring(), | 872 std::wstring(), |
871 L"changeSize(-30);")); | 873 L"changeSize(-30);")); |
872 | 874 shrink.Wait(); |
873 // Wait until the bounds get changed. | 875 gfx::Rect bounds_on_shrink = panel->GetBounds(); |
874 gfx::Rect bounds_on_shrink; | |
875 while ((bounds_on_shrink = panel->GetBounds()) == bounds_on_grow) { | |
876 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | |
877 MessageLoop::current()->RunAllPending(); | |
878 } | |
879 EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width()); | 876 EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width()); |
880 EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width()); | 877 EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width()); |
881 EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height()); | 878 EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height()); |
882 | 879 |
883 panel->Close(); | 880 panel->Close(); |
884 } | 881 } |
885 | 882 |
886 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) { | 883 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) { |
887 // Disable mouse watcher. We don't care about mouse movements in this test. | 884 // Disable mouse watcher. We don't care about mouse movements in this test. |
888 PanelManager* panel_manager = PanelManager::GetInstance(); | 885 PanelManager* panel_manager = PanelManager::GetInstance(); |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 | 1390 |
1394 // Wait for the panels opened by the first extension to close. | 1391 // Wait for the panels opened by the first extension to close. |
1395 signal.Wait(); | 1392 signal.Wait(); |
1396 signal1.Wait(); | 1393 signal1.Wait(); |
1397 | 1394 |
1398 // Verify that the panel that's left is the panel from the second extension. | 1395 // Verify that the panel that's left is the panel from the second extension. |
1399 EXPECT_EQ(panel_other, panel_manager->panels()[0]); | 1396 EXPECT_EQ(panel_other, panel_manager->panels()[0]); |
1400 panel_other->Close(); | 1397 panel_other->Close(); |
1401 } | 1398 } |
1402 | 1399 |
| 1400 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateWithExistingContents) { |
| 1401 PanelManager::GetInstance()->enable_auto_sizing(true); |
| 1402 |
| 1403 // Load contents into regular tabbed browser. |
| 1404 GURL url(ui_test_utils::GetTestUrl( |
| 1405 FilePath(FilePath::kCurrentDirectory), |
| 1406 FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); |
| 1407 ui_test_utils::NavigateToURL(browser(), url); |
| 1408 EXPECT_EQ(1, browser()->tab_count()); |
| 1409 |
| 1410 Profile* profile = browser()->profile(); |
| 1411 CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 100, 100), |
| 1412 SHOW_AS_ACTIVE); |
| 1413 Panel* panel = CreatePanelWithParams(params); |
| 1414 Browser* panel_browser = panel->browser(); |
| 1415 EXPECT_EQ(2U, BrowserList::size()); |
| 1416 |
| 1417 // Swap tab contents over to the panel from the tabbed browser. |
| 1418 TabContentsWrapper* contents = |
| 1419 browser()->tabstrip_model()->DetachTabContentsAt(0); |
| 1420 panel_browser->tabstrip_model()->InsertTabContentsAt( |
| 1421 0, contents, TabStripModel::ADD_NONE); |
| 1422 panel_browser->SelectNumberedTab(0); |
| 1423 EXPECT_EQ(contents, panel_browser->GetSelectedTabContentsWrapper()); |
| 1424 EXPECT_EQ(1, PanelManager::GetInstance()->num_panels()); |
| 1425 |
| 1426 // Ensure that the tab contents were noticed by the panel by |
| 1427 // verifying that the panel auto resizes correctly. (Panel |
| 1428 // enables auto resizing when tab contents are detected.) |
| 1429 int initial_width = panel->GetBounds().width(); |
| 1430 EXPECT_LE(100, initial_width); |
| 1431 |
| 1432 // Expand the test page. |
| 1433 ui_test_utils::WindowedNotificationObserver enlarge( |
| 1434 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 1435 content::Source<Panel>(panel)); |
| 1436 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 1437 panel_browser->GetSelectedTabContents()->render_view_host(), |
| 1438 std::wstring(), |
| 1439 L"changeSize(50);")); |
| 1440 enlarge.Wait(); |
| 1441 EXPECT_GT(panel->GetBounds().width(), initial_width); |
| 1442 |
| 1443 // Swapping tab contents back to the browser should close the panel. |
| 1444 ui_test_utils::WindowedNotificationObserver signal( |
| 1445 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 1446 content::Source<Browser>(panel_browser)); |
| 1447 panel_browser->ConvertPopupToTabbedBrowser(); |
| 1448 signal.Wait(); |
| 1449 EXPECT_EQ(0, PanelManager::GetInstance()->num_panels()); |
| 1450 |
| 1451 Browser* tabbed_browser = BrowserList::FindTabbedBrowser(profile, false); |
| 1452 EXPECT_EQ(contents, tabbed_browser->GetSelectedTabContentsWrapper()); |
| 1453 tabbed_browser->window()->Close(); |
| 1454 } |
| 1455 |
1403 class PanelDownloadTest : public PanelBrowserTest { | 1456 class PanelDownloadTest : public PanelBrowserTest { |
1404 public: | 1457 public: |
1405 PanelDownloadTest() : PanelBrowserTest() { } | 1458 PanelDownloadTest() : PanelBrowserTest() { } |
1406 | 1459 |
1407 // Creates a temporary directory for downloads that is auto-deleted | 1460 // Creates a temporary directory for downloads that is auto-deleted |
1408 // on destruction. | 1461 // on destruction. |
1409 bool CreateDownloadDirectory(Profile* profile) { | 1462 bool CreateDownloadDirectory(Profile* profile) { |
1410 bool created = downloads_directory_.CreateUniqueTempDir(); | 1463 bool created = downloads_directory_.CreateUniqueTempDir(); |
1411 if (!created) | 1464 if (!created) |
1412 return false; | 1465 return false; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1717 // the same position when short panel is first created. | 1770 // the same position when short panel is first created. |
1718 panel1->SetExpansionState(Panel::EXPANDED); | 1771 panel1->SetExpansionState(Panel::EXPANDED); |
1719 WaitForBoundsAnimationFinished(panel1); | 1772 WaitForBoundsAnimationFinished(panel1); |
1720 int balloon_bottom_after_short_panel_expanded = | 1773 int balloon_bottom_after_short_panel_expanded = |
1721 GetBalloonBottomPosition(balloon); | 1774 GetBalloonBottomPosition(balloon); |
1722 EXPECT_EQ(balloon_bottom_after_short_panel_created, | 1775 EXPECT_EQ(balloon_bottom_after_short_panel_created, |
1723 balloon_bottom_after_short_panel_expanded); | 1776 balloon_bottom_after_short_panel_expanded); |
1724 | 1777 |
1725 // 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 |
1726 // position when tall panel brings up its titlebar. | 1779 // position when tall panel brings up its titlebar. |
1727 panel1->Close(); | 1780 CloseWindowAndWait(panel1->browser()); |
1728 WaitForBoundsAnimationFinished(panel1); | |
1729 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, | 1781 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, |
1730 GetBalloonBottomPosition(balloon)); | 1782 GetBalloonBottomPosition(balloon)); |
1731 | 1783 |
1732 // Closing the remaining tall panel should move the notification balloon back | 1784 // Closing the remaining tall panel should move the notification balloon back |
1733 // to its original position. | 1785 // to its original position. |
1734 panel2->Close(); | 1786 CloseWindowAndWait(panel2->browser()); |
1735 WaitForBoundsAnimationFinished(panel2); | |
1736 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); | 1787 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); |
1737 } | 1788 } |
OLD | NEW |