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

Side by Side Diff: chrome/browser/ui/panels/old_panel_browsertest.cc

Issue 10694145: Remove browser::FindTabbedBrowser from old_panel_browsertest.cc by deleting the tests now that use … (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/utf_string_conversions.h" 6 #include "base/utf_string_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/browser_prefs.h" 10 #include "chrome/browser/prefs/browser_prefs.h"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #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" 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" 14 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_commands.h" 16 #include "chrome/browser/ui/browser_commands.h"
16 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/browser_tabstrip.h" 18 #include "chrome/browser/ui/browser_tabstrip.h"
19 #include "chrome/browser/ui/browser_window.h" 19 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/browser/ui/find_bar/find_bar.h" 20 #include "chrome/browser/ui/find_bar/find_bar.h"
21 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 21 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
22 #include "chrome/browser/ui/panels/old_base_panel_browser_test.h" 22 #include "chrome/browser/ui/panels/old_base_panel_browser_test.h"
23 #include "chrome/browser/ui/panels/docked_panel_strip.h" 23 #include "chrome/browser/ui/panels/docked_panel_strip.h"
24 #include "chrome/browser/ui/panels/native_panel.h" 24 #include "chrome/browser/ui/panels/native_panel.h"
25 #include "chrome/browser/ui/panels/panel.h" 25 #include "chrome/browser/ui/panels/panel.h"
26 #include "chrome/browser/ui/panels/panel_manager.h" 26 #include "chrome/browser/ui/panels/panel_manager.h"
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 ui_test_utils::WindowedNotificationObserver signal( 1403 ui_test_utils::WindowedNotificationObserver signal(
1404 chrome::NOTIFICATION_PANEL_CLOSED, 1404 chrome::NOTIFICATION_PANEL_CLOSED,
1405 content::Source<Panel>(panel)); 1405 content::Source<Panel>(panel));
1406 panel->Close(); 1406 panel->Close();
1407 alert = ui_test_utils::WaitForAppModalDialog(); 1407 alert = ui_test_utils::WaitForAppModalDialog();
1408 alert->native_dialog()->AcceptAppModalDialog(); 1408 alert->native_dialog()->AcceptAppModalDialog();
1409 signal.Wait(); 1409 signal.Wait();
1410 EXPECT_EQ(0, panel_manager->num_panels()); 1410 EXPECT_EQ(0, panel_manager->num_panels());
1411 } 1411 }
1412 1412
1413 // http://crbug.com/126381 - should find a better notification to wait
1414 // for resize completion. Bounds animation could happen for all sorts of
1415 // reasons.
1416 IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest,
1417 DISABLED_CreateWithExistingContents) {
1418 PanelManager::GetInstance()->enable_auto_sizing(true);
1419
1420 // Load contents into regular tabbed browser.
1421 GURL url(ui_test_utils::GetTestUrl(
1422 FilePath(kTestDir),
1423 FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
1424 ui_test_utils::NavigateToURL(browser(), url);
1425 EXPECT_EQ(1, browser()->tab_count());
1426
1427 Profile* profile = browser()->profile();
1428 CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE);
1429 Panel* panel = CreatePanelWithParams(params);
1430 Browser* panel_browser = panel->browser();
1431 EXPECT_EQ(2U, BrowserList::size());
1432
1433 // Swap tab contents over to the panel from the tabbed browser.
1434 TabContents* contents = browser()->tab_strip_model()->DetachTabContentsAt(0);
1435 panel_browser->tab_strip_model()->InsertTabContentsAt(
1436 0, contents, TabStripModel::ADD_NONE);
1437 chrome::SelectNumberedTab(panel_browser, 0);
1438 EXPECT_EQ(contents, chrome::GetActiveTabContents(panel_browser));
1439 EXPECT_EQ(1, PanelManager::GetInstance()->num_panels());
1440
1441 // Ensure that the tab contents were noticed by the panel by
1442 // verifying that the panel auto resizes correctly. (Panel
1443 // enables auto resizing when tab contents are detected.)
1444 int initial_width = panel->GetBounds().width();
1445 ui_test_utils::WindowedNotificationObserver enlarge(
1446 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED,
1447 content::Source<Panel>(panel));
1448 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript(
1449 chrome::GetActiveWebContents(panel_browser)->GetRenderViewHost(),
1450 std::wstring(),
1451 L"changeSize(50);"));
1452 enlarge.Wait();
1453 EXPECT_GT(panel->GetBounds().width(), initial_width);
1454
1455 // Swapping tab contents back to the browser should close the panel.
1456 ui_test_utils::WindowedNotificationObserver signal(
1457 chrome::NOTIFICATION_PANEL_CLOSED,
1458 content::Source<Panel>(panel));
1459 chrome::ConvertPopupToTabbedBrowser(panel_browser);
1460 signal.Wait();
1461 EXPECT_EQ(0, PanelManager::GetInstance()->num_panels());
1462
1463 Browser* tabbed_browser = browser::FindTabbedBrowser(profile, false);
1464 EXPECT_EQ(contents, chrome::GetActiveTabContents(tabbed_browser));
1465 tabbed_browser->window()->Close();
1466 }
1467
1468 IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, SizeClamping) { 1413 IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, SizeClamping) {
1469 // Using '0' sizes is equivalent of not providing sizes in API and causes 1414 // Using '0' sizes is equivalent of not providing sizes in API and causes
1470 // minimum sizes to be applied to facilitate auto-sizing. 1415 // minimum sizes to be applied to facilitate auto-sizing.
1471 CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE); 1416 CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE);
1472 Panel* panel = CreatePanelWithParams(params); 1417 Panel* panel = CreatePanelWithParams(params);
1473 EXPECT_EQ(panel->min_size().width(), panel->GetBounds().width()); 1418 EXPECT_EQ(panel->min_size().width(), panel->GetBounds().width());
1474 EXPECT_EQ(panel->min_size().height(), panel->GetBounds().height()); 1419 EXPECT_EQ(panel->min_size().height(), panel->GetBounds().height());
1475 int reasonable_width = panel->min_size().width() + 10; 1420 int reasonable_width = panel->min_size().width() + 10;
1476 int reasonable_height = panel->min_size().height() + 20; 1421 int reasonable_height = panel->min_size().height() + 20;
1477 1422
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 EXPECT_GE(smaller_work_area_size.width(), panel->max_size().width()); 1525 EXPECT_GE(smaller_work_area_size.width(), panel->max_size().width());
1581 EXPECT_EQ(smaller_work_area_size.height(), panel->max_size().height()); 1526 EXPECT_EQ(smaller_work_area_size.height(), panel->max_size().height());
1582 EXPECT_GT(old_full_size.width(), panel->full_size().width()); 1527 EXPECT_GT(old_full_size.width(), panel->full_size().width());
1583 EXPECT_GT(old_full_size.height(), panel->full_size().height()); 1528 EXPECT_GT(old_full_size.height(), panel->full_size().height());
1584 EXPECT_GE(panel->max_size().width(), panel->full_size().width()); 1529 EXPECT_GE(panel->max_size().width(), panel->full_size().width());
1585 EXPECT_GE(panel->max_size().height(), panel->full_size().height()); 1530 EXPECT_GE(panel->max_size().height(), panel->full_size().height());
1586 EXPECT_EQ(smaller_work_area_size.height(), panel->full_size().height()); 1531 EXPECT_EQ(smaller_work_area_size.height(), panel->full_size().height());
1587 1532
1588 panel->Close(); 1533 panel->Close();
1589 } 1534 }
1590
1591 class OldPanelDownloadTest : public OldPanelBrowserTest {
1592 public:
1593 OldPanelDownloadTest() : OldPanelBrowserTest() { }
1594
1595 // Creates a temporary directory for downloads that is auto-deleted
1596 // on destruction.
1597 bool CreateDownloadDirectory(Profile* profile) {
1598 bool created = downloads_directory_.CreateUniqueTempDir();
1599 if (!created)
1600 return false;
1601 profile->GetPrefs()->SetFilePath(
1602 prefs::kDownloadDefaultDirectory,
1603 downloads_directory_.path());
1604 return true;
1605 }
1606
1607 protected:
1608 void SetUpOnMainThread() OVERRIDE {
1609 OldPanelBrowserTest::SetUpOnMainThread();
1610
1611 BrowserThread::PostTask(
1612 BrowserThread::IO, FROM_HERE,
1613 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
1614 }
1615
1616 private:
1617 // Location of the downloads directory for download tests.
1618 ScopedTempDir downloads_directory_;
1619 };
1620
1621 class DownloadObserver : public content::DownloadManager::Observer {
1622 public:
1623 explicit DownloadObserver(Profile* profile)
1624 : download_manager_(
1625 BrowserContext::GetDownloadManager(profile)),
1626 saw_download_(false),
1627 waiting_(false) {
1628 download_manager_->AddObserver(this);
1629 }
1630
1631 ~DownloadObserver() {
1632 download_manager_->RemoveObserver(this);
1633 }
1634
1635 void WaitForDownload() {
1636 if (!saw_download_) {
1637 waiting_ = true;
1638 ui_test_utils::RunMessageLoop();
1639 EXPECT_TRUE(saw_download_);
1640 waiting_ = false;
1641 }
1642 }
1643
1644 // DownloadManager::Observer
1645 virtual void ModelChanged(DownloadManager* manager) {
1646 DCHECK_EQ(download_manager_, manager);
1647
1648 std::vector<DownloadItem*> downloads;
1649 download_manager_->SearchDownloads(string16(), &downloads);
1650 if (downloads.empty())
1651 return;
1652
1653 EXPECT_EQ(1U, downloads.size());
1654 downloads.front()->Cancel(false); // Don't actually need to download it.
1655
1656 saw_download_ = true;
1657 EXPECT_TRUE(waiting_);
1658 MessageLoopForUI::current()->Quit();
1659 }
1660
1661 private:
1662 DownloadManager* download_manager_;
1663 bool saw_download_;
1664 bool waiting_;
1665 };
1666
1667 // Verify that the download shelf is opened in the existing tabbed browser
1668 // when a download is started in a Panel.
1669 IN_PROC_BROWSER_TEST_F(OldPanelDownloadTest, Download) {
1670 Profile* profile = browser()->profile();
1671 ASSERT_TRUE(CreateDownloadDirectory(profile));
1672 Browser* panel_browser = Browser::CreateWithParams(
1673 Browser::CreateParams::CreateForApp(
1674 Browser::TYPE_PANEL, "PanelTest", gfx::Rect(), profile));
1675 EXPECT_EQ(2U, BrowserList::size());
1676 ASSERT_FALSE(browser()->window()->IsDownloadShelfVisible());
1677 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible());
1678
1679 scoped_ptr<DownloadObserver> observer(new DownloadObserver(profile));
1680 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1681 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
1682 ui_test_utils::NavigateToURLWithDisposition(
1683 panel_browser,
1684 download_url,
1685 CURRENT_TAB,
1686 ui_test_utils::BROWSER_TEST_NONE);
1687 observer->WaitForDownload();
1688
1689 #if defined(OS_CHROMEOS)
1690 // ChromeOS uses a download panel instead of a download shelf.
1691 EXPECT_EQ(3U, BrowserList::size());
1692 ASSERT_FALSE(browser()->window()->IsDownloadShelfVisible());
1693
1694 std::set<Browser*> original_browsers;
1695 original_browsers.insert(browser());
1696 original_browsers.insert(panel_browser);
1697 Browser* added = ui_test_utils::GetBrowserNotInSet(original_browsers);
1698 ASSERT_TRUE(added->is_type_panel());
1699 ASSERT_FALSE(added->window()->IsDownloadShelfVisible());
1700 #else
1701 EXPECT_EQ(2U, BrowserList::size());
1702 ASSERT_TRUE(browser()->window()->IsDownloadShelfVisible());
1703 #endif
1704
1705 EXPECT_EQ(1, browser()->tab_count());
1706 EXPECT_EQ(1, panel_browser->tab_count());
1707 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible());
1708
1709 chrome::CloseWindow(panel_browser);
1710 chrome::CloseWindow(browser());
1711 }
1712
1713 // See crbug 113779.
1714 #if defined(OS_MACOSX)
1715 #define MAYBE_DownloadNoTabbedBrowser DISABLED_DownloadNoTabbedBrowser
1716 #else
1717 #define MAYBE_DownloadNoTabbedBrowser DownloadNoTabbedBrowser
1718 #endif
1719 // Verify that a new tabbed browser is created to display a download
1720 // shelf when a download is started in a Panel and there is no existing
1721 // tabbed browser.
1722 IN_PROC_BROWSER_TEST_F(OldPanelDownloadTest, MAYBE_DownloadNoTabbedBrowser) {
1723 Profile* profile = browser()->profile();
1724 ASSERT_TRUE(CreateDownloadDirectory(profile));
1725 Browser* panel_browser = Browser::CreateWithParams(
1726 Browser::CreateParams::CreateForApp(
1727 Browser::TYPE_PANEL, "PanelTest", gfx::Rect(), profile));
1728 EXPECT_EQ(2U, BrowserList::size());
1729 ASSERT_FALSE(browser()->window()->IsDownloadShelfVisible());
1730 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible());
1731
1732 ui_test_utils::WindowedNotificationObserver signal(
1733 chrome::NOTIFICATION_BROWSER_CLOSED,
1734 content::Source<Browser>(browser()));
1735 chrome::CloseWindow(browser());
1736 signal.Wait();
1737 ASSERT_EQ(1U, BrowserList::size());
1738 ASSERT_EQ(NULL, browser::FindTabbedBrowser(profile, false));
1739
1740 scoped_ptr<DownloadObserver> observer(new DownloadObserver(profile));
1741 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1742 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
1743 ui_test_utils::NavigateToURLWithDisposition(
1744 panel_browser,
1745 download_url,
1746 CURRENT_TAB,
1747 ui_test_utils::BROWSER_TEST_NONE);
1748 observer->WaitForDownload();
1749
1750 EXPECT_EQ(2U, BrowserList::size());
1751
1752 Browser* tabbed_browser = browser::FindTabbedBrowser(profile, false);
1753 EXPECT_EQ(1, tabbed_browser->tab_count());
1754 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible());
1755 chrome::CloseWindow(tabbed_browser);
1756
1757 EXPECT_EQ(1, panel_browser->tab_count());
1758 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible());
1759
1760 chrome::CloseWindow(panel_browser);
1761 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698