| 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 1bc1eac1ae248a56c861da8de03788acb98ff51c..4722f4983e79c2f6cb8618df30d10b99aa544d79 100644
|
| --- a/chrome/browser/extensions/api/tabs/tabs_test.cc
|
| +++ b/chrome/browser/extensions/api/tabs/tabs_test.cc
|
| @@ -37,6 +37,7 @@
|
| #include "chrome/test/base/ui_test_utils.h"
|
| #include "components/prefs/pref_service.h"
|
| #include "content/public/browser/browser_context.h"
|
| +#include "content/public/browser/notification_service.h"
|
| #include "content/public/browser/storage_partition.h"
|
| #include "content/public/common/page_zoom.h"
|
| #include "content/public/common/url_constants.h"
|
| @@ -1439,6 +1440,74 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardedProperty) {
|
| }
|
| }
|
|
|
| +// Tests chrome.tabs.discard(tabId).
|
| +IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardWithId) {
|
| + // Create an aditional tab.
|
| + ui_test_utils::NavigateToURLWithDisposition(
|
| + browser(), GURL(url::kAboutBlankURL), NEW_BACKGROUND_TAB,
|
| + ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
|
| + content::WebContents* web_contents =
|
| + browser()->tab_strip_model()->GetWebContentsAt(1);
|
| +
|
| + // Set up the function with an extension.
|
| + scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension();
|
| + scoped_refptr<TabsDiscardFunction> discard(new TabsDiscardFunction());
|
| + discard->set_extension(extension.get());
|
| +
|
| + // Run function passing the tab id as argument.
|
| + int tab_id = ExtensionTabUtil::GetTabId(web_contents);
|
| + std::unique_ptr<base::DictionaryValue> result(
|
| + utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
|
| + discard.get(), base::StringPrintf("[%u]", tab_id), browser())));
|
| +
|
| + // Confirms that TabManager sees the tab as discarded.
|
| + memory::TabManager* tab_manager = g_browser_process->GetTabManager();
|
| + ASSERT_TRUE(tab_manager);
|
| + web_contents = browser()->tab_strip_model()->GetWebContentsAt(1);
|
| + EXPECT_TRUE(tab_manager->IsTabDiscarded(web_contents));
|
| +
|
| + // Make sure the returned tab is the one discarded and
|
| + // its discarded state is correct.
|
| + tab_id = ExtensionTabUtil::GetTabId(web_contents);
|
| + EXPECT_EQ(tab_id, api_test_utils::GetInteger(result.get(), "id"));
|
| + EXPECT_TRUE(api_test_utils::GetBoolean(result.get(), "discarded"));
|
| +}
|
| +
|
| +// Tests chrome.tabs.discard().
|
| +IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardWithoutId) {
|
| + // Create an aditional tab.
|
| + ui_test_utils::NavigateToURLWithDisposition(
|
| + browser(), GURL(url::kAboutBlankURL), NEW_BACKGROUND_TAB,
|
| + ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
|
| + content::WebContents* web_contents =
|
| + browser()->tab_strip_model()->GetWebContentsAt(1);
|
| +
|
| + // Set up the function with an extension.
|
| + scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension();
|
| + scoped_refptr<TabsDiscardFunction> discard(new TabsDiscardFunction());
|
| + discard->set_extension(extension.get());
|
| +
|
| + // Disable protection time to discard the tab without passing id.
|
| + memory::TabManager* tab_manager = g_browser_process->GetTabManager();
|
| + ASSERT_TRUE(tab_manager);
|
| + tab_manager->set_minimum_protection_time_for_tests(
|
| + base::TimeDelta::FromSeconds(0));
|
| +
|
| + // Run without passing an id.
|
| + std::unique_ptr<base::DictionaryValue> result(utils::ToDictionary(
|
| + utils::RunFunctionAndReturnSingleResult(discard.get(), "[]", browser())));
|
| +
|
| + // Confirms that TabManager sees the tab as discarded.
|
| + web_contents = browser()->tab_strip_model()->GetWebContentsAt(1);
|
| + EXPECT_TRUE(tab_manager->IsTabDiscarded(web_contents));
|
| +
|
| + // Make sure the returned tab is the one discarded and
|
| + // its discarded state is correct.
|
| + EXPECT_EQ(ExtensionTabUtil::GetTabId(web_contents),
|
| + api_test_utils::GetInteger(result.get(), "id"));
|
| + EXPECT_TRUE(api_test_utils::GetBoolean(result.get(), "discarded"));
|
| +}
|
| +
|
| // Tester class for the tabs.zoom* api functions.
|
| class ExtensionTabsZoomTest : public ExtensionTabsTest {
|
| public:
|
|
|