| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/test/ui_test_utils.h" | 5 #include "chrome/test/ui_test_utils.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
| 9 #include "chrome/browser/dom_operation_notification_details.h" |
| 9 #include "chrome/browser/tab_contents/navigation_controller.h" | 10 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 10 #include "chrome/browser/tab_contents/web_contents.h" | 11 #include "chrome/browser/tab_contents/web_contents.h" |
| 11 #include "chrome/common/notification_registrar.h" | 12 #include "chrome/common/notification_registrar.h" |
| 12 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
| 13 #include "chrome/views/widget/accelerator_handler.h" | 14 #include "chrome/views/widget/accelerator_handler.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 15 | 16 |
| 16 namespace ui_test_utils { | 17 namespace ui_test_utils { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 void NavigateToURLBlockUntilNavigationsComplete(Browser* browser, | 92 void NavigateToURLBlockUntilNavigationsComplete(Browser* browser, |
| 92 const GURL& url, | 93 const GURL& url, |
| 93 int number_of_navigations) { | 94 int number_of_navigations) { |
| 94 NavigationController* controller = | 95 NavigationController* controller = |
| 95 browser->GetSelectedTabContents()->controller(); | 96 browser->GetSelectedTabContents()->controller(); |
| 96 browser->OpenURLFromTab(browser->GetSelectedTabContents(), url, GURL(), | 97 browser->OpenURLFromTab(browser->GetSelectedTabContents(), url, GURL(), |
| 97 CURRENT_TAB, PageTransition::TYPED); | 98 CURRENT_TAB, PageTransition::TYPED); |
| 98 WaitForNavigations(controller, number_of_navigations); | 99 WaitForNavigations(controller, number_of_navigations); |
| 99 } | 100 } |
| 100 | 101 |
| 102 JavaScriptRunner::JavaScriptRunner(WebContents* web_contents, |
| 103 const std::wstring& frame_xpath, |
| 104 const std::wstring& jscript) |
| 105 : web_contents_(web_contents), |
| 106 frame_xpath_(frame_xpath), |
| 107 jscript_(jscript) { |
| 108 NotificationService::current()-> |
| 109 AddObserver(this, NotificationType::DOM_OPERATION_RESPONSE, |
| 110 Source<WebContents>(web_contents)); |
| 111 } |
| 112 |
| 113 void JavaScriptRunner::Observe(NotificationType type, |
| 114 const NotificationSource& source, |
| 115 const NotificationDetails& details) { |
| 116 Details<DomOperationNotificationDetails> dom_op_details(details); |
| 117 result_ = dom_op_details->json(); |
| 118 // The Jasonified response has quotes, remove them. |
| 119 if (result_.length() > 1 && result_[0] == '"') |
| 120 result_ = result_.substr(1, result_.length() - 2); |
| 121 |
| 122 NotificationService::current()-> |
| 123 RemoveObserver(this, NotificationType::DOM_OPERATION_RESPONSE, |
| 124 Source<WebContents>(web_contents_)); |
| 125 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 126 } |
| 127 |
| 128 std::string JavaScriptRunner::Run() { |
| 129 // The DOMAutomationController requires an automation ID, even though we are |
| 130 // not using it in this case. |
| 131 web_contents_->render_view_host()->ExecuteJavascriptInWebFrame( |
| 132 frame_xpath_, L"window.domAutomationController.setAutomationId(0);"); |
| 133 |
| 134 web_contents_->render_view_host()->ExecuteJavascriptInWebFrame(frame_xpath_, |
| 135 jscript_); |
| 136 ui_test_utils::RunMessageLoop(); |
| 137 return result_; |
| 138 } |
| 139 |
| 101 } // namespace ui_test_utils | 140 } // namespace ui_test_utils |
| OLD | NEW |