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

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, 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 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 content::WebContents* web_contents =
220 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.
221 web_contentses[i].reset(web_contents);
222 browser()->tab_strip_model()->AppendWebContents(web_contents, true);
223 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.
224 web_contents);
225 content::WebContentsTester* web_contents_tester =
226 content::WebContentsTester::For(web_contents);
227 web_contents_tester->NavigateAndCommit(tab_urls[i]);
228 }
229
230 // Create the extension.
231 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.
232 ExtensionBuilder()
233 .SetManifest(
234 DictionaryBuilder()
235 .Set("name", "Testing Discarded Property")
236 .Set("version", "1.0")
237 .Set("manifest_version", 2)
238 .Set("permissions", ListBuilder().Append("tabs").Build())
239 .Build())
240 .Build();
241
242 // Get all non discarded tabs.
243 {
244 const char* kQueryInfo = "[{\"discarded\": false}]";
245 std::unique_ptr<base::ListValue> tabs_list_(
246 RunTabsQueryFunction(browser(), extension_.get(), kQueryInfo));
247 ASSERT_TRUE(tabs_list_);
248 ASSERT_EQ(2u, tabs_list_->GetSize());
249 }
250
251 // Get non-discarded tabs with google.com url (testing compound queries).
252 {
253 const char* kQueryInfo =
254 "[{\"discarded\": false, \"url\": \"*://www.google.com/*\"}]";
255 std::unique_ptr<base::ListValue> tabs_list_(
256 RunTabsQueryFunction(browser(), extension_.get(), kQueryInfo));
257 ASSERT_TRUE(tabs_list_);
258 ASSERT_EQ(1u, tabs_list_->GetSize());
259 }
260
261 // Query all discarded tabs.
262 {
263 const char* kQueryInfo = "[{\"discarded\": true}]";
264 std::unique_ptr<base::ListValue> tabs_list_(
265 RunTabsQueryFunction(browser(), extension_.get(), kQueryInfo));
266 ASSERT_TRUE(tabs_list_);
267 ASSERT_EQ(0u, tabs_list_->GetSize());
268 }
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.
269 }
270
212 } // namespace extensions 271 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698