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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 browser_list_.erase(iter); | 62 browser_list_.erase(iter); |
63 return true; | 63 return true; |
64 } | 64 } |
65 } | 65 } |
66 return false; | 66 return false; |
67 } | 67 } |
68 | 68 |
69 Browser::CreateParams CreateParamsForApp(const std::string name, | 69 Browser::CreateParams CreateParamsForApp(const std::string name, |
70 bool trusted) { | 70 bool trusted) { |
71 return Browser::CreateParams::CreateForApp(name, trusted, gfx::Rect(), | 71 return Browser::CreateParams::CreateForApp(name, trusted, gfx::Rect(), |
72 profile()); | 72 profile(), true); |
73 } | 73 } |
74 | 74 |
75 // Turn on session restore before we restart. | 75 // Turn on session restore before we restart. |
76 void TurnOnSessionRestore() { | 76 void TurnOnSessionRestore() { |
77 SessionStartupPref::SetStartupPref( | 77 SessionStartupPref::SetStartupPref( |
78 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); | 78 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); |
79 } | 79 } |
80 | 80 |
81 Profile* profile() { return browser()->profile(); } | 81 Profile* profile() { return browser()->profile(); } |
82 | 82 |
83 std::list<Browser*> browser_list_; | 83 std::list<Browser*> browser_list_; |
84 }; | 84 }; |
85 | 85 |
86 // Thse tests are in pairs. The PRE_ test creates some browser windows and | 86 // Thse tests are in pairs. The PRE_ test creates some browser windows and |
87 // the following test confirms that the correct windows are restored after a | 87 // the following test confirms that the correct windows are restored after a |
88 // restart. | 88 // restart. |
89 | 89 |
90 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreBrowserWindows) { | 90 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreBrowserWindows) { |
91 // One browser window is always created by default. | 91 // One browser window is always created by default. |
92 EXPECT_TRUE(browser()); | 92 EXPECT_TRUE(browser()); |
93 // Create a second normal browser window. | 93 // Create a second normal browser window. |
94 CreateBrowserWithParams(Browser::CreateParams(profile())); | 94 CreateBrowserWithParams(Browser::CreateParams(profile(), true)); |
95 // Create a third incognito browser window which should not get restored. | 95 // Create a third incognito browser window which should not get restored. |
96 CreateBrowserWithParams( | 96 CreateBrowserWithParams( |
97 Browser::CreateParams(profile()->GetOffTheRecordProfile())); | 97 Browser::CreateParams(profile()->GetOffTheRecordProfile(), true)); |
98 TurnOnSessionRestore(); | 98 TurnOnSessionRestore(); |
99 } | 99 } |
100 | 100 |
101 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreBrowserWindows) { | 101 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreBrowserWindows) { |
102 size_t total_count = 0; | 102 size_t total_count = 0; |
103 size_t incognito_count = 0; | 103 size_t incognito_count = 0; |
104 for (auto* browser : *BrowserList::GetInstance()) { | 104 for (auto* browser : *BrowserList::GetInstance()) { |
105 ++total_count; | 105 ++total_count; |
106 if (browser->profile()->IsOffTheRecord()) | 106 if (browser->profile()->IsOffTheRecord()) |
107 ++incognito_count; | 107 ++incognito_count; |
(...skipping 27 matching lines...) Expand all Loading... |
135 } | 135 } |
136 EXPECT_EQ(1u, app1_count); | 136 EXPECT_EQ(1u, app1_count); |
137 EXPECT_EQ(2u, app2_count); // Only the trusted app windows are restored. | 137 EXPECT_EQ(2u, app2_count); // Only the trusted app windows are restored. |
138 EXPECT_EQ(4u, total_count); // Default browser() + 3 app windows | 138 EXPECT_EQ(4u, total_count); // Default browser() + 3 app windows |
139 } | 139 } |
140 | 140 |
141 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreMaximized) { | 141 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreMaximized) { |
142 // One browser window is always created by default. | 142 // One browser window is always created by default. |
143 ASSERT_TRUE(browser()); | 143 ASSERT_TRUE(browser()); |
144 // Create a second browser window and maximize it. | 144 // Create a second browser window and maximize it. |
145 Browser* browser2 = CreateBrowserWithParams(Browser::CreateParams(profile())); | 145 Browser* browser2 = |
| 146 CreateBrowserWithParams(Browser::CreateParams(profile(), true)); |
146 browser2->window()->Maximize(); | 147 browser2->window()->Maximize(); |
147 | 148 |
148 // Create two app popup windows and maximize the second one. | 149 // Create two app popup windows and maximize the second one. |
149 Browser* app_browser1 = | 150 Browser* app_browser1 = |
150 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true)); | 151 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true)); |
151 Browser* app_browser2 = | 152 Browser* app_browser2 = |
152 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true)); | 153 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true)); |
153 app_browser2->window()->Maximize(); | 154 app_browser2->window()->Maximize(); |
154 | 155 |
155 EXPECT_FALSE(browser()->window()->IsMaximized()); | 156 EXPECT_FALSE(browser()->window()->IsMaximized()); |
(...skipping 15 matching lines...) Expand all Loading... |
171 EXPECT_EQ(4u, total_count); | 172 EXPECT_EQ(4u, total_count); |
172 EXPECT_EQ(2u, maximized_count); | 173 EXPECT_EQ(2u, maximized_count); |
173 } | 174 } |
174 | 175 |
175 // Test for crash when restoring minimized windows. http://crbug.com/679513. | 176 // Test for crash when restoring minimized windows. http://crbug.com/679513. |
176 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreMinimized) { | 177 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreMinimized) { |
177 // One browser window is always created by default. | 178 // One browser window is always created by default. |
178 ASSERT_TRUE(browser()); | 179 ASSERT_TRUE(browser()); |
179 browser()->window()->Minimize(); | 180 browser()->window()->Minimize(); |
180 | 181 |
181 Browser* browser2 = CreateBrowserWithParams(Browser::CreateParams(profile())); | 182 Browser* browser2 = |
| 183 CreateBrowserWithParams(Browser::CreateParams(profile(), true)); |
182 browser2->window()->Minimize(); | 184 browser2->window()->Minimize(); |
183 | 185 |
184 EXPECT_TRUE(browser()->window()->IsMinimized()); | 186 EXPECT_TRUE(browser()->window()->IsMinimized()); |
185 EXPECT_TRUE(browser2->window()->IsMinimized()); | 187 EXPECT_TRUE(browser2->window()->IsMinimized()); |
186 | 188 |
187 TurnOnSessionRestore(); | 189 TurnOnSessionRestore(); |
188 } | 190 } |
189 | 191 |
190 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreMinimized) { | 192 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreMinimized) { |
191 size_t total_count = 0; | 193 size_t total_count = 0; |
192 size_t minimized_count = 0; | 194 size_t minimized_count = 0; |
193 for (auto* browser : *BrowserList::GetInstance()) { | 195 for (auto* browser : *BrowserList::GetInstance()) { |
194 ++total_count; | 196 ++total_count; |
195 if (browser->window()->IsMinimized()) | 197 if (browser->window()->IsMinimized()) |
196 ++minimized_count; | 198 ++minimized_count; |
197 } | 199 } |
198 EXPECT_EQ(2u, total_count); | 200 EXPECT_EQ(2u, total_count); |
199 // Chrome OS always activates the last browser window on login, which results | 201 // Chrome OS always activates the last browser window on login, which results |
200 // in one window being restored. This seems reasonable as it reminds users | 202 // in one window being restored. This seems reasonable as it reminds users |
201 // they have a browser running instead of just showing them an empty desktop. | 203 // they have a browser running instead of just showing them an empty desktop. |
202 EXPECT_EQ(1u, minimized_count); | 204 EXPECT_EQ(1u, minimized_count); |
203 } | 205 } |
OLD | NEW |