OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/process/launch.h" | 6 #include "base/process/launch.h" |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "net/base/filename_util.h" | 21 #include "net/base/filename_util.h" |
22 | 22 |
23 // These tests don't apply to the Mac version; see GetCommandLineForRelaunch | 23 // These tests don't apply to the Mac version; see GetCommandLineForRelaunch |
24 // for details. | 24 // for details. |
25 #if !defined(OS_MACOSX) | 25 #if !defined(OS_MACOSX) |
26 | 26 |
27 class ChromeMainTest : public InProcessBrowserTest { | 27 class ChromeMainTest : public InProcessBrowserTest { |
28 public: | 28 public: |
29 ChromeMainTest() {} | 29 ChromeMainTest() {} |
30 | 30 |
31 void Relaunch(const CommandLine& new_command_line) { | 31 void Relaunch(const base::CommandLine& new_command_line) { |
32 base::LaunchProcess(new_command_line, base::LaunchOptionsForTest(), NULL); | 32 base::LaunchProcess(new_command_line, base::LaunchOptionsForTest(), NULL); |
33 } | 33 } |
34 }; | 34 }; |
35 | 35 |
36 // Make sure that the second invocation creates a new window. | 36 // Make sure that the second invocation creates a new window. |
37 IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunch) { | 37 IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunch) { |
38 #if defined(OS_WIN) && defined(USE_ASH) | 38 #if defined(OS_WIN) && defined(USE_ASH) |
39 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 39 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
40 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 40 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 41 switches::kAshBrowserTests)) |
41 return; | 42 return; |
42 #endif | 43 #endif |
43 | 44 |
44 ui_test_utils::BrowserAddedObserver observer; | 45 ui_test_utils::BrowserAddedObserver observer; |
45 Relaunch(GetCommandLineForRelaunch()); | 46 Relaunch(GetCommandLineForRelaunch()); |
46 observer.WaitForSingleNewBrowser(); | 47 observer.WaitForSingleNewBrowser(); |
47 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), | 48 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), |
48 browser()->host_desktop_type())); | 49 browser()->host_desktop_type())); |
49 } | 50 } |
50 | 51 |
51 IN_PROC_BROWSER_TEST_F(ChromeMainTest, ReuseBrowserInstanceWhenOpeningFile) { | 52 IN_PROC_BROWSER_TEST_F(ChromeMainTest, ReuseBrowserInstanceWhenOpeningFile) { |
52 #if defined(OS_WIN) && defined(USE_ASH) | 53 #if defined(OS_WIN) && defined(USE_ASH) |
53 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 54 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
54 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 55 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 56 switches::kAshBrowserTests)) |
55 return; | 57 return; |
56 #endif | 58 #endif |
57 | 59 |
58 base::FilePath test_file_path = ui_test_utils::GetTestFilePath( | 60 base::FilePath test_file_path = ui_test_utils::GetTestFilePath( |
59 base::FilePath(), base::FilePath().AppendASCII("empty.html")); | 61 base::FilePath(), base::FilePath().AppendASCII("empty.html")); |
60 CommandLine new_command_line(GetCommandLineForRelaunch()); | 62 base::CommandLine new_command_line(GetCommandLineForRelaunch()); |
61 new_command_line.AppendArgPath(test_file_path); | 63 new_command_line.AppendArgPath(test_file_path); |
62 content::WindowedNotificationObserver observer( | 64 content::WindowedNotificationObserver observer( |
63 chrome::NOTIFICATION_TAB_ADDED, | 65 chrome::NOTIFICATION_TAB_ADDED, |
64 content::NotificationService::AllSources()); | 66 content::NotificationService::AllSources()); |
65 Relaunch(new_command_line); | 67 Relaunch(new_command_line); |
66 observer.Wait(); | 68 observer.Wait(); |
67 | 69 |
68 GURL url = net::FilePathToFileURL(test_file_path); | 70 GURL url = net::FilePathToFileURL(test_file_path); |
69 content::WebContents* tab = | 71 content::WebContents* tab = |
70 browser()->tab_strip_model()->GetActiveWebContents(); | 72 browser()->tab_strip_model()->GetActiveWebContents(); |
71 ASSERT_EQ(url, tab->GetController().GetActiveEntry()->GetVirtualURL()); | 73 ASSERT_EQ(url, tab->GetController().GetActiveEntry()->GetVirtualURL()); |
72 } | 74 } |
73 | 75 |
74 // ChromeMainTest.SecondLaunchWithIncognitoUrl is flaky on Win and Linux. | 76 // ChromeMainTest.SecondLaunchWithIncognitoUrl is flaky on Win and Linux. |
75 // http://crbug.com/130395 | 77 // http://crbug.com/130395 |
76 #if defined(OS_WIN) || defined(OS_LINUX) | 78 #if defined(OS_WIN) || defined(OS_LINUX) |
77 #define MAYBE_SecondLaunchWithIncognitoUrl DISABLED_SecondLaunchWithIncognitoUrl | 79 #define MAYBE_SecondLaunchWithIncognitoUrl DISABLED_SecondLaunchWithIncognitoUrl |
78 #else | 80 #else |
79 #define MAYBE_SecondLaunchWithIncognitoUrl SecondLaunchWithIncognitoUrl | 81 #define MAYBE_SecondLaunchWithIncognitoUrl SecondLaunchWithIncognitoUrl |
80 #endif | 82 #endif |
81 | 83 |
82 IN_PROC_BROWSER_TEST_F(ChromeMainTest, MAYBE_SecondLaunchWithIncognitoUrl) { | 84 IN_PROC_BROWSER_TEST_F(ChromeMainTest, MAYBE_SecondLaunchWithIncognitoUrl) { |
83 // We should start with one normal window. | 85 // We should start with one normal window. |
84 ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(browser()->profile(), | 86 ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(browser()->profile(), |
85 browser()->host_desktop_type())); | 87 browser()->host_desktop_type())); |
86 | 88 |
87 // Run with --incognito switch and an URL specified. | 89 // Run with --incognito switch and an URL specified. |
88 base::FilePath test_file_path = ui_test_utils::GetTestFilePath( | 90 base::FilePath test_file_path = ui_test_utils::GetTestFilePath( |
89 base::FilePath(), base::FilePath().AppendASCII("empty.html")); | 91 base::FilePath(), base::FilePath().AppendASCII("empty.html")); |
90 CommandLine new_command_line(GetCommandLineForRelaunch()); | 92 base::CommandLine new_command_line(GetCommandLineForRelaunch()); |
91 new_command_line.AppendSwitch(switches::kIncognito); | 93 new_command_line.AppendSwitch(switches::kIncognito); |
92 new_command_line.AppendArgPath(test_file_path); | 94 new_command_line.AppendArgPath(test_file_path); |
93 | 95 |
94 Relaunch(new_command_line); | 96 Relaunch(new_command_line); |
95 | 97 |
96 // There should be one normal and one incognito window now. | 98 // There should be one normal and one incognito window now. |
97 ui_test_utils::BrowserAddedObserver observer; | 99 ui_test_utils::BrowserAddedObserver observer; |
98 Relaunch(new_command_line); | 100 Relaunch(new_command_line); |
99 observer.WaitForSingleNewBrowser(); | 101 observer.WaitForSingleNewBrowser(); |
100 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); | 102 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); |
101 | 103 |
102 ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(browser()->profile(), | 104 ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(browser()->profile(), |
103 browser()->host_desktop_type())); | 105 browser()->host_desktop_type())); |
104 } | 106 } |
105 | 107 |
106 IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunchFromIncognitoWithNormalUrl) { | 108 IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunchFromIncognitoWithNormalUrl) { |
107 #if defined(OS_WIN) && defined(USE_ASH) | 109 #if defined(OS_WIN) && defined(USE_ASH) |
108 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 110 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
109 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 111 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 112 switches::kAshBrowserTests)) |
110 return; | 113 return; |
111 #endif | 114 #endif |
112 | 115 |
113 // We should start with one normal window. | 116 // We should start with one normal window. |
114 ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(browser()->profile(), | 117 ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(browser()->profile(), |
115 browser()->host_desktop_type())); | 118 browser()->host_desktop_type())); |
116 | 119 |
117 // Create an incognito window. | 120 // Create an incognito window. |
118 chrome::NewIncognitoWindow(browser()); | 121 chrome::NewIncognitoWindow(browser()); |
119 | 122 |
(...skipping 10 matching lines...) Expand all Loading... |
130 chrome::CloseWindow(browser()); | 133 chrome::CloseWindow(browser()); |
131 observer.Wait(); | 134 observer.Wait(); |
132 | 135 |
133 // There should only be the incognito window open now. | 136 // There should only be the incognito window open now. |
134 ASSERT_EQ(1u, chrome::GetTotalBrowserCount()); | 137 ASSERT_EQ(1u, chrome::GetTotalBrowserCount()); |
135 ASSERT_EQ(0u, chrome::GetTabbedBrowserCount(profile, host_desktop_type)); | 138 ASSERT_EQ(0u, chrome::GetTabbedBrowserCount(profile, host_desktop_type)); |
136 | 139 |
137 // Run with just an URL specified, no --incognito switch. | 140 // Run with just an URL specified, no --incognito switch. |
138 base::FilePath test_file_path = ui_test_utils::GetTestFilePath( | 141 base::FilePath test_file_path = ui_test_utils::GetTestFilePath( |
139 base::FilePath(), base::FilePath().AppendASCII("empty.html")); | 142 base::FilePath(), base::FilePath().AppendASCII("empty.html")); |
140 CommandLine new_command_line(GetCommandLineForRelaunch()); | 143 base::CommandLine new_command_line(GetCommandLineForRelaunch()); |
141 new_command_line.AppendArgPath(test_file_path); | 144 new_command_line.AppendArgPath(test_file_path); |
142 content::WindowedNotificationObserver tab_observer( | 145 content::WindowedNotificationObserver tab_observer( |
143 chrome::NOTIFICATION_TAB_ADDED, | 146 chrome::NOTIFICATION_TAB_ADDED, |
144 content::NotificationService::AllSources()); | 147 content::NotificationService::AllSources()); |
145 Relaunch(new_command_line); | 148 Relaunch(new_command_line); |
146 tab_observer.Wait(); | 149 tab_observer.Wait(); |
147 | 150 |
148 // There should be one normal and one incognito window now. | 151 // There should be one normal and one incognito window now. |
149 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); | 152 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); |
150 ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(profile, host_desktop_type)); | 153 ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(profile, host_desktop_type)); |
151 } | 154 } |
152 | 155 |
153 #endif // !OS_MACOSX | 156 #endif // !OS_MACOSX |
OLD | NEW |