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

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

Issue 2698413004: Implemented WebStateObserver::DidFinishNavigation(NavigationHandle*). (Closed)
Patch Set: Addressed review comments Created 3 years, 10 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
« no previous file with comments | « ios/web/test/test_url_constants.cc ('k') | ios/web/web_state/navigation_context_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <memory>
6
7 #include "base/memory/ptr_util.h"
8 #import "ios/web/public/test/http_server.h"
9 #include "ios/web/public/test/http_server_util.h"
10 #include "ios/web/public/web_state/navigation_context.h"
11 #include "ios/web/public/web_state/web_state_observer.h"
12 #include "ios/web/test/test_url_constants.h"
13 #import "ios/web/test/web_int_test.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h"
17 #include "url/scheme_host_port.h"
18
19 namespace web {
20
21 namespace {
22
23 // Verifies correctness of |NavigationContext| for new page navigation passed to
24 // |DidFinishNavigation|.
25 ACTION_P2(VerifyNewPageContext, web_state, url) {
26 NavigationContext* context = arg0;
27 ASSERT_TRUE(context);
28 EXPECT_EQ(web_state, context->GetWebState());
29 EXPECT_EQ(url, context->GetUrl());
30 EXPECT_FALSE(context->IsSamePage());
31 EXPECT_FALSE(context->IsErrorPage());
32 }
33
34 // Verifies correctness of |NavigationContext| for same page navigation passed
35 // to |DidFinishNavigation|.
36 ACTION_P2(VerifySamePageContext, web_state, url) {
37 NavigationContext* context = arg0;
38 ASSERT_TRUE(context);
39 EXPECT_EQ(web_state, context->GetWebState());
40 EXPECT_EQ(url, context->GetUrl());
41 EXPECT_TRUE(context->IsSamePage());
42 EXPECT_FALSE(context->IsErrorPage());
43 }
44
45 // Mocks DidFinishNavigation navigation callback.
46 class WebStateObserverMock : public WebStateObserver {
47 public:
48 WebStateObserverMock(WebState* web_state) : WebStateObserver(web_state) {}
49 MOCK_METHOD1(DidFinishNavigation, void(NavigationContext* context));
50 };
51
52 } // namespace
53
54 using test::HttpServer;
55 using testing::_;
56
57 // Test fixture for WebStateDelegate::DidFinishNavigation integration tests.
58 class DidFinishNavigationTest : public WebIntTest {
59 void SetUp() override {
60 WebIntTest::SetUp();
61 observer_ = base::MakeUnique<WebStateObserverMock>(web_state());
62 }
63
64 protected:
65 std::unique_ptr<WebStateObserverMock> observer_;
66 };
67
68 // Tests successful navigation to a new page.
69 TEST_F(DidFinishNavigationTest, NewPageNavigation) {
70 const GURL url = HttpServer::MakeUrl("http://chromium.test");
71 std::map<GURL, std::string> responses;
72 responses[url] = "Chromium Test";
73 web::test::SetUpSimpleHttpServer(responses);
74
75 // Perform new page navigation.
76 EXPECT_CALL(*observer_, DidFinishNavigation(_))
77 .WillOnce(VerifyNewPageContext(web_state(), url));
78 LoadUrl(url);
79 }
80
81 // Tests user-initiated hash change.
82 TEST_F(DidFinishNavigationTest, UserInitiatedHashChangeNavigation) {
83 const GURL url = HttpServer::MakeUrl("http://chromium.test");
84 std::map<GURL, std::string> responses;
85 responses[url] = "Chromium Test";
86 web::test::SetUpSimpleHttpServer(responses);
87
88 // Perform new page navigation.
89 EXPECT_CALL(*observer_, DidFinishNavigation(_))
90 .WillOnce(VerifyNewPageContext(web_state(), url));
91 LoadUrl(url);
92
93 // Perform same-page navigation.
94 const GURL hash_url = HttpServer::MakeUrl("http://chromium.test#1");
95 EXPECT_CALL(*observer_, DidFinishNavigation(_))
96 .WillOnce(VerifySamePageContext(web_state(), hash_url));
97 LoadUrl(hash_url);
98
99 // Perform same-page navigation by going back.
100 EXPECT_CALL(*observer_, DidFinishNavigation(_))
101 .WillOnce(VerifySamePageContext(web_state(), url));
102 ExecuteBlockAndWaitForLoad(url, ^{
103 navigation_manager()->GoBack();
104 });
105 }
106
107 // Tests renderer-initiated hash change.
108 TEST_F(DidFinishNavigationTest, RendererInitiatedHashChangeNavigation) {
109 const GURL url = HttpServer::MakeUrl("http://chromium.test");
110 std::map<GURL, std::string> responses;
111 responses[url] = "Chromium Test";
112 web::test::SetUpSimpleHttpServer(responses);
113
114 // Perform new page navigation.
115 EXPECT_CALL(*observer_, DidFinishNavigation(_))
116 .WillOnce(VerifyNewPageContext(web_state(), url));
117 LoadUrl(url);
118
119 // Perform same-page navigation using JavaScript.
120 const GURL hash_url = HttpServer::MakeUrl("http://chromium.test#1");
121 EXPECT_CALL(*observer_, DidFinishNavigation(_))
122 .WillOnce(VerifySamePageContext(web_state(), hash_url));
123 ExecuteJavaScript(@"window.location.hash = '#1'");
124 }
125
126 // Tests state change.
127 TEST_F(DidFinishNavigationTest, StateNavigation) {
128 const GURL url = HttpServer::MakeUrl("http://chromium.test");
129 std::map<GURL, std::string> responses;
130 responses[url] = "Chromium Test";
131 web::test::SetUpSimpleHttpServer(responses);
132
133 // Perform new page navigation.
134 EXPECT_CALL(*observer_, DidFinishNavigation(_))
135 .WillOnce(VerifyNewPageContext(web_state(), url));
136 LoadUrl(url);
137
138 // Perform push state using JavaScript.
139 const GURL push_url = HttpServer::MakeUrl("http://chromium.test/test.html");
140 EXPECT_CALL(*observer_, DidFinishNavigation(_))
141 .WillOnce(VerifySamePageContext(web_state(), push_url));
142 ExecuteJavaScript(@"window.history.pushState('', 'Test', 'test.html')");
143
144 // Perform replace state using JavaScript.
145 const GURL replace_url = HttpServer::MakeUrl("http://chromium.test/1.html");
146 EXPECT_CALL(*observer_, DidFinishNavigation(_))
147 .WillOnce(VerifySamePageContext(web_state(), replace_url));
148 ExecuteJavaScript(@"window.history.replaceState('', 'Test', '1.html')");
149 }
150
151 // Tests native content navigation.
152 TEST_F(DidFinishNavigationTest, NativeContentNavigation) {
153 GURL url(url::SchemeHostPort(kTestNativeContentScheme, "ui", 0).Serialize());
154 EXPECT_CALL(*observer_, DidFinishNavigation(_))
155 .WillOnce(VerifyNewPageContext(web_state(), url));
156 LoadUrl(url);
157 }
158
159 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/test/test_url_constants.cc ('k') | ios/web/web_state/navigation_context_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698