Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: chrome/test/data/extensions/api_test/window_open/focus/test.html

Issue 8775046: Convert another batch of extension tests to manifest_version 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 <script> 1 <!--
2 var expectFocusChange; 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this
3 var createdWinId; 3 * source code is governed by a BSD-style license that can be found in the
4 var focusedWinId; 4 * LICENSE file.
5 var listenDoneCallback; 5 -->
6 6 <script src="test.js"></script>
7 function resetTest(focused) {
8 expectFocusChange = focused;
9 createdWinId = chrome.windows.WINDOW_ID_NONE;
10 focusedWinId = chrome.windows.WINDOW_ID_NONE;
11 listenDoneCallback = chrome.test.listenForever(
12 chrome.windows.onFocusChanged, onFocusChanged);
13 }
14
15 function onFocusChanged(changedWinId) {
16 if (chrome.windows.WINDOW_ID_NONE != changedWinId) {
17 focusedWinId = changedWinId;
18 if (expectFocusChange)
19 maybeFocusedTestDone();
20 }
21 }
22
23 function checkFocused(win) {
24 createdWinId = win.id;
25 maybeFocusedTestDone();
26 }
27
28 // Test is done when focus has changed to the created window.
29 function maybeFocusedTestDone() {
30 if (focusedWinId != chrome.windows.WINDOW_ID_NONE &&
31 createdWinId != chrome.windows.WINDOW_ID_NONE) {
32 listenDoneCallback();
33 chrome.test.assertEq(focusedWinId, createdWinId);
34 }
35 }
36
37 function checkUnfocused(win) {
38 createdWinId = win.id;
39 setTimeout(chrome.test.callbackPass(function () {
40 listenDoneCallback();
41 chrome.test.assertTrue(focusedWinId != createdWinId);
42 }), 500);
43 }
44
45 chrome.test.runTests([
46 function defaultHasFocus() {
47 resetTest(true);
48 chrome.windows.create(
49 { 'url': 'blank.html' },
50 chrome.test.callbackPass(checkFocused)
51 );
52 },
53 function defaultHasFocusPopup() {
54 resetTest(true);
55 chrome.windows.create(
56 { 'url': 'blank.html', 'type': 'popup' },
57 chrome.test.callbackPass(checkFocused)
58 );
59 },
60 function defaultUnfocusedPanel() {
61 resetTest(false);
62 chrome.windows.create(
63 { 'url': 'blank.html', 'type': 'panel' },
64 chrome.test.callbackPass(checkUnfocused)
65 );
66 },
67 function withFocus() {
68 resetTest(true);
69 chrome.windows.create(
70 { 'url': 'blank.html', 'focused': true },
71 chrome.test.callbackPass(checkFocused)
72 );
73 },
74 function withFocusPopup() {
75 resetTest(true);
76 chrome.windows.create(
77 { 'url': 'blank.html', 'focused': true, 'type': 'popup' },
78 chrome.test.callbackPass(checkFocused)
79 );
80 },
81 function withFocusPanel() {
82 resetTest(true);
83 chrome.windows.create(
84 { 'url': 'blank.html', 'focused': true, 'type': 'panel' },
85 chrome.test.callbackPass(checkFocused)
86 );
87 },
88 function withoutFocus() {
89 resetTest(false);
90 chrome.windows.create(
91 { 'url': 'blank.html', 'focused': false },
92 chrome.test.callbackPass(checkUnfocused)
93 );
94 },
95 function withoutFocusPopup() {
96 resetTest(false);
97 chrome.windows.create(
98 { 'url': 'blank.html', 'focused': false, 'type': 'popup' },
99 chrome.test.callbackPass(checkUnfocused)
100 );
101 },
102 function withoutFocusPanel() {
103 resetTest(false);
104 chrome.windows.create(
105 { 'url': 'blank.html', 'focused': false, 'type': 'panel' },
106 chrome.test.callbackPass(checkUnfocused)
107 );
108 }
109 ]);
110 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698