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

Side by Side Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 14066022: Use the last committed entry in DidStopLoading, not the pending entry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/content_tests.gypi » ('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 2013 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 "base/values.h"
6 #include "content/browser/web_contents/web_contents_impl.h"
7 #include "content/public/browser/load_notification_details.h"
8 #include "content/public/browser/navigation_controller.h"
9 #include "content/public/browser/notification_details.h"
10 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_types.h"
12 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/test_utils.h"
14 #include "content/shell/shell.h"
15 #include "content/test/content_browser_test.h"
16 #include "content/test/content_browser_test_utils.h"
17 #include "net/test/test_server.h"
18
19 namespace content {
20
21 class WebContentsImplBrowserTest : public ContentBrowserTest {
22 public:
23 WebContentsImplBrowserTest() {}
24
25 private:
26 DISALLOW_COPY_AND_ASSIGN(WebContentsImplBrowserTest);
27 };
28
29 // Keeps track of data from LoadNotificationDetails so we can later verify that
30 // they are correct, after the LoadNotificationDetails object is deleted.
31 class LoadStopNotificationObserver : public WindowedNotificationObserver {
32 public:
33 LoadStopNotificationObserver(NavigationController* controller)
34 : WindowedNotificationObserver(NOTIFICATION_LOAD_STOP,
35 Source<NavigationController>(controller)),
36 session_index_(-1),
37 controller_(NULL) {
38 }
39 virtual void Observe(int type,
40 const NotificationSource& source,
41 const NotificationDetails& details) OVERRIDE {
42 if (type == NOTIFICATION_LOAD_STOP) {
43 const Details<LoadNotificationDetails> load_details(details);
44 url_ = load_details->url;
45 session_index_ = load_details->session_index;
46 controller_ = load_details->controller;
47 }
48 WindowedNotificationObserver::Observe(type, source, details);
49 }
50
51 GURL url_;
52 int session_index_;
53 NavigationController* controller_;
54 };
55
56 // Starts a new navigation as soon as the current one commits, but does not
57 // wait for it to complete. This allows us to observe DidStopLoading while
58 // a pending entry is present.
59 class NavigateOnCommitObserver : public WindowedNotificationObserver {
60 public:
61 NavigateOnCommitObserver(Shell* shell, GURL url)
62 : WindowedNotificationObserver(
63 NOTIFICATION_NAV_ENTRY_COMMITTED,
64 Source<NavigationController>(
65 &shell->web_contents()->GetController())),
66 shell_(shell),
67 url_(url),
68 done_(false) {
69 }
70 virtual void Observe(int type,
71 const NotificationSource& source,
72 const NotificationDetails& details) OVERRIDE {
73 if (type == NOTIFICATION_NAV_ENTRY_COMMITTED && !done_) {
74 done_ = true;
75 shell_->LoadURL(url_);
76 }
77 WindowedNotificationObserver::Observe(type, source, details);
78 }
79
80 Shell* shell_;
81 GURL url_;
82 bool done_;
83 };
84
85 // Test that DidStopLoading includes the correct URL in the details.
86 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DidStopLoadingDetails) {
87 ASSERT_TRUE(test_server()->Start());
88
89 LoadStopNotificationObserver load_observer(
90 &shell()->web_contents()->GetController());
91 NavigateToURL(shell(), test_server()->GetURL("files/title1.html"));
92 load_observer.Wait();
93
94 EXPECT_EQ("/files/title1.html", load_observer.url_.path());
95 EXPECT_EQ(0, load_observer.session_index_);
96 EXPECT_EQ(&shell()->web_contents()->GetController(),
97 load_observer.controller_);
98 }
99
100 // Test that DidStopLoading includes the correct URL in the details when a
101 // pending entry is present.
102 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
103 DidStopLoadingDetailsWithPending) {
104 ASSERT_TRUE(test_server()->Start());
105
106 // Listen for the first load to stop.
107 LoadStopNotificationObserver load_observer(
108 &shell()->web_contents()->GetController());
109 // Start a new pending navigation as soon as the first load commits.
110 // We will hear a DidStopLoading from the first load as the new load
111 // is started.
112 NavigateOnCommitObserver commit_observer(
113 shell(), test_server()->GetURL("files/title2.html"));
114 NavigateToURL(shell(), test_server()->GetURL("files/title1.html"));
115 commit_observer.Wait();
116 load_observer.Wait();
117
118 EXPECT_EQ("/files/title1.html", load_observer.url_.path());
119 EXPECT_EQ(0, load_observer.session_index_);
120 EXPECT_EQ(&shell()->web_contents()->GetController(),
121 load_observer.controller_);
122 }
123
124 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698