| OLD | NEW |
| 1 // Copyright (c) 2009 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/browser/browser.h" | 5 #include "chrome/browser/browser.h" |
| 6 #include "chrome/browser/tab_contents/tab_contents.h" | 6 #include "chrome/browser/tab_contents/tab_contents.h" |
| 7 #include "chrome/browser/download/download_manager.h" |
| 8 #include "chrome/browser/profile.h" |
| 7 #include "chrome/common/chrome_paths.h" | 9 #include "chrome/common/chrome_paths.h" |
| 8 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 9 #include "chrome/common/notification_details.h" | 11 #include "chrome/common/notification_details.h" |
| 10 #include "chrome/common/notification_observer.h" | 12 #include "chrome/common/notification_observer.h" |
| 11 #include "chrome/common/notification_registrar.h" | 13 #include "chrome/common/notification_registrar.h" |
| 12 #include "chrome/common/notification_service.h" | 14 #include "chrome/common/notification_service.h" |
| 13 #include "chrome/common/notification_type.h" | 15 #include "chrome/common/notification_type.h" |
| 14 #include "chrome/common/extensions/extension_error_reporter.h" | 16 #include "chrome/common/extensions/extension_error_reporter.h" |
| 15 #include "chrome/test/in_process_browser_test.h" | 17 #include "chrome/test/in_process_browser_test.h" |
| 16 #include "chrome/test/ui_test_utils.h" | 18 #include "chrome/test/ui_test_utils.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 31 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ChromeURLAfterDownload) { | 33 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ChromeURLAfterDownload) { |
| 32 GURL downloads_url("chrome://downloads"); | 34 GURL downloads_url("chrome://downloads"); |
| 33 GURL extensions_url("chrome://extensions"); | 35 GURL extensions_url("chrome://extensions"); |
| 34 FilePath zip_download; | 36 FilePath zip_download; |
| 35 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &zip_download)); | 37 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &zip_download)); |
| 36 zip_download = zip_download.AppendASCII("zip").AppendASCII("test.zip"); | 38 zip_download = zip_download.AppendASCII("zip").AppendASCII("test.zip"); |
| 37 GURL zip_url = net::FilePathToFileURL(zip_download); | 39 GURL zip_url = net::FilePathToFileURL(zip_download); |
| 38 | 40 |
| 39 ui_test_utils::NavigateToURL(browser(), downloads_url); | 41 ui_test_utils::NavigateToURL(browser(), downloads_url); |
| 40 ui_test_utils::NavigateToURL(browser(), zip_url); | 42 ui_test_utils::NavigateToURL(browser(), zip_url); |
| 43 ui_test_utils::WaitForDownloadCount( |
| 44 browser()->profile()->GetDownloadManager(), 1); |
| 41 ui_test_utils::NavigateToURL(browser(), extensions_url); | 45 ui_test_utils::NavigateToURL(browser(), extensions_url); |
| 42 | 46 |
| 43 TabContents *contents = browser()->GetSelectedTabContents(); | 47 TabContents *contents = browser()->GetSelectedTabContents(); |
| 44 ASSERT_TRUE(contents); | 48 ASSERT_TRUE(contents); |
| 45 bool domui_responded = false; | 49 bool domui_responded = false; |
| 46 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 50 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 47 contents, | 51 contents, |
| 48 L"", | 52 L"", |
| 49 L"window.domAutomationController.send(window.domui_responded_);", | 53 L"window.domAutomationController.send(window.domui_responded_);", |
| 50 &domui_responded)); | 54 &domui_responded)); |
| 51 EXPECT_TRUE(domui_responded); | 55 EXPECT_TRUE(domui_responded); |
| 52 } | 56 } |
| 53 | 57 |
| 54 class BrowserClosedObserver : public NotificationObserver { | 58 class BrowserClosedObserver : public NotificationObserver { |
| 55 public: | 59 public: |
| 56 BrowserClosedObserver(Browser* browser) { | 60 explicit BrowserClosedObserver(Browser* browser) { |
| 57 registrar_.Add(this, NotificationType::BROWSER_CLOSED, | 61 registrar_.Add(this, NotificationType::BROWSER_CLOSED, |
| 58 Source<Browser>(browser)); | 62 Source<Browser>(browser)); |
| 59 ui_test_utils::RunMessageLoop(); | 63 ui_test_utils::RunMessageLoop(); |
| 60 } | 64 } |
| 61 | 65 |
| 62 // NotificationObserver | 66 // NotificationObserver |
| 63 virtual void Observe(NotificationType type, | 67 virtual void Observe(NotificationType type, |
| 64 const NotificationSource& source, | 68 const NotificationSource& source, |
| 65 const NotificationDetails& details) { | 69 const NotificationDetails& details) { |
| 66 switch (type.value) { | 70 switch (type.value) { |
| 67 case NotificationType::BROWSER_CLOSED: | 71 case NotificationType::BROWSER_CLOSED: |
| 68 MessageLoopForUI::current()->Quit(); | 72 MessageLoopForUI::current()->Quit(); |
| 69 break; | 73 break; |
| 70 } | 74 } |
| 71 } | 75 } |
| 72 | 76 |
| 73 private: | 77 private: |
| 74 NotificationRegistrar registrar_; | 78 NotificationRegistrar registrar_; |
| 75 }; | 79 }; |
| 76 | 80 |
| 77 // Test for crbug.com/12745. This tests that if a download is initiated from | 81 // Test for crbug.com/12745. This tests that if a download is initiated from |
| 78 // a chrome:// page that has registered and onunload handler, the browser | 82 // a chrome:// page that has registered and onunload handler, the browser |
| 79 // will be able to close. | 83 // will be able to close. |
| 80 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, DISABLED_BrowserCloseAfterDown
load) { | 84 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BrowserCloseAfterDownload) { |
| 81 GURL downloads_url("chrome://downloads"); | 85 GURL downloads_url("chrome://downloads"); |
| 82 FilePath zip_download; | 86 FilePath zip_download; |
| 83 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &zip_download)); | 87 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &zip_download)); |
| 84 zip_download = zip_download.AppendASCII("zip").AppendASCII("test.zip"); | 88 zip_download = zip_download.AppendASCII("zip").AppendASCII("test.zip"); |
| 85 ASSERT_TRUE(file_util::PathExists(zip_download)); | 89 ASSERT_TRUE(file_util::PathExists(zip_download)); |
| 86 GURL zip_url = net::FilePathToFileURL(zip_download); | 90 GURL zip_url = net::FilePathToFileURL(zip_download); |
| 87 | 91 |
| 88 ui_test_utils::NavigateToURL(browser(), downloads_url); | 92 ui_test_utils::NavigateToURL(browser(), downloads_url); |
| 89 TabContents *contents = browser()->GetSelectedTabContents(); | 93 TabContents *contents = browser()->GetSelectedTabContents(); |
| 90 ASSERT_TRUE(contents); | 94 ASSERT_TRUE(contents); |
| 91 bool result = false; | 95 bool result = false; |
| 92 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 96 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 93 contents, | 97 contents, |
| 94 L"", | 98 L"", |
| 95 L"window.onunload = function() { var do_nothing = 0; }; " | 99 L"window.onunload = function() { var do_nothing = 0; }; " |
| 96 L"window.domAutomationController.send(true);", | 100 L"window.domAutomationController.send(true);", |
| 97 &result)); | 101 &result)); |
| 98 EXPECT_TRUE(result); | 102 EXPECT_TRUE(result); |
| 99 ui_test_utils::NavigateToURL(browser(), zip_url); | 103 ui_test_utils::NavigateToURL(browser(), zip_url); |
| 104 |
| 105 ui_test_utils::WaitForDownloadCount( |
| 106 browser()->profile()->GetDownloadManager(), 1); |
| 107 |
| 100 browser()->CloseWindow(); | 108 browser()->CloseWindow(); |
| 101 BrowserClosedObserver observe(browser()); | 109 BrowserClosedObserver wait_for_close(browser()); |
| 102 } | 110 } |
| OLD | NEW |