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

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

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

Powered by Google App Engine
This is Rietveld 408576698