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