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

Unified Diff: chrome/browser/extensions/api/tabs/tabs_api_unittest.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_api_unittest.cc
diff --git a/chrome/browser/extensions/api/tabs/tabs_api_unittest.cc b/chrome/browser/extensions/api/tabs/tabs_api_unittest.cc
index f8edf1b93711c07c14c804347652f5ab19d5c6fb..39d1935b6df7b3404a70dde8c4bd0a0eb24cdf26 100644
--- a/chrome/browser/extensions/api/tabs/tabs_api_unittest.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_api_unittest.cc
@@ -209,4 +209,63 @@ TEST_F(TabsApiUnitTest, QueryWithHostPermission) {
}
}
+TEST_F(TabsApiUnitTest, QueryDiscarded) {
+ GURL tab_urls[] = {GURL("http://www.google.com"),
+ GURL("http://www.example.com")};
+
+ // Add web contentses to the browser.
+ std::unique_ptr<content::WebContents> web_contentses[arraysize(tab_urls)];
+ for (size_t i = 0; i < arraysize(tab_urls); ++i) {
+ content::WebContents* web_contents =
+ content::WebContentsTester::CreateTestWebContents(profile(), nullptr);
Devlin 2016/06/21 20:27:08 inline this, rather than assigning ownership and k
Anderson Silva 2016/06/27 18:21:53 Done.
+ web_contentses[i].reset(web_contents);
+ browser()->tab_strip_model()->AppendWebContents(web_contents, true);
+ EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
Devlin 2016/06/21 20:27:08 nit: switch the order here - expected, actual. Al
Anderson Silva 2016/06/27 18:21:53 Done.
+ web_contents);
+ content::WebContentsTester* web_contents_tester =
+ content::WebContentsTester::For(web_contents);
+ web_contents_tester->NavigateAndCommit(tab_urls[i]);
+ }
+
+ // Create the extension.
+ scoped_refptr<const Extension> extension_ =
Devlin 2016/06/21 20:27:08 the '_' suffix is used when it's a private member
Anderson Silva 2016/06/27 18:21:53 Done.
+ ExtensionBuilder()
+ .SetManifest(
+ DictionaryBuilder()
+ .Set("name", "Testing Discarded Property")
+ .Set("version", "1.0")
+ .Set("manifest_version", 2)
+ .Set("permissions", ListBuilder().Append("tabs").Build())
+ .Build())
+ .Build();
+
+ // Get all non discarded tabs.
+ {
+ const char* kQueryInfo = "[{\"discarded\": false}]";
+ std::unique_ptr<base::ListValue> tabs_list_(
+ RunTabsQueryFunction(browser(), extension_.get(), kQueryInfo));
+ ASSERT_TRUE(tabs_list_);
+ ASSERT_EQ(2u, tabs_list_->GetSize());
+ }
+
+ // Get non-discarded tabs with google.com url (testing compound queries).
+ {
+ const char* kQueryInfo =
+ "[{\"discarded\": false, \"url\": \"*://www.google.com/*\"}]";
+ std::unique_ptr<base::ListValue> tabs_list_(
+ RunTabsQueryFunction(browser(), extension_.get(), kQueryInfo));
+ ASSERT_TRUE(tabs_list_);
+ ASSERT_EQ(1u, tabs_list_->GetSize());
+ }
+
+ // Query all discarded tabs.
+ {
+ const char* kQueryInfo = "[{\"discarded\": true}]";
+ std::unique_ptr<base::ListValue> tabs_list_(
+ RunTabsQueryFunction(browser(), extension_.get(), kQueryInfo));
+ ASSERT_TRUE(tabs_list_);
+ ASSERT_EQ(0u, tabs_list_->GetSize());
+ }
Devlin 2016/06/21 20:27:08 It would be good to test the case of successfully
Anderson Silva 2016/06/27 18:21:53 Acknowledged.
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698