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

Unified Diff: content/renderer/render_view_browsertest.cc

Issue 6874038: Remove the last Chrome dependencies from renderer, and enforce no more includes through DEPS. I ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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: content/renderer/render_view_browsertest.cc
===================================================================
--- content/renderer/render_view_browsertest.cc (revision 81920)
+++ content/renderer/render_view_browsertest.cc (working copy)
@@ -4,47 +4,27 @@
#include "base/basictypes.h"
-#include "base/file_util.h"
#include "base/shared_memory.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
-#include "chrome/common/autofill_messages.h"
-#include "chrome/common/content_settings.h"
#include "chrome/common/render_messages.h"
-#include "chrome/renderer/print_web_view_helper.h"
#include "chrome/test/render_view_test.h"
#include "content/common/native_web_keyboard_event.h"
#include "content/common/view_messages.h"
#include "net/base/net_errors.h"
-#include "printing/image.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/gfx/codec/jpeg_codec.h"
-#include "webkit/glue/form_data.h"
-#include "webkit/glue/form_field.h"
#include "webkit/glue/web_io_operators.h"
-using WebKit::WebDocument;
using WebKit::WebFrame;
-using WebKit::WebInputElement;
using WebKit::WebString;
using WebKit::WebTextDirection;
using WebKit::WebURLError;
-using webkit_glue::FormData;
-using webkit_glue::FormField;
-namespace {
-
-const char kPrintWithJSHTML[] =
- "<body>Hello<script>window.print()</script>World</body>";
-
-} // namespace
-
// Test that we get form state change notifications when input fields change.
TEST_F(RenderViewTest, OnNavStateChanged) {
// Don't want any delay for form state sync changes. This will still post a
@@ -394,186 +374,6 @@
}
}
-// Tests that printing pages work and sending and receiving messages through
-// that channel all works.
-TEST_F(RenderViewTest, OnPrintPages) {
- // Lets simulate a print pages with Hello world.
- LoadHTML("<body><p>Hello World!</p></body>");
- PrintWebViewHelper::Get(view_)->OnPrintPages();
-
- VerifyPageCount(1);
- VerifyPagesPrinted(true);
-}
-
-// Duplicate of OnPrintPagesTest only using javascript to print.
-TEST_F(RenderViewTest, PrintWithJavascript) {
- // HTML contains a call to window.print()
- LoadHTML(kPrintWithJSHTML);
-
- VerifyPageCount(1);
- VerifyPagesPrinted(true);
-}
-
-// Tests that the renderer blocks window.print() calls if they occur too
-// frequently.
-TEST_F(RenderViewTest, BlockScriptInitiatedPrinting) {
- // Pretend user will cancel printing.
- render_thread_.set_print_dialog_user_response(false);
- // Try to print with window.print() a few times.
- LoadHTML(kPrintWithJSHTML);
- LoadHTML(kPrintWithJSHTML);
- LoadHTML(kPrintWithJSHTML);
- VerifyPagesPrinted(false);
-
- // Pretend user will print. (but printing is blocked.)
- render_thread_.set_print_dialog_user_response(true);
- LoadHTML(kPrintWithJSHTML);
- VerifyPagesPrinted(false);
-
- // Unblock script initiated printing and verify printing works.
- PrintWebViewHelper::Get(view_)->ResetScriptedPrintCount();
- render_thread_.printer()->ResetPrinter();
- LoadHTML(kPrintWithJSHTML);
- VerifyPageCount(1);
- VerifyPagesPrinted(true);
-}
-
-#if defined(OS_WIN) || defined(OS_MACOSX)
-// TODO(estade): I don't think this test is worth porting to Linux. We will have
-// to rip out and replace most of the IPC code if we ever plan to improve
-// printing, and the comment below by sverrir suggests that it doesn't do much
-// for us anyway.
-TEST_F(RenderViewTest, PrintWithIframe) {
- // Document that populates an iframe.
- const char html[] =
- "<html><body>Lorem Ipsum:"
- "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>"
- " document.write(frames['sub1'].name);"
- " frames['sub1'].document.write("
- " '<p>Cras tempus ante eu felis semper luctus!</p>');"
- "</script></body></html>";
-
- LoadHTML(html);
-
- // Find the frame and set it as the focused one. This should mean that that
- // the printout should only contain the contents of that frame.
- WebFrame* sub1_frame =
- view_->webview()->findFrameByName(WebString::fromUTF8("sub1"));
- ASSERT_TRUE(sub1_frame);
- view_->webview()->setFocusedFrame(sub1_frame);
- ASSERT_NE(view_->webview()->focusedFrame(),
- view_->webview()->mainFrame());
-
- // Initiate printing.
- PrintWebViewHelper::Get(view_)->OnPrintPages();
-
- // Verify output through MockPrinter.
- const MockPrinter* printer(render_thread_.printer());
- ASSERT_EQ(1, printer->GetPrintedPages());
- const printing::Image& image1(printer->GetPrintedPage(0)->image());
-
- // TODO(sverrir): Figure out a way to improve this test to actually print
- // only the content of the iframe. Currently image1 will contain the full
- // page.
- EXPECT_NE(0, image1.size().width());
- EXPECT_NE(0, image1.size().height());
-}
-#endif
-
-// Tests if we can print a page and verify its results.
-// This test prints HTML pages into a pseudo printer and check their outputs,
-// i.e. a simplified version of the PrintingLayoutTextTest UI test.
-namespace {
-// Test cases used in this test.
-struct TestPageData {
- const char* page;
- size_t printed_pages;
- int width;
- int height;
- const char* checksum;
- const wchar_t* file;
-};
-
-const TestPageData kTestPages[] = {
- {"<html>"
- "<head>"
- "<meta"
- " http-equiv=\"Content-Type\""
- " content=\"text/html; charset=utf-8\"/>"
- "<title>Test 1</title>"
- "</head>"
- "<body style=\"background-color: white;\">"
- "<p style=\"font-family: arial;\">Hello World!</p>"
- "</body>",
-#if defined(OS_MACOSX)
- // Mac printing code compensates for the WebKit scale factor while generating
- // the metafile, so we expect smaller pages.
- 1, 540, 720,
-#else
- 1, 675, 900,
-#endif
- NULL,
- NULL,
- },
-};
-} // namespace
-
-// TODO(estade): need to port MockPrinter to get this on Linux. This involves
-// hooking up Cairo to read a pdf stream, or accessing the cairo surface in the
-// metafile directly.
-#if defined(OS_WIN) || defined(OS_MACOSX)
-TEST_F(RenderViewTest, PrintLayoutTest) {
- bool baseline = false;
-
- EXPECT_TRUE(render_thread_.printer() != NULL);
- for (size_t i = 0; i < arraysize(kTestPages); ++i) {
- // Load an HTML page and print it.
- LoadHTML(kTestPages[i].page);
- PrintWebViewHelper::Get(view_)->OnPrintPages();
-
- // MockRenderThread::Send() just calls MockRenderThread::OnMsgReceived().
- // So, all IPC messages sent in the above RenderView::OnPrintPages() call
- // has been handled by the MockPrinter object, i.e. this printing job
- // has been already finished.
- // So, we can start checking the output pages of this printing job.
- // Retrieve the number of pages actually printed.
- size_t pages = render_thread_.printer()->GetPrintedPages();
- EXPECT_EQ(kTestPages[i].printed_pages, pages);
-
- // Retrieve the width and height of the output page.
- int width = render_thread_.printer()->GetWidth(0);
- int height = render_thread_.printer()->GetHeight(0);
-
- // Check with margin for error. This has been failing with a one pixel
- // offset on our buildbot.
- const int kErrorMargin = 5; // 5%
- EXPECT_GT(kTestPages[i].width * (100 + kErrorMargin) / 100, width);
- EXPECT_LT(kTestPages[i].width * (100 - kErrorMargin) / 100, width);
- EXPECT_GT(kTestPages[i].height * (100 + kErrorMargin) / 100, height);
- EXPECT_LT(kTestPages[i].height* (100 - kErrorMargin) / 100, height);
-
- // Retrieve the checksum of the bitmap data from the pseudo printer and
- // compare it with the expected result.
- std::string bitmap_actual;
- EXPECT_TRUE(render_thread_.printer()->GetBitmapChecksum(0, &bitmap_actual));
- if (kTestPages[i].checksum)
- EXPECT_EQ(kTestPages[i].checksum, bitmap_actual);
-
- if (baseline) {
- // Save the source data and the bitmap data into temporary files to
- // create base-line results.
- FilePath source_path;
- file_util::CreateTemporaryFile(&source_path);
- render_thread_.printer()->SaveSource(0, source_path);
-
- FilePath bitmap_path;
- file_util::CreateTemporaryFile(&bitmap_path);
- render_thread_.printer()->SaveBitmap(0, bitmap_path);
- }
- }
-}
-#endif
-
// Test that we can receive correct DOM events when we send input events
// through the RenderWidget::OnHandleInputEvent() function.
TEST_F(RenderViewTest, OnHandleKeyboardEvent) {
@@ -1027,213 +827,3 @@
view_->setMouseOverURL(WebKit::WebURL(invalid_gurl));
EXPECT_EQ(invalid_gurl, view_->target_url_);
}
-
-TEST_F(RenderViewTest, SendForms) {
- // Don't want any delay for form state sync changes. This will still post a
- // message so updates will get coalesced, but as soon as we spin the message
- // loop, it will generate an update.
- view_->set_send_content_state_immediately(true);
-
- LoadHTML("<form method=\"POST\">"
- " <input type=\"text\" id=\"firstname\"/>"
- " <input type=\"text\" id=\"middlename\" autoComplete=\"off\"/>"
- " <input type=\"hidden\" id=\"lastname\"/>"
- " <select id=\"state\"/>"
- " <option>?</option>"
- " <option>California</option>"
- " <option>Texas</option>"
- " </select>"
- "</form>");
-
- // Verify that "FormsSeen" sends the expected number of fields.
- ProcessPendingMessages();
- const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching(
- AutofillHostMsg_FormsSeen::ID);
- ASSERT_NE(static_cast<IPC::Message*>(NULL), message);
- AutofillHostMsg_FormsSeen::Param params;
- AutofillHostMsg_FormsSeen::Read(message, &params);
- const std::vector<FormData>& forms = params.a;
- ASSERT_EQ(1UL, forms.size());
- ASSERT_EQ(3UL, forms[0].fields.size());
- EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack(
- FormField(string16(),
- ASCIIToUTF16("firstname"),
- string16(),
- ASCIIToUTF16("text"),
- WebInputElement::defaultMaxLength(),
- false))) << forms[0].fields[0];
- EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack(
- FormField(string16(),
- ASCIIToUTF16("middlename"),
- string16(),
- ASCIIToUTF16("text"),
- WebInputElement::defaultMaxLength(),
- false))) << forms[0].fields[1];
- EXPECT_TRUE(forms[0].fields[2].StrictlyEqualsHack(
- FormField(string16(),
- ASCIIToUTF16("state"),
- ASCIIToUTF16("?"),
- ASCIIToUTF16("select-one"),
- 0,
- false))) << forms[0].fields[2];
-
- // Verify that |didAcceptAutoFillSuggestion()| sends the expected number of
- // fields.
- WebFrame* web_frame = GetMainFrame();
- WebDocument document = web_frame->document();
- WebInputElement firstname =
- document.getElementById("firstname").to<WebInputElement>();
-
- // Accept suggestion that contains a label. Labeled items indicate Autofill
- // as opposed to Autocomplete. We're testing this distinction below with
- // the |AutofillHostMsg_FillAutofillFormData::ID| message.
- autofill_agent_->didAcceptAutoFillSuggestion(
- firstname,
- WebKit::WebString::fromUTF8("Johnny"),
- WebKit::WebString::fromUTF8("Home"),
- 1,
- -1);
-
- ProcessPendingMessages();
- const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching(
- AutofillHostMsg_FillAutofillFormData::ID);
- ASSERT_NE(static_cast<IPC::Message*>(NULL), message2);
- AutofillHostMsg_FillAutofillFormData::Param params2;
- AutofillHostMsg_FillAutofillFormData::Read(message2, &params2);
- const FormData& form2 = params2.b;
- ASSERT_EQ(3UL, form2.fields.size());
- EXPECT_TRUE(form2.fields[0].StrictlyEqualsHack(
- FormField(string16(),
- ASCIIToUTF16("firstname"),
- string16(),
- ASCIIToUTF16("text"),
- WebInputElement::defaultMaxLength(),
- false))) << form2.fields[0];
- EXPECT_TRUE(form2.fields[1].StrictlyEqualsHack(
- FormField(string16(),
- ASCIIToUTF16("middlename"),
- string16(),
- ASCIIToUTF16("text"),
- WebInputElement::defaultMaxLength(),
- false))) << form2.fields[1];
- EXPECT_TRUE(form2.fields[2].StrictlyEqualsHack(
- FormField(string16(),
- ASCIIToUTF16("state"),
- ASCIIToUTF16("?"),
- ASCIIToUTF16("select-one"),
- 0,
- false))) << form2.fields[2];
-}
-
-TEST_F(RenderViewTest, FillFormElement) {
- // Don't want any delay for form state sync changes. This will still post a
- // message so updates will get coalesced, but as soon as we spin the message
- // loop, it will generate an update.
- view_->set_send_content_state_immediately(true);
-
- LoadHTML("<form method=\"POST\">"
- " <input type=\"text\" id=\"firstname\"/>"
- " <input type=\"text\" id=\"middlename\"/>"
- "</form>");
-
- // Verify that "FormsSeen" isn't sent, as there are too few fields.
- ProcessPendingMessages();
- const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching(
- AutofillHostMsg_FormsSeen::ID);
- ASSERT_EQ(static_cast<IPC::Message*>(NULL), message);
-
- // Verify that |didAcceptAutoFillSuggestion()| sets the value of the expected
- // field.
- WebFrame* web_frame = GetMainFrame();
- WebDocument document = web_frame->document();
- WebInputElement firstname =
- document.getElementById("firstname").to<WebInputElement>();
- WebInputElement middlename =
- document.getElementById("middlename").to<WebInputElement>();
- middlename.setAutofilled(true);
-
- // Accept a suggestion in a form that has been auto-filled. This triggers
- // the direct filling of the firstname element with value parameter.
- autofill_agent_->didAcceptAutoFillSuggestion(firstname,
- WebString::fromUTF8("David"),
- WebString(),
- 0,
- 0);
-
- ProcessPendingMessages();
- const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching(
- AutofillHostMsg_FillAutofillFormData::ID);
-
- // No message should be sent in this case. |firstname| is filled directly.
- ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2);
- EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David"));
-}
-
-// Tests that we send the right translatable for a page and that we respect the
-// "no translate" meta-tag.
-TEST_F(RenderViewTest, TranslatablePage) {
- // Suppress the normal delay that occurs when the page is loaded before which
- // the renderer sends the page contents to the browser.
- view_->set_send_content_state_immediately(true);
-
- LoadHTML("<html><body>A random page with random content.</body></html>");
- ProcessPendingMessages();
- const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching(
- ViewHostMsg_TranslateLanguageDetermined::ID);
- ASSERT_NE(static_cast<IPC::Message*>(NULL), message);
- ViewHostMsg_TranslateLanguageDetermined::Param params;
- ViewHostMsg_TranslateLanguageDetermined::Read(message, &params);
- EXPECT_TRUE(params.b); // Translatable should be true.
- render_thread_.sink().ClearMessages();
-
- // Now the page specifies the META tag to prevent translation.
- LoadHTML("<html><head><meta name=\"google\" value=\"notranslate\"></head>"
- "<body>A random page with random content.</body></html>");
- ProcessPendingMessages();
- message = render_thread_.sink().GetUniqueMessageMatching(
- ViewHostMsg_TranslateLanguageDetermined::ID);
- ASSERT_NE(static_cast<IPC::Message*>(NULL), message);
- ViewHostMsg_TranslateLanguageDetermined::Read(message, &params);
- EXPECT_FALSE(params.b); // Translatable should be false.
- render_thread_.sink().ClearMessages();
-
- // Try the alternate version of the META tag (content instead of value).
- LoadHTML("<html><head><meta name=\"google\" content=\"notranslate\"></head>"
- "<body>A random page with random content.</body></html>");
- ProcessPendingMessages();
- message = render_thread_.sink().GetUniqueMessageMatching(
- ViewHostMsg_TranslateLanguageDetermined::ID);
- ASSERT_NE(static_cast<IPC::Message*>(NULL), message);
- ViewHostMsg_TranslateLanguageDetermined::Read(message, &params);
- EXPECT_FALSE(params.b); // Translatable should be false.
-}
-
-// Tests that the language meta tag takes precedence over the CLD when reporting
-// the page's language.
-TEST_F(RenderViewTest, LanguageMetaTag) {
- // Suppress the normal delay that occurs when the page is loaded before which
- // the renderer sends the page contents to the browser.
- view_->set_send_content_state_immediately(true);
-
- LoadHTML("<html><head><meta http-equiv=\"content-language\" content=\"es\">"
- "</head><body>A random page with random content.</body></html>");
- ProcessPendingMessages();
- const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching(
- ViewHostMsg_TranslateLanguageDetermined::ID);
- ASSERT_NE(static_cast<IPC::Message*>(NULL), message);
- ViewHostMsg_TranslateLanguageDetermined::Param params;
- ViewHostMsg_TranslateLanguageDetermined::Read(message, &params);
- EXPECT_EQ("es", params.a);
- render_thread_.sink().ClearMessages();
-
- // Makes sure we support multiple languages specified.
- LoadHTML("<html><head><meta http-equiv=\"content-language\" "
- "content=\" fr , es,en \">"
- "</head><body>A random page with random content.</body></html>");
- ProcessPendingMessages();
- message = render_thread_.sink().GetUniqueMessageMatching(
- ViewHostMsg_TranslateLanguageDetermined::ID);
- ASSERT_NE(static_cast<IPC::Message*>(NULL), message);
- ViewHostMsg_TranslateLanguageDetermined::Read(message, &params);
- EXPECT_EQ("fr", params.a);
-}

Powered by Google App Engine
This is Rietveld 408576698