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/common/chrome_paths.h" | 7 #include "chrome/common/chrome_paths.h" |
8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
| 9 #include "chrome/common/notification_details.h" |
| 10 #include "chrome/common/notification_observer.h" |
| 11 #include "chrome/common/notification_registrar.h" |
| 12 #include "chrome/common/notification_service.h" |
| 13 #include "chrome/common/notification_type.h" |
9 #include "chrome/common/extensions/extension_error_reporter.h" | 14 #include "chrome/common/extensions/extension_error_reporter.h" |
10 #include "chrome/test/in_process_browser_test.h" | 15 #include "chrome/test/in_process_browser_test.h" |
11 #include "chrome/test/ui_test_utils.h" | 16 #include "chrome/test/ui_test_utils.h" |
12 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
13 | 18 |
14 class RenderViewHostManagerTest : public InProcessBrowserTest { | 19 class RenderViewHostManagerTest : public InProcessBrowserTest { |
15 public: | 20 public: |
16 RenderViewHostManagerTest() { | 21 RenderViewHostManagerTest() { |
17 EnableDOMAutomation(); | 22 EnableDOMAutomation(); |
18 } | 23 } |
(...skipping 19 matching lines...) Expand all Loading... |
38 TabContents *contents = browser()->GetSelectedTabContents(); | 43 TabContents *contents = browser()->GetSelectedTabContents(); |
39 ASSERT_TRUE(contents); | 44 ASSERT_TRUE(contents); |
40 bool domui_responded = false; | 45 bool domui_responded = false; |
41 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 46 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
42 contents, | 47 contents, |
43 L"", | 48 L"", |
44 L"window.domAutomationController.send(window.domui_responded_);", | 49 L"window.domAutomationController.send(window.domui_responded_);", |
45 &domui_responded)); | 50 &domui_responded)); |
46 EXPECT_TRUE(domui_responded); | 51 EXPECT_TRUE(domui_responded); |
47 } | 52 } |
| 53 |
| 54 class BrowserClosedObserver : public NotificationObserver { |
| 55 public: |
| 56 BrowserClosedObserver(Browser* browser) { |
| 57 registrar_.Add(this, NotificationType::BROWSER_CLOSED, |
| 58 Source<Browser>(browser)); |
| 59 ui_test_utils::RunMessageLoop(); |
| 60 } |
| 61 |
| 62 // NotificationObserver |
| 63 virtual void Observe(NotificationType type, |
| 64 const NotificationSource& source, |
| 65 const NotificationDetails& details) { |
| 66 switch (type.value) { |
| 67 case NotificationType::BROWSER_CLOSED: |
| 68 MessageLoopForUI::current()->Quit(); |
| 69 break; |
| 70 } |
| 71 } |
| 72 |
| 73 private: |
| 74 NotificationRegistrar registrar_; |
| 75 }; |
| 76 |
| 77 // 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 |
| 79 // will be able to close. |
| 80 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BrowserCloseAfterDownload) { |
| 81 GURL downloads_url("chrome://downloads"); |
| 82 FilePath zip_download; |
| 83 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &zip_download)); |
| 84 zip_download = zip_download.AppendASCII("zip").AppendASCII("test.zip"); |
| 85 ASSERT_TRUE(file_util::PathExists(zip_download)); |
| 86 GURL zip_url = net::FilePathToFileURL(zip_download); |
| 87 |
| 88 ui_test_utils::NavigateToURL(browser(), downloads_url); |
| 89 TabContents *contents = browser()->GetSelectedTabContents(); |
| 90 ASSERT_TRUE(contents); |
| 91 bool result = false; |
| 92 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 93 contents, |
| 94 L"", |
| 95 L"window.onunload = function() { var do_nothing = 0; }; " |
| 96 L"window.domAutomationController.send(true);", |
| 97 &result)); |
| 98 EXPECT_TRUE(result); |
| 99 ui_test_utils::NavigateToURL(browser(), zip_url); |
| 100 browser()->CloseWindow(); |
| 101 BrowserClosedObserver observe(browser()); |
| 102 } |
OLD | NEW |