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

Side by Side Diff: content/test/content_browser_test_utils_internal.h

Issue 1825523002: Do not reset navigation state when BeforeUnload is cancelled by a commit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_ 5 #ifndef CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_
6 #define CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_ 6 #define CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_
7 7
8 // A collection of functions designed for use with content_shell based browser 8 // A collection of functions designed for use with content_shell based browser
9 // tests internal to the content/ module. 9 // tests internal to the content/ module.
10 // Note: If a function here also works with browser_tests, it should be in 10 // Note: If a function here also works with browser_tests, it should be in
11 // the content public API. 11 // the content public API.
12 12
13 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h"
17 #include "cc/surfaces/surface_id.h" 18 #include "cc/surfaces/surface_id.h"
19 #include "content/public/browser/navigation_handle.h"
18 #include "content/public/browser/resource_dispatcher_host_delegate.h" 20 #include "content/public/browser/resource_dispatcher_host_delegate.h"
21 #include "content/public/browser/web_contents_observer.h"
19 #include "url/gurl.h" 22 #include "url/gurl.h"
20 23
21 namespace cc { 24 namespace cc {
22 class SurfaceManager; 25 class SurfaceManager;
23 } 26 }
24 27
25 namespace content { 28 namespace content {
26 29
27 class FrameTreeNode; 30 class FrameTreeNode;
31 class MessageLoopRunner;
28 class RenderWidgetHostViewChildFrame; 32 class RenderWidgetHostViewChildFrame;
29 class Shell; 33 class Shell;
30 class SiteInstance; 34 class SiteInstance;
31 class ToRenderFrameHost; 35 class ToRenderFrameHost;
32 36
33 // Navigates the frame represented by |node| to |url|, blocking until the 37 // Navigates the frame represented by |node| to |url|, blocking until the
34 // navigation finishes. 38 // navigation finishes.
35 void NavigateFrameToURL(FrameTreeNode* node, const GURL& url); 39 void NavigateFrameToURL(FrameTreeNode* node, const GURL& url);
36 40
41 // Sets the DialogManager to proceed by default or not when showing a
42 // BeforeUnload dialog.
43 void SetProceedByDefaultOnBeforeUnload(Shell* shell, bool proceed);
44
37 // Creates compact textual representations of the state of the frame tree that 45 // Creates compact textual representations of the state of the frame tree that
38 // is appropriate for use in assertions. 46 // is appropriate for use in assertions.
39 // 47 //
40 // The diagrams show frame tree structure, the SiteInstance of current frames, 48 // The diagrams show frame tree structure, the SiteInstance of current frames,
41 // presence of pending frames, and the SiteInstances of any and all proxies. 49 // presence of pending frames, and the SiteInstances of any and all proxies.
42 // They look like this: 50 // They look like this:
43 // 51 //
44 // Site A (D pending) -- proxies for B C 52 // Site A (D pending) -- proxies for B C
45 // |--Site B --------- proxies for A C 53 // |--Site B --------- proxies for A C
46 // +--Site C --------- proxies for B A 54 // +--Site C --------- proxies for B A
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 void RequestBeginning( 104 void RequestBeginning(
97 net::URLRequest* request, 105 net::URLRequest* request,
98 content::ResourceContext* resource_context, 106 content::ResourceContext* resource_context,
99 content::AppCacheService* appcache_service, 107 content::AppCacheService* appcache_service,
100 ResourceType resource_type, 108 ResourceType resource_type,
101 ScopedVector<content::ResourceThrottle>* throttles) override; 109 ScopedVector<content::ResourceThrottle>* throttles) override;
102 110
103 GURL url_; 111 GURL url_;
104 }; 112 };
105 113
114 // This class can be used to pause and resume navigations, based on a URL
115 // match. Note that it only keeps track of one navigation at a time.
116 class NavigationDelayer : public WebContentsObserver {
Charlie Reis 2016/03/29 18:33:21 Nasko, can you review this part? I know you've be
nasko 2016/03/29 20:19:06 I'd call this something more generic, as it ideall
clamy 2016/03/30 13:31:11 I went with TestNavigationManager. I can switch to
117 public:
118 NavigationDelayer(WebContents* web_contents, const GURL& url);
nasko 2016/03/29 20:19:06 Is the goal for this class to monitor any frame in
clamy 2016/03/30 13:31:11 Precised it in a comment, + adde a TODO for a fram
119 ~NavigationDelayer() override;
120
121 // Waits until the navigation has been paused.
122 void WaitForNavigationPaused();
nasko 2016/03/29 20:19:06 At what point will navigation be paused? Let's use
clamy 2016/03/30 13:31:11 I renamed the method WaitForWillStartRequest since
123
124 // Waits until the navigation has been finished. This should be called after
125 // WaitForNavigationPaused.
Charlie Reis 2016/03/29 18:33:21 Do you also need to call ResumeNavigation before c
clamy 2016/03/30 13:31:11 Yes. I precised it in the comment. Added a TODO to
126 void WaitForNavigationFinished();
127
128 // Resumes the navigation if it was previously paused.
129 void ResumeNavigation();
130
131 private:
132 // WebContentsObserver implementation.
133 void DidStartNavigation(NavigationHandle* handle) override;
134 void DidFinishNavigation(NavigationHandle* handle) override;
135
136 // Called when the NavigationThrottlePauses the navigation.
nasko 2016/03/29 20:19:06 nit: s/NavigationThrottlePauses/NavigationThrottle
clamy 2016/03/30 13:31:11 Done.
137 void OnPausedNavigation();
138
139 const GURL url_;
140 bool navigation_paused_;
141 NavigationHandle* handle_;
142 scoped_refptr<MessageLoopRunner> loop_runner_;
143
144 base::WeakPtrFactory<NavigationDelayer> weak_factory_;
145 };
146
106 // Helper class to assist with hit testing surfaces in multiple processes. 147 // Helper class to assist with hit testing surfaces in multiple processes.
107 // WaitForSurfaceReady() will only return after a Surface from |target_view| 148 // WaitForSurfaceReady() will only return after a Surface from |target_view|
108 // has been composited in the top-level frame's Surface. At that point, 149 // has been composited in the top-level frame's Surface. At that point,
109 // browser process hit testing to target_view's Surface can succeed. 150 // browser process hit testing to target_view's Surface can succeed.
110 class SurfaceHitTestReadyNotifier { 151 class SurfaceHitTestReadyNotifier {
111 public: 152 public:
112 SurfaceHitTestReadyNotifier(RenderWidgetHostViewChildFrame* target_view); 153 SurfaceHitTestReadyNotifier(RenderWidgetHostViewChildFrame* target_view);
113 ~SurfaceHitTestReadyNotifier() {} 154 ~SurfaceHitTestReadyNotifier() {}
114 155
115 void WaitForSurfaceReady(); 156 void WaitForSurfaceReady();
116 157
117 private: 158 private:
118 bool ContainsSurfaceId(cc::SurfaceId container_surface_id); 159 bool ContainsSurfaceId(cc::SurfaceId container_surface_id);
119 160
120 cc::SurfaceManager* surface_manager_; 161 cc::SurfaceManager* surface_manager_;
121 cc::SurfaceId root_surface_id_; 162 cc::SurfaceId root_surface_id_;
122 RenderWidgetHostViewChildFrame* target_view_; 163 RenderWidgetHostViewChildFrame* target_view_;
123 164
124 DISALLOW_COPY_AND_ASSIGN(SurfaceHitTestReadyNotifier); 165 DISALLOW_COPY_AND_ASSIGN(SurfaceHitTestReadyNotifier);
125 }; 166 };
126 167
127 } // namespace content 168 } // namespace content
128 169
129 #endif // CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_ 170 #endif // CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698