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 "chrome/test/ui/ui_test.h" | 5 #include "chrome/test/ui/ui_test.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" |
12 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
13 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
19 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
20 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
(...skipping 10 matching lines...) Expand all Loading... |
32 void Relaunch(const CommandLine& new_command_line) { | 33 void Relaunch(const CommandLine& new_command_line) { |
33 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); | 34 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); |
34 } | 35 } |
35 }; | 36 }; |
36 | 37 |
37 // Make sure that the second invocation creates a new window. | 38 // Make sure that the second invocation creates a new window. |
38 IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunch) { | 39 IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunch) { |
39 ui_test_utils::BrowserAddedObserver observer; | 40 ui_test_utils::BrowserAddedObserver observer; |
40 Relaunch(GetCommandLineForRelaunch()); | 41 Relaunch(GetCommandLineForRelaunch()); |
41 observer.WaitForSingleNewBrowser(); | 42 observer.WaitForSingleNewBrowser(); |
42 ASSERT_EQ(BrowserList::GetBrowserCount(browser()->profile()), 2u); | 43 ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile())); |
43 } | 44 } |
44 | 45 |
45 IN_PROC_BROWSER_TEST_F(ChromeMainTest, ReuseBrowserInstanceWhenOpeningFile) { | 46 IN_PROC_BROWSER_TEST_F(ChromeMainTest, ReuseBrowserInstanceWhenOpeningFile) { |
46 FilePath test_file_path = ui_test_utils::GetTestFilePath( | 47 FilePath test_file_path = ui_test_utils::GetTestFilePath( |
47 FilePath(), FilePath().AppendASCII("empty.html")); | 48 FilePath(), FilePath().AppendASCII("empty.html")); |
48 CommandLine new_command_line(GetCommandLineForRelaunch()); | 49 CommandLine new_command_line(GetCommandLineForRelaunch()); |
49 new_command_line.AppendArgPath(test_file_path); | 50 new_command_line.AppendArgPath(test_file_path); |
50 ui_test_utils::WindowedNotificationObserver observer( | 51 ui_test_utils::WindowedNotificationObserver observer( |
51 chrome::NOTIFICATION_TAB_ADDED, | 52 chrome::NOTIFICATION_TAB_ADDED, |
52 content::NotificationService::AllSources()); | 53 content::NotificationService::AllSources()); |
53 Relaunch(new_command_line); | 54 Relaunch(new_command_line); |
54 observer.Wait(); | 55 observer.Wait(); |
55 | 56 |
56 GURL url = net::FilePathToFileURL(test_file_path); | 57 GURL url = net::FilePathToFileURL(test_file_path); |
57 content::WebContents* tab = browser()->GetSelectedWebContents(); | 58 content::WebContents* tab = browser()->GetSelectedWebContents(); |
58 ASSERT_EQ(url, tab->GetController().GetActiveEntry()->GetVirtualURL()); | 59 ASSERT_EQ(url, tab->GetController().GetActiveEntry()->GetVirtualURL()); |
59 } | 60 } |
60 | 61 |
61 | 62 |
62 IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunchWithIncognitoUrl) { | 63 IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunchWithIncognitoUrl) { |
63 // We should start with one normal window. | 64 // We should start with one normal window. |
64 ASSERT_EQ(1u, | 65 ASSERT_EQ(1u, browser::GetTabbedBrowserCount(browser()->profile())); |
65 BrowserList::GetBrowserCountForType(browser()->profile(), true)); | |
66 | 66 |
67 // Run with --incognito switch and an URL specified. | 67 // Run with --incognito switch and an URL specified. |
68 FilePath test_file_path = ui_test_utils::GetTestFilePath( | 68 FilePath test_file_path = ui_test_utils::GetTestFilePath( |
69 FilePath(), FilePath().AppendASCII("empty.html")); | 69 FilePath(), FilePath().AppendASCII("empty.html")); |
70 CommandLine new_command_line(GetCommandLineForRelaunch()); | 70 CommandLine new_command_line(GetCommandLineForRelaunch()); |
71 new_command_line.AppendSwitch(switches::kIncognito); | 71 new_command_line.AppendSwitch(switches::kIncognito); |
72 new_command_line.AppendArgPath(test_file_path); | 72 new_command_line.AppendArgPath(test_file_path); |
73 | 73 |
74 Relaunch(new_command_line); | 74 Relaunch(new_command_line); |
75 | 75 |
76 // There should be one normal and one incognito window now. | 76 // There should be one normal and one incognito window now. |
77 ui_test_utils::BrowserAddedObserver observer; | 77 ui_test_utils::BrowserAddedObserver observer; |
78 Relaunch(new_command_line); | 78 Relaunch(new_command_line); |
79 observer.WaitForSingleNewBrowser(); | 79 observer.WaitForSingleNewBrowser(); |
80 ASSERT_EQ(2u, BrowserList::size()); | 80 ASSERT_EQ(2u, BrowserList::size()); |
81 | 81 |
82 ASSERT_EQ(1u, | 82 ASSERT_EQ(1u, browser::GetTabbedBrowserCount(browser()->profile())); |
83 BrowserList::GetBrowserCountForType(browser()->profile(), true)); | |
84 } | 83 } |
85 | 84 |
86 IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunchFromIncognitoWithNormalUrl) { | 85 IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunchFromIncognitoWithNormalUrl) { |
87 // We should start with one normal window. | 86 // We should start with one normal window. |
88 ASSERT_EQ(1u, | 87 ASSERT_EQ(1u, browser::GetTabbedBrowserCount(browser()->profile())); |
89 BrowserList::GetBrowserCountForType(browser()->profile(), true)); | |
90 | 88 |
91 // Create an incognito window. | 89 // Create an incognito window. |
92 browser()->NewIncognitoWindow(); | 90 browser()->NewIncognitoWindow(); |
93 | 91 |
94 ASSERT_EQ(2u, BrowserList::size()); | 92 ASSERT_EQ(2u, BrowserList::size()); |
95 ASSERT_EQ(1u, | 93 ASSERT_EQ(1u, browser::GetTabbedBrowserCount(browser()->profile())); |
96 BrowserList::GetBrowserCountForType(browser()->profile(), true)); | |
97 | 94 |
98 // Close the first window. | 95 // Close the first window. |
99 Profile* profile = browser()->profile(); | 96 Profile* profile = browser()->profile(); |
100 ui_test_utils::WindowedNotificationObserver observer( | 97 ui_test_utils::WindowedNotificationObserver observer( |
101 chrome::NOTIFICATION_BROWSER_CLOSED, | 98 chrome::NOTIFICATION_BROWSER_CLOSED, |
102 content::NotificationService::AllSources()); | 99 content::NotificationService::AllSources()); |
103 browser()->CloseWindow(); | 100 browser()->CloseWindow(); |
104 observer.Wait(); | 101 observer.Wait(); |
105 | 102 |
106 // There should only be the incognito window open now. | 103 // There should only be the incognito window open now. |
107 ASSERT_EQ(1u, BrowserList::size()); | 104 ASSERT_EQ(1u, BrowserList::size()); |
108 ASSERT_EQ(0u, BrowserList::GetBrowserCountForType(profile, true)); | 105 ASSERT_EQ(0u, browser::GetTabbedBrowserCount(profile)); |
109 | 106 |
110 // Run with just an URL specified, no --incognito switch. | 107 // Run with just an URL specified, no --incognito switch. |
111 FilePath test_file_path = ui_test_utils::GetTestFilePath( | 108 FilePath test_file_path = ui_test_utils::GetTestFilePath( |
112 FilePath(), FilePath().AppendASCII("empty.html")); | 109 FilePath(), FilePath().AppendASCII("empty.html")); |
113 CommandLine new_command_line(GetCommandLineForRelaunch()); | 110 CommandLine new_command_line(GetCommandLineForRelaunch()); |
114 new_command_line.AppendArgPath(test_file_path); | 111 new_command_line.AppendArgPath(test_file_path); |
115 ui_test_utils::WindowedNotificationObserver tab_observer( | 112 ui_test_utils::WindowedNotificationObserver tab_observer( |
116 chrome::NOTIFICATION_TAB_ADDED, | 113 chrome::NOTIFICATION_TAB_ADDED, |
117 content::NotificationService::AllSources()); | 114 content::NotificationService::AllSources()); |
118 Relaunch(new_command_line); | 115 Relaunch(new_command_line); |
119 tab_observer.Wait(); | 116 tab_observer.Wait(); |
120 | 117 |
121 // There should be one normal and one incognito window now. | 118 // There should be one normal and one incognito window now. |
122 ASSERT_EQ(2u, BrowserList::size()); | 119 ASSERT_EQ(2u, BrowserList::size()); |
123 ASSERT_EQ(1u, BrowserList::GetBrowserCountForType(profile, true)); | 120 ASSERT_EQ(1u, browser::GetTabbedBrowserCount(profile)); |
124 } | 121 } |
125 | 122 |
126 #endif // !OS_MACOSX | 123 #endif // !OS_MACOSX |
OLD | NEW |