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 <ApplicationServices/ApplicationServices.h> | 5 #include <ApplicationServices/ApplicationServices.h> |
6 #import <Cocoa/Cocoa.h> | 6 #import <Cocoa/Cocoa.h> |
7 #import <objc/objc-runtime.h> | 7 #import <objc/objc-runtime.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 | 9 |
10 #include "webkit/tools/test_shell/test_shell.h" | 10 #include "webkit/tools/test_shell/test_shell.h" |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 350 |
351 if (IsSVGTestURL(starting_url)) { | 351 if (IsSVGTestURL(starting_url)) { |
352 SizeTo(kSVGTestWindowWidth, kSVGTestWindowHeight); | 352 SizeTo(kSVGTestWindowWidth, kSVGTestWindowHeight); |
353 } else { | 353 } else { |
354 SizeToDefault(); | 354 SizeToDefault(); |
355 } | 355 } |
356 | 356 |
357 return true; | 357 return true; |
358 } | 358 } |
359 | 359 |
360 void TestShell::TestFinished() { | |
361 if (!test_is_pending_) | |
362 return; // reached when running under test_shell_tests | |
363 | |
364 test_is_pending_ = false; | |
365 MessageLoop::current()->Quit(); | |
366 } | |
367 | |
368 // A class to be the target/selector of the "watchdog" thread that ensures | |
369 // pages timeout if they take too long and tells the test harness via stdout. | |
370 @interface WatchDogTarget : NSObject { | |
371 @private | |
372 NSTimeInterval timeout_; | |
373 } | |
374 // |timeout| is in seconds | |
375 - (id)initWithTimeout:(NSTimeInterval)timeout; | |
376 // serves as the "run" method of a NSThread. | |
377 - (void)run:(id)sender; | |
378 @end | |
379 | |
380 @implementation WatchDogTarget | |
381 | |
382 - (id)initWithTimeout:(NSTimeInterval)timeout { | |
383 if ((self = [super init])) { | |
384 timeout_ = timeout; | |
385 } | |
386 return self; | |
387 } | |
388 | |
389 - (void)run:(id)ignore { | |
390 base::mac::ScopedNSAutoreleasePool scoped_pool; | |
391 | |
392 // Check for debugger, just bail if so. We don't want the timeouts hitting | |
393 // when we're trying to track down an issue. | |
394 if (base::debug::BeingDebugged()) | |
395 return; | |
396 | |
397 NSThread* currentThread = [NSThread currentThread]; | |
398 | |
399 // Wait to be cancelled. If we are that means the test finished. If it hasn't, | |
400 // then we need to tell the layout script we timed out and start again. | |
401 NSDate* limitDate = [NSDate dateWithTimeIntervalSinceNow:timeout_]; | |
402 while ([(NSDate*)[NSDate date] compare:limitDate] == NSOrderedAscending && | |
403 ![currentThread isCancelled]) { | |
404 // sleep for a small increment then check again | |
405 NSDate* incrementDate = [NSDate dateWithTimeIntervalSinceNow:1.0]; | |
406 [NSThread sleepUntilDate:incrementDate]; | |
407 } | |
408 if (![currentThread isCancelled]) { | |
409 // Print a warning to be caught by the layout-test script. | |
410 // Note: the layout test driver may or may not recognize | |
411 // this as a timeout. | |
412 puts("#TEST_TIMED_OUT\n"); | |
413 puts("#EOF\n"); | |
414 fflush(stdout); | |
415 abort(); | |
416 } | |
417 } | |
418 | |
419 @end | |
420 | |
421 void TestShell::WaitTestFinished() { | |
422 DCHECK(!test_is_pending_) << "cannot be used recursively"; | |
423 | |
424 test_is_pending_ = true; | |
425 | |
426 // Create a watchdog thread which just sets a timer and | |
427 // kills the process if it times out. This catches really | |
428 // bad hangs where the shell isn't coming back to the | |
429 // message loop. If the watchdog is what catches a | |
430 // timeout, it can't do anything except terminate the test | |
431 // shell, which is unfortunate. | |
432 // Windows multiplies by 2.5, but that causes us to run for far, far too | |
433 // long. We use the passed value and let the scripts flag override | |
434 // the value as needed. | |
435 NSTimeInterval timeout_seconds = GetLayoutTestTimeoutForWatchDog() / 1000; | |
436 WatchDogTarget* watchdog = [[[WatchDogTarget alloc] | |
437 initWithTimeout:timeout_seconds] autorelease]; | |
438 NSThread* thread = [[NSThread alloc] initWithTarget:watchdog | |
439 selector:@selector(run:) | |
440 object:nil]; | |
441 [thread start]; | |
442 | |
443 // TestFinished() will post a quit message to break this loop when the page | |
444 // finishes loading. | |
445 while (test_is_pending_) | |
446 MessageLoop::current()->Run(); | |
447 | |
448 // Tell the watchdog that we're finished. No point waiting to re-join, it'll | |
449 // die on its own. | |
450 [thread cancel]; | |
451 [thread release]; | |
452 } | |
453 | |
454 void TestShell::InteractiveSetFocus(WebWidgetHost* host, bool enable) { | 360 void TestShell::InteractiveSetFocus(WebWidgetHost* host, bool enable) { |
455 if (enable) { | 361 if (enable) { |
456 [[host->view_handle() window] makeKeyAndOrderFront:nil]; | 362 [[host->view_handle() window] makeKeyAndOrderFront:nil]; |
457 } else { | 363 } else { |
458 // There is no way to resign key window status in Cocoa. Fake it by | 364 // There is no way to resign key window status in Cocoa. Fake it by |
459 // ordering the window out (transferring key status to another window) and | 365 // ordering the window out (transferring key status to another window) and |
460 // then ordering the window back in, but without making it key. | 366 // then ordering the window back in, but without making it key. |
461 [[host->view_handle() window] orderOut:nil]; | 367 [[host->view_handle() window] orderOut:nil]; |
462 [[host->view_handle() window] orderFront:nil]; | 368 [[host->view_handle() window] orderFront:nil]; |
463 } | 369 } |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 return false; | 583 return false; |
678 } | 584 } |
679 | 585 |
680 void DidLoadPlugin(const std::string& filename) { | 586 void DidLoadPlugin(const std::string& filename) { |
681 } | 587 } |
682 | 588 |
683 void DidUnloadPlugin(const std::string& filename) { | 589 void DidUnloadPlugin(const std::string& filename) { |
684 } | 590 } |
685 | 591 |
686 } // namespace webkit_glue | 592 } // namespace webkit_glue |
OLD | NEW |