Index: content/browser/frame_host/navigation_handle_impl_unittest.cc |
diff --git a/content/browser/frame_host/navigation_handle_impl_unittest.cc b/content/browser/frame_host/navigation_handle_impl_unittest.cc |
index f77bbdf01231f5eb8670ab5feaa8082e13b736d9..87e1aad4473a32cd87e3d6c1630a601ed4a77f92 100644 |
--- a/content/browser/frame_host/navigation_handle_impl_unittest.cc |
+++ b/content/browser/frame_host/navigation_handle_impl_unittest.cc |
@@ -56,6 +56,34 @@ class TestNavigationThrottle : public NavigationThrottle { |
int will_process_response_calls_; |
}; |
+// A NavigationThrottle which adds console messages in WillStartRequest, |
+// WillRedirectRequest, and always returns PROCEED. |
+class TestConsoleMessagesThrottle : public NavigationThrottle { |
+ public: |
+ TestConsoleMessagesThrottle(NavigationHandle* handle) |
+ : NavigationThrottle(handle) {} |
+ |
+ ~TestConsoleMessagesThrottle() override {} |
+ |
+ NavigationThrottle::ThrottleCheckResult WillStartRequest() override { |
+ static_cast<NavigationHandleImpl*>(navigation_handle()) |
+ ->QueueConsoleMessage(CONSOLE_MESSAGE_LEVEL_LOG, "WillStartRequest"); |
+ return NavigationThrottle::PROCEED; |
+ } |
+ |
+ NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override { |
+ static_cast<NavigationHandleImpl*>(navigation_handle()) |
+ ->QueueConsoleMessage(CONSOLE_MESSAGE_LEVEL_LOG, "WillRedirectRequest"); |
+ return NavigationThrottle::PROCEED; |
+ } |
+ |
+ NavigationThrottle::ThrottleCheckResult WillProcessResponse() override { |
+ static_cast<NavigationHandleImpl*>(navigation_handle()) |
+ ->QueueConsoleMessage(CONSOLE_MESSAGE_LEVEL_LOG, "WillProcessResponse"); |
+ return NavigationThrottle::PROCEED; |
+ } |
+}; |
+ |
class NavigationHandleImplTest : public RenderViewHostImplTestHarness { |
public: |
NavigationHandleImplTest() |
@@ -92,6 +120,11 @@ class NavigationHandleImplTest : public RenderViewHostImplTestHarness { |
return test_handle_->state() == NavigationHandleImpl::CANCELING; |
} |
+ const std::queue<std::pair<ConsoleMessageLevel, const std::string>>& |
+ GetConsoleQueue() const { |
+ return test_handle_->console_queue_; |
+ } |
+ |
// Helper function to call WillStartRequest on |handle|. If this function |
// returns DEFER, |callback_result_| will be set to the actual result of |
// the throttle checks when they are finished. |
@@ -164,6 +197,15 @@ class NavigationHandleImplTest : public RenderViewHostImplTestHarness { |
return test_throttle; |
} |
+ // Creates, register and returns a TestConsoleMessagesThrottle. |
+ TestConsoleMessagesThrottle* CreateTestConsoleMessagesThrottle() { |
+ TestConsoleMessagesThrottle* test_throttle = |
+ new TestConsoleMessagesThrottle(test_handle()); |
+ test_handle()->RegisterThrottleForTesting( |
+ std::unique_ptr<TestConsoleMessagesThrottle>(test_throttle)); |
+ return test_throttle; |
+ } |
+ |
private: |
// The callback provided to NavigationHandleImpl::WillStartRequest and |
// NavigationHandleImpl::WillRedirectRequest during the tests. |
@@ -645,4 +687,26 @@ TEST_F(NavigationHandleImplTest, CancelThenProceedWillProcessResponse) { |
EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
} |
+TEST_F(NavigationHandleImplTest, ConsoleMessages) { |
+ TestConsoleMessagesThrottle* throttle = CreateTestConsoleMessagesThrottle(); |
+ DCHECK(throttle); |
+ SimulateWillStartRequest(); |
+ DCHECK_EQ(1u, GetConsoleQueue().size()); |
+ DCHECK_EQ("WillStartRequest", GetConsoleQueue().back().second); |
+ |
+ SimulateWillRedirectRequest(); |
+ DCHECK_EQ(2u, GetConsoleQueue().size()); |
+ DCHECK_EQ("WillRedirectRequest", GetConsoleQueue().back().second); |
+ |
+ SimulateWillProcessResponse(); |
+ // Calling 'WillProcessResponse' should dump the queue. |
+ DCHECK_EQ(0u, GetConsoleQueue().size()); |
+ |
+ // Verify that messages got to the RFH correctly. |
+ DCHECK_EQ(3u, main_test_rfh()->GetConsoleMessages().size()); |
+ DCHECK_EQ("WillStartRequest", main_test_rfh()->GetConsoleMessages()[0]); |
+ DCHECK_EQ("WillRedirectRequest", main_test_rfh()->GetConsoleMessages()[1]); |
+ DCHECK_EQ("WillProcessResponse", main_test_rfh()->GetConsoleMessages()[2]); |
+} |
+ |
} // namespace content |