| Index: chrome/browser/printing/print_preview_tab_controller_browsertest.cc
|
| ===================================================================
|
| --- chrome/browser/printing/print_preview_tab_controller_browsertest.cc (revision 110066)
|
| +++ chrome/browser/printing/print_preview_tab_controller_browsertest.cc (working copy)
|
| @@ -2,74 +2,53 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "base/command_line.h"
|
| #include "chrome/browser/printing/print_preview_tab_controller.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_list.h"
|
| #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/url_constants.h"
|
| #include "chrome/test/base/in_process_browser_test.h"
|
| #include "chrome/test/base/ui_test_utils.h"
|
| #include "content/browser/tab_contents/tab_contents.h"
|
| +#include "content/browser/tab_contents/tab_contents_observer.h"
|
| +#include "content/public/browser/notification_service.h"
|
| +#include "content/public/browser/notification_types.h"
|
| #include "googleurl/src/gurl.h"
|
|
|
| namespace {
|
|
|
| -typedef InProcessBrowserTest PrintPreviewTabControllerBrowserTest;
|
| +class PrintPreviewTabControllerBrowserTest : public InProcessBrowserTest {
|
| + public:
|
| + PrintPreviewTabControllerBrowserTest() {}
|
| + virtual ~PrintPreviewTabControllerBrowserTest() {}
|
|
|
| -// Test to verify that when a preview tab navigates, we can create a new print
|
| -// preview tab for both initiator tab and new preview tab contents.
|
| -IN_PROC_BROWSER_TEST_F(PrintPreviewTabControllerBrowserTest,
|
| - NavigateFromPrintPreviewTab) {
|
| - ASSERT_TRUE(browser());
|
| - BrowserList::SetLastActive(browser());
|
| - ASSERT_TRUE(BrowserList::GetLastActive());
|
| + virtual void SetUpCommandLine(CommandLine* command_line) {
|
| + command_line->AppendSwitch(switches::kEnablePrintPreview);
|
| + }
|
| +};
|
|
|
| - // Lets start with one window with one tab.
|
| - EXPECT_EQ(1u, BrowserList::size());
|
| - EXPECT_EQ(1, browser()->tab_count());
|
| +class TabDestroyedObserver : public TabContentsObserver {
|
| + public:
|
| + explicit TabDestroyedObserver(TabContents* contents)
|
| + : TabContentsObserver(contents),
|
| + tab_destroyed_(false) {
|
| + }
|
| + virtual ~TabDestroyedObserver() {}
|
|
|
| - // Create a reference to initiator tab contents.
|
| - TabContentsWrapper* initiator_tab =
|
| - browser()->GetSelectedTabContentsWrapper();
|
| - ASSERT_TRUE(initiator_tab);
|
| + bool tab_destroyed() { return tab_destroyed_; }
|
|
|
| - scoped_refptr<printing::PrintPreviewTabController>
|
| - tab_controller(new printing::PrintPreviewTabController());
|
| - ASSERT_TRUE(tab_controller);
|
| + private:
|
| + virtual void TabContentsDestroyed(TabContents* tab) {
|
| + tab_destroyed_ = true;
|
| + }
|
|
|
| - // Get the preview tab for initiator tab.
|
| - TabContentsWrapper* preview_tab =
|
| - tab_controller->GetOrCreatePreviewTab(initiator_tab);
|
| + bool tab_destroyed_;
|
| +};
|
|
|
| - // New print preview tab is created. Current focus is on preview tab.
|
| - EXPECT_EQ(2, browser()->tab_count());
|
| - EXPECT_NE(initiator_tab, preview_tab);
|
| -
|
| - GURL url(chrome::kAboutBlankURL);
|
| - ui_test_utils::NavigateToURL(browser(), url);
|
| - EXPECT_EQ(url, preview_tab->tab_contents()->GetURL());
|
| -
|
| - // Get the print preview tab for initiator tab.
|
| - TabContentsWrapper* new_preview_tab =
|
| - tab_controller->GetOrCreatePreviewTab(initiator_tab);
|
| -
|
| - // New preview tab is created.
|
| - EXPECT_EQ(3, browser()->tab_count());
|
| - EXPECT_NE(new_preview_tab, preview_tab);
|
| -
|
| - // Get the print preview tab for old preview tab.
|
| - TabContentsWrapper* newest_preview_tab =
|
| - tab_controller->GetOrCreatePreviewTab(preview_tab);
|
| -
|
| - // Newest preview tab is created and the previously created preview tab is not
|
| - // merely activated.
|
| - EXPECT_EQ(4, browser()->tab_count());
|
| - EXPECT_NE(newest_preview_tab, new_preview_tab);
|
| -}
|
| -
|
| // Test to verify that when a initiator tab navigates, we can create a new
|
| -// preview tab for the new tab contents. But we cannot create a preview tab for
|
| -// the old preview tab.
|
| +// preview tab for the new tab contents.
|
| IN_PROC_BROWSER_TEST_F(PrintPreviewTabControllerBrowserTest,
|
| NavigateFromInitiatorTab) {
|
| ASSERT_TRUE(browser());
|
| @@ -85,44 +64,39 @@
|
| browser()->GetSelectedTabContentsWrapper();
|
| ASSERT_TRUE(initiator_tab);
|
|
|
| - scoped_refptr<printing::PrintPreviewTabController>
|
| - tab_controller(new printing::PrintPreviewTabController());
|
| + printing::PrintPreviewTabController* tab_controller =
|
| + printing::PrintPreviewTabController::GetInstance();
|
| ASSERT_TRUE(tab_controller);
|
|
|
| // Get the preview tab for initiator tab.
|
| TabContentsWrapper* preview_tab =
|
| tab_controller->GetOrCreatePreviewTab(initiator_tab);
|
|
|
| - // New print preview tab is created. Current focus is on preview tab.
|
| - EXPECT_EQ(2, browser()->tab_count());
|
| - EXPECT_NE(initiator_tab, preview_tab);
|
| + // New print preview tab is created.
|
| + EXPECT_EQ(1, browser()->tab_count());
|
| + ASSERT_TRUE(preview_tab);
|
| + ASSERT_NE(initiator_tab, preview_tab);
|
| + TabDestroyedObserver observer(preview_tab->tab_contents());
|
|
|
| - // Activate initiator tab.
|
| - browser()->ActivateTabAt(0, true);
|
| + // Navigate in the initiator tab.
|
| GURL url(chrome::kChromeUINewTabURL);
|
| ui_test_utils::NavigateToURL(browser(), url);
|
|
|
| + ASSERT_TRUE(observer.tab_destroyed());
|
| +
|
| // Get the print preview tab for initiator tab.
|
| TabContentsWrapper* new_preview_tab =
|
| tab_controller->GetOrCreatePreviewTab(initiator_tab);
|
|
|
| // New preview tab is created.
|
| - EXPECT_EQ(3, browser()->tab_count());
|
| - EXPECT_NE(new_preview_tab, preview_tab);
|
| -
|
| - // Get the print preview tab for old preview tab.
|
| - TabContentsWrapper* newest_preview_tab =
|
| - tab_controller->GetOrCreatePreviewTab(preview_tab);
|
| -
|
| - // Make sure preview tab is not created for |preview_tab|.
|
| - EXPECT_EQ(3, browser()->tab_count());
|
| - EXPECT_EQ(newest_preview_tab, preview_tab);
|
| + EXPECT_EQ(1, browser()->tab_count());
|
| + EXPECT_TRUE(new_preview_tab);
|
| }
|
|
|
| -// Test to verify that even after reloading initiator tab and preview tab,
|
| -// their association exists.
|
| +// Test to verify that after reloading the initiator tab, it creates a new
|
| +// print preview tab.
|
| IN_PROC_BROWSER_TEST_F(PrintPreviewTabControllerBrowserTest,
|
| - ReloadInitiatorTabAndPreviewTab) {
|
| + ReloadInitiatorTab) {
|
| ASSERT_TRUE(browser());
|
| BrowserList::SetLastActive(browser());
|
| ASSERT_TRUE(BrowserList::GetLastActive());
|
| @@ -136,119 +110,35 @@
|
| browser()->GetSelectedTabContentsWrapper();
|
| ASSERT_TRUE(initiator_tab);
|
|
|
| - scoped_refptr<printing::PrintPreviewTabController>
|
| - tab_controller(new printing::PrintPreviewTabController());
|
| + printing::PrintPreviewTabController* tab_controller =
|
| + printing::PrintPreviewTabController::GetInstance();
|
| ASSERT_TRUE(tab_controller);
|
|
|
| // Get the preview tab for initiator tab.
|
| TabContentsWrapper* preview_tab =
|
| tab_controller->GetOrCreatePreviewTab(initiator_tab);
|
|
|
| - // New print preview tab is created. Current focus is on preview tab.
|
| - EXPECT_EQ(2, browser()->tab_count());
|
| - EXPECT_NE(initiator_tab, preview_tab);
|
| + // New print preview tab is created.
|
| + EXPECT_EQ(1, browser()->tab_count());
|
| + ASSERT_TRUE(preview_tab);
|
| + ASSERT_NE(initiator_tab, preview_tab);
|
| + TabDestroyedObserver tab_destroyed_observer(preview_tab->tab_contents());
|
|
|
| - // Activate initiator tab and reload.
|
| - browser()->ActivateTabAt(0, true);
|
| + // Reload the initiator tab.
|
| + ui_test_utils::WindowedNotificationObserver notification_observer(
|
| + content::NOTIFICATION_LOAD_STOP,
|
| + content::NotificationService::AllSources());
|
| browser()->Reload(CURRENT_TAB);
|
| + notification_observer.Wait();
|
|
|
| + ASSERT_TRUE(tab_destroyed_observer.tab_destroyed());
|
| +
|
| // Get the print preview tab for initiator tab.
|
| TabContentsWrapper* new_preview_tab =
|
| tab_controller->GetOrCreatePreviewTab(initiator_tab);
|
|
|
| - // Old preview tab is activated.
|
| - EXPECT_EQ(2, browser()->tab_count());
|
| - EXPECT_EQ(new_preview_tab, preview_tab);
|
| -
|
| - // Reload preview tab.
|
| - browser()->Reload(CURRENT_TAB);
|
| - // Get the print preview tab for old preview tab.
|
| - TabContentsWrapper* newest_preview_tab =
|
| - tab_controller->GetOrCreatePreviewTab(preview_tab);
|
| -
|
| - // Make sure new preview tab is not created for |preview_tab|.
|
| - EXPECT_EQ(2, browser()->tab_count());
|
| - EXPECT_EQ(newest_preview_tab, preview_tab);
|
| + EXPECT_EQ(1, browser()->tab_count());
|
| + EXPECT_TRUE(new_preview_tab);
|
| }
|
|
|
| -// Test that print preview tabs are placed correctly.
|
| -IN_PROC_BROWSER_TEST_F(PrintPreviewTabControllerBrowserTest,
|
| - OpenPreviewTabInCorrectPosition) {
|
| - const int kTabCount = 4;
|
| - // Create kTabCount - 1 tabs since we start with 1 tab already.
|
| - for (int i = 0; i < kTabCount - 1; ++i) {
|
| - browser::NavigateParams p(browser(), GURL(), content::PAGE_TRANSITION_LINK);
|
| - p.disposition = NEW_FOREGROUND_TAB;
|
| - browser::Navigate(&p);
|
| - }
|
| - EXPECT_EQ(kTabCount, browser()->tab_count());
|
| -
|
| - // Create a print preview tab.
|
| - scoped_refptr<printing::PrintPreviewTabController>
|
| - tab_controller(new printing::PrintPreviewTabController());
|
| - ASSERT_TRUE(tab_controller);
|
| -
|
| - const int kInitiatorTabIndex = 1;
|
| - TabContentsWrapper* initiator_tab =
|
| - browser()->GetTabContentsWrapperAt(kInitiatorTabIndex);
|
| - ASSERT_TRUE(initiator_tab);
|
| - TabContentsWrapper* preview_tab =
|
| - tab_controller->GetOrCreatePreviewTab(initiator_tab);
|
| - EXPECT_TRUE(preview_tab);
|
| -
|
| - // Check the preview tab's location.
|
| - EXPECT_EQ(preview_tab,
|
| - browser()->GetTabContentsWrapperAt(kInitiatorTabIndex + 1));
|
| - EXPECT_EQ(preview_tab, browser()->GetSelectedTabContentsWrapper());
|
| -}
|
| -
|
| -// Test that print preview tabs created by pop-up windows are placed correctly.
|
| -IN_PROC_BROWSER_TEST_F(PrintPreviewTabControllerBrowserTest,
|
| - OpenPreviewTabFromPopupInCorrectPosition) {
|
| - const int kTabCount = 4;
|
| - // Create kTabCount - 1 tabs since we start with 1 tab already.
|
| - for (int i = 0; i < kTabCount - 1; ++i) {
|
| - browser::NavigateParams p(browser(), GURL(), content::PAGE_TRANSITION_LINK);
|
| - p.disposition = NEW_FOREGROUND_TAB;
|
| - browser::Navigate(&p);
|
| - }
|
| - EXPECT_EQ(kTabCount, browser()->tab_count());
|
| -
|
| - // Create a popup
|
| - browser::NavigateParams p(browser(), GURL(), content::PAGE_TRANSITION_LINK);
|
| - p.disposition = NEW_POPUP;
|
| - ui_test_utils::NavigateToURL(&p);
|
| -
|
| -
|
| -#if defined(OS_CHROMEOS)
|
| - // Navigate() should have opened a new tab on CrOS.
|
| - EXPECT_EQ(browser(), p.browser);
|
| - EXPECT_EQ(Browser::TYPE_TABBED, p.browser->type());
|
| -#else
|
| - // Navigate() should have opened a new popup window.
|
| - EXPECT_NE(browser(), p.browser);
|
| - EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
|
| -#endif
|
| - ASSERT_TRUE(p.target_contents);
|
| -
|
| - // Create a print preview tab.
|
| - scoped_refptr<printing::PrintPreviewTabController>
|
| - tab_controller(new printing::PrintPreviewTabController());
|
| - ASSERT_TRUE(tab_controller);
|
| -
|
| - TabContentsWrapper* preview_tab =
|
| - tab_controller->GetOrCreatePreviewTab(p.target_contents);
|
| - EXPECT_TRUE(preview_tab);
|
| -
|
| - int tab_position = kTabCount;
|
| -#if defined(OS_CHROMEOS)
|
| - // Increment position since CrOS opened a new tab instead of a popup.
|
| - tab_position++;
|
| -#endif
|
| -
|
| - // Check the preview tab's location.
|
| - EXPECT_EQ(preview_tab, browser()->GetTabContentsWrapperAt(tab_position));
|
| - EXPECT_EQ(preview_tab, browser()->GetSelectedTabContentsWrapper());
|
| -}
|
| -
|
| } // namespace
|
|
|