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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/extensions/api/tabs/tabs_api.h" 6 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
7 #include "chrome/browser/extensions/extension_function_test_utils.h" 7 #include "chrome/browser/extensions/extension_function_test_utils.h"
8 #include "chrome/browser/extensions/extension_service_test_base.h" 8 #include "chrome/browser/extensions/extension_service_test_base.h"
9 #include "chrome/browser/extensions/extension_tab_util.h" 9 #include "chrome/browser/extensions/extension_tab_util.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 int first_tab_id = -1; 202 int first_tab_id = -1;
203 ASSERT_TRUE(first_tab_info->GetInteger("id", &first_tab_id)); 203 ASSERT_TRUE(first_tab_info->GetInteger("id", &first_tab_id));
204 EXPECT_TRUE(ContainsValue(expected_tabs_ids, first_tab_id)); 204 EXPECT_TRUE(ContainsValue(expected_tabs_ids, first_tab_id));
205 205
206 int third_tab_id = -1; 206 int third_tab_id = -1;
207 ASSERT_TRUE(third_tab_info->GetInteger("id", &third_tab_id)); 207 ASSERT_TRUE(third_tab_info->GetInteger("id", &third_tab_id));
208 EXPECT_TRUE(ContainsValue(expected_tabs_ids, third_tab_id)); 208 EXPECT_TRUE(ContainsValue(expected_tabs_ids, third_tab_id));
209 } 209 }
210 } 210 }
211 211
212 TEST_F(TabsApiUnitTest, QueryDiscarded) {
213 GURL tab_urls[] = {GURL("http://www.google.com"),
214 GURL("http://www.example.com")};
215
216 // Add web contentses to the browser.
217 std::unique_ptr<content::WebContents> web_contentses[arraysize(tab_urls)];
218 for (size_t i = 0; i < arraysize(tab_urls); ++i) {
219 web_contentses[i].reset(
220 content::WebContentsTester::CreateTestWebContents(profile(), nullptr));
221 browser()->tab_strip_model()->AppendWebContents(web_contentses[i].get(),
222 true);
223 content::WebContentsTester* web_contents_tester =
224 content::WebContentsTester::For(web_contentses[i].get());
225 web_contents_tester->NavigateAndCommit(tab_urls[i]);
226 }
227
228 // Create the extension.
229 scoped_refptr<const Extension> extension =
230 ExtensionBuilder()
231 .SetManifest(
232 DictionaryBuilder()
233 .Set("name", "Testing Discarded Property")
234 .Set("version", "1.0")
235 .Set("manifest_version", 2)
236 .Set("permissions", ListBuilder().Append("tabs").Build())
237 .Build())
238 .Build();
239
240 // Get all non discarded tabs.
241 {
242 const char* kQueryInfo = "[{\"discarded\": false}]";
243 std::unique_ptr<base::ListValue> tabs_list(
244 RunTabsQueryFunction(browser(), extension.get(), kQueryInfo));
245 ASSERT_TRUE(tabs_list);
246 ASSERT_EQ(2u, tabs_list->GetSize());
247 }
248
249 // Get non-discarded tabs with google.com url (testing compound queries).
250 {
251 const char* kQueryInfo =
252 "[{\"discarded\": false, \"url\": \"*://www.google.com/*\"}]";
253 std::unique_ptr<base::ListValue> tabs_list(
254 RunTabsQueryFunction(browser(), extension.get(), kQueryInfo));
255 ASSERT_TRUE(tabs_list);
256 ASSERT_EQ(1u, tabs_list->GetSize());
257 }
258
259 // Query all discarded tabs.
260 {
261 const char* kQueryInfo = "[{\"discarded\": true}]";
262 std::unique_ptr<base::ListValue> tabs_list(
263 RunTabsQueryFunction(browser(), extension.get(), kQueryInfo));
264 ASSERT_TRUE(tabs_list);
265 ASSERT_EQ(0u, tabs_list->GetSize());
266 }
267 }
268
212 } // namespace extensions 269 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_api.cc ('k') | chrome/browser/extensions/api/tabs/tabs_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698