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 "chrome/browser/download/download_service.h" | 7 #include "chrome/browser/download/download_service.h" |
| 8 #include "chrome/browser/download/download_service_factory.h" | 8 #include "chrome/browser/download/download_service_factory.h" |
| 9 #include "chrome/browser/net/url_request_mock_util.h" | 9 #include "chrome/browser/net/url_request_mock_util.h" |
| 10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/tabs/tab_strip_model.h" | |
| 12 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/find_bar/find_bar.h" | 15 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 15 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 16 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 16 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | 17 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
| 17 #include "chrome/browser/ui/panels/native_panel.h" | 18 #include "chrome/browser/ui/panels/native_panel.h" |
| 18 #include "chrome/browser/ui/panels/panel.h" | 19 #include "chrome/browser/ui/panels/panel.h" |
| 19 #include "chrome/browser/ui/panels/panel_manager.h" | 20 #include "chrome/browser/ui/panels/panel_manager.h" |
| 20 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" | 21 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" |
| 21 #include "chrome/browser/web_applications/web_app.h" | 22 #include "chrome/browser/web_applications/web_app.h" |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 EXPECT_LE(100, initial_bounds.width()); | 841 EXPECT_LE(100, initial_bounds.width()); |
| 841 EXPECT_LE(100, initial_bounds.height()); | 842 EXPECT_LE(100, initial_bounds.height()); |
| 842 | 843 |
| 843 // Expand the test page. | 844 // Expand the test page. |
| 844 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( | 845 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 845 panel->browser()->GetSelectedTabContents()->render_view_host(), | 846 panel->browser()->GetSelectedTabContents()->render_view_host(), |
| 846 std::wstring(), | 847 std::wstring(), |
| 847 L"changeSize(50);")); | 848 L"changeSize(50);")); |
| 848 | 849 |
| 849 // Wait until the bounds get changed. | 850 // Wait until the bounds get changed. |
| 850 gfx::Rect bounds_on_grow; | 851 while (panel->GetBounds() == initial_bounds) { |
| 851 while ((bounds_on_grow = panel->GetBounds()) == initial_bounds) { | |
| 852 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 852 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 853 MessageLoop::current()->RunAllPending(); | 853 MessageLoop::current()->RunAllPending(); |
| 854 } | 854 } |
| 855 WaitForBoundsAnimationFinished(panel); | |
| 856 gfx::Rect bounds_on_grow = panel->GetBounds(); | |
| 855 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); | 857 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); |
| 856 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); | 858 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); |
| 857 | 859 |
| 858 // Shrink the test page. | 860 // Shrink the test page. |
| 859 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( | 861 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 860 panel->browser()->GetSelectedTabContents()->render_view_host(), | 862 panel->browser()->GetSelectedTabContents()->render_view_host(), |
| 861 std::wstring(), | 863 std::wstring(), |
| 862 L"changeSize(-30);")); | 864 L"changeSize(-30);")); |
| 863 | 865 |
| 864 // Wait until the bounds get changed. | 866 // Wait until the bounds get changed. |
| 865 gfx::Rect bounds_on_shrink; | 867 while (panel->GetBounds() == bounds_on_grow) { |
| 866 while ((bounds_on_shrink = panel->GetBounds()) == bounds_on_grow) { | |
| 867 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 868 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 868 MessageLoop::current()->RunAllPending(); | 869 MessageLoop::current()->RunAllPending(); |
| 869 } | 870 } |
| 871 WaitForBoundsAnimationFinished(panel); | |
| 872 gfx::Rect bounds_on_shrink = panel->GetBounds(); | |
| 870 EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width()); | 873 EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width()); |
| 871 EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width()); | 874 EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width()); |
| 872 EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height()); | 875 EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height()); |
| 873 | 876 |
| 874 panel->Close(); | 877 panel->Close(); |
| 875 } | 878 } |
| 876 | 879 |
| 877 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) { | 880 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) { |
| 878 // Disable mouse watcher. We don't care about mouse movements in this test. | 881 // Disable mouse watcher. We don't care about mouse movements in this test. |
| 879 PanelManager* panel_manager = PanelManager::GetInstance(); | 882 PanelManager* panel_manager = PanelManager::GetInstance(); |
| (...skipping 504 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, CreateWithExistingContents) { | |
| 1398 PanelManager::GetInstance()->enable_auto_sizing(true); | |
| 1399 | |
| 1400 // Load contents into regular tabbed browser. | |
| 1401 GURL url(ui_test_utils::GetTestUrl( | |
| 1402 FilePath(FilePath::kCurrentDirectory), | |
| 1403 FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); | |
| 1404 ui_test_utils::NavigateToURL(browser(), url); | |
| 1405 EXPECT_EQ(1, browser()->tab_count()); | |
| 1406 | |
| 1407 Profile* profile = browser()->profile(); | |
| 1408 Browser* panel_browser = Browser::CreateForApp( | |
| 1409 Browser::TYPE_PANEL, "SwapIntoMe", gfx::Rect(0, 0, 100, 100), profile); | |
| 1410 Panel* panel = static_cast<Panel*>(panel_browser->window()); | |
| 1411 EXPECT_EQ(2U, BrowserList::size()); | |
| 1412 | |
| 1413 // Swap tab contents over to the panel from the browser. | |
|
jianli
2011/11/11 22:31:23
browser => tabbed browser
jennb
2011/11/11 22:42:50
Done.
| |
| 1414 TabContentsWrapper* contents = | |
| 1415 browser()->tabstrip_model()->DetachTabContentsAt(0); | |
| 1416 panel_browser->tabstrip_model()->InsertTabContentsAt( | |
| 1417 0, contents, TabStripModel::ADD_NONE); | |
| 1418 panel_browser->SelectNumberedTab(0); | |
| 1419 MessageLoopForUI::current()->RunAllPending(); | |
| 1420 EXPECT_EQ(contents, panel_browser->GetSelectedTabContentsWrapper()); | |
| 1421 EXPECT_EQ(1, PanelManager::GetInstance()->num_panels()); | |
| 1422 | |
| 1423 panel->Show(); | |
| 1424 WaitForWindowSizeAvailable(panel); | |
| 1425 WaitForBoundsAnimationFinished(panel); | |
| 1426 | |
| 1427 // Ensure that the tab contents were noticed by the panel by | |
| 1428 // verifying that the panel auto resizes correctly. (Panel | |
| 1429 // enables auto resizing when tab contents are detected.) | |
| 1430 gfx::Rect initial_bounds = panel->GetBounds(); | |
| 1431 EXPECT_LE(100, initial_bounds.width()); | |
| 1432 EXPECT_LE(100, initial_bounds.height()); | |
| 1433 | |
| 1434 // Expand the test page. | |
| 1435 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( | |
| 1436 panel_browser->GetSelectedTabContents()->render_view_host(), | |
| 1437 std::wstring(), | |
| 1438 L"changeSize(50);")); | |
| 1439 while (panel->GetBounds() == initial_bounds) { | |
| 1440 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | |
| 1441 MessageLoop::current()->RunAllPending(); | |
| 1442 } | |
| 1443 WaitForBoundsAnimationFinished(panel); | |
| 1444 gfx::Rect bounds_on_grow = panel->GetBounds(); | |
| 1445 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); | |
| 1446 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); | |
| 1447 | |
| 1448 // Swapping tab contents back to the browser should close the panel. | |
| 1449 ui_test_utils::WindowedNotificationObserver signal( | |
| 1450 chrome::NOTIFICATION_BROWSER_CLOSED, | |
| 1451 content::Source<Browser>(panel_browser)); | |
| 1452 panel_browser->ConvertPopupToTabbedBrowser(); | |
| 1453 signal.Wait(); | |
| 1454 EXPECT_EQ(0, PanelManager::GetInstance()->num_panels()); | |
| 1455 | |
| 1456 Browser* tabbed_browser = BrowserList::FindTabbedBrowser(profile, false); | |
| 1457 EXPECT_EQ(contents, tabbed_browser->GetSelectedTabContentsWrapper()); | |
| 1458 tabbed_browser->window()->Close(); | |
| 1459 } | |
| 1460 | |
| 1394 class PanelDownloadTest : public PanelBrowserTest { | 1461 class PanelDownloadTest : public PanelBrowserTest { |
| 1395 public: | 1462 public: |
| 1396 PanelDownloadTest() : PanelBrowserTest() { } | 1463 PanelDownloadTest() : PanelBrowserTest() { } |
| 1397 | 1464 |
| 1398 // Creates a temporary directory for downloads that is auto-deleted | 1465 // Creates a temporary directory for downloads that is auto-deleted |
| 1399 // on destruction. | 1466 // on destruction. |
| 1400 bool CreateDownloadDirectory(Profile* profile) { | 1467 bool CreateDownloadDirectory(Profile* profile) { |
| 1401 bool created = downloads_directory_.CreateUniqueTempDir(); | 1468 bool created = downloads_directory_.CreateUniqueTempDir(); |
| 1402 if (!created) | 1469 if (!created) |
| 1403 return false; | 1470 return false; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1558 EXPECT_EQ(1, tabbed_browser->tab_count()); | 1625 EXPECT_EQ(1, tabbed_browser->tab_count()); |
| 1559 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); | 1626 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
| 1560 tabbed_browser->CloseWindow(); | 1627 tabbed_browser->CloseWindow(); |
| 1561 #endif | 1628 #endif |
| 1562 | 1629 |
| 1563 EXPECT_EQ(1, panel_browser->tab_count()); | 1630 EXPECT_EQ(1, panel_browser->tab_count()); |
| 1564 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); | 1631 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
| 1565 | 1632 |
| 1566 panel_browser->CloseWindow(); | 1633 panel_browser->CloseWindow(); |
| 1567 } | 1634 } |
| OLD | NEW |