| 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 <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/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/automation/automation_tab_helper.h" | 11 #include "chrome/browser/automation/automation_tab_helper.h" |
| 12 #include "chrome/browser/automation/mock_tab_event_observer.h" | 12 #include "chrome/browser/automation/mock_tab_event_observer.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 15 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/test/in_process_browser_test.h" | 18 #include "chrome/test/in_process_browser_test.h" |
| 18 #include "chrome/test/ui_test_utils.h" | 19 #include "chrome/test/ui_test_utils.h" |
| 19 #include "content/browser/renderer_host/render_view_host.h" | 20 #include "content/browser/renderer_host/render_view_host.h" |
| 20 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
| 21 #include "content/common/notification_details.h" | 22 #include "content/common/notification_details.h" |
| 22 #include "content/common/notification_observer.h" | 23 #include "content/common/notification_observer.h" |
| 23 #include "content/common/notification_registrar.h" | 24 #include "content/common/notification_registrar.h" |
| 24 #include "content/common/notification_service.h" | 25 #include "content/common/notification_service.h" |
| 25 #include "content/common/notification_source.h" | 26 #include "content/common/notification_source.h" |
| 26 #include "content/common/notification_type.h" | |
| 27 #include "net/base/net_util.h" | 27 #include "net/base/net_util.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| 31 using testing::_; | 31 using testing::_; |
| 32 | 32 |
| 33 class MockNotificationObserver : public NotificationObserver { | 33 class MockNotificationObserver : public NotificationObserver { |
| 34 public: | 34 public: |
| 35 MockNotificationObserver() { } | 35 MockNotificationObserver() { } |
| 36 virtual ~MockNotificationObserver() { } | 36 virtual ~MockNotificationObserver() { } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 61 test_data_dir_ = test_data_dir_.AppendASCII("automation"); | 61 test_data_dir_ = test_data_dir_.AppendASCII("automation"); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Add default expectations for a client redirection initiated by script, | 64 // Add default expectations for a client redirection initiated by script, |
| 65 // and quit the message loop when the redirect has completed. This expects | 65 // and quit the message loop when the redirect has completed. This expects |
| 66 // that the tab receives news of the redirect before the script returns. | 66 // that the tab receives news of the redirect before the script returns. |
| 67 void ExpectClientRedirectAndBreak( | 67 void ExpectClientRedirectAndBreak( |
| 68 MockTabEventObserver* mock_tab_observer, | 68 MockTabEventObserver* mock_tab_observer, |
| 69 MockNotificationObserver* mock_notification_observer) { | 69 MockNotificationObserver* mock_notification_observer) { |
| 70 mock_notification_observer->Register( | 70 mock_notification_observer->Register( |
| 71 NotificationType::DOM_OPERATION_RESPONSE, | 71 chrome::DOM_OPERATION_RESPONSE, |
| 72 NotificationService::AllSources()); | 72 NotificationService::AllSources()); |
| 73 | 73 |
| 74 testing::InSequence expect_in_sequence; | 74 testing::InSequence expect_in_sequence; |
| 75 EXPECT_CALL(*mock_tab_observer, OnFirstPendingLoad(_)); | 75 EXPECT_CALL(*mock_tab_observer, OnFirstPendingLoad(_)); |
| 76 EXPECT_CALL(*mock_notification_observer, Observe( | 76 EXPECT_CALL(*mock_notification_observer, Observe( |
| 77 testing::Eq(NotificationType::DOM_OPERATION_RESPONSE), _, _)); | 77 testing::Eq(chrome::DOM_OPERATION_RESPONSE), _, _)); |
| 78 EXPECT_CALL(*mock_tab_observer, OnNoMorePendingLoads(_)) | 78 EXPECT_CALL(*mock_tab_observer, OnNoMorePendingLoads(_)) |
| 79 .WillOnce(testing::InvokeWithoutArgs( | 79 .WillOnce(testing::InvokeWithoutArgs( |
| 80 MessageLoopForUI::current(), &MessageLoop::Quit)); | 80 MessageLoopForUI::current(), &MessageLoop::Quit)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Executes javascript to execute a given test case found in the current | 83 // Executes javascript to execute a given test case found in the current |
| 84 // page's script. If |wait_for_response| is true, this method will not | 84 // page's script. If |wait_for_response| is true, this method will not |
| 85 // return until the javascript has been executed. | 85 // return until the javascript has been executed. |
| 86 // Use with [ASSERT|EXPECT]_NO_FATAL_FAILURE. | 86 // Use with [ASSERT|EXPECT]_NO_FATAL_FAILURE. |
| 87 void RunTestCaseInJavaScript(int test_case_number, bool wait_for_response) { | 87 void RunTestCaseInJavaScript(int test_case_number, bool wait_for_response) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 174 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 175 browser(), | 175 browser(), |
| 176 net::FilePathToFileURL(test_data_dir_.AppendASCII("meta_redirect.html")), | 176 net::FilePathToFileURL(test_data_dir_.AppendASCII("meta_redirect.html")), |
| 177 2); | 177 2); |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Tests that the load stop event occurs after the window onload handler. | 180 // Tests that the load stop event occurs after the window onload handler. |
| 181 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, | 181 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, |
| 182 LoadStopComesAfterOnLoad) { | 182 LoadStopComesAfterOnLoad) { |
| 183 MockNotificationObserver mock_notification_observer; | 183 MockNotificationObserver mock_notification_observer; |
| 184 mock_notification_observer.Register(NotificationType::DOM_OPERATION_RESPONSE, | 184 mock_notification_observer.Register(chrome::DOM_OPERATION_RESPONSE, |
| 185 NotificationService::AllSources()); | 185 NotificationService::AllSources()); |
| 186 MockTabEventObserver mock_tab_observer(tab_helper()); | 186 MockTabEventObserver mock_tab_observer(tab_helper()); |
| 187 | 187 |
| 188 EXPECT_CALL(mock_tab_observer, OnFirstPendingLoad(_)); | 188 EXPECT_CALL(mock_tab_observer, OnFirstPendingLoad(_)); |
| 189 { | 189 { |
| 190 testing::InSequence expect_in_sequence; | 190 testing::InSequence expect_in_sequence; |
| 191 EXPECT_CALL(mock_notification_observer, Observe( | 191 EXPECT_CALL(mock_notification_observer, Observe( |
| 192 testing::Eq(NotificationType::DOM_OPERATION_RESPONSE), _, _)); | 192 testing::Eq(chrome::DOM_OPERATION_RESPONSE), _, _)); |
| 193 EXPECT_CALL(mock_tab_observer, OnNoMorePendingLoads(_)); | 193 EXPECT_CALL(mock_tab_observer, OnNoMorePendingLoads(_)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL( | 196 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL( |
| 197 test_data_dir_.AppendASCII("sends_message_on_load.html"))); | 197 test_data_dir_.AppendASCII("sends_message_on_load.html"))); |
| 198 } | 198 } |
| 199 | 199 |
| 200 // Tests that a crashed tab reports that it has stopped loading. | 200 // Tests that a crashed tab reports that it has stopped loading. |
| 201 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, | 201 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, |
| 202 CrashedTabStopsLoading) { | 202 CrashedTabStopsLoading) { |
| 203 MockTabEventObserver mock_tab_observer(tab_helper()); | 203 MockTabEventObserver mock_tab_observer(tab_helper()); |
| 204 | 204 |
| 205 testing::InSequence expect_in_sequence; | 205 testing::InSequence expect_in_sequence; |
| 206 EXPECT_CALL(mock_tab_observer, OnFirstPendingLoad(_)); | 206 EXPECT_CALL(mock_tab_observer, OnFirstPendingLoad(_)); |
| 207 EXPECT_CALL(mock_tab_observer, OnNoMorePendingLoads(_)); | 207 EXPECT_CALL(mock_tab_observer, OnNoMorePendingLoads(_)); |
| 208 | 208 |
| 209 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); | 209 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); |
| 210 } | 210 } |
| OLD | NEW |