| OLD | NEW |
| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string16.h" | 9 #include "base/string16.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/automation/automation_tab_helper.h" | 12 #include "chrome/browser/automation/automation_tab_helper.h" |
| 13 #include "chrome/browser/automation/mock_tab_event_observer.h" | 13 #include "chrome/browser/automation/mock_tab_event_observer.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
| 21 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Executes javascript to execute a given test case found in the current | 86 // Executes javascript to execute a given test case found in the current |
| 87 // page's script. If |wait_for_response| is true, this method will not | 87 // page's script. If |wait_for_response| is true, this method will not |
| 88 // return until the javascript has been executed. | 88 // return until the javascript has been executed. |
| 89 // Use with [ASSERT|EXPECT]_NO_FATAL_FAILURE. | 89 // Use with [ASSERT|EXPECT]_NO_FATAL_FAILURE. |
| 90 void RunTestCaseInJavaScript(int test_case_number, bool wait_for_response) { | 90 void RunTestCaseInJavaScript(int test_case_number, bool wait_for_response) { |
| 91 std::string script = base::StringPrintf("runTestCase(%d);", | 91 std::string script = base::StringPrintf("runTestCase(%d);", |
| 92 test_case_number); | 92 test_case_number); |
| 93 content::RenderViewHost* host = | 93 content::RenderViewHost* host = |
| 94 browser()->GetSelectedWebContents()->GetRenderViewHost(); | 94 browser()->GetActiveWebContents()->GetRenderViewHost(); |
| 95 if (wait_for_response) { | 95 if (wait_for_response) { |
| 96 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 96 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 97 host, L"", ASCIIToWide(script))); | 97 host, L"", ASCIIToWide(script))); |
| 98 } else { | 98 } else { |
| 99 script += "window.domAutomationController.setAutomationId(0);" | 99 script += "window.domAutomationController.setAutomationId(0);" |
| 100 "window.domAutomationController.send(0);"; | 100 "window.domAutomationController.send(0);"; |
| 101 host->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(script)); | 101 host->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(script)); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Returns the |AutomationTabHelper| for the first browser's first tab. | 105 // Returns the |AutomationTabHelper| for the first browser's first tab. |
| 106 AutomationTabHelper* tab_helper() { | 106 AutomationTabHelper* tab_helper() { |
| 107 return browser()->GetTabContentsWrapperAt(0)->automation_tab_helper(); | 107 return browser()->GetTabContentsAt(0)->automation_tab_helper(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 protected: | 110 protected: |
| 111 FilePath test_data_dir_; | 111 FilePath test_data_dir_; |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, FormSubmission) { | 114 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, FormSubmission) { |
| 115 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL( | 115 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL( |
| 116 test_data_dir_.AppendASCII("client_redirects.html"))); | 116 test_data_dir_.AppendASCII("client_redirects.html"))); |
| 117 | 117 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, | 207 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, |
| 208 CrashedTabStopsLoading) { | 208 CrashedTabStopsLoading) { |
| 209 MockTabEventObserver mock_tab_observer(tab_helper()); | 209 MockTabEventObserver mock_tab_observer(tab_helper()); |
| 210 | 210 |
| 211 testing::InSequence expect_in_sequence; | 211 testing::InSequence expect_in_sequence; |
| 212 EXPECT_CALL(mock_tab_observer, OnFirstPendingLoad(_)); | 212 EXPECT_CALL(mock_tab_observer, OnFirstPendingLoad(_)); |
| 213 EXPECT_CALL(mock_tab_observer, OnNoMorePendingLoads(_)); | 213 EXPECT_CALL(mock_tab_observer, OnNoMorePendingLoads(_)); |
| 214 | 214 |
| 215 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); | 215 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); |
| 216 } | 216 } |
| OLD | NEW |