This source file includes following definitions.
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/printing/print_preview_dialog_controller.h"
#include "chrome/browser/printing/print_preview_test.h"
#include "chrome/browser/printing/print_view_manager.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/common/url_constants.h"
using content::WebContents;
#if defined(USE_AURA)
#define MAYBE_GetOrCreatePreviewDialog DISABLED_GetOrCreatePreviewDialog
#define MAYBE_MultiplePreviewDialogs DISABLED_MultiplePreviewDialogs
#define MAYBE_ClearInitiatorDetails DISABLED_ClearInitiatorDetails
#else
#define MAYBE_GetOrCreatePreviewDialog GetOrCreatePreviewDialog
#define MAYBE_MultiplePreviewDialogs MultiplePreviewDialogs
#define MAYBE_ClearInitiatorDetails ClearInitiatorDetails
#endif
namespace printing {
typedef PrintPreviewTest PrintPreviewDialogControllerUnitTest;
TEST_F(PrintPreviewDialogControllerUnitTest, MAYBE_GetOrCreatePreviewDialog) {
EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
EXPECT_EQ(0, browser()->tab_strip_model()->count());
chrome::NewTab(browser());
EXPECT_EQ(1, browser()->tab_strip_model()->count());
WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents();
PrintPreviewDialogController* dialog_controller =
PrintPreviewDialogController::GetInstance();
ASSERT_TRUE(dialog_controller);
PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(false);
WebContents* preview_dialog =
dialog_controller->GetOrCreatePreviewDialog(initiator);
EXPECT_EQ(1, browser()->tab_strip_model()->count());
EXPECT_NE(initiator, preview_dialog);
WebContents* new_preview_dialog =
dialog_controller->GetOrCreatePreviewDialog(initiator);
EXPECT_EQ(1, browser()->tab_strip_model()->count());
EXPECT_EQ(new_preview_dialog, preview_dialog);
}
TEST_F(PrintPreviewDialogControllerUnitTest, MAYBE_MultiplePreviewDialogs) {
EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
TabStripModel* tab_strip_model = browser()->tab_strip_model();
ASSERT_TRUE(tab_strip_model);
EXPECT_EQ(0, tab_strip_model->count());
chrome::NewTab(browser());
WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents();
ASSERT_TRUE(web_contents_1);
chrome::NewTab(browser());
WebContents* web_contents_2 = tab_strip_model->GetActiveWebContents();
ASSERT_TRUE(web_contents_2);
EXPECT_EQ(2, tab_strip_model->count());
PrintPreviewDialogController* dialog_controller =
PrintPreviewDialogController::GetInstance();
ASSERT_TRUE(dialog_controller);
PrintViewManager::FromWebContents(web_contents_1)->PrintPreviewNow(false);
WebContents* preview_dialog_1 =
dialog_controller->GetOrCreatePreviewDialog(web_contents_1);
EXPECT_NE(web_contents_1, preview_dialog_1);
EXPECT_EQ(2, tab_strip_model->count());
PrintViewManager::FromWebContents(web_contents_2)->PrintPreviewNow(false);
WebContents* preview_dialog_2 =
dialog_controller->GetOrCreatePreviewDialog(web_contents_2);
EXPECT_NE(web_contents_2, preview_dialog_2);
EXPECT_NE(preview_dialog_1, preview_dialog_2);
EXPECT_EQ(2, tab_strip_model->count());
int tab_1_index = tab_strip_model->GetIndexOfWebContents(web_contents_1);
int tab_2_index = tab_strip_model->GetIndexOfWebContents(web_contents_2);
int preview_dialog_1_index =
tab_strip_model->GetIndexOfWebContents(preview_dialog_1);
int preview_dialog_2_index =
tab_strip_model->GetIndexOfWebContents(preview_dialog_2);
EXPECT_EQ(-1, preview_dialog_1_index);
EXPECT_EQ(-1, preview_dialog_2_index);
EXPECT_EQ(tab_2_index, tab_strip_model->active_index());
dialog_controller->GetOrCreatePreviewDialog(web_contents_1);
EXPECT_EQ(tab_1_index, tab_strip_model->active_index());
}
TEST_F(PrintPreviewDialogControllerUnitTest, MAYBE_ClearInitiatorDetails) {
EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
EXPECT_EQ(0, browser()->tab_strip_model()->count());
chrome::NewTab(browser());
EXPECT_EQ(1, browser()->tab_strip_model()->count());
WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents();
PrintPreviewDialogController* dialog_controller =
PrintPreviewDialogController::GetInstance();
ASSERT_TRUE(dialog_controller);
PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(false);
WebContents* preview_dialog =
dialog_controller->GetOrCreatePreviewDialog(initiator);
EXPECT_EQ(1, browser()->tab_strip_model()->count());
EXPECT_NE(initiator, preview_dialog);
dialog_controller->EraseInitiatorInfo(preview_dialog);
WebContents* new_preview_dialog =
dialog_controller->GetOrCreatePreviewDialog(initiator);
EXPECT_EQ(1, browser()->tab_strip_model()->count());
EXPECT_NE(new_preview_dialog, preview_dialog);
}
}