Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: ios/web/web_state/navigation_callbacks_inttest.mm

Issue 2901633002: Replaced NavigationContext::IsErrorPage with NavigationContext::GetError (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <string> 6 #include <string>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #import "ios/web/public/navigation_item.h" 9 #import "ios/web/public/navigation_item.h"
10 #import "ios/web/public/navigation_manager.h" 10 #import "ios/web/public/navigation_manager.h"
11 #import "ios/web/public/test/http_server.h" 11 #import "ios/web/public/test/http_server.h"
12 #include "ios/web/public/test/http_server_util.h" 12 #include "ios/web/public/test/http_server_util.h"
13 #include "ios/web/public/web_state/navigation_context.h" 13 #import "ios/web/public/web_state/navigation_context.h"
14 #include "ios/web/public/web_state/web_state_observer.h" 14 #include "ios/web/public/web_state/web_state_observer.h"
15 #include "ios/web/test/test_url_constants.h" 15 #include "ios/web/test/test_url_constants.h"
16 #import "ios/web/test/web_int_test.h" 16 #import "ios/web/test/web_int_test.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 #include "url/scheme_host_port.h" 20 #include "url/scheme_host_port.h"
21 21
22 namespace web { 22 namespace web {
23 23
24 namespace { 24 namespace {
25 25
26 const char kExpectedMimeType[] = "text/html"; 26 const char kExpectedMimeType[] = "text/html";
27 27
28 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation 28 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation
29 // passed to |DidStartNavigation|. Stores |NavigationContext| in |context| 29 // passed to |DidStartNavigation|. Stores |NavigationContext| in |context|
30 // pointer. 30 // pointer.
31 ACTION_P3(VerifyNewPageStartedContext, web_state, url, context) { 31 ACTION_P3(VerifyNewPageStartedContext, web_state, url, context) {
32 *context = arg0; 32 *context = arg0;
33 ASSERT_TRUE(*context); 33 ASSERT_TRUE(*context);
34 EXPECT_EQ(web_state, (*context)->GetWebState()); 34 EXPECT_EQ(web_state, (*context)->GetWebState());
35 EXPECT_EQ(url, (*context)->GetUrl()); 35 EXPECT_EQ(url, (*context)->GetUrl());
36 EXPECT_FALSE((*context)->IsSameDocument()); 36 EXPECT_FALSE((*context)->IsSameDocument());
37 EXPECT_FALSE((*context)->IsErrorPage()); 37 EXPECT_FALSE((*context)->GetError());
38 ASSERT_FALSE((*context)->GetResponseHeaders()); 38 ASSERT_FALSE((*context)->GetResponseHeaders());
39 NavigationManager* navigation_manager = web_state->GetNavigationManager(); 39 NavigationManager* navigation_manager = web_state->GetNavigationManager();
40 NavigationItem* item = navigation_manager->GetPendingItem(); 40 NavigationItem* item = navigation_manager->GetPendingItem();
41 EXPECT_EQ(url, item->GetURL()); 41 EXPECT_EQ(url, item->GetURL());
42 } 42 }
43 43
44 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation 44 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation
45 // passed to |DidFinishNavigation|. Asserts that |NavigationContext| the same as 45 // passed to |DidFinishNavigation|. Asserts that |NavigationContext| the same as
46 // |context|. 46 // |context|.
47 ACTION_P3(VerifyNewPageFinishedContext, web_state, url, context) { 47 ACTION_P3(VerifyNewPageFinishedContext, web_state, url, context) {
48 ASSERT_EQ(*context, arg0); 48 ASSERT_EQ(*context, arg0);
49 EXPECT_EQ(web_state, (*context)->GetWebState()); 49 EXPECT_EQ(web_state, (*context)->GetWebState());
50 ASSERT_TRUE((*context)); 50 ASSERT_TRUE((*context));
51 EXPECT_EQ(web_state, (*context)->GetWebState()); 51 EXPECT_EQ(web_state, (*context)->GetWebState());
52 EXPECT_EQ(url, (*context)->GetUrl()); 52 EXPECT_EQ(url, (*context)->GetUrl());
53 EXPECT_FALSE((*context)->IsSameDocument()); 53 EXPECT_FALSE((*context)->IsSameDocument());
54 EXPECT_FALSE((*context)->IsErrorPage()); 54 EXPECT_FALSE((*context)->GetError());
55 ASSERT_TRUE((*context)->GetResponseHeaders()); 55 ASSERT_TRUE((*context)->GetResponseHeaders());
56 std::string mime_type; 56 std::string mime_type;
57 (*context)->GetResponseHeaders()->GetMimeType(&mime_type); 57 (*context)->GetResponseHeaders()->GetMimeType(&mime_type);
58 EXPECT_EQ(kExpectedMimeType, mime_type); 58 EXPECT_EQ(kExpectedMimeType, mime_type);
59 NavigationManager* navigation_manager = web_state->GetNavigationManager(); 59 NavigationManager* navigation_manager = web_state->GetNavigationManager();
60 NavigationItem* item = navigation_manager->GetLastCommittedItem(); 60 NavigationItem* item = navigation_manager->GetLastCommittedItem();
61 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); 61 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0);
62 EXPECT_EQ(url, item->GetURL()); 62 EXPECT_EQ(url, item->GetURL());
63 } 63 }
64 64
65 // Verifies correctness of |NavigationContext| (|arg0|) for same page navigation 65 // Verifies correctness of |NavigationContext| (|arg0|) for same page navigation
66 // passed to |DidFinishNavigation|. Stores |NavigationContext| in |context| 66 // passed to |DidFinishNavigation|. Stores |NavigationContext| in |context|
67 // pointer. 67 // pointer.
68 ACTION_P3(VerifySameDocumentStartedContext, web_state, url, context) { 68 ACTION_P3(VerifySameDocumentStartedContext, web_state, url, context) {
69 *context = arg0; 69 *context = arg0;
70 ASSERT_TRUE(*context); 70 ASSERT_TRUE(*context);
71 EXPECT_EQ(web_state, (*context)->GetWebState()); 71 EXPECT_EQ(web_state, (*context)->GetWebState());
72 EXPECT_EQ(url, (*context)->GetUrl()); 72 EXPECT_EQ(url, (*context)->GetUrl());
73 EXPECT_FALSE((*context)->IsSameDocument()); 73 EXPECT_FALSE((*context)->IsSameDocument());
74 EXPECT_FALSE((*context)->IsErrorPage()); 74 EXPECT_FALSE((*context)->GetError());
75 EXPECT_FALSE((*context)->GetResponseHeaders()); 75 EXPECT_FALSE((*context)->GetResponseHeaders());
76 } 76 }
77 77
78 // Verifies correctness of |NavigationContext| (|arg0|) for same page navigation 78 // Verifies correctness of |NavigationContext| (|arg0|) for same page navigation
79 // passed to |DidFinishNavigation|. Asserts that |NavigationContext| the same as 79 // passed to |DidFinishNavigation|. Asserts that |NavigationContext| the same as
80 // |context|. 80 // |context|.
81 ACTION_P3(VerifySameDocumentFinishedContext, web_state, url, context) { 81 ACTION_P3(VerifySameDocumentFinishedContext, web_state, url, context) {
82 ASSERT_EQ(*context, arg0); 82 ASSERT_EQ(*context, arg0);
83 ASSERT_TRUE(*context); 83 ASSERT_TRUE(*context);
84 EXPECT_EQ(web_state, (*context)->GetWebState()); 84 EXPECT_EQ(web_state, (*context)->GetWebState());
85 EXPECT_EQ(url, (*context)->GetUrl()); 85 EXPECT_EQ(url, (*context)->GetUrl());
86 EXPECT_TRUE((*context)->IsSameDocument()); 86 EXPECT_TRUE((*context)->IsSameDocument());
87 EXPECT_FALSE((*context)->IsErrorPage()); 87 EXPECT_FALSE((*context)->GetError());
88 EXPECT_FALSE((*context)->GetResponseHeaders()); 88 EXPECT_FALSE((*context)->GetResponseHeaders());
89 NavigationManager* navigation_manager = web_state->GetNavigationManager(); 89 NavigationManager* navigation_manager = web_state->GetNavigationManager();
90 NavigationItem* item = navigation_manager->GetLastCommittedItem(); 90 NavigationItem* item = navigation_manager->GetLastCommittedItem();
91 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); 91 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0);
92 EXPECT_EQ(url, item->GetURL()); 92 EXPECT_EQ(url, item->GetURL());
93 } 93 }
94 94
95 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation 95 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation
96 // to native URLs passed to |DidStartNavigation|. Stores |NavigationContext| in 96 // to native URLs passed to |DidStartNavigation|. Stores |NavigationContext| in
97 // |context| pointer. 97 // |context| pointer.
98 ACTION_P3(VerifyNewNativePageStartedContext, web_state, url, context) { 98 ACTION_P3(VerifyNewNativePageStartedContext, web_state, url, context) {
99 *context = arg0; 99 *context = arg0;
100 ASSERT_TRUE(*context); 100 ASSERT_TRUE(*context);
101 EXPECT_EQ(web_state, (*context)->GetWebState()); 101 EXPECT_EQ(web_state, (*context)->GetWebState());
102 EXPECT_EQ(url, (*context)->GetUrl()); 102 EXPECT_EQ(url, (*context)->GetUrl());
103 EXPECT_FALSE((*context)->IsSameDocument()); 103 EXPECT_FALSE((*context)->IsSameDocument());
104 EXPECT_FALSE((*context)->IsErrorPage()); 104 EXPECT_FALSE((*context)->GetError());
105 EXPECT_FALSE((*context)->GetResponseHeaders()); 105 EXPECT_FALSE((*context)->GetResponseHeaders());
106 NavigationManager* navigation_manager = web_state->GetNavigationManager(); 106 NavigationManager* navigation_manager = web_state->GetNavigationManager();
107 NavigationItem* item = navigation_manager->GetPendingItem(); 107 NavigationItem* item = navigation_manager->GetPendingItem();
108 EXPECT_EQ(url, item->GetURL()); 108 EXPECT_EQ(url, item->GetURL());
109 } 109 }
110 110
111 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation 111 // Verifies correctness of |NavigationContext| (|arg0|) for new page navigation
112 // to native URLs passed to |DidFinishNavigation|. Asserts that 112 // to native URLs passed to |DidFinishNavigation|. Asserts that
113 // |NavigationContext| the same as |context|. 113 // |NavigationContext| the same as |context|.
114 ACTION_P3(VerifyNewNativePageFinishedContext, web_state, url, context) { 114 ACTION_P3(VerifyNewNativePageFinishedContext, web_state, url, context) {
115 ASSERT_EQ(*context, arg0); 115 ASSERT_EQ(*context, arg0);
116 ASSERT_TRUE(*context); 116 ASSERT_TRUE(*context);
117 EXPECT_EQ(web_state, (*context)->GetWebState()); 117 EXPECT_EQ(web_state, (*context)->GetWebState());
118 EXPECT_EQ(url, (*context)->GetUrl()); 118 EXPECT_EQ(url, (*context)->GetUrl());
119 EXPECT_FALSE((*context)->IsSameDocument()); 119 EXPECT_FALSE((*context)->IsSameDocument());
120 EXPECT_FALSE((*context)->IsErrorPage()); 120 EXPECT_FALSE((*context)->GetError());
121 EXPECT_FALSE((*context)->GetResponseHeaders()); 121 EXPECT_FALSE((*context)->GetResponseHeaders());
122 NavigationManager* navigation_manager = web_state->GetNavigationManager(); 122 NavigationManager* navigation_manager = web_state->GetNavigationManager();
123 NavigationItem* item = navigation_manager->GetLastCommittedItem(); 123 NavigationItem* item = navigation_manager->GetLastCommittedItem();
124 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0); 124 EXPECT_GT(item->GetTimestamp().ToInternalValue(), 0);
125 EXPECT_EQ(url, item->GetURL()); 125 EXPECT_EQ(url, item->GetURL());
126 } 126 }
127 127
128 // Mocks DidFinishNavigation navigation callback. 128 // Mocks DidFinishNavigation navigation callback.
129 class WebStateObserverMock : public WebStateObserver { 129 class WebStateObserverMock : public WebStateObserver {
130 public: 130 public:
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize()); 268 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize());
269 NavigationContext* context = nullptr; 269 NavigationContext* context = nullptr;
270 EXPECT_CALL(*observer_, DidStartNavigation(_)) 270 EXPECT_CALL(*observer_, DidStartNavigation(_))
271 .WillOnce(VerifyNewNativePageStartedContext(web_state(), url, &context)); 271 .WillOnce(VerifyNewNativePageStartedContext(web_state(), url, &context));
272 EXPECT_CALL(*observer_, DidFinishNavigation(_)) 272 EXPECT_CALL(*observer_, DidFinishNavigation(_))
273 .WillOnce(VerifyNewNativePageFinishedContext(web_state(), url, &context)); 273 .WillOnce(VerifyNewNativePageFinishedContext(web_state(), url, &context));
274 LoadUrl(url); 274 LoadUrl(url);
275 } 275 }
276 276
277 } // namespace web 277 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/public/web_state/web_state_observer.h ('k') | ios/web/web_state/navigation_context_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698