Chromium Code Reviews| 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/base/in_process_browser_test.h" | 5 #include "chrome/test/base/in_process_browser_test.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "chrome/browser/ui/browser_tabstrip.h" | 28 #include "chrome/browser/ui/browser_tabstrip.h" |
| 29 #include "chrome/browser/ui/browser_window.h" | 29 #include "chrome/browser/ui/browser_window.h" |
| 30 #include "chrome/browser/ui/host_desktop.h" | 30 #include "chrome/browser/ui/host_desktop.h" |
| 31 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 31 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 32 #include "chrome/common/chrome_constants.h" | 32 #include "chrome/common/chrome_constants.h" |
| 33 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
| 34 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/logging_chrome.h" | 35 #include "chrome/common/logging_chrome.h" |
| 36 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
| 37 #include "chrome/renderer/chrome_content_renderer_client.h" | 37 #include "chrome/renderer/chrome_content_renderer_client.h" |
| 38 #include "chrome/test/base/accessibility_test_helper.h" | |
| 38 #include "chrome/test/base/chrome_test_suite.h" | 39 #include "chrome/test/base/chrome_test_suite.h" |
| 39 #include "chrome/test/base/test_launcher_utils.h" | 40 #include "chrome/test/base/test_launcher_utils.h" |
| 40 #include "chrome/test/base/test_switches.h" | 41 #include "chrome/test/base/test_switches.h" |
| 41 #include "chrome/test/base/testing_browser_process.h" | 42 #include "chrome/test/base/testing_browser_process.h" |
| 42 #include "components/google/core/browser/google_util.h" | 43 #include "components/google/core/browser/google_util.h" |
| 43 #include "components/os_crypt/os_crypt.h" | 44 #include "components/os_crypt/os_crypt.h" |
| 44 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
| 45 #include "content/public/browser/notification_types.h" | 46 #include "content/public/browser/notification_types.h" |
| 46 #include "content/public/test/browser_test_utils.h" | 47 #include "content/public/test/browser_test_utils.h" |
| 47 #include "content/public/test/test_launcher.h" | 48 #include "content/public/test/test_launcher.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 CHECK(CalledOnValidThread()); | 110 CHECK(CalledOnValidThread()); |
| 110 CHECK_EQ(browser->host_desktop_type(), allowed_desktop_); | 111 CHECK_EQ(browser->host_desktop_type(), allowed_desktop_); |
| 111 } | 112 } |
| 112 | 113 |
| 113 } // namespace | 114 } // namespace |
| 114 | 115 |
| 115 InProcessBrowserTest::InProcessBrowserTest() | 116 InProcessBrowserTest::InProcessBrowserTest() |
| 116 : browser_(NULL), | 117 : browser_(NULL), |
| 117 exit_when_last_browser_closes_(true), | 118 exit_when_last_browser_closes_(true), |
| 118 open_about_blank_on_browser_launch_(true), | 119 open_about_blank_on_browser_launch_(true), |
| 119 multi_desktop_test_(false) | 120 multi_desktop_test_(false), |
| 121 run_accessibility_checks_(false) | |
| 120 #if defined(OS_MACOSX) | 122 #if defined(OS_MACOSX) |
| 121 , autorelease_pool_(NULL) | 123 , autorelease_pool_(NULL) |
| 122 #endif // OS_MACOSX | 124 #endif // OS_MACOSX |
| 123 { | 125 { |
| 124 #if defined(OS_MACOSX) | 126 #if defined(OS_MACOSX) |
| 125 // TODO(phajdan.jr): Make browser_tests self-contained on Mac, remove this. | 127 // TODO(phajdan.jr): Make browser_tests self-contained on Mac, remove this. |
| 126 // Before we run the browser, we have to hack the path to the exe to match | 128 // Before we run the browser, we have to hack the path to the exe to match |
| 127 // what it would be if Chrome was running, because it is used to fork renderer | 129 // what it would be if Chrome was running, because it is used to fork renderer |
| 128 // processes, on Linux at least (failure to do so will cause a browser_test to | 130 // processes, on Linux at least (failure to do so will cause a browser_test to |
| 129 // be run instead of a renderer). | 131 // be run instead of a renderer). |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 #endif | 255 #endif |
| 254 | 256 |
| 255 // TODO(pkotwicz): Investigate if we can remove this switch. | 257 // TODO(pkotwicz): Investigate if we can remove this switch. |
| 256 if (exit_when_last_browser_closes_) | 258 if (exit_when_last_browser_closes_) |
| 257 command_line->AppendSwitch(switches::kDisableZeroBrowsersOpenForTests); | 259 command_line->AppendSwitch(switches::kDisableZeroBrowsersOpenForTests); |
| 258 | 260 |
| 259 if (open_about_blank_on_browser_launch_ && command_line->GetArgs().empty()) | 261 if (open_about_blank_on_browser_launch_ && command_line->GetArgs().empty()) |
| 260 command_line->AppendArg(url::kAboutBlankURL); | 262 command_line->AppendArg(url::kAboutBlankURL); |
| 261 } | 263 } |
| 262 | 264 |
| 265 void InProcessBrowserTest::RunAccessibilityChecks() { | |
| 266 // A failure here means it is not possible to test for accessibility and it | |
|
Paweł Hajdan Jr.
2015/01/29 13:01:19
nit: All the comments in this method seem to just
hcarmona
2015/01/30 22:19:47
Done.
| |
| 267 // doesn't make sense to continue. | |
| 268 ASSERT_TRUE(browser()); | |
| 269 auto tab_strip = browser()->tab_strip_model(); | |
| 270 ASSERT_TRUE(tab_strip); | |
| 271 auto web_contents = tab_strip->GetActiveWebContents(); | |
| 272 ASSERT_TRUE(web_contents); | |
| 273 auto focused_frame = web_contents->GetFocusedFrame(); | |
| 274 ASSERT_TRUE(focused_frame); | |
| 275 | |
| 276 AccessibilityTestHelper helper; | |
| 277 // Failing to load libraries or failing to run the test is fatal. | |
| 278 ASSERT_TRUE(helper.LoadLibrary(web_contents)); | |
| 279 ASSERT_TRUE(helper.RunAccessibilityTest(focused_frame)); | |
| 280 | |
| 281 // Failing the test is not fatal and we should continue to report other | |
| 282 // failures. | |
| 283 EXPECT_EQ(AccessibilityTestHelper::kExpectedResults, | |
| 284 helper.accessibility_message()); | |
| 285 } | |
| 286 | |
| 263 bool InProcessBrowserTest::CreateUserDataDirectory() { | 287 bool InProcessBrowserTest::CreateUserDataDirectory() { |
| 264 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 288 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 265 base::FilePath user_data_dir = | 289 base::FilePath user_data_dir = |
| 266 command_line->GetSwitchValuePath(switches::kUserDataDir); | 290 command_line->GetSwitchValuePath(switches::kUserDataDir); |
| 267 if (user_data_dir.empty()) { | 291 if (user_data_dir.empty()) { |
| 268 if (temp_user_data_dir_.CreateUniqueTempDir() && | 292 if (temp_user_data_dir_.CreateUniqueTempDir() && |
| 269 temp_user_data_dir_.IsValid()) { | 293 temp_user_data_dir_.IsValid()) { |
| 270 user_data_dir = temp_user_data_dir_.path(); | 294 user_data_dir = temp_user_data_dir_.path(); |
| 271 } else { | 295 } else { |
| 272 LOG(ERROR) << "Could not create temporary user data directory \"" | 296 LOG(ERROR) << "Could not create temporary user data directory \"" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 content::NOTIFICATION_LOAD_STOP, | 382 content::NOTIFICATION_LOAD_STOP, |
| 359 content::NotificationService::AllSources()); | 383 content::NotificationService::AllSources()); |
| 360 chrome::AddSelectedTabWithURL(browser, | 384 chrome::AddSelectedTabWithURL(browser, |
| 361 GURL(url::kAboutBlankURL), | 385 GURL(url::kAboutBlankURL), |
| 362 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); | 386 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); |
| 363 observer.Wait(); | 387 observer.Wait(); |
| 364 | 388 |
| 365 browser->window()->Show(); | 389 browser->window()->Show(); |
| 366 } | 390 } |
| 367 | 391 |
| 392 void InProcessBrowserTest::DisableAccessibilityChecks() { | |
| 393 run_accessibility_checks_for_test_case_ = false; | |
| 394 } | |
| 395 | |
| 396 void InProcessBrowserTest::EnableAccessibilityChecks() { | |
| 397 run_accessibility_checks_for_test_case_ = true; | |
| 398 } | |
| 399 | |
| 368 #if !defined(OS_MACOSX) | 400 #if !defined(OS_MACOSX) |
| 369 base::CommandLine InProcessBrowserTest::GetCommandLineForRelaunch() { | 401 base::CommandLine InProcessBrowserTest::GetCommandLineForRelaunch() { |
| 370 base::CommandLine new_command_line( | 402 base::CommandLine new_command_line( |
| 371 base::CommandLine::ForCurrentProcess()->GetProgram()); | 403 base::CommandLine::ForCurrentProcess()->GetProgram()); |
| 372 base::CommandLine::SwitchMap switches = | 404 base::CommandLine::SwitchMap switches = |
| 373 base::CommandLine::ForCurrentProcess()->GetSwitches(); | 405 base::CommandLine::ForCurrentProcess()->GetSwitches(); |
| 374 switches.erase(switches::kUserDataDir); | 406 switches.erase(switches::kUserDataDir); |
| 375 switches.erase(content::kSingleProcessTestsFlag); | 407 switches.erase(content::kSingleProcessTestsFlag); |
| 376 switches.erase(switches::kSingleProcess); | 408 switches.erase(switches::kSingleProcess); |
| 377 new_command_line.AppendSwitch(content::kLaunchAsBrowser); | 409 new_command_line.AppendSwitch(content::kLaunchAsBrowser); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 | 464 |
| 433 // Pump any pending events that were created as a result of creating a | 465 // Pump any pending events that were created as a result of creating a |
| 434 // browser. | 466 // browser. |
| 435 content::RunAllPendingInMessageLoop(); | 467 content::RunAllPendingInMessageLoop(); |
| 436 | 468 |
| 437 SetUpOnMainThread(); | 469 SetUpOnMainThread(); |
| 438 #if defined(OS_MACOSX) | 470 #if defined(OS_MACOSX) |
| 439 autorelease_pool_->Recycle(); | 471 autorelease_pool_->Recycle(); |
| 440 #endif | 472 #endif |
| 441 | 473 |
| 474 // run_accessibility_checks_for_test_case_ must be set BEFORE calling | |
| 475 // RunTestOnMainThread because a test has the option to override the decision | |
| 476 // to run accessibility tests in the test body. | |
| 477 run_accessibility_checks_for_test_case_ = run_accessibility_checks_; | |
| 478 | |
| 442 if (!HasFatalFailure()) | 479 if (!HasFatalFailure()) |
| 443 RunTestOnMainThread(); | 480 RunTestOnMainThread(); |
| 444 #if defined(OS_MACOSX) | 481 #if defined(OS_MACOSX) |
| 445 autorelease_pool_->Recycle(); | 482 autorelease_pool_->Recycle(); |
| 446 #endif | 483 #endif |
| 447 | 484 |
| 485 // This will be true if | |
| 486 // - The current test called EnableAccessibilityChecks | |
| 487 // - The current test did NOT call DisableAccessibilityChecks and | |
| 488 // run_accessibility_checks_ is true. | |
| 489 if (run_accessibility_checks_for_test_case_) | |
| 490 RunAccessibilityChecks(); | |
| 491 | |
| 448 // Invoke cleanup and quit even if there are failures. This is similar to | 492 // Invoke cleanup and quit even if there are failures. This is similar to |
| 449 // gtest in that it invokes TearDown even if Setup fails. | 493 // gtest in that it invokes TearDown even if Setup fails. |
| 450 TearDownOnMainThread(); | 494 TearDownOnMainThread(); |
| 451 #if defined(OS_MACOSX) | 495 #if defined(OS_MACOSX) |
| 452 autorelease_pool_->Recycle(); | 496 autorelease_pool_->Recycle(); |
| 453 #endif | 497 #endif |
| 454 | 498 |
| 455 // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's | 499 // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's |
| 456 // run all pending messages here to avoid preempting the QuitBrowsers tasks. | 500 // run all pending messages here to avoid preempting the QuitBrowsers tasks. |
| 457 // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it | 501 // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 488 // On the Mac, this eventually reaches | 532 // On the Mac, this eventually reaches |
| 489 // -[BrowserWindowController windowWillClose:], which will post a deferred | 533 // -[BrowserWindowController windowWillClose:], which will post a deferred |
| 490 // -autorelease on itself to ultimately destroy the Browser object. The line | 534 // -autorelease on itself to ultimately destroy the Browser object. The line |
| 491 // below is necessary to pump these pending messages to ensure all Browsers | 535 // below is necessary to pump these pending messages to ensure all Browsers |
| 492 // get deleted. | 536 // get deleted. |
| 493 content::RunAllPendingInMessageLoop(); | 537 content::RunAllPendingInMessageLoop(); |
| 494 delete autorelease_pool_; | 538 delete autorelease_pool_; |
| 495 autorelease_pool_ = NULL; | 539 autorelease_pool_ = NULL; |
| 496 #endif | 540 #endif |
| 497 } | 541 } |
| OLD | NEW |