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

Side by Side Diff: chrome/test/data/extensions/api_test/tabs/basics/discarding.js

Issue 2205523002: AutoDiscardable property support on Chrome Extensions Tabs API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change javascript test Created 4 years, 4 months 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var testTab; 5 var testTab;
6 chrome.test.runTests([ 6 chrome.test.runTests([
7 7
8 function setupWindow() { 8 function setupWindow() {
9 var testTabId; 9 var testTabId;
10 10
11 createWindow(["about:blank", "chrome://newtab/"], {}, 11 createWindow(["about:blank", "chrome://newtab/"], {},
12 pass(function(winId, tabIds) { 12 pass(function(winId, tabIds) {
13 testTabId = tabIds[1]; 13 testTabId = tabIds[1];
14 })); 14 }));
15 15
16 waitForAllTabs(pass(function() { 16 waitForAllTabs(pass(function() {
17 queryForTab(testTabId, {}, pass(function(tab) { 17 queryForTab(testTabId, {}, pass(function(tab) {
18 testTab = tab; 18 testTab = tab;
19 })); 19 }));
20 })); 20 }));
21 }, 21 },
22 22
23 // Tests chrome.tabs.onUpdated for Discarded property.
23 function discard() { 24 function discard() {
24 // Initially tab isn't discarded. 25 // Initially tab isn't discarded.
25 assertFalse(testTab.discarded); 26 assertFalse(testTab.discarded);
26 27
27 var onUpdatedCompleted = chrome.test.listenForever( 28 var onUpdatedCompleted = chrome.test.listenForever(
28 chrome.tabs.onUpdated, 29 chrome.tabs.onUpdated,
29 function(tabId, changeInfo, tab) { 30 function(tabId, changeInfo, tab) {
30 if ('discarded' in changeInfo) { 31 if ('discarded' in changeInfo) {
31 // Make sure it's the right tab. 32 // Make sure it's the right tab.
32 assertEq(testTab.index, tab.index); 33 assertEq(testTab.index, tab.index);
(...skipping 30 matching lines...) Expand all
63 64
64 // Make sure the discarded state changed correctly. 65 // Make sure the discarded state changed correctly.
65 assertFalse(changeInfo.discarded); 66 assertFalse(changeInfo.discarded);
66 assertFalse(tab.discarded); 67 assertFalse(tab.discarded);
67 68
68 onUpdatedCompleted(); 69 onUpdatedCompleted();
69 } 70 }
70 }); 71 });
71 72
72 chrome.tabs.reload(testTab.id); 73 chrome.tabs.reload(testTab.id);
74 },
75
76 // Tests chrome.tabs.onUpdated for autoDiscardable property.
77 function setNonAutoDiscardable() {
78 // Initially the tab is auto-discardable.
79 assertTrue(testTab.autoDiscardable);
80
81 var onUpdatedCompleted = chrome.test.listenForever(
82 chrome.tabs.onUpdated,
83 function (tabId, changeInfo, tab) {
Devlin 2016/08/11 16:45:54 nit: no space after function
Anderson Silva 2016/08/11 17:26:57 Done.
84 if ('autoDiscardable' in changeInfo) {
85 // Make sure it's the right tab.
86 assertEq(testTab.id, tab.id);
87
88 // Make sure the auto-discardable state changed correctly.
89 assertFalse(changeInfo.autoDiscardable);
90 assertFalse(tab.autoDiscardable);
91
92 onUpdatedCompleted();
93 }
94 });
95
96 chrome.tabs.update(testTab.id, { autoDiscardable: false },
97 pass(function (tab) {
Devlin 2016/08/11 16:45:54 nit: no space after function
Anderson Silva 2016/08/11 17:26:57 Done.
98 assertFalse(tab.autoDiscardable);
99 testTab = tab;
100 }));
101 },
102
103 function resetAutoDiscardable() {
104 // Tab was set to non auto-discardable.
105 assertFalse(testTab.autoDiscardable);
106
107 var onUpdatedCompleted = chrome.test.listenForever(
108 chrome.tabs.onUpdated,
109 function (tabId, changeInfo, tab) {
Devlin 2016/08/11 16:45:54 ditto
Anderson Silva 2016/08/11 17:26:57 Done.
110 if ('autoDiscardable' in changeInfo) {
111 // Make sure it's the right tab.
112 assertEq(testTab.id, tab.id);
113
114 // Make sure the auto-discardable state changed correctly.
115 assertTrue(changeInfo.autoDiscardable);
116 assertTrue(tab.autoDiscardable);
117
118 onUpdatedCompleted();
119 }
120 });
121
122 chrome.tabs.update(testTab.id, { autoDiscardable: true },
123 pass(function (tab) {
124 assertTrue(tab.autoDiscardable);
125 }));
73 } 126 }
74 ]); 127 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698