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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 10168019: Adds an automation hook WaitUntilNavigationCompletes() which blocks until pending navigation comple… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Slight comment rewording. Created 8 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
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 "chrome/browser/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 2143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2154 } 2154 }
2155 2155
2156 // Map json commands to their handlers. 2156 // Map json commands to their handlers.
2157 std::map<std::string, JsonHandler> handler_map; 2157 std::map<std::string, JsonHandler> handler_map;
2158 handler_map["WaitForAllTabsToStopLoading"] = 2158 handler_map["WaitForAllTabsToStopLoading"] =
2159 &TestingAutomationProvider::WaitForAllViewsToStopLoading; 2159 &TestingAutomationProvider::WaitForAllViewsToStopLoading;
2160 handler_map["GetIndicesFromTab"] = 2160 handler_map["GetIndicesFromTab"] =
2161 &TestingAutomationProvider::GetIndicesFromTab; 2161 &TestingAutomationProvider::GetIndicesFromTab;
2162 handler_map["NavigateToURL"] = 2162 handler_map["NavigateToURL"] =
2163 &TestingAutomationProvider::NavigateToURL; 2163 &TestingAutomationProvider::NavigateToURL;
2164 handler_map["WaitUntilNavigationCompletes"] =
2165 &TestingAutomationProvider::WaitUntilNavigationCompletes;
2164 handler_map["GetLocalStatePrefsInfo"] = 2166 handler_map["GetLocalStatePrefsInfo"] =
2165 &TestingAutomationProvider::GetLocalStatePrefsInfo; 2167 &TestingAutomationProvider::GetLocalStatePrefsInfo;
2166 handler_map["SetLocalStatePrefs"] = 2168 handler_map["SetLocalStatePrefs"] =
2167 &TestingAutomationProvider::SetLocalStatePrefs; 2169 &TestingAutomationProvider::SetLocalStatePrefs;
2168 handler_map["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; 2170 handler_map["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo;
2169 handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; 2171 handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs;
2170 handler_map["ExecuteJavascript"] = 2172 handler_map["ExecuteJavascript"] =
2171 &TestingAutomationProvider::ExecuteJavascriptJSON; 2173 &TestingAutomationProvider::ExecuteJavascriptJSON;
2172 handler_map["AddDomEventObserver"] = 2174 handler_map["AddDomEventObserver"] =
2173 &TestingAutomationProvider::AddDomEventObserver; 2175 &TestingAutomationProvider::AddDomEventObserver;
(...skipping 4158 matching lines...) Expand 10 before | Expand all | Expand 10 after
6332 return; 6334 return;
6333 } 6335 }
6334 new NavigationNotificationObserver( 6336 new NavigationNotificationObserver(
6335 &web_contents->GetController(), this, reply_message, 6337 &web_contents->GetController(), this, reply_message,
6336 navigation_count, false, true); 6338 navigation_count, false, true);
6337 browser->OpenURLFromTab(web_contents, OpenURLParams( 6339 browser->OpenURLFromTab(web_contents, OpenURLParams(
6338 GURL(url), content::Referrer(), CURRENT_TAB, 6340 GURL(url), content::Referrer(), CURRENT_TAB,
6339 content::PAGE_TRANSITION_TYPED, false)); 6341 content::PAGE_TRANSITION_TYPED, false));
6340 } 6342 }
6341 6343
6344 void TestingAutomationProvider::WaitUntilNavigationCompletes(
6345 DictionaryValue* args,
6346 IPC::Message* reply_message) {
6347 if (SendErrorIfModalDialogActive(this, reply_message))
6348 return;
6349
6350 std::string error;
6351 Browser* browser;
6352 WebContents* web_contents;
6353 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &web_contents, &error)) {
6354 AutomationJSONReply(this, reply_message).SendError(error);
6355 return;
6356 }
6357 if (!web_contents->IsLoading()) {
6358 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
6359 return;
6360 }
dennis_jeffrey 2012/04/20 22:11:32 possible race condition here? The check above cou
craigdh 2012/04/20 23:04:55 Yes, you're right. Somehow I thought I had avoided
6361 new NavigationNotificationObserver(
6362 &web_contents->GetController(), this, reply_message, 1, true, true);
6363 }
6364
6342 void TestingAutomationProvider::ExecuteJavascriptJSON( 6365 void TestingAutomationProvider::ExecuteJavascriptJSON(
6343 DictionaryValue* args, 6366 DictionaryValue* args,
6344 IPC::Message* reply_message) { 6367 IPC::Message* reply_message) {
6345 if (SendErrorIfModalDialogActive(this, reply_message)) 6368 if (SendErrorIfModalDialogActive(this, reply_message))
6346 return; 6369 return;
6347 6370
6348 string16 frame_xpath, javascript; 6371 string16 frame_xpath, javascript;
6349 std::string error; 6372 std::string error;
6350 RenderViewHost* render_view; 6373 RenderViewHost* render_view;
6351 if (!GetRenderViewFromJSONArgs(args, profile(), &render_view, &error)) { 6374 if (!GetRenderViewFromJSONArgs(args, profile(), &render_view, &error)) {
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
6978 *browser_handle = browser_tracker_->Add(browser); 7001 *browser_handle = browser_tracker_->Add(browser);
6979 *success = true; 7002 *success = true;
6980 } 7003 }
6981 } 7004 }
6982 } 7005 }
6983 7006
6984 void TestingAutomationProvider::OnRemoveProvider() { 7007 void TestingAutomationProvider::OnRemoveProvider() {
6985 if (g_browser_process) 7008 if (g_browser_process)
6986 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 7009 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6987 } 7010 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698