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

Unified Diff: chrome/renderer/printing/print_web_view_helper_browsertest.cc

Issue 12087005: Async frame preparation for Preview with support if selection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/printing/print_web_view_helper_browsertest.cc
diff --git a/chrome/renderer/printing/print_web_view_helper_browsertest.cc b/chrome/renderer/printing/print_web_view_helper_browsertest.cc
index 07cc657083ed3ab5403f6da62eee4ca0574dbefa..acd929fbab081bc7f121d3daa1446ba6bb6e0f95 100644
--- a/chrome/renderer/printing/print_web_view_helper_browsertest.cc
+++ b/chrome/renderer/printing/print_web_view_helper_browsertest.cc
@@ -13,6 +13,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#if defined(OS_WIN) || defined(OS_MACOSX)
@@ -30,6 +31,17 @@ namespace {
// A simple web page.
const char kHelloWorldHTML[] = "<body><p>Hello World!</p></body>";
+// HTML with 3 pages.
+const char kMultipageHTML[] =
+ "<html><head><style>"
+ ".break { page-break-after: always; }"
+ "</style></head>"
+ "<body>"
+ "<div class='break'>page1</div>"
+ "<div class='break'>page2</div>"
+ "<div>page3</div>"
+ "</body></html>";
+
// A simple web page with print page size css.
const char kHTMLWithPageSizeCss[] =
"<html><head><style>"
@@ -87,6 +99,8 @@ void CreatePrintSettingsDictionary(DictionaryValue* dict) {
dict->SetBoolean(kSettingPreviewModifiable, false);
dict->SetBoolean(kSettingHeaderFooterEnabled, false);
dict->SetBoolean(kSettingGenerateDraftData, true);
+ dict->SetBoolean(kSettingShouldPrintBackgrounds, false);
+ dict->SetBoolean(kSettingShouldPrintSelectionOnly, false);
}
} // namespace
@@ -101,7 +115,6 @@ class PrintWebViewHelperTestBase : public ChromeRenderViewTest {
// according to the specified settings defined in the mock render thread.
// Verify the page count is correct.
void VerifyPageCount(int count) {
- ProcessPendingMessages();
#if defined(OS_CHROMEOS)
// The DidGetPrintedPagesCount message isn't sent on ChromeOS. Right now we
// always print all pages, and there are checks to that effect built into
@@ -118,9 +131,22 @@ class PrintWebViewHelperTestBase : public ChromeRenderViewTest {
#endif // defined(OS_CHROMEOS)
}
+ // The renderer should be done calculating the number of rendered pages
+ // according to the specified settings defined in the mock render thread.
+ // Verify the page count is correct.
+ void VerifyPreviewPageCount(int count) {
+ const IPC::Message* page_cnt_msg =
+ render_thread_->sink().GetUniqueMessageMatching(
+ PrintHostMsg_DidGetPreviewPageCount::ID);
+ ASSERT_TRUE(page_cnt_msg);
+ PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param;
+ PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg,
+ &post_page_count_param);
+ EXPECT_EQ(count, post_page_count_param.a.page_count);
+ }
+
// Verifies whether the pages printed or not.
void VerifyPagesPrinted(bool printed) {
- ProcessPendingMessages();
#if defined(OS_CHROMEOS)
bool did_print_msg = (render_thread_->sink().GetUniqueMessageMatching(
PrintHostMsg_TempFileForPrintingWritten::ID) != NULL);
@@ -138,15 +164,21 @@ class PrintWebViewHelperTestBase : public ChromeRenderViewTest {
}
#endif // defined(OS_CHROMEOS)
}
+ void OnPrintPages() {
+ PrintWebViewHelper::Get(view_)->OnPrintPages();
+ ProcessPendingMessages();
+ }
void OnPrintPreview(const DictionaryValue& dict) {
PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_);
print_web_view_helper->OnInitiatePrintPreview();
print_web_view_helper->OnPrintPreview(dict);
+ ProcessPendingMessages();
}
void OnPrintForPrintPreview(const DictionaryValue& dict) {
PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict);
+ ProcessPendingMessages();
}
DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTestBase);
@@ -169,7 +201,7 @@ class PrintWebViewHelperTest : public PrintWebViewHelperTestBase {
// that channel all works.
TEST_F(PrintWebViewHelperTest, OnPrintPages) {
LoadHTML(kHelloWorldHTML);
- PrintWebViewHelper::Get(view_)->OnPrintPages();
+ OnPrintPages();
VerifyPageCount(1);
VerifyPagesPrinted(true);
@@ -241,6 +273,7 @@ TEST_F(PrintWebViewHelperTest, AllowUserOriginatedPrinting) {
SendWebMouseEvent(mouse_event);
mouse_event.type = WebKit::WebInputEvent::MouseUp;
SendWebMouseEvent(mouse_event);
+ ProcessPendingMessages();
VerifyPageCount(1);
VerifyPagesPrinted(true);
@@ -285,7 +318,7 @@ TEST_F(PrintWebViewHelperTest, PrintWithIframe) {
view_->GetWebView()->mainFrame());
// Initiate printing.
- PrintWebViewHelper::Get(view_)->OnPrintPages();
+ OnPrintPages();
VerifyPagesPrinted(true);
// Verify output through MockPrinter.
@@ -350,7 +383,7 @@ TEST_F(PrintWebViewHelperTest, PrintLayoutTest) {
for (size_t i = 0; i < arraysize(kTestPages); ++i) {
// Load an HTML page and print it.
LoadHTML(kTestPages[i].page);
- PrintWebViewHelper::Get(view_)->OnPrintPages();
+ OnPrintPages();
VerifyPagesPrinted(true);
// MockRenderThread::Send() just calls MockRenderThread::OnReceived().
@@ -443,7 +476,6 @@ class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase {
}
void VerifyPrintFailed(bool did_fail) {
- ProcessPendingMessages();
bool print_failed = (render_thread_->sink().GetUniqueMessageMatching(
PrintHostMsg_PrintingFailed::ID) != NULL);
EXPECT_EQ(did_fail, print_failed);
@@ -710,7 +742,7 @@ TEST_F(PrintWebViewHelperPreviewTest, PrintToPDFSelectedHonorOrientationCss) {
// Test to verify that complete metafile is generated for a subset of pages
// without creating draft pages.
TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedPages) {
- LoadHTML(kHelloWorldHTML);
+ LoadHTML(kMultipageHTML);
// Fill in some dummy values.
DictionaryValue dict;
@@ -720,8 +752,8 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedPages) {
// metafile with the selected pages. Page numbers used in the dictionary
// are 1-based.
DictionaryValue* page_range = new DictionaryValue();
- page_range->SetInteger(kSettingPageRangeFrom, 1);
- page_range->SetInteger(kSettingPageRangeTo, 1);
+ page_range->SetInteger(kSettingPageRangeFrom, 2);
+ page_range->SetInteger(kSettingPageRangeTo, 3);
ListValue* page_range_array = new ListValue();
page_range_array->Append(page_range);
@@ -731,9 +763,30 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedPages) {
OnPrintPreview(dict);
- // Verify that we did not create the draft metafile for the first page.
VerifyDidPreviewPage(false, 0);
+ VerifyDidPreviewPage(false, 1);
+ VerifyDidPreviewPage(false, 2);
+ VerifyPreviewPageCount(3);
+ VerifyPrintPreviewCancelled(false);
+ VerifyPrintPreviewFailed(false);
+ VerifyPrintPreviewGenerated(true);
+ VerifyPagesPrinted(false);
+}
+
+// Test to verify that preview generated only for one page.
+TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedText) {
+ LoadHTML(kMultipageHTML);
+ GetMainFrame()->selectRange(
+ WebKit::WebRange::fromDocumentRange(GetMainFrame(), 1, 3));
+
+ // Fill in some dummy values.
+ DictionaryValue dict;
+ CreatePrintSettingsDictionary(&dict);
+ dict.SetBoolean(kSettingShouldPrintSelectionOnly, true);
+
+ OnPrintPreview(dict);
+ VerifyPreviewPageCount(1);
VerifyPrintPreviewCancelled(false);
VerifyPrintPreviewFailed(false);
VerifyPrintPreviewGenerated(true);
« no previous file with comments | « chrome/renderer/printing/print_web_view_helper.cc ('k') | chrome/renderer/printing/print_web_view_helper_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698