diff options
4 files changed, 68 insertions, 28 deletions
diff --git a/chrome/browser/apps/app_browsertest.cc b/chrome/browser/apps/app_browsertest.cc index 8dbd88f..792695a 100644 --- a/chrome/browser/apps/app_browsertest.cc +++ b/chrome/browser/apps/app_browsertest.cc @@ -120,15 +120,15 @@ class TabsAddedNotificationObserver class ScopedPreviewTestingDelegate : PrintPreviewUI::TestingDelegate { public: - ScopedPreviewTestingDelegate(bool auto_cancel) + explicit ScopedPreviewTestingDelegate(bool auto_cancel) : auto_cancel_(auto_cancel), - waiting_for_ready_(false), - waiting_runner_(new content::MessageLoopRunner) { - PrintPreviewUI::SetTestingDelegate(this); + total_page_count_(1), + rendered_page_count_(0) { + PrintPreviewUI::SetDelegateForTesting(this); } ~ScopedPreviewTestingDelegate() { - PrintPreviewUI::SetTestingDelegate(NULL); + PrintPreviewUI::SetDelegateForTesting(NULL); } // PrintPreviewUI::TestingDelegate implementation. @@ -137,22 +137,40 @@ class ScopedPreviewTestingDelegate : PrintPreviewUI::TestingDelegate { } // PrintPreviewUI::TestingDelegate implementation. - virtual void PreviewIsReady() OVERRIDE { - waiting_runner_->Quit(); - waiting_for_ready_ = false; + virtual void DidGetPreviewPageCount(int page_count) OVERRIDE { + total_page_count_ = page_count; + } + + // PrintPreviewUI::TestingDelegate implementation. + virtual void DidRenderPreviewPage(const content::WebContents& preview_dialog) + OVERRIDE { + dialog_size_ = preview_dialog.GetView()->GetContainerSize(); + ++rendered_page_count_; + CHECK(rendered_page_count_ <= total_page_count_); + if (waiting_runner_ && rendered_page_count_ == total_page_count_) { + waiting_runner_->Quit(); + } } void WaitUntilPreviewIsReady() { - if (!waiting_for_ready_) { - waiting_for_ready_ = true; + CHECK(!waiting_runner_); + if (rendered_page_count_ < total_page_count_) { + waiting_runner_ = new content::MessageLoopRunner; waiting_runner_->Run(); + waiting_runner_ = NULL; } } + gfx::Size dialog_size() { + return dialog_size_; + } + private: bool auto_cancel_; - bool waiting_for_ready_; + int total_page_count_; + int rendered_page_count_; scoped_refptr<content::MessageLoopRunner> waiting_runner_; + gfx::Size dialog_size_; }; bool CopyTestDataAndSetCommandLineArg( @@ -1077,7 +1095,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_WebContentsHasFocus) { GetRenderWidgetHostView()->HasFocus()); } -// The next two tests will only run automatically with Chrome branded builds +// The next three tests will only run automatically with Chrome branded builds // because they require the PDF preview plug-in. To run these tests manually for // Chromium (non-Chrome branded) builds in a development environment: // @@ -1124,6 +1142,32 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, GetFirstShellWindow()->GetBaseWindow()->Close(); } +// This test currently only passes on OS X (on other platforms the print preview +// dialog's size is limited by the size of the window being printed). +#if !defined(GOOGLE_CHROME_BUILD) || !defined(OS_MACOSX) +#define MAYBE_PrintPreviewShouldNotBeTooSmall \ + DISABLED_PrintPreviewShouldNotBeTooSmall +#else +#define MAYBE_PrintPreviewShouldNotBeTooSmall \ + PrintPreviewShouldNotBeTooSmall +#endif + +IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, + MAYBE_PrintPreviewShouldNotBeTooSmall) { + // Print preview dialogs with widths less than 410 pixels will have preview + // areas that are too small, and ones with heights less than 191 pixels will + // have vertical scrollers for their controls that are too small. + gfx::Size minimum_dialog_size(410, 191); + ScopedPreviewTestingDelegate preview_delegate(false); + ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; + preview_delegate.WaitUntilPreviewIsReady(); + EXPECT_GE(preview_delegate.dialog_size().width(), + minimum_dialog_size.width()); + EXPECT_GE(preview_delegate.dialog_size().height(), + minimum_dialog_size.height()); + GetFirstShellWindow()->GetBaseWindow()->Close(); +} + #if defined(OS_CHROMEOS) diff --git a/chrome/browser/ui/webui/print_preview/print_preview_ui.cc b/chrome/browser/ui/webui/print_preview/print_preview_ui.cc index 649aeb4..a6352a6 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_ui.cc +++ b/chrome/browser/ui/webui/print_preview/print_preview_ui.cc @@ -340,16 +340,6 @@ content::WebUIDataSource* CreatePrintPreviewUISource() { PrintPreviewUI::TestingDelegate *g_testing_delegate_ = NULL; -bool IsAutoCancelEnabledForTesting() { - return (g_testing_delegate_ != NULL && - g_testing_delegate_->IsAutoCancelEnabled()); -} - -void NotifyDelegateThatPreviewIsReadyForTesting() { - if (g_testing_delegate_ != NULL) - g_testing_delegate_->PreviewIsReady(); -} - } // namespace PrintPreviewUI::PrintPreviewUI(content::WebUI* web_ui) @@ -464,6 +454,8 @@ void PrintPreviewUI::OnShowSystemDialog() { void PrintPreviewUI::OnDidGetPreviewPageCount( const PrintHostMsg_DidGetPreviewPageCount_Params& params) { DCHECK_GT(params.page_count, 0); + if (g_testing_delegate_) + g_testing_delegate_->DidGetPreviewPageCount(params.page_count); base::FundamentalValue count(params.page_count); base::FundamentalValue request_id(params.preview_request_id); web_ui()->CallJavascriptFunction("onDidGetPreviewPageCount", @@ -507,10 +499,11 @@ void PrintPreviewUI::OnDidPreviewPage(int page_number, base::FundamentalValue number(page_number); base::FundamentalValue ui_identifier(id_); base::FundamentalValue request_id(preview_request_id); - NotifyDelegateThatPreviewIsReadyForTesting(); + if (g_testing_delegate_) + g_testing_delegate_->DidRenderPreviewPage(*web_ui()->GetWebContents()); web_ui()->CallJavascriptFunction( "onDidPreviewPage", number, ui_identifier, request_id); - if (IsAutoCancelEnabledForTesting()) + if (g_testing_delegate_ && g_testing_delegate_->IsAutoCancelEnabled()) web_ui()->CallJavascriptFunction("autoCancelForTesting"); } @@ -599,6 +592,6 @@ void PrintPreviewUI::OnPrintPreviewScalingDisabled() { } // static -void PrintPreviewUI::SetTestingDelegate(TestingDelegate* delegate) { +void PrintPreviewUI::SetDelegateForTesting(TestingDelegate* delegate) { g_testing_delegate_ = delegate; } diff --git a/chrome/browser/ui/webui/print_preview/print_preview_ui.h b/chrome/browser/ui/webui/print_preview/print_preview_ui.h index 39354db..ab893bb 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_ui.h +++ b/chrome/browser/ui/webui/print_preview/print_preview_ui.h @@ -151,11 +151,13 @@ class PrintPreviewUI : public ConstrainedWebDialogUI { // also instructs the dialog to auto-cancel, which is used for testing only. class TestingDelegate { public: - virtual void PreviewIsReady() = 0; virtual bool IsAutoCancelEnabled() = 0; + virtual void DidGetPreviewPageCount(int page_count) = 0; + virtual void DidRenderPreviewPage( + const content::WebContents& preview_dialog) = 0; }; - static void SetTestingDelegate(TestingDelegate* delegate); + static void SetDelegateForTesting(TestingDelegate* delegate); private: friend class PrintPreviewHandlerTest; diff --git a/chrome/test/data/extensions/platform_apps/print_api/test.js b/chrome/test/data/extensions/platform_apps/print_api/test.js index b041f16..8e9966e 100644 --- a/chrome/test/data/extensions/platform_apps/print_api/test.js +++ b/chrome/test/data/extensions/platform_apps/print_api/test.js @@ -4,7 +4,8 @@ chrome.app.runtime.onLaunched.addListener(function() { chrome.test.getConfig(function(config) { - chrome.app.window.create('test.html', {}, function(appWindow) { + var options = {bounds: {width: 200, height: 100}}; + chrome.app.window.create('test.html', options, function(appWindow) { appWindow.contentWindow.onload = function() { appWindow.contentWindow.print(); chrome.test.notifyPass(); |