| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/shared_memory.h" | 8 #include "base/shared_memory.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/common/autofill_messages.h" | 11 #include "chrome/common/autofill_messages.h" |
| 12 #include "chrome/common/content_settings.h" | |
| 13 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
| 14 #include "chrome/renderer/print_web_view_helper.h" | 13 #include "chrome/renderer/print_web_view_helper.h" |
| 15 #include "chrome/test/render_view_test.h" | 14 #include "chrome/test/render_view_test.h" |
| 16 #include "content/common/native_web_keyboard_event.h" | 15 #include "content/common/native_web_keyboard_event.h" |
| 17 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
| 18 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 19 #include "printing/image.h" | 18 #include "printing/image.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| (...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 error.domain.fromUTF8("test_domain"); | 963 error.domain.fromUTF8("test_domain"); |
| 965 error.reason = net::ERR_ABORTED; | 964 error.reason = net::ERR_ABORTED; |
| 966 error.unreachableURL = GURL("http://foo"); | 965 error.unreachableURL = GURL("http://foo"); |
| 967 WebFrame* web_frame = GetMainFrame(); | 966 WebFrame* web_frame = GetMainFrame(); |
| 968 // A cancellation occurred. | 967 // A cancellation occurred. |
| 969 view_->didFailProvisionalLoad(web_frame, error); | 968 view_->didFailProvisionalLoad(web_frame, error); |
| 970 // Frame should stay in view-source mode. | 969 // Frame should stay in view-source mode. |
| 971 EXPECT_TRUE(web_frame->isViewSourceModeEnabled()); | 970 EXPECT_TRUE(web_frame->isViewSourceModeEnabled()); |
| 972 } | 971 } |
| 973 | 972 |
| 974 // Regression test for http://crbug.com/35011 | |
| 975 TEST_F(RenderViewTest, JSBlockSentAfterPageLoad) { | |
| 976 // 1. Load page with JS. | |
| 977 std::string html = "<html>" | |
| 978 "<head>" | |
| 979 "<script>document.createElement('div');</script>" | |
| 980 "</head>" | |
| 981 "<body>" | |
| 982 "</body>" | |
| 983 "</html>"; | |
| 984 render_thread_.sink().ClearMessages(); | |
| 985 LoadHTML(html.c_str()); | |
| 986 | |
| 987 // 2. Block JavaScript. | |
| 988 ContentSettings settings; | |
| 989 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) | |
| 990 settings.settings[i] = CONTENT_SETTING_ALLOW; | |
| 991 settings.settings[CONTENT_SETTINGS_TYPE_JAVASCRIPT] = CONTENT_SETTING_BLOCK; | |
| 992 view_->SetContentSettings(settings); | |
| 993 | |
| 994 // Make sure no pending messages are in the queue. | |
| 995 ProcessPendingMessages(); | |
| 996 render_thread_.sink().ClearMessages(); | |
| 997 | |
| 998 // 3. Reload page. | |
| 999 ViewMsg_Navigate_Params params; | |
| 1000 std::string url_str = "data:text/html;charset=utf-8,"; | |
| 1001 url_str.append(html); | |
| 1002 GURL url(url_str); | |
| 1003 params.url = url; | |
| 1004 params.navigation_type = ViewMsg_Navigate_Type::RELOAD; | |
| 1005 view_->OnNavigate(params); | |
| 1006 ProcessPendingMessages(); | |
| 1007 | |
| 1008 // 4. Verify that the notification that javascript was blocked is sent after | |
| 1009 // the navigation notifiction is sent. | |
| 1010 int navigation_index = -1; | |
| 1011 int block_index = -1; | |
| 1012 for (size_t i = 0; i < render_thread_.sink().message_count(); ++i) { | |
| 1013 const IPC::Message* msg = render_thread_.sink().GetMessageAt(i); | |
| 1014 if (msg->type() == ViewHostMsg_FrameNavigate::ID) | |
| 1015 navigation_index = i; | |
| 1016 if (msg->type() == ViewHostMsg_ContentBlocked::ID) | |
| 1017 block_index = i; | |
| 1018 } | |
| 1019 EXPECT_NE(-1, navigation_index); | |
| 1020 EXPECT_NE(-1, block_index); | |
| 1021 EXPECT_LT(navigation_index, block_index); | |
| 1022 } | |
| 1023 | |
| 1024 // Regression test for http://crbug.com/41562 | 973 // Regression test for http://crbug.com/41562 |
| 1025 TEST_F(RenderViewTest, UpdateTargetURLWithInvalidURL) { | 974 TEST_F(RenderViewTest, UpdateTargetURLWithInvalidURL) { |
| 1026 const GURL invalid_gurl("http://"); | 975 const GURL invalid_gurl("http://"); |
| 1027 view_->setMouseOverURL(WebKit::WebURL(invalid_gurl)); | 976 view_->setMouseOverURL(WebKit::WebURL(invalid_gurl)); |
| 1028 EXPECT_EQ(invalid_gurl, view_->target_url_); | 977 EXPECT_EQ(invalid_gurl, view_->target_url_); |
| 1029 } | 978 } |
| 1030 | 979 |
| 1031 TEST_F(RenderViewTest, SendForms) { | 980 TEST_F(RenderViewTest, SendForms) { |
| 1032 // Don't want any delay for form state sync changes. This will still post a | 981 // Don't want any delay for form state sync changes. This will still post a |
| 1033 // message so updates will get coalesced, but as soon as we spin the message | 982 // message so updates will get coalesced, but as soon as we spin the message |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 LoadHTML("<html><head><meta http-equiv=\"content-language\" " | 1179 LoadHTML("<html><head><meta http-equiv=\"content-language\" " |
| 1231 "content=\" fr , es,en \">" | 1180 "content=\" fr , es,en \">" |
| 1232 "</head><body>A random page with random content.</body></html>"); | 1181 "</head><body>A random page with random content.</body></html>"); |
| 1233 ProcessPendingMessages(); | 1182 ProcessPendingMessages(); |
| 1234 message = render_thread_.sink().GetUniqueMessageMatching( | 1183 message = render_thread_.sink().GetUniqueMessageMatching( |
| 1235 ViewHostMsg_TranslateLanguageDetermined::ID); | 1184 ViewHostMsg_TranslateLanguageDetermined::ID); |
| 1236 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 1185 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 1237 ViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); | 1186 ViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); |
| 1238 EXPECT_EQ("fr", params.a); | 1187 EXPECT_EQ("fr", params.a); |
| 1239 } | 1188 } |
| OLD | NEW |