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/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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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. |
| 853 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( | 854 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 854 panel->browser()->GetSelectedTabContents()->render_view_host(), | 855 panel->browser()->GetSelectedTabContents()->render_view_host(), |
| 855 std::wstring(), | 856 std::wstring(), |
| 856 L"changeSize(50);")); | 857 L"changeSize(50);")); |
| 857 | 858 |
| 858 // Wait until the bounds get changed. | 859 // Wait until the bounds get changed. |
| 859 gfx::Rect bounds_on_grow; | 860 while (panel->GetBounds() == initial_bounds) { |
|
Paweł Hajdan Jr.
2011/11/14 12:24:33
Ouch, this is generally bad style (running Message
| |
| 860 while ((bounds_on_grow = panel->GetBounds()) == initial_bounds) { | |
| 861 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 861 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
|
Paweł Hajdan Jr.
2011/11/14 12:24:33
By the way, I think this QuitTask is redundant wit
| |
| 862 MessageLoop::current()->RunAllPending(); | 862 MessageLoop::current()->RunAllPending(); |
| 863 } | 863 } |
| 864 WaitForBoundsAnimationFinished(panel); | |
| 865 gfx::Rect bounds_on_grow = panel->GetBounds(); | |
| 864 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); | 866 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); |
| 865 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); | 867 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); |
| 866 | 868 |
| 867 // Shrink the test page. | 869 // Shrink the test page. |
| 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 |
| 873 // Wait until the bounds get changed. | 875 // Wait until the bounds get changed. |
| 874 gfx::Rect bounds_on_shrink; | 876 while (panel->GetBounds() == bounds_on_grow) { |
| 875 while ((bounds_on_shrink = panel->GetBounds()) == bounds_on_grow) { | |
| 876 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 877 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 877 MessageLoop::current()->RunAllPending(); | 878 MessageLoop::current()->RunAllPending(); |
| 878 } | 879 } |
| 880 WaitForBoundsAnimationFinished(panel); | |
| 881 gfx::Rect bounds_on_shrink = panel->GetBounds(); | |
| 879 EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width()); | 882 EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width()); |
| 880 EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width()); | 883 EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width()); |
| 881 EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height()); | 884 EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height()); |
| 882 | 885 |
| 883 panel->Close(); | 886 panel->Close(); |
| 884 } | 887 } |
| 885 | 888 |
| 886 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) { | 889 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) { |
| 887 // Disable mouse watcher. We don't care about mouse movements in this test. | 890 // Disable mouse watcher. We don't care about mouse movements in this test. |
| 888 PanelManager* panel_manager = PanelManager::GetInstance(); | 891 PanelManager* panel_manager = PanelManager::GetInstance(); |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, CreateWithExistingContents) { | |
| 1407 PanelManager::GetInstance()->enable_auto_sizing(true); | |
| 1408 | |
| 1409 // Load contents into regular tabbed browser. | |
| 1410 GURL url(ui_test_utils::GetTestUrl( | |
| 1411 FilePath(FilePath::kCurrentDirectory), | |
| 1412 FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); | |
| 1413 ui_test_utils::NavigateToURL(browser(), url); | |
| 1414 EXPECT_EQ(1, browser()->tab_count()); | |
| 1415 | |
| 1416 Profile* profile = browser()->profile(); | |
| 1417 Browser* panel_browser = Browser::CreateForApp( | |
| 1418 Browser::TYPE_PANEL, "SwapIntoMe", gfx::Rect(0, 0, 100, 100), profile); | |
| 1419 Panel* panel = static_cast<Panel*>(panel_browser->window()); | |
| 1420 EXPECT_EQ(2U, BrowserList::size()); | |
| 1421 | |
| 1422 // Swap tab contents over to the panel from the tabbed browser. | |
| 1423 TabContentsWrapper* contents = | |
| 1424 browser()->tabstrip_model()->DetachTabContentsAt(0); | |
| 1425 panel_browser->tabstrip_model()->InsertTabContentsAt( | |
| 1426 0, contents, TabStripModel::ADD_NONE); | |
| 1427 panel_browser->SelectNumberedTab(0); | |
| 1428 MessageLoopForUI::current()->RunAllPending(); | |
| 1429 EXPECT_EQ(contents, panel_browser->GetSelectedTabContentsWrapper()); | |
| 1430 EXPECT_EQ(1, PanelManager::GetInstance()->num_panels()); | |
| 1431 | |
| 1432 panel->Show(); | |
| 1433 WaitForWindowSizeAvailable(panel); | |
| 1434 WaitForBoundsAnimationFinished(panel); | |
| 1435 | |
| 1436 // Ensure that the tab contents were noticed by the panel by | |
| 1437 // verifying that the panel auto resizes correctly. (Panel | |
| 1438 // enables auto resizing when tab contents are detected.) | |
| 1439 gfx::Rect initial_bounds = panel->GetBounds(); | |
| 1440 EXPECT_LE(100, initial_bounds.width()); | |
| 1441 EXPECT_LE(100, initial_bounds.height()); | |
| 1442 | |
| 1443 // Expand the test page. | |
| 1444 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( | |
| 1445 panel_browser->GetSelectedTabContents()->render_view_host(), | |
| 1446 std::wstring(), | |
| 1447 L"changeSize(50);")); | |
| 1448 while (panel->GetBounds() == initial_bounds) { | |
|
Paweł Hajdan Jr.
2011/11/14 12:24:33
Ah, and here the bad code is being repeated. This
| |
| 1449 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | |
| 1450 MessageLoop::current()->RunAllPending(); | |
| 1451 } | |
| 1452 WaitForBoundsAnimationFinished(panel); | |
| 1453 gfx::Rect bounds_on_grow = panel->GetBounds(); | |
| 1454 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); | |
| 1455 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); | |
| 1456 | |
| 1457 // Swapping tab contents back to the browser should close the panel. | |
| 1458 ui_test_utils::WindowedNotificationObserver signal( | |
| 1459 chrome::NOTIFICATION_BROWSER_CLOSED, | |
| 1460 content::Source<Browser>(panel_browser)); | |
| 1461 panel_browser->ConvertPopupToTabbedBrowser(); | |
| 1462 signal.Wait(); | |
| 1463 EXPECT_EQ(0, PanelManager::GetInstance()->num_panels()); | |
| 1464 | |
| 1465 Browser* tabbed_browser = BrowserList::FindTabbedBrowser(profile, false); | |
| 1466 EXPECT_EQ(contents, tabbed_browser->GetSelectedTabContentsWrapper()); | |
| 1467 tabbed_browser->window()->Close(); | |
| 1468 } | |
| 1469 | |
| 1403 class PanelDownloadTest : public PanelBrowserTest { | 1470 class PanelDownloadTest : public PanelBrowserTest { |
| 1404 public: | 1471 public: |
| 1405 PanelDownloadTest() : PanelBrowserTest() { } | 1472 PanelDownloadTest() : PanelBrowserTest() { } |
| 1406 | 1473 |
| 1407 // Creates a temporary directory for downloads that is auto-deleted | 1474 // Creates a temporary directory for downloads that is auto-deleted |
| 1408 // on destruction. | 1475 // on destruction. |
| 1409 bool CreateDownloadDirectory(Profile* profile) { | 1476 bool CreateDownloadDirectory(Profile* profile) { |
| 1410 bool created = downloads_directory_.CreateUniqueTempDir(); | 1477 bool created = downloads_directory_.CreateUniqueTempDir(); |
| 1411 if (!created) | 1478 if (!created) |
| 1412 return false; | 1479 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. | 1784 // the same position when short panel is first created. |
| 1718 panel1->SetExpansionState(Panel::EXPANDED); | 1785 panel1->SetExpansionState(Panel::EXPANDED); |
| 1719 WaitForBoundsAnimationFinished(panel1); | 1786 WaitForBoundsAnimationFinished(panel1); |
| 1720 int balloon_bottom_after_short_panel_expanded = | 1787 int balloon_bottom_after_short_panel_expanded = |
| 1721 GetBalloonBottomPosition(balloon); | 1788 GetBalloonBottomPosition(balloon); |
| 1722 EXPECT_EQ(balloon_bottom_after_short_panel_created, | 1789 EXPECT_EQ(balloon_bottom_after_short_panel_created, |
| 1723 balloon_bottom_after_short_panel_expanded); | 1790 balloon_bottom_after_short_panel_expanded); |
| 1724 | 1791 |
| 1725 // Closing short panel should move the notification balloon down to the same | 1792 // Closing short panel should move the notification balloon down to the same |
| 1726 // position when tall panel brings up its titlebar. | 1793 // position when tall panel brings up its titlebar. |
| 1727 panel1->Close(); | 1794 CloseWindowAndWait(panel1->browser()); |
| 1728 WaitForBoundsAnimationFinished(panel1); | |
| 1729 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, | 1795 EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, |
| 1730 GetBalloonBottomPosition(balloon)); | 1796 GetBalloonBottomPosition(balloon)); |
| 1731 | 1797 |
| 1732 // Closing the remaining tall panel should move the notification balloon back | 1798 // Closing the remaining tall panel should move the notification balloon back |
| 1733 // to its original position. | 1799 // to its original position. |
| 1734 panel2->Close(); | 1800 CloseWindowAndWait(panel2->browser()); |
| 1735 WaitForBoundsAnimationFinished(panel2); | |
| 1736 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); | 1801 EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); |
| 1737 } | 1802 } |
| OLD | NEW |