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

Side by Side Diff: chrome/test/data/extensions/api_test/incognito/apis/background.html

Issue 8758008: Move another block 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 normalWindow, normalTab; 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this
3 var incognitoWindow, incognitoTab; 3 * source code is governed by a BSD-style license that can be found in the
4 4 * LICENSE file.
5 var pass = chrome.test.callbackPass; 5 -->
6 var fail = chrome.test.callbackFail; 6 <script src="background.js"></script>
7 var assertEq = chrome.test.assertEq;
8 var assertTrue = chrome.test.assertTrue;
9
10 chrome.test.getConfig(function(config) {
11 chrome.test.runTests([
12 function setupWindows() {
13 // The test harness should have set us up with 2 windows: 1 incognito
14 // and 1 regular. Verify that we can see both when we ask for it.
15 chrome.windows.getAll({populate: true}, pass(function(windows) {
16 assertEq(2, windows.length);
17
18 if (windows[0].incognito) {
19 incognitoWindow = windows[0];
20 normalWindow = windows[1];
21 } else {
22 normalWindow = windows[0];
23 incognitoWindow = windows[1];
24 }
25 normalTab = normalWindow.tabs[0];
26 incognitoTab = incognitoWindow.tabs[0];
27 assertTrue(!normalWindow.incognito);
28 assertTrue(incognitoWindow.incognito);
29 }));
30 },
31
32 // Tests that we can update an incognito tab and get the event for it.
33 function tabUpdate() {
34 var newUrl = "about:blank";
35
36 // Prepare the event listeners first.
37 var done = chrome.test.listenForever(chrome.tabs.onUpdated,
38 function(id, info, tab) {
39 if (id == incognitoTab.id) {
40 assertTrue(tab.incognito);
41 assertEq(newUrl, tab.url);
42 if (info.status == "complete")
43 done();
44 }
45 });
46
47 // Update our tabs.
48 chrome.tabs.update(incognitoTab.id, {"url": newUrl}, pass());
49 },
50
51 // Tests a sequence of tab API calls.
52 function tabNested() {
53 // Setup our listeners. We check that the events fire in order.
54 var eventCounter = 0;
55 chrome.test.listenOnce(chrome.tabs.onCreated, function(tab) {
56 assertEq(1, ++eventCounter);
57 assertEq(incognitoTab.windowId, tab.windowId);
58 assertTrue(tab.incognito);
59 });
60 chrome.test.listenOnce(chrome.tabs.onMoved, function(tabId) {
61 assertEq(2, ++eventCounter);
62 });
63 chrome.test.listenOnce(chrome.tabs.onRemoved, function(tabId) {
64 assertEq(3, ++eventCounter);
65 });
66
67 // Create, select, move, and close a tab in our incognito window.
68 chrome.tabs.create({windowId: incognitoTab.windowId},
69 pass(function(tab) {
70 chrome.tabs.move(tab.id, {index: 0},
71 pass(function(tab) {
72 assertEq(incognitoTab.incognito, tab.incognito);
73 chrome.tabs.remove(tab.id, pass());
74 }));
75 }));
76 },
77
78 // Tests content script injection to verify that the script can tell its
79 // in incongnito.
80 function contentScriptTestIncognito() {
81 assertTrue(!chrome.extension.inIncognitoContext);
82
83 var testUrl = "http://localhost:PORT/files/extensions/test_file.html"
84 .replace(/PORT/, config.testServer.port);
85
86 // Test that chrome.extension.inIncognitoTab is true for incognito tabs.
87 chrome.tabs.create({windowId: incognitoWindow.id, url: testUrl},
88 pass(function(tab) {
89 chrome.tabs.executeScript(tab.id,
90 {code: 'document.title = chrome.extension.inIncognitoContext'},
91 pass(function() {
92 assertEq(undefined, chrome.extension.lastError);
93 chrome.tabs.get(tab.id, pass(function(tab) {
94 assertEq("true", tab.title);
95 }));
96 }));
97 }));
98
99 // ... and false for normal tabs.
100 chrome.tabs.create({windowId: normalWindow.id, url: testUrl},
101 pass(function(tab) {
102 chrome.tabs.executeScript(tab.id,
103 {code: 'document.title = chrome.extension.inIncognitoContext'},
104 pass(function() {
105 assertEq(undefined, chrome.extension.lastError);
106 chrome.tabs.get(tab.id, pass(function(tab) {
107 assertEq("false", tab.title);
108 }));
109 }));
110 }));
111 },
112
113 // Tests that extensions can't move tabs between incognito and
114 // non-incognito windows.
115 function moveTabBetweenProfiles() {
116 var errorMsg = "Tabs can only be moved between " +
117 "windows in the same profile.";
118
119 // Create a tab in the non-incognito window...
120 chrome.tabs.create({windowId: normalWindow.id, url: 'about:blank'},
121 pass(function(tab) {
122 // ... and then try to move it to the incognito window.
123 chrome.tabs.move(tab.id,
124 {windowId: incognitoWindow.id, index: 0}, fail(errorMsg));
125 }));
126 }
127 ]);
128 });
129
130 </script>
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/idle/test.html ('k') | chrome/test/data/extensions/api_test/incognito/apis/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698