Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/tabs/basics/discarded.js |
| diff --git a/chrome/test/data/extensions/api_test/tabs/basics/discarded.js b/chrome/test/data/extensions/api_test/tabs/basics/discarded.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..436ac9fc77f779d53fc680f000764a19c6c92caf |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/api_test/tabs/basics/discarded.js |
| @@ -0,0 +1,74 @@ |
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
|
Devlin
2016/07/29 16:01:09
ditto
Anderson Silva
2016/07/29 19:05:59
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +var testTab; |
| +chrome.test.runTests([ |
| + |
| + function setupWindow() { |
| + var testTabId; |
| + |
| + createWindow(["about:blank", "chrome://newtab/"], {}, |
| + pass(function (winId, tabIds) { |
| + testTabId = tabIds[1]; |
| + })); |
| + |
| + waitForAllTabs(pass(function () { |
| + queryForTab(testTabId, {}, pass(function (tab) { |
| + testTab = tab; |
| + })); |
| + })); |
| + }, |
| + |
| + function discard() { |
| + // Initially tab isn't discarded. |
| + assertFalse(testTab.discarded); |
| + |
| + var onUpdatedCompleted = chrome.test.listenForever( |
| + chrome.tabs.onUpdated, |
| + function (tabId, changeInfo, tab) { |
| + if ('discarded' in changeInfo) { |
| + // Make sure it's the right tab. |
| + assertEq(testTab.index, tab.index); |
| + assertEq(testTab.windowId, tab.windowId); |
| + |
| + // Make sure the discarded state changed correctly. |
| + assertTrue(changeInfo.discarded); |
| + assertTrue(tab.discarded); |
| + |
| + onUpdatedCompleted(); |
| + } |
| + } |
| + ); |
| + |
| + // Discard and update testTab (the id changes after a tab is discarded). |
|
Devlin
2016/07/29 16:01:09
The id changes? That's a bit yucky. We normally
Anderson Silva
2016/07/29 19:05:59
Yeah, you're right, this is weird. But it isn't re
Devlin
2016/07/29 20:17:33
Cool, thanks! I don't want to block this issue on
|
| + chrome.tabs.discard(testTab.id, pass(function (tab) { |
| + assertTrue(tab.discarded); |
| + testTab = tab; |
| + })); |
| + }, |
| + |
| + function reload() { |
| + // Tab is already discarded. |
| + assertTrue(testTab.discarded); |
| + |
| + var onUpdatedCompleted = chrome.test.listenForever( |
| + chrome.tabs.onUpdated, |
| + function (tabId, changeInfo, tab) { |
| + if ('discarded' in changeInfo) { |
| + // Make sure it's the right tab. |
| + assertEq(testTab.index, tab.index); |
| + assertEq(testTab.windowId, tab.windowId); |
| + |
| + // Make sure the discarded state changed correctly. |
| + assertFalse(changeInfo.discarded); |
| + assertFalse(tab.discarded); |
| + |
| + onUpdatedCompleted(); |
| + } |
| + } |
| + ); |
| + |
| + chrome.tabs.reload(testTab.id); |
| + } |
| +]); |