OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 Source<NavigationController>(controller)); | 228 Source<NavigationController>(controller)); |
229 } | 229 } |
230 | 230 |
231 SiteInstance* GetSiteInstanceFromEntry(NavigationEntry* entry) { | 231 SiteInstance* GetSiteInstanceFromEntry(NavigationEntry* entry) { |
232 return NavigationEntryImpl::FromNavigationEntry(entry)->site_instance(); | 232 return NavigationEntryImpl::FromNavigationEntry(entry)->site_instance(); |
233 } | 233 } |
234 | 234 |
235 class TestWebContentsDelegate : public WebContentsDelegate { | 235 class TestWebContentsDelegate : public WebContentsDelegate { |
236 public: | 236 public: |
237 explicit TestWebContentsDelegate() : | 237 explicit TestWebContentsDelegate() : |
238 navigation_state_change_count_(0) {} | 238 navigation_state_change_count_(0), |
| 239 repost_form_warning_count_(0) {} |
239 | 240 |
240 int navigation_state_change_count() { | 241 int navigation_state_change_count() { |
241 return navigation_state_change_count_; | 242 return navigation_state_change_count_; |
242 } | 243 } |
243 | 244 |
| 245 int repost_form_warning_count() { |
| 246 return repost_form_warning_count_; |
| 247 } |
| 248 |
244 // Keep track of whether the tab has notified us of a navigation state change. | 249 // Keep track of whether the tab has notified us of a navigation state change. |
245 virtual void NavigationStateChanged(const WebContents* source, | 250 virtual void NavigationStateChanged(const WebContents* source, |
246 unsigned changed_flags) OVERRIDE { | 251 unsigned changed_flags) OVERRIDE { |
247 navigation_state_change_count_++; | 252 navigation_state_change_count_++; |
248 } | 253 } |
249 | 254 |
| 255 virtual void ShowRepostFormWarningDialog(WebContents* source) OVERRIDE { |
| 256 repost_form_warning_count_++; |
| 257 } |
| 258 |
250 private: | 259 private: |
251 // The number of times NavigationStateChanged has been called. | 260 // The number of times NavigationStateChanged has been called. |
252 int navigation_state_change_count_; | 261 int navigation_state_change_count_; |
| 262 |
| 263 // The number of times ShowRepostFormWarningDialog() was called. |
| 264 int repost_form_warning_count_; |
253 }; | 265 }; |
254 | 266 |
255 // ----------------------------------------------------------------------------- | 267 // ----------------------------------------------------------------------------- |
256 | 268 |
257 TEST_F(NavigationControllerTest, Defaults) { | 269 TEST_F(NavigationControllerTest, Defaults) { |
258 NavigationControllerImpl& controller = controller_impl(); | 270 NavigationControllerImpl& controller = controller_impl(); |
259 | 271 |
260 EXPECT_FALSE(controller.GetPendingEntry()); | 272 EXPECT_FALSE(controller.GetPendingEntry()); |
261 EXPECT_FALSE(controller.GetVisibleEntry()); | 273 EXPECT_FALSE(controller.GetVisibleEntry()); |
262 EXPECT_FALSE(controller.GetLastCommittedEntry()); | 274 EXPECT_FALSE(controller.GetLastCommittedEntry()); |
(...skipping 3954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4217 // cleared. | 4229 // cleared. |
4218 EXPECT_EQ(1, controller.GetEntryCount()); | 4230 EXPECT_EQ(1, controller.GetEntryCount()); |
4219 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 4231 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
4220 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4232 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
4221 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4233 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
4222 EXPECT_FALSE(controller.CanGoBack()); | 4234 EXPECT_FALSE(controller.CanGoBack()); |
4223 EXPECT_FALSE(controller.CanGoForward()); | 4235 EXPECT_FALSE(controller.CanGoForward()); |
4224 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 4236 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
4225 } | 4237 } |
4226 | 4238 |
| 4239 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) { |
| 4240 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
| 4241 EXPECT_FALSE(contents()->GetDelegate()); |
| 4242 contents()->SetDelegate(delegate.get()); |
| 4243 |
| 4244 // Submit a form. |
| 4245 GURL url("http://foo"); |
| 4246 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
| 4247 params.page_id = 1; |
| 4248 params.url = url; |
| 4249 params.transition = PAGE_TRANSITION_FORM_SUBMIT; |
| 4250 params.gesture = NavigationGestureUser; |
| 4251 params.page_state = PageState::CreateFromURL(url); |
| 4252 params.was_within_same_page = false; |
| 4253 params.is_post = true; |
| 4254 params.post_id = 2; |
| 4255 test_rvh()->SendNavigateWithParams(¶ms); |
| 4256 |
| 4257 // history.replaceState() is called. |
| 4258 GURL replace_url("http://foo#foo"); |
| 4259 params.page_id = 1; |
| 4260 params.url = replace_url; |
| 4261 params.transition = PAGE_TRANSITION_LINK; |
| 4262 params.gesture = NavigationGestureUser; |
| 4263 params.page_state = PageState::CreateFromURL(replace_url); |
| 4264 params.was_within_same_page = true; |
| 4265 params.is_post = false; |
| 4266 params.post_id = -1; |
| 4267 test_rvh()->SendNavigateWithParams(¶ms); |
| 4268 |
| 4269 // Now reload. replaceState overrides the POST, so we should not show a |
| 4270 // repost warning dialog. |
| 4271 controller_impl().Reload(true); |
| 4272 EXPECT_EQ(0, delegate->repost_form_warning_count()); |
| 4273 } |
| 4274 |
4227 } // namespace content | 4275 } // namespace content |
OLD | NEW |