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

Unified Diff: chrome/browser/extensions/api/tabs/tabs_test.cc

Issue 2067033002: Discarded property on chrome.tabs.Tab and chrome.tabs.query() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/tabs/tabs_test.cc
diff --git a/chrome/browser/extensions/api/tabs/tabs_test.cc b/chrome/browser/extensions/api/tabs/tabs_test.cc
index 4de45b0b11723a1dbeb1d053fe890798a886c8da..2f8938f3ff86ad6e1687f7104e66daf6c6d529ff 100644
--- a/chrome/browser/extensions/api/tabs/tabs_test.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_test.cc
@@ -17,6 +17,7 @@
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/apps/app_browsertest_util.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/devtools/devtools_window_testing.h"
#include "chrome/browser/extensions/api/tabs/tabs_api.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
@@ -24,6 +25,7 @@
#include "chrome/browser/extensions/extension_function_test_utils.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/window_controller.h"
+#include "chrome/browser/memory/tab_manager.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
@@ -634,6 +636,133 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryAllTabsWithDevTools) {
DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
}
+IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryDiscardedProperty) {
+ ASSERT_TRUE(g_browser_process && g_browser_process->GetTabManager());
+ memory::TabManager* tab_manager = g_browser_process->GetTabManager();
+
+ // Create two new tabs.
+ content::OpenURLParams params(GURL(url::kAboutBlankURL), content::Referrer(),
+ NEW_BACKGROUND_TAB, ui::PAGE_TRANSITION_LINK,
+ false);
+ content::WebContents* web_contents_a = browser()->OpenURL(params);
+ content::WebContents* web_contents_b = browser()->OpenURL(params);
+
+ // Get non-discarded tabs.
+ {
+ const char* kQueryInfo = "[{\"discarded\": false}]";
+ scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction();
+ function->set_extension(test_util::CreateEmptyExtension().get());
+ std::unique_ptr<base::ListValue> result(
+ utils::ToList(utils::RunFunctionAndReturnSingleResult(
+ function.get(), kQueryInfo, browser())));
+
+ // We should have the initial plus two new non-discarded tabs.
+ EXPECT_EQ(3u, result.get()->GetSize());
+ }
+
+ // Get discarded tabs.
+ {
+ const char* kQueryInfo = "[{\"discarded\": true}]";
+ scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction();
+ function->set_extension(test_util::CreateEmptyExtension().get());
+ std::unique_ptr<base::ListValue> result(
+ utils::ToList(utils::RunFunctionAndReturnSingleResult(
+ function.get(), kQueryInfo, browser())));
+
+ // We should have zero discarded tabs.
+ EXPECT_EQ(0u, result.get()->GetSize());
+ }
+
+ // Discards one tab.
+ EXPECT_TRUE(
+ tab_manager->DiscardTabById(reinterpret_cast<int64_t>(web_contents_a)));
+
+ // Get non-discarded tabs after discarding one tab.
+ {
+ const char* kQueryInfo = "[{\"discarded\": false}]";
+ scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction();
+ function->set_extension(test_util::CreateEmptyExtension().get());
+ std::unique_ptr<base::ListValue> result(
+ utils::ToList(utils::RunFunctionAndReturnSingleResult(
+ function.get(), kQueryInfo, browser())));
+
+ // Now we should have two non-discarded tabs after discarding one.
+ EXPECT_EQ(2u, result.get()->GetSize());
+ }
+
+ // Get discarded tabs after discarding one tab.
+ {
+ const char* kQueryInfo = "[{\"discarded\": true}]";
+ scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction();
+ function->set_extension(test_util::CreateEmptyExtension().get());
+ std::unique_ptr<base::ListValue> result(
+ utils::ToList(utils::RunFunctionAndReturnSingleResult(
+ function.get(), kQueryInfo, browser())));
+
+ // Only one tab was discarded.
+ EXPECT_EQ(1u, result.get()->GetSize());
+ }
+
+ // Discards the other created tab.
+ EXPECT_TRUE(
+ tab_manager->DiscardTabById(reinterpret_cast<int64_t>(web_contents_b)));
+
+ // Get non-discarded tabs after discarding all created tabs.
+ {
+ const char* kQueryInfo = "[{\"discarded\": false}]";
+ scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction();
+ function->set_extension(test_util::CreateEmptyExtension().get());
+ std::unique_ptr<base::ListValue> result(
+ utils::ToList(utils::RunFunctionAndReturnSingleResult(
+ function.get(), kQueryInfo, browser())));
+
+ // Now only the initial tab wasn't discarded.
+ EXPECT_EQ(1u, result.get()->GetSize());
+ }
+
+ // Get discarded tabs after discarding all created tabs.
+ {
+ const char* kQueryInfo = "[{\"discarded\": true}]";
+ scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction();
+ function->set_extension(test_util::CreateEmptyExtension().get());
+ std::unique_ptr<base::ListValue> result(
+ utils::ToList(utils::RunFunctionAndReturnSingleResult(
+ function.get(), kQueryInfo, browser())));
+
+ // Both created tabs were discarded.
+ EXPECT_EQ(2u, result.get()->GetSize());
+ }
+
+ auto tsm = browser()->tab_strip_model();
+ tsm->ActivateTabAt(1, false);
+
+ // Get non-discarded tabs after activating a discarded tab.
+ {
+ const char* kQueryInfo = "[{\"discarded\": false}]";
+ scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction();
+ function->set_extension(test_util::CreateEmptyExtension().get());
+ std::unique_ptr<base::ListValue> result(
+ utils::ToList(utils::RunFunctionAndReturnSingleResult(
+ function.get(), kQueryInfo, browser())));
+
+ // Should have one more non-discarded.
+ EXPECT_EQ(2u, result.get()->GetSize());
+ }
+
+ // Get discarded tabs after activating a discarded tab.
+ {
+ const char* kQueryInfo = "[{\"discarded\": true}]";
+ scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction();
+ function->set_extension(test_util::CreateEmptyExtension().get());
+ std::unique_ptr<base::ListValue> result(
+ utils::ToList(utils::RunFunctionAndReturnSingleResult(
+ function.get(), kQueryInfo, browser())));
+
+ // Should have only one discarded.
+ EXPECT_EQ(1u, result.get()->GetSize());
+ }
+}
+
IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) {
// Test creates new popup window, closes it right away and then tries to open
// a new tab in it. Tab should not be opened in the popup window, but in a
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_api_unittest.cc ('k') | chrome/browser/extensions/extension_tab_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698