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

Side by Side Diff: chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc

Issue 2272243002: Remove use of deprecated APIs in WebNavigationApiTest (Closed)
Patch Set: Addressed comments Created 4 years, 3 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <list> 5 #include <list>
6 #include <set> 6 #include <set>
7 7
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/extensions/extension_apitest.h" 25 #include "chrome/browser/extensions/extension_apitest.h"
26 #include "chrome/browser/extensions/extension_service.h" 26 #include "chrome/browser/extensions/extension_service.h"
27 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 28 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
29 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h" 29 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h"
30 #include "chrome/browser/ui/browser.h" 30 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/browser_navigator_params.h" 31 #include "chrome/browser/ui/browser_navigator_params.h"
32 #include "chrome/browser/ui/tabs/tab_strip_model.h" 32 #include "chrome/browser/ui/tabs/tab_strip_model.h"
33 #include "chrome/test/base/ui_test_utils.h" 33 #include "chrome/test/base/ui_test_utils.h"
34 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
35 #include "content/public/browser/navigation_handle.h"
35 #include "content/public/browser/render_frame_host.h" 36 #include "content/public/browser/render_frame_host.h"
36 #include "content/public/browser/render_process_host.h" 37 #include "content/public/browser/render_process_host.h"
37 #include "content/public/browser/render_view_host.h" 38 #include "content/public/browser/render_view_host.h"
38 #include "content/public/browser/render_widget_host.h" 39 #include "content/public/browser/render_widget_host.h"
39 #include "content/public/browser/resource_controller.h" 40 #include "content/public/browser/resource_controller.h"
40 #include "content/public/browser/resource_dispatcher_host.h" 41 #include "content/public/browser/resource_dispatcher_host.h"
41 #include "content/public/browser/resource_throttle.h" 42 #include "content/public/browser/resource_throttle.h"
42 #include "content/public/browser/web_contents.h" 43 #include "content/public/browser/web_contents.h"
43 #include "content/public/common/context_menu_params.h" 44 #include "content/public/common/context_menu_params.h"
44 #include "content/public/common/resource_type.h" 45 #include "content/public/common/resource_type.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 const GURL& delay_url, 182 const GURL& delay_url,
182 const std::string& script, 183 const std::string& script,
183 const std::string& until_url_suffix) 184 const std::string& until_url_suffix)
184 : content::WebContentsObserver(), 185 : content::WebContentsObserver(),
185 test_navigation_listener_(test_navigation_listener), 186 test_navigation_listener_(test_navigation_listener),
186 delay_url_(delay_url), 187 delay_url_(delay_url),
187 until_url_suffix_(until_url_suffix), 188 until_url_suffix_(until_url_suffix),
188 script_(script), 189 script_(script),
189 has_user_gesture_(false), 190 has_user_gesture_(false),
190 script_was_executed_(false), 191 script_was_executed_(false),
191 rvh_(NULL) { 192 rfh_(nullptr) {
192 registrar_.Add(this, 193 registrar_.Add(this,
193 chrome::NOTIFICATION_TAB_ADDED, 194 chrome::NOTIFICATION_TAB_ADDED,
194 content::NotificationService::AllSources()); 195 content::NotificationService::AllSources());
195 test_navigation_listener_->DelayRequestsForURL(delay_url_); 196 test_navigation_listener_->DelayRequestsForURL(delay_url_);
196 } 197 }
197 ~DelayLoadStartAndExecuteJavascript() override {} 198 ~DelayLoadStartAndExecuteJavascript() override {}
198 199
199 void Observe(int type, 200 void Observe(int type,
200 const content::NotificationSource& source, 201 const content::NotificationSource& source,
201 const content::NotificationDetails& details) override { 202 const content::NotificationDetails& details) override {
202 if (type != chrome::NOTIFICATION_TAB_ADDED) { 203 if (type != chrome::NOTIFICATION_TAB_ADDED) {
203 NOTREACHED(); 204 NOTREACHED();
204 return; 205 return;
205 } 206 }
206 content::WebContentsObserver::Observe( 207 content::WebContentsObserver::Observe(
207 content::Details<content::WebContents>(details).ptr()); 208 content::Details<content::WebContents>(details).ptr());
208 registrar_.RemoveAll(); 209 registrar_.RemoveAll();
209 } 210 }
210 211
211 void DidStartProvisionalLoadForFrame( 212 void DidStartNavigation(
212 content::RenderFrameHost* render_frame_host, 213 content::NavigationHandle* navigation_handle) override {
213 const GURL& validated_url, 214 if (navigation_handle->GetURL() != delay_url_ || !rfh_)
214 bool is_error_page,
215 bool is_iframe_srcdoc) override {
216 if (validated_url != delay_url_ || !rvh_)
217 return; 215 return;
218 216
219 if (has_user_gesture_) { 217 if (has_user_gesture_) {
220 rvh_->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests( 218 rfh_->ExecuteJavaScriptWithUserGestureForTests(
221 base::UTF8ToUTF16(script_)); 219 base::UTF8ToUTF16(script_));
222 } else { 220 } else {
223 rvh_->GetMainFrame()->ExecuteJavaScriptForTests( 221 rfh_->ExecuteJavaScriptForTests(base::UTF8ToUTF16(script_));
224 base::UTF8ToUTF16(script_));
225 } 222 }
226 script_was_executed_ = true; 223 script_was_executed_ = true;
227 } 224 }
228 225
229 void DidCommitProvisionalLoadForFrame( 226 void DidFinishNavigation(
230 content::RenderFrameHost* render_frame_host, 227 content::NavigationHandle* navigation_handle) override {
231 const GURL& url, 228 if (!navigation_handle->HasCommitted() || navigation_handle->IsErrorPage())
232 ui::PageTransition transition_type) override { 229 return;
230
233 if (script_was_executed_ && 231 if (script_was_executed_ &&
234 base::EndsWith(url.spec(), until_url_suffix_, 232 base::EndsWith(navigation_handle->GetURL().spec(), until_url_suffix_,
235 base::CompareCase::SENSITIVE)) { 233 base::CompareCase::SENSITIVE)) {
236 content::WebContentsObserver::Observe(NULL); 234 content::WebContentsObserver::Observe(NULL);
237 test_navigation_listener_->ResumeAll(); 235 test_navigation_listener_->ResumeAll();
238 } 236 }
239 rvh_ = render_frame_host->GetRenderViewHost(); 237
238 if (navigation_handle->IsInMainFrame())
239 rfh_ = navigation_handle->GetRenderFrameHost();
240 } 240 }
241 241
242 void set_has_user_gesture(bool has_user_gesture) { 242 void set_has_user_gesture(bool has_user_gesture) {
243 has_user_gesture_ = has_user_gesture; 243 has_user_gesture_ = has_user_gesture;
244 } 244 }
245 245
246 private: 246 private:
247 content::NotificationRegistrar registrar_; 247 content::NotificationRegistrar registrar_;
248 248
249 scoped_refptr<TestNavigationListener> test_navigation_listener_; 249 scoped_refptr<TestNavigationListener> test_navigation_listener_;
250 250
251 GURL delay_url_; 251 GURL delay_url_;
252 std::string until_url_suffix_; 252 std::string until_url_suffix_;
253 std::string script_; 253 std::string script_;
254 bool has_user_gesture_; 254 bool has_user_gesture_;
255 bool script_was_executed_; 255 bool script_was_executed_;
256 content::RenderViewHost* rvh_; 256 content::RenderFrameHost* rfh_;
257 257
258 DISALLOW_COPY_AND_ASSIGN(DelayLoadStartAndExecuteJavascript); 258 DISALLOW_COPY_AND_ASSIGN(DelayLoadStartAndExecuteJavascript);
259 }; 259 };
260 260
261 class StartProvisionalLoadObserver : public content::WebContentsObserver { 261 class StartProvisionalLoadObserver : public content::WebContentsObserver {
262 public: 262 public:
263 StartProvisionalLoadObserver(WebContents* web_contents, 263 StartProvisionalLoadObserver(WebContents* web_contents,
264 const GURL& expected_url) 264 const GURL& expected_url)
265 : content::WebContentsObserver(web_contents), 265 : content::WebContentsObserver(web_contents),
266 url_(expected_url), 266 url_(expected_url),
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 "extensions/api_test/webnavigation/crash/b.html", 790 "extensions/api_test/webnavigation/crash/b.html",
791 embedded_test_server()->port())); 791 embedded_test_server()->port()));
792 ui_test_utils::NavigateToURL(browser(), url); 792 ui_test_utils::NavigateToURL(browser(), url);
793 793
794 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 794 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
795 } 795 }
796 796
797 #endif 797 #endif
798 798
799 } // namespace extensions 799 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698