Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | |
| 6 | |
| 5 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | |
| 6 #include "content/browser/frame_host/navigation_handle_impl.h" | 9 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 10 #include "content/public/browser/navigation_data.h" | |
| 7 #include "content/public/browser/navigation_throttle.h" | 11 #include "content/public/browser/navigation_throttle.h" |
| 8 #include "content/test/test_render_frame_host.h" | 12 #include "content/test/test_render_frame_host.h" |
| 9 | 13 |
| 10 namespace content { | 14 namespace content { |
| 11 | 15 |
| 12 // Test version of a NavigationThrottle. It will always return the current | 16 // Test version of a NavigationThrottle. It will always return the current |
| 13 // NavigationThrottle::ThrottleCheckResult |result_|, It also monitors the | 17 // NavigationThrottle::ThrottleCheckResult |result_|, It also monitors the |
| 14 // number of times WillStartRequest, WillRedirectRequest, and | 18 // number of times WillStartRequest, WillRedirectRequest, and |
| 15 // WillProcessResponse were called. | 19 // WillProcessResponse were called. |
| 16 class TestNavigationThrottle : public NavigationThrottle { | 20 class TestNavigationThrottle : public NavigationThrottle { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 private: | 53 private: |
| 50 // The result returned by the TestNavigationThrottle. | 54 // The result returned by the TestNavigationThrottle. |
| 51 NavigationThrottle::ThrottleCheckResult result_; | 55 NavigationThrottle::ThrottleCheckResult result_; |
| 52 | 56 |
| 53 // The number of times each handler was called. | 57 // The number of times each handler was called. |
| 54 int will_start_calls_; | 58 int will_start_calls_; |
| 55 int will_redirect_calls_; | 59 int will_redirect_calls_; |
| 56 int will_process_response_calls_; | 60 int will_process_response_calls_; |
| 57 }; | 61 }; |
| 58 | 62 |
| 63 class TestNavigationData : public NavigationData { | |
| 64 public: | |
| 65 TestNavigationData() {} | |
| 66 ~TestNavigationData() override {} | |
| 67 std::unique_ptr<NavigationData> Clone() const override { | |
| 68 return base::WrapUnique(new TestNavigationData()); | |
| 69 } | |
| 70 }; | |
| 71 | |
| 59 class NavigationHandleImplTest : public RenderViewHostImplTestHarness { | 72 class NavigationHandleImplTest : public RenderViewHostImplTestHarness { |
| 60 public: | 73 public: |
| 61 NavigationHandleImplTest() | 74 NavigationHandleImplTest() |
| 62 : was_callback_called_(false), | 75 : was_callback_called_(false), |
| 63 callback_result_(NavigationThrottle::DEFER) {} | 76 callback_result_(NavigationThrottle::DEFER) {} |
| 64 | 77 |
| 65 void SetUp() override { | 78 void SetUp() override { |
| 66 RenderViewHostImplTestHarness::SetUp(); | 79 RenderViewHostImplTestHarness::SetUp(); |
| 67 test_handle_ = | 80 test_handle_ = |
| 68 NavigationHandleImpl::Create(GURL(), main_test_rfh()->frame_tree_node(), | 81 NavigationHandleImpl::Create(GURL(), main_test_rfh()->frame_tree_node(), |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 EXPECT_TRUE(was_callback_called()); | 651 EXPECT_TRUE(was_callback_called()); |
| 639 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 652 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
| 640 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 653 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 641 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 654 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 642 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 655 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
| 643 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 656 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 644 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 657 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 645 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 658 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
| 646 } | 659 } |
| 647 | 660 |
| 661 TEST_F(NavigationHandleImplTest, NavigationData) { | |
| 662 TestNavigationData* test_data = new TestNavigationData(); | |
| 663 test_handle()->SetNavigationData(base::WrapUnique(test_data)); | |
| 664 EXPECT_EQ(test_data, test_handle()->GetNavigationData()); | |
|
nasko
2016/05/02 22:02:49
This test case doesn't test much, what's the goal
RyanSturm
2016/05/02 23:02:56
I like to unittest everything individually, but th
| |
| 665 } | |
| 666 | |
| 648 } // namespace content | 667 } // namespace content |
| OLD | NEW |