Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/chromium/windowclient-focus.html |
| diff --git a/LayoutTests/http/tests/serviceworker/chromium/windowclient-focus.html b/LayoutTests/http/tests/serviceworker/chromium/windowclient-focus.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0399ab7031579f2e575132ff8b3e7fc42757a6c5 |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/chromium/windowclient-focus.html |
| @@ -0,0 +1,90 @@ |
| +<!DOCTYPE html> |
| +<title>Service Worker: WindowClient.focus() tests (using testRunner)</title> |
| +<script src="../../resources/testharness.js"></script> |
| +<script src="../../resources/testharnessreport.js"></script> |
| +<script src="../resources/test-helpers.js"></script> |
| +<script> |
| +// This test is using testRunner to grant itself the notification permission and |
| +// to simulate a click on a notification. A couple of changes would allow it to |
| +// be run as a manual test by other browser vendors. |
| +if (window.testRunner) |
| + testRunner.grantWebNotificationPermission(location.origin, true); |
| + |
| +var t = async_test('WindowClient.focus() behaved as expected'); |
| +t.step(function() { |
| + var scope = 'resources/windowclient-focus.html' |
| + service_worker_unregister_and_register( |
| + t, 'resources/windowclient-focus.js', scope) |
| + .then(function(registration) { |
| + return wait_for_state(t, registration.installing, 'activated'); |
| + }) |
| + .then(function() { return with_iframe(scope); }) |
| + .then(function(frame) { |
| + var w = frame.contentWindow; |
| + w.onmessage = t.step_func(onMessage); |
| + w.navigator.serviceWorker.controller.postMessage('start'); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + |
| + var result = []; |
| + var expected = ['focus() can\'t focus a window without a user interaction', |
| + 'focus() error is InvalidAccessError', |
| + 'focus() succeeded', |
| + 'focus() result: [object WindowClient]', |
| + ' url: ' + location.origin + '/serviceworker/chromium/resources/windowclient-focus.html', |
|
Michael van Ouwerkerk
2015/02/18 10:55:47
No need to indent this much, this line is over 100
mlamouri (slow - plz ping)
2015/02/18 11:34:56
Done.
|
| + ' visibilityState: visible', |
| + ' focused: true', |
| + ' frameType: nested', |
| + 'focused clients: 1', |
| + 'focus() succeeded', |
| + 'focus() result: [object WindowClient]', |
| + ' url: ' + location.origin + '/serviceworker/chromium/resources/windowclient-focus.html?1', |
| + ' visibilityState: visible', |
| + ' focused: true', |
| + ' frameType: nested', |
| + 'focused clients: 2', |
| + 'focus() succeeded', |
| + 'focus() result: [object WindowClient]', |
| + ' url: ' + location.origin + '/serviceworker/chromium/resources/windowclient-focus.html?2', |
| + ' visibilityState: visible', |
| + ' focused: true', |
| + ' frameType: nested', |
| + 'focused clients: 2', |
| + 'focus() succeeded', |
| + 'focus() result: [object WindowClient]', |
| + ' url: ' + location.origin + '/serviceworker/chromium/resources/windowclient-focus.html?3', |
| + ' visibilityState: visible', |
| + ' focused: true', |
| + ' frameType: top-level', |
| + 'focused clients: 1', |
| + ]; |
| + |
| + // On Mac, focusing and LayoutTests are no friend. This is amending the |
| + // above |expected| array to match Mac's expectations. |
| + var isMac = navigator.platform.indexOf('Mac') == 0; |
| + if (isMac) { |
| + expected[27] = ' focused: false'; |
| + expected[29] = 'focused clients: 3'; |
| + } |
| + |
| + function onMessage(e) { |
| + var message = e.data; |
| + |
| + if (typeof(message) === 'object') { |
| + if (message.type !== 'click') |
| + return; |
| + if (window.testRunner) |
| + testRunner.simulateWebNotificationClick(message.title); |
| + return; |
| + } |
| + |
| + if (message === 'quit') { |
| + assert_array_equals(result, expected, |
| + 'Worker should post back expected messages.'); |
| + service_worker_unregister_and_done(t, scope); |
| + } else { |
| + result.push(message); |
| + } |
| + } |
| + }); |
| +</script> |