| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #import "ios/web/public/navigation_item.h" |
| 9 #import "ios/web/public/navigation_manager.h" |
| 8 #import "ios/web/public/test/http_server.h" | 10 #import "ios/web/public/test/http_server.h" |
| 9 #include "ios/web/public/test/http_server_util.h" | 11 #include "ios/web/public/test/http_server_util.h" |
| 10 #include "ios/web/public/web_state/navigation_context.h" | 12 #include "ios/web/public/web_state/navigation_context.h" |
| 11 #include "ios/web/public/web_state/web_state_observer.h" | 13 #include "ios/web/public/web_state/web_state_observer.h" |
| 12 #include "ios/web/test/test_url_constants.h" | 14 #include "ios/web/test/test_url_constants.h" |
| 13 #import "ios/web/test/web_int_test.h" | 15 #import "ios/web/test/web_int_test.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 17 #include "url/scheme_host_port.h" | 19 #include "url/scheme_host_port.h" |
| 18 | 20 |
| 19 namespace web { | 21 namespace web { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // Verifies correctness of |NavigationContext| for new page navigation passed to | 25 // Verifies correctness of |NavigationContext| for new page navigation passed to |
| 24 // |DidFinishNavigation|. | 26 // |DidFinishNavigation|. |
| 25 ACTION_P2(VerifyNewPageContext, web_state, url) { | 27 ACTION_P2(VerifyNewPageContext, web_state, url) { |
| 26 NavigationContext* context = arg0; | 28 NavigationContext* context = arg0; |
| 27 ASSERT_TRUE(context); | 29 ASSERT_TRUE(context); |
| 28 EXPECT_EQ(web_state, context->GetWebState()); | 30 EXPECT_EQ(web_state, context->GetWebState()); |
| 29 EXPECT_EQ(url, context->GetUrl()); | 31 EXPECT_EQ(url, context->GetUrl()); |
| 30 EXPECT_FALSE(context->IsSamePage()); | 32 EXPECT_FALSE(context->IsSamePage()); |
| 31 EXPECT_FALSE(context->IsErrorPage()); | 33 EXPECT_FALSE(context->IsErrorPage()); |
| 34 NavigationManager* navigation_manager = web_state->GetNavigationManager(); |
| 35 NavigationItem* item = navigation_manager->GetLastCommittedItem(); |
| 36 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); |
| 37 EXPECT_EQ(url, item->GetURL()); |
| 32 } | 38 } |
| 33 | 39 |
| 34 // Verifies correctness of |NavigationContext| for same page navigation passed | 40 // Verifies correctness of |NavigationContext| for same page navigation passed |
| 35 // to |DidFinishNavigation|. | 41 // to |DidFinishNavigation|. |
| 36 ACTION_P2(VerifySamePageContext, web_state, url) { | 42 ACTION_P2(VerifySamePageContext, web_state, url) { |
| 37 NavigationContext* context = arg0; | 43 NavigationContext* context = arg0; |
| 38 ASSERT_TRUE(context); | 44 ASSERT_TRUE(context); |
| 39 EXPECT_EQ(web_state, context->GetWebState()); | 45 EXPECT_EQ(web_state, context->GetWebState()); |
| 40 EXPECT_EQ(url, context->GetUrl()); | 46 EXPECT_EQ(url, context->GetUrl()); |
| 41 EXPECT_TRUE(context->IsSamePage()); | 47 EXPECT_TRUE(context->IsSamePage()); |
| 42 EXPECT_FALSE(context->IsErrorPage()); | 48 EXPECT_FALSE(context->IsErrorPage()); |
| 49 NavigationManager* navigation_manager = web_state->GetNavigationManager(); |
| 50 NavigationItem* item = navigation_manager->GetLastCommittedItem(); |
| 51 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); |
| 52 EXPECT_EQ(url, item->GetURL()); |
| 43 } | 53 } |
| 44 | 54 |
| 45 // Mocks DidFinishNavigation navigation callback. | 55 // Mocks DidFinishNavigation navigation callback. |
| 46 class WebStateObserverMock : public WebStateObserver { | 56 class WebStateObserverMock : public WebStateObserver { |
| 47 public: | 57 public: |
| 48 WebStateObserverMock(WebState* web_state) : WebStateObserver(web_state) {} | 58 WebStateObserverMock(WebState* web_state) : WebStateObserver(web_state) {} |
| 49 MOCK_METHOD1(DidFinishNavigation, void(NavigationContext* context)); | 59 MOCK_METHOD1(DidFinishNavigation, void(NavigationContext* context)); |
| 50 }; | 60 }; |
| 51 | 61 |
| 52 } // namespace | 62 } // namespace |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 160 |
| 151 // Tests native content navigation. | 161 // Tests native content navigation. |
| 152 TEST_F(DidFinishNavigationTest, NativeContentNavigation) { | 162 TEST_F(DidFinishNavigationTest, NativeContentNavigation) { |
| 153 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize()); | 163 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize()); |
| 154 EXPECT_CALL(*observer_, DidFinishNavigation(_)) | 164 EXPECT_CALL(*observer_, DidFinishNavigation(_)) |
| 155 .WillOnce(VerifyNewPageContext(web_state(), url)); | 165 .WillOnce(VerifyNewPageContext(web_state(), url)); |
| 156 LoadUrl(url); | 166 LoadUrl(url); |
| 157 } | 167 } |
| 158 | 168 |
| 159 } // namespace web | 169 } // namespace web |
| OLD | NEW |