Commit 94afe44e authored by andersoncss's avatar andersoncss Committed by Commit bot

Adding Discarded property support for onUpdate function.

BUG=621070

Review-Url: https://codereview.chromium.org/2142413003
Cr-Commit-Position: refs/heads/master@{#408822}
parent f50e159e
......@@ -31,6 +31,7 @@ const char kOldWindowIdKey[] = "oldWindowId";
const char kOpenerTabIdKey[] = "openerTabId";
const char kPinnedKey[] = "pinned";
const char kAudibleKey[] = "audible";
const char kDiscardedKey[] = "discarded";
const char kMutedKey[] = "muted";
const char kMutedInfoKey[] = "mutedInfo";
const char kQualityKey[] = "quality";
......
......@@ -36,6 +36,7 @@ extern const char kOldWindowIdKey[];
extern const char kOpenerTabIdKey[];
extern const char kPinnedKey[];
extern const char kAudibleKey[];
extern const char kDiscardedKey[];
extern const char kMutedKey[];
extern const char kMutedInfoKey[];
extern const char kQualityKey[];
......
......@@ -11,10 +11,12 @@
#include "base/memory/ptr_util.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
#include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
#include "chrome/browser/extensions/api/tabs/windows_event_router.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/memory/tab_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
......@@ -135,11 +137,14 @@ void TabsEventRouter::TabEntry::WebContentsDestroyed() {
TabsEventRouter::TabsEventRouter(Profile* profile)
: profile_(profile),
favicon_scoped_observer_(this),
browser_tab_strip_tracker_(this, this, this) {
browser_tab_strip_tracker_(this, this, this),
tab_manager_scoped_observer_(this) {
DCHECK(!profile->IsOffTheRecord());
browser_tab_strip_tracker_.Init(
BrowserTabStripTracker::InitWith::ALL_BROWERS);
tab_manager_scoped_observer_.Add(g_browser_process->GetTabManager());
}
TabsEventRouter::~TabsEventRouter() {
......@@ -552,4 +557,16 @@ void TabsEventRouter::OnFaviconUpdated(
}
}
void TabsEventRouter::OnDiscardedStateChange(WebContents* contents,
bool is_discarded) {
TabStripModel* tab_strip = nullptr;
int tab_index = -1;
if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) {
std::set<std::string> changed_property_names;
changed_property_names.insert(tabs_constants::kDiscardedKey);
DispatchTabUpdatedEvent(contents, std::move(changed_property_names));
}
}
} // namespace extensions
......@@ -12,6 +12,8 @@
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "chrome/browser/extensions/api/tabs/tabs_api.h"
#include "chrome/browser/memory/tab_manager.h"
#include "chrome/browser/memory/tab_manager_observer.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/browser_tab_strip_tracker.h"
#include "chrome/browser/ui/browser_tab_strip_tracker_delegate.h"
......@@ -39,7 +41,8 @@ class TabsEventRouter : public TabStripModelObserver,
public BrowserTabStripTrackerDelegate,
public chrome::BrowserListObserver,
public favicon::FaviconDriverObserver,
public zoom::ZoomObserver {
public zoom::ZoomObserver,
public memory::TabManagerObserver {
public:
explicit TabsEventRouter(Profile* profile);
~TabsEventRouter() override;
......@@ -88,6 +91,10 @@ class TabsEventRouter : public TabStripModelObserver,
bool icon_url_changed,
const gfx::Image& image) override;
// memory::TabManagerObserver:
void OnDiscardedStateChange(content::WebContents* contents,
bool is_discarded) override;
private:
// "Synthetic" event. Called from TabInsertedAt if new tab is detected.
void TabCreatedAt(content::WebContents* contents, int index, bool active);
......@@ -196,6 +203,9 @@ class TabsEventRouter : public TabStripModelObserver,
BrowserTabStripTracker browser_tab_strip_tracker_;
ScopedObserver<memory::TabManager, TabsEventRouter>
tab_manager_scoped_observer_;
DISALLOW_COPY_AND_ASSIGN(TabsEventRouter);
};
......
......@@ -277,6 +277,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_GetViewsOfCreatedWindow) {
<< message_;
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DiscardedState) {
ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "discarded.html")) << message_;
}
// Adding a new test? Awesome. But API tests are the old hotness. The new
// hotness is extension_function_test_utils. See tabs_test.cc for an example.
// We are trying to phase out many uses of API tests as they tend to be flaky.
......@@ -981,6 +981,11 @@
"optional": true,
"description": "The tab's new audible state."
},
"discarded": {
"type": "boolean",
"optional": true,
"description": "The tab's new discarded state."
},
"mutedInfo": {
"$ref": "MutedInfo",
"optional": true,
......
<!--
* Copyright 2016 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<script src="tabs_util.js"></script>
<script src="discarded.js"></script>
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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();
}
});
// TODO(georgesak): Remove tab update when http://crbug.com/632839 is
// resolved.
// Discard and update testTab (the id changes after a tab is discarded).
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);
}
]);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment