| 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_notification_types.h" |
| 16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "content/browser/renderer_host/render_view_host.h" | 20 #include "content/browser/renderer_host/render_view_host.h" |
| 21 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
| 22 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 23 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
| 24 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
| 25 #include "content/common/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.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 content::NotificationObserver { | 33 class MockNotificationObserver : public content::NotificationObserver { |
| 34 public: | 34 public: |
| 35 MockNotificationObserver() { } | 35 MockNotificationObserver() { } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 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 chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, | 71 chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 72 NotificationService::AllSources()); | 72 content::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( | 77 testing::Eq( |
| 78 static_cast<int>(chrome::NOTIFICATION_DOM_OPERATION_RESPONSE)), | 78 static_cast<int>(chrome::NOTIFICATION_DOM_OPERATION_RESPONSE)), |
| 79 _, _)); | 79 _, _)); |
| 80 EXPECT_CALL(*mock_tab_observer, OnNoMorePendingLoads(_)) | 80 EXPECT_CALL(*mock_tab_observer, OnNoMorePendingLoads(_)) |
| 81 .WillOnce(testing::InvokeWithoutArgs( | 81 .WillOnce(testing::InvokeWithoutArgs( |
| 82 MessageLoopForUI::current(), &MessageLoop::Quit)); | 82 MessageLoopForUI::current(), &MessageLoop::Quit)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 net::FilePathToFileURL(test_data_dir_.AppendASCII("meta_redirect.html")), | 178 net::FilePathToFileURL(test_data_dir_.AppendASCII("meta_redirect.html")), |
| 179 2); | 179 2); |
| 180 } | 180 } |
| 181 | 181 |
| 182 // Tests that the load stop event occurs after the window onload handler. | 182 // Tests that the load stop event occurs after the window onload handler. |
| 183 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, | 183 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, |
| 184 LoadStopComesAfterOnLoad) { | 184 LoadStopComesAfterOnLoad) { |
| 185 MockNotificationObserver mock_notification_observer; | 185 MockNotificationObserver mock_notification_observer; |
| 186 mock_notification_observer.Register( | 186 mock_notification_observer.Register( |
| 187 chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, | 187 chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 188 NotificationService::AllSources()); | 188 content::NotificationService::AllSources()); |
| 189 MockTabEventObserver mock_tab_observer(tab_helper()); | 189 MockTabEventObserver mock_tab_observer(tab_helper()); |
| 190 | 190 |
| 191 EXPECT_CALL(mock_tab_observer, OnFirstPendingLoad(_)); | 191 EXPECT_CALL(mock_tab_observer, OnFirstPendingLoad(_)); |
| 192 { | 192 { |
| 193 testing::InSequence expect_in_sequence; | 193 testing::InSequence expect_in_sequence; |
| 194 EXPECT_CALL(mock_notification_observer, Observe( | 194 EXPECT_CALL(mock_notification_observer, Observe( |
| 195 testing::Eq( | 195 testing::Eq( |
| 196 static_cast<int>(chrome::NOTIFICATION_DOM_OPERATION_RESPONSE)), | 196 static_cast<int>(chrome::NOTIFICATION_DOM_OPERATION_RESPONSE)), |
| 197 _, _)); | 197 _, _)); |
| 198 EXPECT_CALL(mock_tab_observer, OnNoMorePendingLoads(_)); | 198 EXPECT_CALL(mock_tab_observer, OnNoMorePendingLoads(_)); |
| 199 } | 199 } |
| 200 | 200 |
| 201 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL( | 201 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL( |
| 202 test_data_dir_.AppendASCII("sends_message_on_load.html"))); | 202 test_data_dir_.AppendASCII("sends_message_on_load.html"))); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // Tests that a crashed tab reports that it has stopped loading. | 205 // Tests that a crashed tab reports that it has stopped loading. |
| 206 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, | 206 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, |
| 207 CrashedTabStopsLoading) { | 207 CrashedTabStopsLoading) { |
| 208 MockTabEventObserver mock_tab_observer(tab_helper()); | 208 MockTabEventObserver mock_tab_observer(tab_helper()); |
| 209 | 209 |
| 210 testing::InSequence expect_in_sequence; | 210 testing::InSequence expect_in_sequence; |
| 211 EXPECT_CALL(mock_tab_observer, OnFirstPendingLoad(_)); | 211 EXPECT_CALL(mock_tab_observer, OnFirstPendingLoad(_)); |
| 212 EXPECT_CALL(mock_tab_observer, OnNoMorePendingLoads(_)); | 212 EXPECT_CALL(mock_tab_observer, OnNoMorePendingLoads(_)); |
| 213 | 213 |
| 214 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); | 214 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); |
| 215 } | 215 } |
| OLD | NEW |