| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
| (...skipping 1658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1669 | 1669 |
| 1670 void TestingAutomationProvider::ClickInfoBarAccept( | 1670 void TestingAutomationProvider::ClickInfoBarAccept( |
| 1671 int handle, | 1671 int handle, |
| 1672 int info_bar_index, | 1672 int info_bar_index, |
| 1673 bool wait_for_navigation, | 1673 bool wait_for_navigation, |
| 1674 IPC::Message* reply_message) { | 1674 IPC::Message* reply_message) { |
| 1675 bool success = false; | 1675 bool success = false; |
| 1676 if (tab_tracker_->ContainsHandle(handle)) { | 1676 if (tab_tracker_->ContainsHandle(handle)) { |
| 1677 NavigationController* nav_controller = tab_tracker_->GetResource(handle); | 1677 NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
| 1678 if (nav_controller) { | 1678 if (nav_controller) { |
| 1679 int count = nav_controller->tab_contents()->infobar_delegate_count(); | 1679 if (info_bar_index >= 0 && info_bar_index < nav_controller-> |
| 1680 if (info_bar_index >= 0 && info_bar_index < count) { | 1680 tab_contents()->infobar_delegate_count()) { |
| 1681 if (wait_for_navigation) { | 1681 if (wait_for_navigation) |
| 1682 AddNavigationStatusListener(nav_controller, reply_message, 1, false); | 1682 AddNavigationStatusListener(nav_controller, reply_message, 1, false); |
| 1683 } | |
| 1684 InfoBarDelegate* delegate = | 1683 InfoBarDelegate* delegate = |
| 1685 nav_controller->tab_contents()->GetInfoBarDelegateAt( | 1684 nav_controller->tab_contents()->GetInfoBarDelegateAt( |
| 1686 info_bar_index); | 1685 info_bar_index); |
| 1687 if (delegate->AsConfirmInfoBarDelegate()) | 1686 if (delegate->AsConfirmInfoBarDelegate()) |
| 1688 delegate->AsConfirmInfoBarDelegate()->Accept(); | 1687 delegate->AsConfirmInfoBarDelegate()->Accept(); |
| 1689 success = true; | 1688 success = true; |
| 1690 } | 1689 } |
| 1691 } | 1690 } |
| 1692 } | 1691 } |
| 1693 | 1692 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1807 if ((button & ui::MessageBoxFlags::DIALOGBUTTON_CANCEL) == | 1806 if ((button & ui::MessageBoxFlags::DIALOGBUTTON_CANCEL) == |
| 1808 ui::MessageBoxFlags::DIALOGBUTTON_CANCEL) { | 1807 ui::MessageBoxFlags::DIALOGBUTTON_CANCEL) { |
| 1809 DCHECK(!*success) << "invalid param, OK and CANCEL specified"; | 1808 DCHECK(!*success) << "invalid param, OK and CANCEL specified"; |
| 1810 native_dialog->CancelAppModalDialog(); | 1809 native_dialog->CancelAppModalDialog(); |
| 1811 *success = true; | 1810 *success = true; |
| 1812 } | 1811 } |
| 1813 } | 1812 } |
| 1814 } | 1813 } |
| 1815 | 1814 |
| 1816 void TestingAutomationProvider::WaitForBrowserWindowCountToBecome( | 1815 void TestingAutomationProvider::WaitForBrowserWindowCountToBecome( |
| 1817 int target_count, IPC::Message* reply_message) { | 1816 int target_count, |
| 1817 IPC::Message* reply_message) { |
| 1818 if (static_cast<int>(BrowserList::size()) == target_count) { | 1818 if (static_cast<int>(BrowserList::size()) == target_count) { |
| 1819 AutomationMsg_WaitForBrowserWindowCountToBecome::WriteReplyParams( | 1819 AutomationMsg_WaitForBrowserWindowCountToBecome::WriteReplyParams( |
| 1820 reply_message, true); | 1820 reply_message, true); |
| 1821 Send(reply_message); | 1821 Send(reply_message); |
| 1822 return; | 1822 return; |
| 1823 } | 1823 } |
| 1824 | 1824 |
| 1825 // Set up an observer (it will delete itself). | 1825 // Set up an observer (it will delete itself). |
| 1826 new BrowserCountChangeNotificationObserver(target_count, this, reply_message); | 1826 new BrowserCountChangeNotificationObserver(target_count, this, reply_message); |
| 1827 } | 1827 } |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2116 rect.set_width(width); | 2116 rect.set_width(width); |
| 2117 if (args->GetInteger("height", &height)) | 2117 if (args->GetInteger("height", &height)) |
| 2118 rect.set_height(height); | 2118 rect.set_height(height); |
| 2119 browser->window()->SetBounds(rect); | 2119 browser->window()->SetBounds(rect); |
| 2120 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 2120 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 2121 } | 2121 } |
| 2122 | 2122 |
| 2123 ListValue* TestingAutomationProvider::GetInfobarsInfo(TabContents* tc) { | 2123 ListValue* TestingAutomationProvider::GetInfobarsInfo(TabContents* tc) { |
| 2124 // Each infobar may have different properties depending on the type. | 2124 // Each infobar may have different properties depending on the type. |
| 2125 ListValue* infobars = new ListValue; | 2125 ListValue* infobars = new ListValue; |
| 2126 for (int infobar_index = 0; | 2126 for (int i = 0; i < tc->infobar_delegate_count(); ++i) { |
| 2127 infobar_index < tc->infobar_delegate_count(); | |
| 2128 ++infobar_index) { | |
| 2129 DictionaryValue* infobar_item = new DictionaryValue; | 2127 DictionaryValue* infobar_item = new DictionaryValue; |
| 2130 InfoBarDelegate* infobar = tc->GetInfoBarDelegateAt(infobar_index); | 2128 InfoBarDelegate* infobar = tc->GetInfoBarDelegateAt(i); |
| 2131 if (infobar->AsConfirmInfoBarDelegate()) { | 2129 if (infobar->AsConfirmInfoBarDelegate()) { |
| 2132 // Also covers ThemeInstalledInfoBarDelegate and | 2130 // Also covers ThemeInstalledInfoBarDelegate and |
| 2133 // CrashedExtensionInfoBarDelegate. | 2131 // CrashedExtensionInfoBarDelegate. |
| 2134 infobar_item->SetString("type", "confirm_infobar"); | 2132 infobar_item->SetString("type", "confirm_infobar"); |
| 2135 ConfirmInfoBarDelegate* confirm_infobar = | 2133 ConfirmInfoBarDelegate* confirm_infobar = |
| 2136 infobar->AsConfirmInfoBarDelegate(); | 2134 infobar->AsConfirmInfoBarDelegate(); |
| 2137 infobar_item->SetString("text", confirm_infobar->GetMessageText()); | 2135 infobar_item->SetString("text", confirm_infobar->GetMessageText()); |
| 2138 infobar_item->SetString("link_text", confirm_infobar->GetLinkText()); | 2136 infobar_item->SetString("link_text", confirm_infobar->GetLinkText()); |
| 2139 ListValue* buttons_list = new ListValue; | 2137 ListValue* buttons_list = new ListValue; |
| 2140 int buttons = confirm_infobar->GetButtons(); | 2138 int buttons = confirm_infobar->GetButtons(); |
| 2141 if (ConfirmInfoBarDelegate::BUTTON_OK & buttons) { | 2139 if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) { |
| 2142 StringValue* button_label = new StringValue( | 2140 StringValue* button_label = new StringValue( |
| 2143 confirm_infobar->GetButtonLabel( | 2141 confirm_infobar->GetButtonLabel( |
| 2144 ConfirmInfoBarDelegate::BUTTON_OK)); | 2142 ConfirmInfoBarDelegate::BUTTON_OK)); |
| 2145 buttons_list->Append(button_label); | 2143 buttons_list->Append(button_label); |
| 2146 } | 2144 } |
| 2147 if (ConfirmInfoBarDelegate::BUTTON_CANCEL & buttons) { | 2145 if (buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL) { |
| 2148 StringValue* button_label = new StringValue( | 2146 StringValue* button_label = new StringValue( |
| 2149 confirm_infobar->GetButtonLabel( | 2147 confirm_infobar->GetButtonLabel( |
| 2150 ConfirmInfoBarDelegate::BUTTON_CANCEL)); | 2148 ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| 2151 buttons_list->Append(button_label); | 2149 buttons_list->Append(button_label); |
| 2152 } | 2150 } |
| 2153 infobar_item->Set("buttons", buttons_list); | 2151 infobar_item->Set("buttons", buttons_list); |
| 2154 } else if (infobar->AsAlertInfoBarDelegate()) { | 2152 } else if (infobar->AsAlertInfoBarDelegate()) { |
| 2155 infobar_item->SetString("type", "alert_infobar"); | 2153 infobar_item->SetString("type", "alert_infobar"); |
| 2156 AlertInfoBarDelegate* alert_infobar = | 2154 AlertInfoBarDelegate* alert_infobar = |
| 2157 infobar->AsAlertInfoBarDelegate(); | 2155 infobar->AsAlertInfoBarDelegate(); |
| (...skipping 2354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4512 // If you change this, update Observer for NotificationType::SESSION_END | 4510 // If you change this, update Observer for NotificationType::SESSION_END |
| 4513 // below. | 4511 // below. |
| 4514 MessageLoop::current()->PostTask(FROM_HERE, | 4512 MessageLoop::current()->PostTask(FROM_HERE, |
| 4515 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 4513 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
| 4516 } | 4514 } |
| 4517 } | 4515 } |
| 4518 | 4516 |
| 4519 void TestingAutomationProvider::OnRemoveProvider() { | 4517 void TestingAutomationProvider::OnRemoveProvider() { |
| 4520 AutomationProviderList::GetInstance()->RemoveProvider(this); | 4518 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 4521 } | 4519 } |
| OLD | NEW |