OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <tuple> | 7 #include <tuple> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 #include "content/renderer/gpu/render_widget_compositor.h" | 51 #include "content/renderer/gpu/render_widget_compositor.h" |
52 #include "content/renderer/history_controller.h" | 52 #include "content/renderer/history_controller.h" |
53 #include "content/renderer/history_serialization.h" | 53 #include "content/renderer/history_serialization.h" |
54 #include "content/renderer/navigation_state_impl.h" | 54 #include "content/renderer/navigation_state_impl.h" |
55 #include "content/renderer/render_frame_proxy.h" | 55 #include "content/renderer/render_frame_proxy.h" |
56 #include "content/renderer/render_process.h" | 56 #include "content/renderer/render_process.h" |
57 #include "content/renderer/render_view_impl.h" | 57 #include "content/renderer/render_view_impl.h" |
58 #include "content/shell/browser/shell.h" | 58 #include "content/shell/browser/shell.h" |
59 #include "content/shell/browser/shell_browser_context.h" | 59 #include "content/shell/browser/shell_browser_context.h" |
60 #include "content/test/mock_keyboard.h" | 60 #include "content/test/mock_keyboard.h" |
61 #include "content/test/mock_weburlloader.h" | |
61 #include "content/test/test_render_frame.h" | 62 #include "content/test/test_render_frame.h" |
62 #include "net/base/net_errors.h" | 63 #include "net/base/net_errors.h" |
63 #include "net/cert/cert_status_flags.h" | 64 #include "net/cert/cert_status_flags.h" |
64 #include "testing/gtest/include/gtest/gtest.h" | 65 #include "testing/gtest/include/gtest/gtest.h" |
65 #include "third_party/WebKit/public/platform/WebData.h" | 66 #include "third_party/WebKit/public/platform/WebData.h" |
66 #include "third_party/WebKit/public/platform/WebHTTPBody.h" | 67 #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
67 #include "third_party/WebKit/public/platform/WebString.h" | 68 #include "third_party/WebKit/public/platform/WebString.h" |
68 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 69 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
69 #include "third_party/WebKit/public/web/WebDataSource.h" | 70 #include "third_party/WebKit/public/web/WebDataSource.h" |
70 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" | 71 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
90 #include "ui/events/test/events_test_utils.h" | 91 #include "ui/events/test/events_test_utils.h" |
91 #include "ui/events/test/events_test_utils_x11.h" | 92 #include "ui/events/test/events_test_utils_x11.h" |
92 #endif | 93 #endif |
93 | 94 |
94 #if defined(USE_OZONE) | 95 #if defined(USE_OZONE) |
95 #include "ui/events/keycodes/keyboard_code_conversion.h" | 96 #include "ui/events/keycodes/keyboard_code_conversion.h" |
96 #endif | 97 #endif |
97 | 98 |
98 #include "url/url_constants.h" | 99 #include "url/url_constants.h" |
99 | 100 |
101 using base::TimeDelta; | |
100 using blink::WebFrame; | 102 using blink::WebFrame; |
101 using blink::WebFrameContentDumper; | 103 using blink::WebFrameContentDumper; |
102 using blink::WebInputEvent; | 104 using blink::WebInputEvent; |
103 using blink::WebLocalFrame; | 105 using blink::WebLocalFrame; |
104 using blink::WebMouseEvent; | 106 using blink::WebMouseEvent; |
105 using blink::WebRuntimeFeatures; | 107 using blink::WebRuntimeFeatures; |
106 using blink::WebString; | 108 using blink::WebString; |
107 using blink::WebTextDirection; | 109 using blink::WebTextDirection; |
108 using blink::WebURLError; | 110 using blink::WebURLError; |
109 | 111 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 result.unique_name = | 184 result.unique_name = |
183 base::UTF16ToUTF8(base::StringPiece16(frame->uniqueName())); | 185 base::UTF16ToUTF8(base::StringPiece16(frame->uniqueName())); |
184 result.sandbox_flags = frame->effectiveSandboxFlags(); | 186 result.sandbox_flags = frame->effectiveSandboxFlags(); |
185 // result.should_enforce_strict_mixed_content_checking is calculated in the | 187 // result.should_enforce_strict_mixed_content_checking is calculated in the |
186 // browser... | 188 // browser... |
187 result.origin = frame->getSecurityOrigin(); | 189 result.origin = frame->getSecurityOrigin(); |
188 | 190 |
189 return result; | 191 return result; |
190 } | 192 } |
191 | 193 |
194 // Returns CommonNavigationParams for a normal navigation to a data: url, with | |
195 // navigation_start set to Now() plus the given offset. | |
196 CommonNavigationParams MakeCommonNavigationParams( | |
197 TimeDelta navigation_start_offset) { | |
198 CommonNavigationParams params; | |
199 params.url = GURL("data:text/html,<div>Page</div>"); | |
200 params.navigation_start = base::TimeTicks::Now() + navigation_start_offset; | |
201 params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | |
202 params.transition = ui::PAGE_TRANSITION_TYPED; | |
203 return params; | |
204 } | |
205 | |
206 blink::WebURLLoader* CreateMockURLLoader() { | |
207 return new testing::NiceMock<MockWebURLLoader>(); | |
208 } | |
209 | |
192 } // namespace | 210 } // namespace |
193 | 211 |
194 class RenderViewImplTest : public RenderViewTest { | 212 class RenderViewImplTest : public RenderViewTest { |
195 public: | 213 public: |
196 RenderViewImplTest() { | 214 RenderViewImplTest() { |
197 // Attach a pseudo keyboard device to this object. | 215 // Attach a pseudo keyboard device to this object. |
198 mock_keyboard_.reset(new MockKeyboard()); | 216 mock_keyboard_.reset(new MockKeyboard()); |
199 } | 217 } |
200 | 218 |
201 ~RenderViewImplTest() override {} | 219 ~RenderViewImplTest() override {} |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 // the pending continuation. | 258 // the pending continuation. |
241 FrameLoadWaiter(frame()).Wait(); | 259 FrameLoadWaiter(frame()).Wait(); |
242 } | 260 } |
243 | 261 |
244 template<class T> | 262 template<class T> |
245 typename T::Param ProcessAndReadIPC() { | 263 typename T::Param ProcessAndReadIPC() { |
246 ProcessPendingMessages(); | 264 ProcessPendingMessages(); |
247 const IPC::Message* message = | 265 const IPC::Message* message = |
248 render_thread_->sink().GetUniqueMessageMatching(T::ID); | 266 render_thread_->sink().GetUniqueMessageMatching(T::ID); |
249 typename T::Param param; | 267 typename T::Param param; |
250 T::Read(message, ¶m); | 268 EXPECT_TRUE(message); |
269 if (message) | |
270 T::Read(message, ¶m); | |
251 return param; | 271 return param; |
252 } | 272 } |
253 | 273 |
254 // Sends IPC messages that emulates a key-press event. | 274 // Sends IPC messages that emulates a key-press event. |
255 int SendKeyEvent(MockKeyboard::Layout layout, | 275 int SendKeyEvent(MockKeyboard::Layout layout, |
256 int key_code, | 276 int key_code, |
257 MockKeyboard::Modifiers modifiers, | 277 MockKeyboard::Modifiers modifiers, |
258 base::string16* output) { | 278 base::string16* output) { |
259 #if defined(OS_WIN) | 279 #if defined(OS_WIN) |
260 // Retrieve the Unicode character for the given tuple (keyboard-layout, | 280 // Retrieve the Unicode character for the given tuple (keyboard-layout, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 const gfx::Size& GetPreferredSize() { | 389 const gfx::Size& GetPreferredSize() { |
370 view()->CheckPreferredSize(); | 390 view()->CheckPreferredSize(); |
371 return view()->preferred_size_; | 391 return view()->preferred_size_; |
372 } | 392 } |
373 | 393 |
374 void SetZoomLevel(double level) { | 394 void SetZoomLevel(double level) { |
375 view()->OnSetZoomLevel( | 395 view()->OnSetZoomLevel( |
376 PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE, level); | 396 PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE, level); |
377 } | 397 } |
378 | 398 |
399 // Closes a view created during the test, i.e. not the |view()|. Checks that | |
400 // the main frame is detached and deleted, and makes sure the view does not | |
401 // leak. | |
402 void CloseRenderView(RenderViewImpl* new_view) { | |
403 new_view->Close(); | |
404 EXPECT_FALSE(new_view->GetMainRenderFrame()); | |
405 // Clean up so we don't leak it. | |
clamy
2016/08/17 13:03:55
nit: blank line above.
nit: avoid using we in comm
Alexander Semashko
2016/08/17 17:10:25
Ok. I just removed the comment since it duplicates
| |
406 new_view->Release(); | |
407 } | |
408 | |
379 private: | 409 private: |
380 std::unique_ptr<MockKeyboard> mock_keyboard_; | 410 std::unique_ptr<MockKeyboard> mock_keyboard_; |
381 }; | 411 }; |
382 | 412 |
383 class DevToolsAgentTest : public RenderViewImplTest { | 413 class DevToolsAgentTest : public RenderViewImplTest { |
384 public: | 414 public: |
385 void Attach() { | 415 void Attach() { |
386 notifications_ = std::vector<std::string>(); | 416 notifications_ = std::vector<std::string>(); |
387 expecting_pause_ = false; | 417 expecting_pause_ = false; |
388 std::string host_id = "host_id"; | 418 std::string host_id = "host_id"; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 // after closing it. | 562 // after closing it. |
533 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { | 563 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { |
534 // Create a new main frame RenderFrame so that we don't interfere with the | 564 // Create a new main frame RenderFrame so that we don't interfere with the |
535 // shutdown of frame() in RenderViewTest.TearDown. | 565 // shutdown of frame() in RenderViewTest.TearDown. |
536 blink::WebURLRequest popup_request(GURL("http://foo.com")); | 566 blink::WebURLRequest popup_request(GURL("http://foo.com")); |
537 blink::WebView* new_web_view = view()->createView( | 567 blink::WebView* new_web_view = view()->createView( |
538 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", | 568 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", |
539 blink::WebNavigationPolicyNewForegroundTab, false); | 569 blink::WebNavigationPolicyNewForegroundTab, false); |
540 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); | 570 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); |
541 | 571 |
542 // Close the view, causing the main RenderFrame to be detached and deleted. | 572 // Checks that the frame is deleted properly and cleans up the view. |
543 new_view->Close(); | 573 CloseRenderView(new_view); |
544 EXPECT_FALSE(new_view->GetMainRenderFrame()); | |
545 | |
546 // Clean up after the new view so we don't leak it. | |
547 new_view->Release(); | |
548 } | 574 } |
549 | 575 |
550 // Test that we get form state change notifications when input fields change. | 576 // Test that we get form state change notifications when input fields change. |
551 TEST_F(RenderViewImplTest, OnNavStateChanged) { | 577 TEST_F(RenderViewImplTest, OnNavStateChanged) { |
552 view()->set_send_content_state_immediately(true); | 578 view()->set_send_content_state_immediately(true); |
553 LoadHTML("<input type=\"text\" id=\"elt_text\"></input>"); | 579 LoadHTML("<input type=\"text\" id=\"elt_text\"></input>"); |
554 | 580 |
555 // We should NOT have gotten a form state change notification yet. | 581 // We should NOT have gotten a form state change notification yet. |
556 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 582 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
557 FrameHostMsg_UpdateState::ID)); | 583 FrameHostMsg_UpdateState::ID)); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
814 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", | 840 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", |
815 blink::WebNavigationPolicyNewForegroundTab, false); | 841 blink::WebNavigationPolicyNewForegroundTab, false); |
816 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); | 842 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); |
817 blink::WebFrameClient::NavigationPolicyInfo popup_policy_info(popup_request); | 843 blink::WebFrameClient::NavigationPolicyInfo popup_policy_info(popup_request); |
818 popup_policy_info.navigationType = blink::WebNavigationTypeLinkClicked; | 844 popup_policy_info.navigationType = blink::WebNavigationTypeLinkClicked; |
819 popup_policy_info.defaultPolicy = blink::WebNavigationPolicyNewForegroundTab; | 845 popup_policy_info.defaultPolicy = blink::WebNavigationPolicyNewForegroundTab; |
820 policy = static_cast<RenderFrameImpl*>(new_view->GetMainRenderFrame())-> | 846 policy = static_cast<RenderFrameImpl*>(new_view->GetMainRenderFrame())-> |
821 decidePolicyForNavigation(popup_policy_info); | 847 decidePolicyForNavigation(popup_policy_info); |
822 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); | 848 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); |
823 | 849 |
824 // Clean up after the new view so we don't leak it. | 850 CloseRenderView(new_view); |
825 new_view->Close(); | |
826 new_view->Release(); | |
827 } | 851 } |
828 | 852 |
829 // Verify that security origins are replicated properly to RenderFrameProxies | 853 // Verify that security origins are replicated properly to RenderFrameProxies |
830 // when swapping out. | 854 // when swapping out. |
831 TEST_F(RenderViewImplTest, OriginReplicationForSwapOut) { | 855 TEST_F(RenderViewImplTest, OriginReplicationForSwapOut) { |
832 // This test should only run with --site-per-process, since origin | 856 // This test should only run with --site-per-process, since origin |
833 // replication only happens in that mode. | 857 // replication only happens in that mode. |
834 if (!AreAllSitesIsolatedForTesting()) | 858 if (!AreAllSitesIsolatedForTesting()) |
835 return; | 859 return; |
836 | 860 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
944 // Respond to a swap out request. | 968 // Respond to a swap out request. |
945 TestRenderFrame* new_main_frame = | 969 TestRenderFrame* new_main_frame = |
946 static_cast<TestRenderFrame*>(new_view->GetMainRenderFrame()); | 970 static_cast<TestRenderFrame*>(new_view->GetMainRenderFrame()); |
947 new_main_frame->SwapOut( | 971 new_main_frame->SwapOut( |
948 kProxyRoutingId, true, | 972 kProxyRoutingId, true, |
949 ReconstructReplicationStateForTesting(new_main_frame)); | 973 ReconstructReplicationStateForTesting(new_main_frame)); |
950 | 974 |
951 // Simulate getting painted after swapping out. | 975 // Simulate getting painted after swapping out. |
952 new_view->DidFlushPaint(); | 976 new_view->DidFlushPaint(); |
953 | 977 |
954 new_view->Close(); | 978 CloseRenderView(new_view); |
955 new_view->Release(); | |
956 } | 979 } |
957 | 980 |
958 // Verify that the renderer process doesn't crash when device scale factor | 981 // Verify that the renderer process doesn't crash when device scale factor |
959 // changes after a cross-process navigation has commited. | 982 // changes after a cross-process navigation has commited. |
960 // See https://crbug.com/571603. | 983 // See https://crbug.com/571603. |
961 TEST_F(RenderViewImplTest, SetZoomLevelAfterCrossProcessNavigation) { | 984 TEST_F(RenderViewImplTest, SetZoomLevelAfterCrossProcessNavigation) { |
962 // This test should only run with out-of-process iframes enabled. | 985 // This test should only run with out-of-process iframes enabled. |
963 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) | 986 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) |
964 return; | 987 return; |
965 | 988 |
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2016 | 2039 |
2017 frame()->SetAccessibilityMode(AccessibilityModeOff); | 2040 frame()->SetAccessibilityMode(AccessibilityModeOff); |
2018 ASSERT_EQ(AccessibilityModeOff, frame()->accessibility_mode()); | 2041 ASSERT_EQ(AccessibilityModeOff, frame()->accessibility_mode()); |
2019 ASSERT_FALSE(frame()->render_accessibility()); | 2042 ASSERT_FALSE(frame()->render_accessibility()); |
2020 | 2043 |
2021 frame()->SetAccessibilityMode(AccessibilityModeComplete); | 2044 frame()->SetAccessibilityMode(AccessibilityModeComplete); |
2022 ASSERT_EQ(AccessibilityModeComplete, frame()->accessibility_mode()); | 2045 ASSERT_EQ(AccessibilityModeComplete, frame()->accessibility_mode()); |
2023 ASSERT_TRUE(frame()->render_accessibility()); | 2046 ASSERT_TRUE(frame()->render_accessibility()); |
2024 } | 2047 } |
2025 | 2048 |
2049 TEST_F(RenderViewImplTest, RendererNavigationStartTransmittedToBrowser) { | |
clamy
2016/08/17 13:03:55
Could you add comments explaining what the test do
Alexander Semashko
2016/08/17 17:10:25
Done.
| |
2050 base::TimeTicks lower_bound_navigation_start(base::TimeTicks::Now()); | |
2051 frame()->GetWebFrame()->loadHTMLString( | |
2052 "hello world", blink::WebURL(GURL("data:text/html,"))); | |
2053 | |
2054 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = | |
2055 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); | |
2056 base::TimeTicks transmitted_start = std::get<1>(host_nav_params); | |
2057 EXPECT_FALSE(transmitted_start.is_null()); | |
2058 EXPECT_LT(lower_bound_navigation_start, transmitted_start); | |
2059 } | |
2060 | |
2061 TEST_F(RenderViewImplTest, BrowserNavigationStart) { | |
clamy
2016/08/17 13:03:55
Isn't this test testing that the browser navigatio
Alexander Semashko
2016/08/17 17:10:25
Assuming that these tests will always start with a
clamy
2016/08/24 23:23:09
Well it was working when you just added a subframe
Alexander Semashko
2016/08/25 10:44:33
Yeah, it is working currently. To elaborate more o
clamy
2016/08/25 18:00:14
Your test is on the commit queue, which means it c
Alexander Semashko
2016/08/25 21:32:10
I meant major refactorings, where it sometimes is
clamy
2016/08/25 22:24:29
If the routing id part is not used in the tests, t
Alexander Semashko
2016/08/25 22:50:19
Done.
| |
2062 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1)); | |
2063 | |
2064 frame()->Navigate(common_params, StartNavigationParams(), | |
2065 RequestNavigationParams()); | |
2066 FrameHostMsg_DidStartProvisionalLoad::Param nav_params = | |
2067 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); | |
2068 EXPECT_EQ(common_params.navigation_start, std::get<1>(nav_params)); | |
2069 } | |
2070 | |
2026 // Sanity check for the Navigation Timing API |navigationStart| override. We | 2071 // Sanity check for the Navigation Timing API |navigationStart| override. We |
2027 // are asserting only most basic constraints, as TimeTicks (passed as the | 2072 // are asserting only most basic constraints, as TimeTicks (passed as the |
2028 // override) are not comparable with the wall time (returned by the Blink API). | 2073 // override) are not comparable with the wall time (returned by the Blink API). |
2029 TEST_F(RenderViewImplTest, NavigationStartOverride) { | 2074 TEST_F(RenderViewImplTest, BrowserNavigationStartSanitized) { |
2030 // Verify that a navigation that claims to have started in the future - 42 | 2075 // Verify that a navigation that claims to have started in the future - 42 |
2031 // days from now is *not* reported as one that starts in the future; as we | 2076 // days from now is *not* reported as one that starts in the future; as we |
2032 // sanitize the override allowing a maximum of ::Now(). | 2077 // sanitize the override allowing a maximum of ::Now(). |
2033 CommonNavigationParams late_common_params; | 2078 auto late_common_params = MakeCommonNavigationParams(TimeDelta::FromDays(42)); |
2034 late_common_params.url = GURL("data:text/html,<div>Another page</div>"); | |
2035 late_common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | |
2036 late_common_params.transition = ui::PAGE_TRANSITION_TYPED; | |
2037 late_common_params.navigation_start = | |
2038 base::TimeTicks::Now() + base::TimeDelta::FromDays(42); | |
2039 late_common_params.method = "POST"; | 2079 late_common_params.method = "POST"; |
2040 | 2080 |
2041 frame()->Navigate(late_common_params, StartNavigationParams(), | 2081 frame()->Navigate(late_common_params, StartNavigationParams(), |
2042 RequestNavigationParams()); | 2082 RequestNavigationParams()); |
2043 ProcessPendingMessages(); | 2083 ProcessPendingMessages(); |
2044 base::Time after_navigation = | 2084 base::Time after_navigation = |
2045 base::Time::Now() + base::TimeDelta::FromDays(1); | 2085 base::Time::Now() + base::TimeDelta::FromDays(1); |
2046 | 2086 |
2047 base::Time late_nav_reported_start = | 2087 base::Time late_nav_reported_start = |
2048 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); | 2088 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); |
2049 EXPECT_LE(late_nav_reported_start, after_navigation); | 2089 EXPECT_LE(late_nav_reported_start, after_navigation); |
2050 } | 2090 } |
2051 | 2091 |
2052 TEST_F(RenderViewImplTest, RendererNavigationStartTransmittedToBrowser) { | 2092 // Checks that a browser-initiated navigation in an initial document that was |
2053 base::TimeTicks lower_bound_navigation_start; | 2093 // not accessed uses browser-side timestamp. |
2054 frame()->GetWebFrame()->loadHTMLString( | 2094 TEST_F(RenderViewImplTest, |
2055 "hello world", blink::WebURL(GURL("data:text/html,"))); | 2095 BrowserNavigationStartUsedIfInitialDocumentWasNotAccessed) { |
2096 blink_platform_impl_.SetWebURLLoaderFactory(base::Bind(&CreateMockURLLoader)); | |
2097 // Open a page that will be navigated later. | |
2098 ExecuteJavaScriptForTests("window.open('https://google.com/');"); | |
2099 // The new page starts a provisional load (it will not commit). | |
2056 ProcessPendingMessages(); | 2100 ProcessPendingMessages(); |
2057 const IPC::Message* frame_navigate_msg = | 2101 render_thread_->sink().ClearMessages(); |
2058 render_thread_->sink().GetUniqueMessageMatching( | 2102 |
2059 FrameHostMsg_DidStartProvisionalLoad::ID); | 2103 auto* new_main_frame = |
2060 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params; | 2104 static_cast<TestRenderFrame*>(RenderFrame::FromRoutingID( |
2061 FrameHostMsg_DidStartProvisionalLoad::Read(frame_navigate_msg, | 2105 render_thread_->new_window_main_frame_routing_id())); |
2062 &host_nav_params); | 2106 ASSERT_TRUE(new_main_frame); |
2063 base::TimeTicks transmitted_start = std::get<1>(host_nav_params); | 2107 |
2064 EXPECT_FALSE(transmitted_start.is_null()); | 2108 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1)); |
2065 EXPECT_LT(lower_bound_navigation_start, transmitted_start); | 2109 new_main_frame->Navigate(common_params, StartNavigationParams(), |
2110 RequestNavigationParams()); | |
2111 | |
2112 FrameHostMsg_DidStartProvisionalLoad::Param nav_params = | |
2113 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); | |
2114 EXPECT_EQ(common_params.navigation_start, std::get<1>(nav_params)); | |
2115 | |
2116 CloseRenderView( | |
2117 RenderViewImpl::FromRoutingID(render_thread_->new_window_routing_id())); | |
2118 } | |
2119 | |
2120 // Checks that a browser-initiated navigation in an initial document that has | |
2121 // been accessed does not use browser-side timestamp (there may be arbitrary | |
2122 // content and/or scripts injected, including beforeunload handler that shows | |
2123 // a confirmation dialog). | |
2124 TEST_F(RenderViewImplTest, | |
2125 BrowserNavigationStartDiscardedIfInitialDocumentWasAccessed) { | |
2126 blink_platform_impl_.SetWebURLLoaderFactory(base::Bind(&CreateMockURLLoader)); | |
2127 // Open a page that will be navigated later. | |
2128 ExecuteJavaScriptForTests( | |
2129 "var w = window.open('https://google.com/');" | |
2130 "w.document.body.appendChild(w.document.createElement('div'));"); | |
2131 // The new page starts a provisional load (it will not commit). | |
2132 ProcessPendingMessages(); | |
2133 render_thread_->sink().ClearMessages(); | |
2134 | |
2135 auto* new_main_frame = | |
2136 static_cast<TestRenderFrame*>(RenderFrame::FromRoutingID( | |
2137 render_thread_->new_window_main_frame_routing_id())); | |
2138 ASSERT_TRUE(new_main_frame); | |
2139 | |
2140 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1)); | |
2141 new_main_frame->Navigate(common_params, StartNavigationParams(), | |
2142 RequestNavigationParams()); | |
2143 | |
2144 FrameHostMsg_DidStartProvisionalLoad::Param nav_params = | |
2145 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); | |
2146 EXPECT_GT(std::get<1>(nav_params), common_params.navigation_start); | |
2147 | |
2148 CloseRenderView( | |
2149 RenderViewImpl::FromRoutingID(render_thread_->new_window_routing_id())); | |
2150 } | |
2151 | |
2152 TEST_F(RenderViewImplTest, | |
2153 FiringBeforeUnloadInSubFrameDiscardsBrowserNavigationStart) { | |
clamy
2016/08/17 13:03:55
This doesn't seem correct to me: based on how the
Alexander Semashko
2016/08/17 17:10:25
Well, now the test name does not reflect what is h
| |
2154 // Add a beforeunload handler in the initial document. | |
2155 ExecuteJavaScriptForTests( | |
2156 "var frame = document.createElement('iframe');" | |
2157 "document.body.appendChild(frame);" | |
2158 "frame.contentWindow.onbeforeunload = function() { return null; };"); | |
2159 // Need to drop the DidStartProvisionalLoad message from the child frame. | |
2160 ProcessPendingMessages(); | |
2161 render_thread_->sink().ClearMessages(); | |
2162 | |
2163 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1)); | |
2164 frame()->Navigate(common_params, StartNavigationParams(), | |
2165 RequestNavigationParams()); | |
2166 | |
2167 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = | |
2168 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); | |
2169 EXPECT_GT(std::get<1>(host_nav_params), common_params.navigation_start); | |
2066 } | 2170 } |
2067 | 2171 |
2068 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForReload) { | 2172 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForReload) { |
clamy
2016/08/17 13:03:55
Can you rename it NavigationStartForReload?
Alexander Semashko
2016/08/17 17:10:25
Done.
| |
2069 const char url_string[] = "data:text/html,<div>Page</div>"; | 2173 const char url_string[] = "data:text/html,<div>Page</div>"; |
2070 // Navigate once, then reload. | 2174 // Navigate once, then reload. |
2071 LoadHTML(url_string); | 2175 LoadHTML(url_string); |
2072 ProcessPendingMessages(); | 2176 ProcessPendingMessages(); |
2073 render_thread_->sink().ClearMessages(); | 2177 render_thread_->sink().ClearMessages(); |
2074 | 2178 |
2075 CommonNavigationParams common_params; | 2179 CommonNavigationParams common_params; |
2076 common_params.url = GURL(url_string); | 2180 common_params.url = GURL(url_string); |
2077 common_params.navigation_type = | 2181 common_params.navigation_type = |
2078 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; | 2182 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; |
2079 common_params.transition = ui::PAGE_TRANSITION_RELOAD; | 2183 common_params.transition = ui::PAGE_TRANSITION_RELOAD; |
2080 | 2184 |
2185 // The browser navigation_start should not be used because beforeunload will | |
2186 // be fired during Navigate. | |
2081 frame()->Navigate(common_params, StartNavigationParams(), | 2187 frame()->Navigate(common_params, StartNavigationParams(), |
2082 RequestNavigationParams()); | 2188 RequestNavigationParams()); |
2083 | 2189 |
2084 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = | 2190 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = |
2085 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); | 2191 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); |
2086 // The true timestamp is later than the browser initiated one. | |
2087 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params), | 2192 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params), |
2088 common_params.navigation_start); | 2193 common_params.navigation_start); |
clamy
2016/08/17 13:03:55
Can you do the following:
if (!IsBrowserSideNaviga
Alexander Semashko
2016/08/17 17:10:25
Done.
| |
2089 } | 2194 } |
2090 | 2195 |
2091 TEST_F(RenderViewImplTest, BrowserNavigationStartNotUsedForHistoryNavigation) { | 2196 TEST_F(RenderViewImplTest, |
2197 BrowserNavigationStartNotUsedForSameProcessHistoryNavigation) { | |
clamy
2016/08/17 13:03:55
Please rename it NavigationStartForSameProcessHist
Alexander Semashko
2016/08/17 17:10:25
Done. Also renamed the cross-process counterpart a
| |
2092 LoadHTML("<div id=pagename>Page A</div>"); | 2198 LoadHTML("<div id=pagename>Page A</div>"); |
2093 LoadHTML("<div id=pagename>Page B</div>"); | 2199 LoadHTML("<div id=pagename>Page B</div>"); |
2094 PageState back_state = GetCurrentPageState(); | 2200 PageState back_state = GetCurrentPageState(); |
2095 LoadHTML("<div id=pagename>Page C</div>"); | 2201 LoadHTML("<div id=pagename>Page C</div>"); |
2096 PageState forward_state = GetCurrentPageState(); | 2202 PageState forward_state = GetCurrentPageState(); |
2097 ProcessPendingMessages(); | 2203 ProcessPendingMessages(); |
2098 render_thread_->sink().ClearMessages(); | 2204 render_thread_->sink().ClearMessages(); |
2099 | 2205 |
2100 // Go back. | 2206 // Go back. |
2207 // The browser navigation_start should not be used because beforeunload will | |
2208 // be fired during GoToOffsetWithParams. | |
2101 CommonNavigationParams common_params_back; | 2209 CommonNavigationParams common_params_back; |
2102 common_params_back.url = | 2210 common_params_back.url = |
2103 GURL("data:text/html;charset=utf-8,<div id=pagename>Page B</div>"); | 2211 GURL("data:text/html;charset=utf-8,<div id=pagename>Page B</div>"); |
2104 common_params_back.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | 2212 common_params_back.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
2105 GoToOffsetWithParams(-1, back_state, common_params_back, | 2213 GoToOffsetWithParams(-1, back_state, common_params_back, |
2106 StartNavigationParams(), RequestNavigationParams()); | 2214 StartNavigationParams(), RequestNavigationParams()); |
2107 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = | 2215 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = |
2108 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); | 2216 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); |
2109 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params), | 2217 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params), |
2110 common_params_back.navigation_start); | 2218 common_params_back.navigation_start); |
2111 render_thread_->sink().ClearMessages(); | 2219 render_thread_->sink().ClearMessages(); |
2112 | 2220 |
2113 // Go forward. | 2221 // Go forward. |
2222 // The browser navigation_start should not be used because beforeunload will | |
2223 // be fired during GoToOffsetWithParams. | |
2114 CommonNavigationParams common_params_forward; | 2224 CommonNavigationParams common_params_forward; |
2115 common_params_forward.url = | 2225 common_params_forward.url = |
2116 GURL("data:text/html;charset=utf-8,<div id=pagename>Page C</div>"); | 2226 GURL("data:text/html;charset=utf-8,<div id=pagename>Page C</div>"); |
2117 common_params_forward.transition = ui::PAGE_TRANSITION_FORWARD_BACK; | 2227 common_params_forward.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
2118 GoToOffsetWithParams(1, forward_state, common_params_forward, | 2228 GoToOffsetWithParams(1, forward_state, common_params_forward, |
2119 StartNavigationParams(), RequestNavigationParams()); | 2229 StartNavigationParams(), RequestNavigationParams()); |
2120 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params2 = | 2230 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params2 = |
2121 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); | 2231 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); |
2122 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params2), | 2232 EXPECT_PRED2(TimeTicksGT, std::get<1>(host_nav_params2), |
2123 common_params_forward.navigation_start); | 2233 common_params_forward.navigation_start); |
2124 } | 2234 } |
2125 | 2235 |
2126 TEST_F(RenderViewImplTest, BrowserNavigationStartSuccessfullyTransmitted) { | 2236 TEST_F(RenderViewImplTest, |
2127 CommonNavigationParams common_params; | 2237 BrowserNavigationStartUsedForCrossProcessHistoryNavigation) { |
2128 common_params.url = GURL("data:text/html,<div>Page</div>"); | 2238 auto common_params = MakeCommonNavigationParams(-TimeDelta::FromSeconds(1)); |
2129 common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 2239 common_params.transition = ui::PAGE_TRANSITION_FORWARD_BACK; |
2130 common_params.transition = ui::PAGE_TRANSITION_TYPED; | |
2131 | 2240 |
2132 frame()->Navigate(common_params, StartNavigationParams(), | 2241 RequestNavigationParams request_params; |
2133 RequestNavigationParams()); | 2242 request_params.page_state = |
2243 PageState::CreateForTesting(common_params.url, false, nullptr, nullptr); | |
2244 request_params.page_id = 1; | |
2245 request_params.nav_entry_id = 42; | |
2246 request_params.pending_history_list_offset = 1; | |
2247 request_params.current_history_list_offset = 0; | |
2248 request_params.current_history_list_length = 1; | |
2249 frame()->Navigate(common_params, StartNavigationParams(), request_params); | |
2134 | 2250 |
2135 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = | 2251 FrameHostMsg_DidStartProvisionalLoad::Param host_nav_params = |
2136 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); | 2252 ProcessAndReadIPC<FrameHostMsg_DidStartProvisionalLoad>(); |
2137 EXPECT_EQ(std::get<1>(host_nav_params), common_params.navigation_start); | 2253 EXPECT_EQ(std::get<1>(host_nav_params), common_params.navigation_start); |
2138 } | 2254 } |
2139 | 2255 |
2140 TEST_F(RenderViewImplTest, PreferredSizeZoomed) { | 2256 TEST_F(RenderViewImplTest, PreferredSizeZoomed) { |
2141 LoadHTML("<body style='margin:0;'><div style='display:inline-block; " | 2257 LoadHTML("<body style='margin:0;'><div style='display:inline-block; " |
2142 "width:400px; height:400px;'/></body>"); | 2258 "width:400px; height:400px;'/></body>"); |
2143 view()->webview()->mainFrame()->setCanHaveScrollbars(false); | 2259 view()->webview()->mainFrame()->setCanHaveScrollbars(false); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2480 ExpectPauseAndResume(3); | 2596 ExpectPauseAndResume(3); |
2481 blink::WebScriptSource source2( | 2597 blink::WebScriptSource source2( |
2482 WebString::fromUTF8("function func2() { func1(); }; func2();")); | 2598 WebString::fromUTF8("function func2() { func1(); }; func2();")); |
2483 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); | 2599 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); |
2484 | 2600 |
2485 EXPECT_FALSE(IsPaused()); | 2601 EXPECT_FALSE(IsPaused()); |
2486 Detach(); | 2602 Detach(); |
2487 } | 2603 } |
2488 | 2604 |
2489 } // namespace content | 2605 } // namespace content |
OLD | NEW |