diff options
Diffstat (limited to 'chrome/test')
3 files changed, 155 insertions, 0 deletions
diff --git a/chrome/test/data/extensions/platform_apps/window_api_interactive/manifest.json b/chrome/test/data/extensions/platform_apps/window_api_interactive/manifest.json new file mode 100644 index 0000000..327c7dc --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/window_api_interactive/manifest.json @@ -0,0 +1,9 @@ +{ + "name": "Platform App Test: Window API Interative", + "version": "1", + "app": { + "background": { + "scripts": ["test.js"] + } + } +} diff --git a/chrome/test/data/extensions/platform_apps/window_api_interactive/test.html b/chrome/test/data/extensions/platform_apps/window_api_interactive/test.html new file mode 100644 index 0000000..42fa1f8 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/window_api_interactive/test.html @@ -0,0 +1,8 @@ +<!DOCTYPE html> +<html> +<head> + <title>Window API Interactive Tests</title> +</head> +<body> +</body> +</html> diff --git a/chrome/test/data/extensions/platform_apps/window_api_interactive/test.js b/chrome/test/data/extensions/platform_apps/window_api_interactive/test.js new file mode 100644 index 0000000..ecff515 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/window_api_interactive/test.js @@ -0,0 +1,138 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var callbackPass = chrome.test.callbackPass; + +function testWindowGetsFocus(win) { + // If the window is already focused, we are done. + if (win.contentWindow.document.hasFocus()) { + chrome.test.assertTrue(win.contentWindow.document.hasFocus(), + "window has been focused"); + win.close(); + return; + } + + // Otherwise, we wait for the focus event. + win.contentWindow.onfocus = callbackPass(function() { + chrome.test.assertTrue(win.contentWindow.document.hasFocus(), + "window has been focused"); + win.close(); + }); +} + +function testWindowNeverGetsFocus(win) { + win.contentWindow.onfocus = function() { + chrome.test.assertFalse(win.contentWindow.document.hasFocus(), + "window should not be focused"); + win.close(); + }; + + if (win.contentWindow.document.hasFocus()) { + chrome.test.assertFalse(win.contentWindow.document.hasFocus(), + "window should not be focused"); + win.close(); + return; + }; + + if (win.contentWindow.document.readyState == 'complete') { + chrome.test.assertFalse(win.contentWindow.document.hasFocus(), + "window should not be focused"); + win.close(); + return; + } + + win.contentWindow.onload = callbackPass(function() { + chrome.test.assertFalse(win.contentWindow.document.hasFocus(), + "window should not be focused"); + win.close(); + }); +} + +function testCreate() { + chrome.test.runTests([ + function createUnfocusedWindow() { + chrome.app.window.create('test.html', { + bounds: { width: 200, height: 200 }, + focused: false + }, callbackPass(testWindowNeverGetsFocus)); + }, + function createTwiceUnfocused() { + chrome.app.window.create('test.html', { + id: 'createTwiceUnfocused', focused: false, + bounds: { width: 200, height: 200 } + }, callbackPass(function(win) { + win.contentWindow.onload = callbackPass(function() { + chrome.app.window.create('test.html', { + id: 'createTwiceUnfocused', focused: false, + bounds: { width: 200, height: 200 } + }, callbackPass(testWindowNeverGetsFocus)); + }); + })); + }, + function createFocusedWindow() { + chrome.app.window.create('test.html', { + bounds: { width: 200, height: 200 }, + focused: true + }, callbackPass(testWindowGetsFocus)); + }, + function createDefaultFocusStateWindow() { + chrome.app.window.create('test.html', { + bounds: { width: 200, height: 200 }, + }, callbackPass(testWindowGetsFocus)); + }, + function createTwiceFocusUnfocus() { + chrome.app.window.create('test.html', { + id: 'createTwiceFocusUnfocus', focused: true, + bounds: { width: 200, height: 200 } + }, callbackPass(function(win) { + win.contentWindow.onload = callbackPass(function() { + chrome.app.window.create('test.html', { + id: 'createTwiceFocusUnfocus', focused: false, + bounds: { width: 200, height: 200 } + }, callbackPass(testWindowGetsFocus)); + }); + })); + }, + function createTwiceUnfocusFocus() { + chrome.app.window.create('test.html', { + id: 'createTwiceUnfocusFocus', focused: false, + bounds: { width: 200, height: 200 } + }, callbackPass(function(win) { + win.contentWindow.onload = callbackPass(function() { + chrome.app.window.create('test.html', { + id: 'createTwiceUnfocusFocus', focused: true, + bounds: { width: 200, height: 200 } + }, callbackPass(function() { + // This test fails on Linux GTK, see http://crbug.com/325219 + // And none of those tests run on Linux Aura, see + // http://crbug.com/325142 + if (navigator.platform.indexOf('Linux') != 0) + testWindowGetsFocus(win); + })); + }); + })); + }, + function createUnfocusThenShow() { + chrome.app.window.create('test.html', { + id: 'createUnfocusThenShow', focused: false, + bounds: { width: 200, height: 200 } + }, callbackPass(function(win) { + win.contentWindow.onload = callbackPass(function() { + win.show(); + // This test fails on Linux GTK, see http://crbug.com/325219 + // And none of those tests run on Linux Aura, see + // http://crbug.com/325142 + if (navigator.platform.indexOf('Linux') != 0) + testWindowGetsFocus(win); + }); + })); + }, + ]); +} + +chrome.app.runtime.onLaunched.addListener(function() { + chrome.test.sendMessage('Launched', function(reply) { + window[reply](); + }); +}); |