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/logging.h" | 6 #include "base/logging.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 | 248 |
249 DownloadTestFileActivityObserver(first_profile_) .EnableFileChooser(false); | 249 DownloadTestFileActivityObserver(first_profile_) .EnableFileChooser(false); |
250 DownloadTestFileActivityObserver(second_profile_).EnableFileChooser(false); | 250 DownloadTestFileActivityObserver(second_profile_).EnableFileChooser(false); |
251 return true; | 251 return true; |
252 } | 252 } |
253 | 253 |
254 // Test a specific DownloadsCloseCheckCase. Returns false if | 254 // Test a specific DownloadsCloseCheckCase. Returns false if |
255 // an assertion has failed and the test should be aborted. | 255 // an assertion has failed and the test should be aborted. |
256 bool ExecuteDownloadCloseCheckCase(size_t i) { | 256 bool ExecuteDownloadCloseCheckCase(size_t i) { |
257 const DownloadsCloseCheckCase& check_case(download_close_check_cases[i]); | 257 const DownloadsCloseCheckCase& check_case(download_close_check_cases[i]); |
258 SCOPED_TRACE(testing::Message() << "Case" << i | |
259 << ": " << check_case.DebugString()); | |
Peter Kasting
2013/10/15 19:10:28
Nit: <<s should line up; try
SCOPED_TRACE(tes
felt
2013/10/18 01:50:53
Done.
| |
258 | 260 |
259 // Test invariant: so that we don't actually try and close the browser, | 261 // Test invariant: so that we don't actually try and close the browser, |
260 // we always enter the function with a single browser window open on the | 262 // we always enter the function with a single browser window open on the |
261 // main profile. That means we need to exit the function the same way. | 263 // main profile. That means we need to exit the function the same way. |
262 // So we setup everything except for the |first_profile_| regular, and then | 264 // So we setup everything except for the |first_profile_| regular, and then |
263 // flip the bit on the main window. | 265 // flip the bit on the main window. |
264 // Note that this means that browser() is unreliable in the context | 266 // Note that this means that browser() is unreliable in the context |
265 // of this function or its callers; we'll be killing that main window | 267 // of this function or its callers; we'll be killing that main window |
266 // and recreating it fairly frequently. | 268 // and recreating it fairly frequently. |
267 int unclosed_browsers = TotalUnclosedBrowsers(); | 269 int unclosed_browsers = TotalUnclosedBrowsers(); |
268 EXPECT_EQ(1, unclosed_browsers); | 270 EXPECT_EQ(1, unclosed_browsers); |
269 if (1 != unclosed_browsers) | 271 if (1 != unclosed_browsers) |
270 return false; | 272 return false; |
271 | 273 |
272 Browser* entry_browser = FirstUnclosedBrowser(); | 274 Browser* entry_browser = FirstUnclosedBrowser(); |
273 EXPECT_EQ(first_profile_, entry_browser->profile()) | 275 EXPECT_EQ(first_profile_, entry_browser->profile()); |
274 << "Case" << i | |
275 << ": " << check_case.DebugString(); | |
276 if (first_profile_ != entry_browser->profile()) | 276 if (first_profile_ != entry_browser->profile()) |
277 return false; | 277 return false; |
Peter Kasting
2013/10/15 19:10:28
Don't EXPECT_EQ and then handle failure; if you tr
felt
2013/10/18 01:50:53
This isn't my test -- I am just tweaking someone e
| |
278 int total_download_count = DownloadService::DownloadCountAllProfiles(); | 278 int total_download_count = |
279 EXPECT_EQ(0, total_download_count) | 279 DownloadService::NonDangerousDownloadCountAllProfiles(); |
280 << "Case " << i | 280 EXPECT_EQ(0, total_download_count); |
281 << ": " << check_case.DebugString(); | |
282 if (0 != total_download_count) | 281 if (0 != total_download_count) |
283 return false; | 282 return false; |
284 | |
285 Profile* first_profile_incognito = first_profile_->GetOffTheRecordProfile(); | 283 Profile* first_profile_incognito = first_profile_->GetOffTheRecordProfile(); |
286 Profile* second_profile_incognito = | 284 Profile* second_profile_incognito = |
287 second_profile_->GetOffTheRecordProfile(); | 285 second_profile_->GetOffTheRecordProfile(); |
288 DownloadTestFileActivityObserver(first_profile_incognito) | 286 DownloadTestFileActivityObserver(first_profile_incognito) |
289 .EnableFileChooser(false); | 287 .EnableFileChooser(false); |
290 DownloadTestFileActivityObserver(second_profile_incognito) | 288 DownloadTestFileActivityObserver(second_profile_incognito) |
291 .EnableFileChooser(false); | 289 .EnableFileChooser(false); |
292 | 290 |
293 // For simplicty of coding, we create a window on each profile so that | 291 // For simplicty of coding, we create a window on each profile so that |
294 // we can easily create downloads, then we destroy or create windows | 292 // we can easily create downloads, then we destroy or create windows |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 return false; | 347 return false; |
350 | 348 |
351 int num_downloads_blocking; | 349 int num_downloads_blocking; |
352 Browser* browser_to_probe = | 350 Browser* browser_to_probe = |
353 (check_case.window_to_probe == DownloadsCloseCheckCase::REGULAR ? | 351 (check_case.window_to_probe == DownloadsCloseCheckCase::REGULAR ? |
354 browser_a_regular : | 352 browser_a_regular : |
355 browser_a_incognito); | 353 browser_a_incognito); |
356 Browser::DownloadClosePreventionType type = | 354 Browser::DownloadClosePreventionType type = |
357 browser_to_probe->OkToCloseWithInProgressDownloads( | 355 browser_to_probe->OkToCloseWithInProgressDownloads( |
358 &num_downloads_blocking); | 356 &num_downloads_blocking); |
359 EXPECT_EQ(check_case.type, type) << "Case " << i | 357 EXPECT_EQ(check_case.type, type); |
360 << ": " << check_case.DebugString(); | |
361 if (type != Browser::DOWNLOAD_CLOSE_OK) | 358 if (type != Browser::DOWNLOAD_CLOSE_OK) |
362 EXPECT_EQ(check_case.num_blocking, num_downloads_blocking) | 359 EXPECT_EQ(check_case.num_blocking, num_downloads_blocking); |
363 << "Case " << i | |
364 << ": " << check_case.DebugString(); | |
365 | 360 |
366 // Release all the downloads. | 361 // Release all the downloads. |
367 CompleteAllDownloads(browser_to_probe); | 362 CompleteAllDownloads(browser_to_probe); |
368 | 363 |
369 // Create a new main window and kill everything else. | 364 // Create a new main window and kill everything else. |
370 entry_browser = CreateBrowserOnProfile(first_profile_, host_desktop_type); | 365 entry_browser = CreateBrowserOnProfile(first_profile_, host_desktop_type); |
371 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 366 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
372 if ((*it) != entry_browser) { | 367 if ((*it) != entry_browser) { |
373 if (!it->window()) { | 368 if (!it->window()) { |
374 ADD_FAILURE(); | 369 ADD_FAILURE(); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 } | 560 } |
566 } | 561 } |
567 | 562 |
568 IN_PROC_BROWSER_TEST_F(BrowserCloseTest, MAYBE_DownloadsCloseCheck_5) { | 563 IN_PROC_BROWSER_TEST_F(BrowserCloseTest, MAYBE_DownloadsCloseCheck_5) { |
569 ASSERT_TRUE(SetupForDownloadCloseCheck()); | 564 ASSERT_TRUE(SetupForDownloadCloseCheck()); |
570 for (size_t i = 5 * arraysize(download_close_check_cases) / 6; | 565 for (size_t i = 5 * arraysize(download_close_check_cases) / 6; |
571 i < 6 * arraysize(download_close_check_cases) / 6; ++i) { | 566 i < 6 * arraysize(download_close_check_cases) / 6; ++i) { |
572 ExecuteDownloadCloseCheckCase(i); | 567 ExecuteDownloadCloseCheckCase(i); |
573 } | 568 } |
574 } | 569 } |
OLD | NEW |